// File: /workspace/github_cpp_makefile_star2_O1/richardposner[P]BioNetFit2/src/code/Swarm.cpp
// Function: Swarm::recvMigrationSetDE(unsigned int, std::map<unsigned int, std::vector<std::vector<double, std::allocator<double>>, std::allocator<std::vector<double, std::allocator<double>>>>, std::less<unsigned int>, std::allocator<std::pair<unsigned int const, std::vector<std::vector<double, std::allocator<double>>, std::allocator<std::vector<double, std::allocator<double>>>>>>>&)
void Swarm::recvMigrationSetDE(unsigned int island, map<unsigned int, vector<vector<double> > > &migrationSets) {
	// If we have any sets to receive..
	if (migrationSets.find(island) != migrationSets.end() && migrationSets.at(island).size()) {

		if (options.verbosity >= 3) {
			cout << "Receiving " << migrationSets.at(island).size() << " migration sets for island " << island << endl;
		}

		// Create a list of particles from the receiving island that will
		// receive the migration set
		vector<unsigned int> particlesToRecv;
		int parID = 0;

		//Raquel: if the user provided constraints, then use the ranks calculated from the fit values and constraints combined in order to select the best particle
		if(options.constraints_.size()>0){
			//Raquel: this will receive the particles with the worst fit to migrate
			for (vector<pair<int,float> >::reverse_iterator fitIt = subParRankFinal.rbegin(); fitIt != subParRankFinal.rend(); ++fitIt) {
				if (options.verbosity >= 3) {
					cout << fitIt->first << endl;
				}
				parID = fcalcParID(fitIt->first, options.models.size());

				if (particleToIsland_[parID] == island) {
					particlesToRecv.push_back(parID);
				}
			}

		}else{

			for (map<double, unsigned int>::reverse_iterator fitIt = particleBestFitsByFit_.rbegin(); fitIt != particleBestFitsByFit_.rend(); ++fitIt) {
				if (options.verbosity >= 3) {
					cout << fitIt->second << endl;
				}
				if (particleToIsland_[fitIt->second] == island) {
					particlesToRecv.push_back(fitIt->second);
				}
			}


		}




		// Iterates through the list of receiving particles
		auto recvIt = particlesToRecv.begin();
		//cout << 999 << endl;
		// For each migration set destined for this island
		unsigned int replacementCounter = 0;
		int subParID = 0;

		for (auto migrationSet = migrationSets[island].begin(); migrationSet != migrationSets[island].end();) {
			if (options.verbosity >= 3) {
				cout << "Replacing " << migrationSet->size() << " params for particle " << *recvIt << " with fit value of " << particleBestFits_.at(*recvIt) << endl;
			}
			vector<string> paramStr;
			unsigned int i = 0;
			// For each parameter in the migration set
			for (auto param = migrationSet->begin(); param != migrationSet->end(); ++param) {
				// Insert parameter to the currentParamSets tracker
				if (options.verbosity >= 3) {
					cout << "param: " << *param << endl;
				}
				particleCurrParamSets_.at(*recvIt)[i] = *param;
				paramStr.push_back(toString(*param));
				++i;
			}
			// Send the parameters to the particle
			//Raquel updating to support subparticles
			for(unsigned int mid = 0; mid < options.models.size(); mid++){

				subParID = fcalcsubParID(*recvIt, mid, options.models.size());
				swarmComm->sendToSwarm(0, subParID, SEND_FINAL_PARAMS_TO_PARTICLE, false, paramStr);

			}
			//swarmComm->sendToSwarm(0, *recvIt, SEND_FINAL_PARAMS_TO_PARTICLE, false, paramStr);
			// Next migration set, choose a new receiver from the island
			++recvIt;
			++replacementCounter;
			migrationSet = migrationSets[island].erase(migrationSet);

			if (replacementCounter >= options.swarmSize / options.numIslands) {
				break;
			}
		}
	}
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x98, %rsp
movq %rdx, %r12
movq %rdi, %r14
movl %esi, 0xc(%rsp)
movq 0x10(%rdx), %rdx
leaq 0x8(%r12), %rax
movq %rax, %rcx
testq %rdx, %rdx
je 0x9d11e
movq %rax, %rcx
xorl %edi, %edi
cmpl %esi, 0x20(%rdx)
setb %dil
cmovaeq %rdx, %rcx
movq 0x10(%rdx,%rdi,8), %rdx
testq %rdx, %rdx
jne 0x9d107
movq %rax, %rdx
cmpq %rax, %rcx
je 0x9d130
cmpl %esi, 0x20(%rcx)
cmovaq %rax, %rcx
movq %rcx, %rdx
cmpq %rax, %rdx
je 0x9d684
leaq 0xc(%rsp), %rsi
movq %r12, %rdi
callq 0xa8a44
movq 0x8(%rax), %rcx
cmpq (%rax), %rcx
je 0x9d684
cmpl $0x3, 0x1614(%r14)
jb 0x9d1f9
movq 0xd8e28(%rip), %rbx     # 0x175f90
leaq 0x63559(%rip), %rsi     # 0x1006c8
movl $0xa, %edx
movq %rbx, %rdi
callq 0x22ab0
leaq 0xc(%rsp), %r15
movq %r12, %rdi
movq %r15, %rsi
callq 0xa8a44
movq 0x8(%rax), %rcx
subq (%rax), %rcx
sarq $0x3, %rcx
movabsq $-0x5555555555555555, %rsi # imm = 0xAAAAAAAAAAAAAAAB
imulq %rcx, %rsi
movq %rbx, %rdi
callq 0x22650
movq %rax, %rbx
leaq 0x6351c(%rip), %rsi     # 0x1006d3
movl $0x1b, %edx
movq %rax, %rdi
callq 0x22ab0
movl (%r15), %esi
movq %rbx, %rdi
callq 0x22650
movq %rax, %rbx
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x22940
movsbl %al, %esi
movq %rbx, %rdi
callq 0x22050
movq %rax, %rdi
callq 0x22660
movq %r12, 0x38(%rsp)
xorps %xmm0, %xmm0
movaps %xmm0, 0x10(%rsp)
movq $0x0, 0x20(%rsp)
cmpq $0x0, 0x1608(%r14)
je 0x9d2ec
movq 0x18f8(%r14), %rbp
cmpq 0x18f0(%r14), %rbp
je 0x9d3ae
movq 0xd8d58(%rip), %rbx     # 0x175f90
leaq 0x10(%rsp), %r15
leaq 0x40(%rsp), %r12
cmpl $0x3, 0x1614(%r14)
jb 0x9d281
movl -0x8(%rbp), %esi
movq %rbx, %rdi
callq 0x231e0
movq %rax, %r13
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r13, %rdi
movl $0xa, %esi
callq 0x22940
movsbl %al, %esi
movq %r13, %rdi
callq 0x22050
movq %rax, %rdi
callq 0x22660
movl -0x8(%rbp), %edi
movq 0x15c8(%r14), %rsi
subq 0x15c0(%r14), %rsi
shrq $0x3, %rsi
callq 0xbf2b8
movslq %eax, %rcx
movq 0x1d20(%r14), %rdx
movl (%rdx,%rcx,4), %ecx
cmpl 0xc(%rsp), %ecx
jne 0x9d2d6
movl %eax, 0x40(%rsp)
movq 0x18(%rsp), %rsi
cmpq 0x20(%rsp), %rsi
je 0x9d2cb
movl %eax, (%rsi)
addq $0x4, %rsi
movq %rsi, 0x18(%rsp)
jmp 0x9d2d6
movq %r15, %rdi
movq %r12, %rdx
callq 0xaf698
addq $-0x8, %rbp
cmpq 0x18f0(%r14), %rbp
jne 0x9d242
jmp 0x9d3ae
leaq 0x1ab8(%r14), %rbx
cmpq 0x1ac8(%r14), %rbx
je 0x9d3ae
movq 0xd8c89(%rip), %r15     # 0x175f90
leaq 0x10(%rsp), %r12
cmpl $0x3, 0x1614(%r14)
jb 0x9d353
movq %rbx, %rdi
callq 0x22a10
movl 0x28(%rax), %esi
movq %r15, %rdi
callq 0x22650
movq %rax, %r13
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r13, %rdi
movl $0xa, %esi
callq 0x22940
movsbl %al, %esi
movq %r13, %rdi
callq 0x22050
movq %rax, %rdi
callq 0x22660
movq %rbx, %rdi
callq 0x22a10
movl 0x28(%rax), %ecx
movq 0x1d20(%r14), %rdx
movl (%rdx,%rcx,4), %edx
cmpl 0xc(%rsp), %edx
jne 0x9d396
movq 0x18(%rsp), %rsi
cmpq 0x20(%rsp), %rsi
je 0x9d387
movl %ecx, (%rsi)
addq $0x4, %rsi
movq %rsi, 0x18(%rsp)
jmp 0x9d396
addq $0x28, %rax
movq %r12, %rdi
movq %rax, %rdx
callq 0x6b5ce
movq %rbx, %rdi
callq 0x22a10
movq %rax, %rbx
cmpq 0x1ac8(%r14), %rax
jne 0x9d30c
movq 0x10(%rsp), %r15
leaq 0xc(%rsp), %rsi
movq 0x38(%rsp), %rbx
movq %rbx, %rdi
callq 0xa89b4
movq (%rax), %rbp
leaq 0x1a20(%r14), %rax
movq %rax, 0x80(%rsp)
leaq 0x1400(%r14), %rax
movq %rax, 0x88(%rsp)
xorl %r12d, %r12d
movq %rbx, %rdi
leaq 0xc(%rsp), %rsi
callq 0xa89b4
cmpq 0x8(%rax), %rbp
je 0x9d66d
movl %r12d, 0x34(%rsp)
cmpl $0x3, 0x1614(%r14)
jb 0x9d4c2
movl $0xa, %edx
movq 0xd8b71(%rip), %rdi     # 0x175f90
leaq 0x632c9(%rip), %rsi     # 0x1006ef
callq 0x22ab0
movq 0x8(%rbp), %rsi
subq (%rbp), %rsi
sarq $0x3, %rsi
movq 0xd8b52(%rip), %rdi     # 0x175f90
callq 0x22650
movq %rax, %r13
movl $0x15, %edx
movq %rax, %rdi
leaq 0x61de3(%rip), %rsi     # 0xff238
callq 0x22ab0
movl (%r15), %esi
movq %r13, %rdi
callq 0x22650
movq %rax, %r13
movl $0x13, %edx
movq %rax, %rdi
leaq 0x63283(%rip), %rsi     # 0x1006fa
callq 0x22ab0
movq 0x80(%rsp), %rdi
movq %r15, %rsi
callq 0xa83c8
movsd (%rax), %xmm0
movq %r13, %rdi
callq 0x23060
movq %rax, %r13
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r13, %rdi
movl $0xa, %esi
callq 0x22940
movsbl %al, %esi
movq %r13, %rdi
callq 0x22050
movq %rax, %rdi
callq 0x22660
xorps %xmm0, %xmm0
movaps %xmm0, 0x60(%rsp)
movq $0x0, 0x70(%rsp)
movq (%rbp), %r12
cmpq 0x8(%rbp), %r12
je 0x9d5bf
xorl %ebx, %ebx
cmpl $0x3, 0x1614(%r14)
jb 0x9d541
movl $0x7, %edx
movq 0xd8a97(%rip), %rdi     # 0x175f90
leaq 0x5bee7(%rip), %rsi     # 0xf93e7
callq 0x22ab0
movsd (%r12), %xmm0
movq 0xd8a7e(%rip), %rdi     # 0x175f90
callq 0x23060
movq %rax, %r13
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r13, %rdi
movl $0xa, %esi
callq 0x22940
movsbl %al, %esi
movq %r13, %rdi
callq 0x22050
movq %rax, %rdi
callq 0x22660
movsd (%r12), %xmm0
movsd %xmm0, 0x90(%rsp)
movq 0x88(%rsp), %rdi
movq %r15, %rsi
callq 0xa837c
movl %ebx, %ecx
movq (%rax), %rax
movsd 0x90(%rsp), %xmm0
movsd %xmm0, (%rax,%rcx,8)
movsd (%r12), %xmm0
leaq 0x40(%rsp), %r13
movq %r13, %rdi
callq 0xc0446
leaq 0x60(%rsp), %rdi
movq %r13, %rsi
callq 0x6a77e
movq 0x40(%rsp), %rdi
leaq 0x50(%rsp), %rax
cmpq %rax, %rdi
je 0x9d5af
movq 0x50(%rsp), %rsi
incq %rsi
callq 0x229c0
incl %ebx
addq $0x8, %r12
cmpq 0x8(%rbp), %r12
jne 0x9d4e3
movq 0x15c8(%r14), %rdx
subq 0x15c0(%r14), %rdx
movq 0x38(%rsp), %rbx
movl 0x34(%rsp), %r12d
je 0x9d625
sarq $0x3, %rdx
xorl %r13d, %r13d
movl (%r15), %edi
movl %r13d, %esi
callq 0xbf2a3
movq (%r14), %rdi
movl $0xffffffff, (%rsp)     # imm = 0xFFFFFFFF
xorl %esi, %esi
movl %eax, %edx
movl $0x15, %ecx
xorl %r8d, %r8d
leaq 0x60(%rsp), %r9
callq 0x6bfb0
incl %r13d
movq 0x15c8(%r14), %rdx
subq 0x15c0(%r14), %rdx
sarq $0x3, %rdx
cmpq %r13, %rdx
ja 0x9d5e0
movq %rbx, %rdi
leaq 0xc(%rsp), %rsi
callq 0xa89b4
movq %rax, %rdi
movq %rbp, %rsi
callq 0xbcaf2
movq %rax, %rbp
addq $0x4, %r15
incl %r12d
movl 0x1620(%r14), %eax
xorl %edx, %edx
divl 0x16fc(%r14)
movl %eax, %r13d
leaq 0x60(%rsp), %rdi
callq 0x31a9e
cmpl %r13d, %r12d
jb 0x9d3e9
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
je 0x9d684
movq 0x20(%rsp), %rsi
subq %rdi, %rsi
callq 0x229c0
addq $0x98, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x9d6a2
jmp 0x9d6a2
jmp 0x9d6a2
jmp 0x9d6a2
jmp 0x9d6cc
jmp 0x9d6a2
movq %rax, %rbx
jmp 0x9d6d9
movq %rax, %rbx
movq 0x40(%rsp), %rdi
leaq 0x50(%rsp), %rax
cmpq %rax, %rdi
je 0x9d6cf
movq 0x50(%rsp), %rsi
incq %rsi
callq 0x229c0
jmp 0x9d6cf
jmp 0x9d6cc
jmp 0x9d6cc
movq %rax, %rbx
leaq 0x60(%rsp), %rdi
callq 0x31a9e
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
je 0x9d6f0
movq 0x20(%rsp), %rsi
subq %rdi, %rsi
callq 0x229c0
movq %rbx, %rdi
callq 0x23240