// File: /workspace/github_cpp_makefile_star2_O3/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
movl %esi, 0xc(%rsp)
movq 0x10(%rdx), %rax
testq %rax, %rax
je 0x9cbdd
movq %rdx, %r12
movq %rdi, %r14
addq $0x8, %rdx
movq %rdx, %rcx
xorl %edi, %edi
cmpl %esi, 0x20(%rax)
setb %dil
cmovaeq %rax, %rcx
movq 0x10(%rax,%rdi,8), %rax
testq %rax, %rax
jne 0x9c669
cmpq %rdx, %rcx
je 0x9cbdd
cmpl %esi, 0x20(%rcx)
ja 0x9cbdd
leaq 0xc(%rsp), %rsi
movq %r12, %rdi
callq 0xa8114
movq 0x8(%rax), %rcx
cmpq (%rax), %rcx
je 0x9cbdd
cmpl $0x3, 0x1614(%r14)
jb 0x9c752
movq 0xd98e7(%rip), %rbx     # 0x175fa8
leaq 0x63fe7(%rip), %rsi     # 0x1006af
movl $0xa, %edx
movq %rbx, %rdi
callq 0x22ab0
leaq 0xc(%rsp), %r15
movq %r12, %rdi
movq %r15, %rsi
callq 0xa8114
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 0x63faa(%rip), %rsi     # 0x1006ba
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 0x9c845
movq 0x18f8(%r14), %rbp
cmpq 0x18f0(%r14), %rbp
je 0x9c907
movq 0xd9817(%rip), %rbx     # 0x175fa8
leaq 0x10(%rsp), %r15
leaq 0x40(%rsp), %r12
cmpl $0x3, 0x1614(%r14)
jb 0x9c7da
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 0xbe99e
movslq %eax, %rcx
movq 0x1d20(%r14), %rdx
movl (%rdx,%rcx,4), %ecx
cmpl 0xc(%rsp), %ecx
jne 0x9c82f
movl %eax, 0x40(%rsp)
movq 0x18(%rsp), %rsi
cmpq 0x20(%rsp), %rsi
je 0x9c824
movl %eax, (%rsi)
addq $0x4, %rsi
movq %rsi, 0x18(%rsp)
jmp 0x9c82f
movq %r15, %rdi
movq %r12, %rdx
callq 0xaeef8
addq $-0x8, %rbp
cmpq 0x18f0(%r14), %rbp
jne 0x9c79b
jmp 0x9c907
leaq 0x1ab8(%r14), %rbx
cmpq 0x1ac8(%r14), %rbx
je 0x9c907
movq 0xd9748(%rip), %r15     # 0x175fa8
leaq 0x10(%rsp), %r12
cmpl $0x3, 0x1614(%r14)
jb 0x9c8ac
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 0x9c8ef
movq 0x18(%rsp), %rsi
cmpq 0x20(%rsp), %rsi
je 0x9c8e0
movl %ecx, (%rsi)
addq $0x4, %rsi
movq %rsi, 0x18(%rsp)
jmp 0x9c8ef
addq $0x28, %rax
movq %r12, %rdi
movq %rax, %rdx
callq 0x6b0da
movq %rbx, %rdi
callq 0x22a10
movq %rax, %rbx
cmpq 0x1ac8(%r14), %rax
jne 0x9c865
movq 0x10(%rsp), %r15
leaq 0xc(%rsp), %rsi
movq 0x38(%rsp), %rbx
movq %rbx, %rdi
callq 0xa8082
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 0xa8082
cmpq 0x8(%rax), %rbp
je 0x9cbc6
movl %r12d, 0x34(%rsp)
cmpl $0x3, 0x1614(%r14)
jb 0x9ca1b
movl $0xa, %edx
movq 0xd9630(%rip), %rdi     # 0x175fa8
leaq 0x63d57(%rip), %rsi     # 0x1006d6
callq 0x22ab0
movq 0x8(%rbp), %rsi
subq (%rbp), %rsi
sarq $0x3, %rsi
movq 0xd9611(%rip), %rdi     # 0x175fa8
callq 0x22650
movq %rax, %r13
movl $0x15, %edx
movq %rax, %rdi
leaq 0x628fa(%rip), %rsi     # 0xff2a8
callq 0x22ab0
movl (%r15), %esi
movq %r13, %rdi
callq 0x22650
movq %rax, %r13
movl $0x13, %edx
movq %rax, %rdi
leaq 0x63d11(%rip), %rsi     # 0x1006e1
callq 0x22ab0
movq 0x80(%rsp), %rdi
movq %r15, %rsi
callq 0xa7a8c
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 0x9cb18
xorl %ebx, %ebx
cmpl $0x3, 0x1614(%r14)
jb 0x9ca9a
movl $0x7, %edx
movq 0xd9556(%rip), %rdi     # 0x175fa8
leaq 0x5c96e(%rip), %rsi     # 0xf93c7
callq 0x22ab0
movsd (%r12), %xmm0
movq 0xd953d(%rip), %rdi     # 0x175fa8
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 0xa7a46
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 0xbfad7
leaq 0x60(%rsp), %rdi
movq %r13, %rsi
callq 0x6a2a2
movq 0x40(%rsp), %rdi
leaq 0x50(%rsp), %rax
cmpq %rax, %rdi
je 0x9cb08
movq 0x50(%rsp), %rsi
incq %rsi
callq 0x229c0
incl %ebx
addq $0x8, %r12
cmpq 0x8(%rbp), %r12
jne 0x9ca3c
movq 0x15c8(%r14), %rdx
subq 0x15c0(%r14), %rdx
movq 0x38(%rsp), %rbx
movl 0x34(%rsp), %r12d
je 0x9cb7e
sarq $0x3, %rdx
xorl %r13d, %r13d
movl (%r15), %edi
movl %r13d, %esi
callq 0xbe989
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 0x6bac2
incl %r13d
movq 0x15c8(%r14), %rdx
subq 0x15c0(%r14), %rdx
sarq $0x3, %rdx
cmpq %r13, %rdx
ja 0x9cb39
movq %rbx, %rdi
leaq 0xc(%rsp), %rsi
callq 0xa8082
movq %rax, %rdi
movq %rbp, %rsi
callq 0xbc222
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 0x31a0a
cmpl %r13d, %r12d
jb 0x9c942
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
je 0x9cbdd
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 0x9cbfb
jmp 0x9cbfb
jmp 0x9cbfb
jmp 0x9cbfb
jmp 0x9cc25
jmp 0x9cbfb
movq %rax, %rbx
jmp 0x9cc32
movq %rax, %rbx
movq 0x40(%rsp), %rdi
leaq 0x50(%rsp), %rax
cmpq %rax, %rdi
je 0x9cc28
movq 0x50(%rsp), %rsi
incq %rsi
callq 0x229c0
jmp 0x9cc28
jmp 0x9cc25
jmp 0x9cc25
movq %rax, %rbx
leaq 0x60(%rsp), %rdi
callq 0x31a0a
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
je 0x9cc49
movq 0x20(%rsp), %rsi
subq %rdi, %rsi
callq 0x229c0
movq %rbx, %rdi
callq 0x23240
nop