// File: /workspace/github_cpp_makefile_star2_O2/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
leaq 0xc(%rsp), %rax
movl %esi, (%rax)
movq %rdx, %rdi
movq %rax, %rsi
callq 0x9c9a4
leaq 0x8(%r12), %rcx
cmpq %rcx, %rax
je 0x7f5bb
leaq 0xc(%rsp), %rsi
movq %r12, %rdi
callq 0x86840
movq 0x8(%rax), %rcx
cmpq (%rax), %rcx
je 0x7f5bb
cmpl $0x3, 0x1614(%r14)
jb 0x7f27a
movq 0xe6d7c(%rip), %rdi     # 0x165f98
leaq 0x5f675(%rip), %rsi     # 0xde898
callq 0x289f0
movq %rax, %rbx
leaq 0xc(%rsp), %r15
movq %r12, %rdi
movq %r15, %rsi
callq 0x86840
movq 0x8(%rax), %rcx
subq (%rax), %rcx
pushq $0x18
popq %rsi
movq %rcx, %rax
cqto
idivq %rsi
movq %rbx, %rdi
movq %rax, %rsi
callq 0x286e0
leaq 0x5f644(%rip), %rsi     # 0xde8a3
movq %rax, %rdi
callq 0x289f0
movl (%r15), %esi
movq %rax, %rdi
callq 0x286e0
movq %rax, %rdi
callq 0x284a0
movq %r12, 0x10(%rsp)
andq $0x0, 0x30(%rsp)
xorps %xmm0, %xmm0
movaps %xmm0, 0x20(%rsp)
cmpq $0x0, 0x1608(%r14)
je 0x7f321
movq 0x18f8(%r14), %r13
movq 0xe6cef(%rip), %rbx     # 0x165f98
leaq 0x20(%rsp), %r15
leaq 0x78(%rsp), %r12
cmpq 0x18f0(%r14), %r13
je 0x7f399
cmpl $0x3, 0x1614(%r14)
jb 0x7f2de
movl -0x8(%r13), %esi
movq %rbx, %rdi
callq 0x29290
movq %rax, %rdi
callq 0x284a0
movl -0x8(%r13), %edi
movq 0x15c8(%r14), %rsi
subq 0x15c0(%r14), %rsi
shrq $0x3, %rsi
callq 0x9ec1e
addq $-0x8, %r13
movslq %eax, %rcx
movq 0x1d20(%r14), %rdx
movl (%rdx,%rcx,4), %ecx
cmpl 0xc(%rsp), %ecx
jne 0x7f2b3
movl %eax, 0x78(%rsp)
movq %r15, %rdi
movq %r12, %rsi
callq 0x8ed06
jmp 0x7f2b3
leaq 0x1ab8(%r14), %r12
movq 0xe6c69(%rip), %rbx     # 0x165f98
leaq 0x20(%rsp), %r15
cmpq 0x1ac8(%r14), %r12
je 0x7f399
cmpl $0x3, 0x1614(%r14)
jb 0x7f362
movq %r12, %rdi
callq 0x28aa0
movl 0x28(%rax), %esi
movq %rbx, %rdi
callq 0x286e0
movq %rax, %rdi
callq 0x284a0
movq %r12, %rdi
callq 0x28aa0
movl 0x28(%rax), %ecx
movq 0x1d20(%r14), %rdx
movl (%rdx,%rcx,4), %ecx
cmpl 0xc(%rsp), %ecx
jne 0x7f38c
addq $0x28, %rax
movq %r15, %rdi
movq %rax, %rsi
callq 0x5a59e
movq %r12, %rdi
callq 0x28aa0
movq %rax, %r12
jmp 0x7f334
movq 0x20(%rsp), %r15
leaq 0xc(%rsp), %rsi
movq 0x10(%rsp), %rdi
callq 0x867c6
movq (%rax), %rbp
leaq 0x1a20(%r14), %rax
movq %rax, 0x60(%rsp)
leaq 0x1400(%r14), %rax
movq %rax, 0x68(%rsp)
xorl %r12d, %r12d
leaq 0x78(%rsp), %rbx
movl %r12d, 0x1c(%rsp)
movq 0x10(%rsp), %rdi
leaq 0xc(%rsp), %rsi
callq 0x867c6
cmpq 0x8(%rax), %rbp
je 0x7f5b1
cmpl $0x3, 0x1614(%r14)
jb 0x7f46c
movq 0xe6b99(%rip), %rdi     # 0x165f98
leaq 0x5f4b9(%rip), %rsi     # 0xde8bf
callq 0x289f0
movq 0x8(%rbp), %rsi
subq (%rbp), %rsi
sarq $0x3, %rsi
movq %rax, %rdi
callq 0x286e0
movq %rax, %rdi
leaq 0x5dfdf(%rip), %rsi     # 0xdd408
callq 0x289f0
movl (%r15), %esi
movq %rax, %rdi
callq 0x286e0
movq %rax, %rdi
leaq 0x5f487(%rip), %rsi     # 0xde8ca
callq 0x289f0
movq %rax, %r13
movq 0x60(%rsp), %rdi
movq %r15, %rsi
callq 0x8626a
movsd (%rax), %xmm0
movq %r13, %rdi
callq 0x290f0
movq %rax, %rdi
callq 0x284a0
andq $0x0, 0x50(%rsp)
xorps %xmm0, %xmm0
movaps %xmm0, 0x40(%rsp)
movq (%rbp), %r13
xorl %r12d, %r12d
cmpq 0x8(%rbp), %r13
je 0x7f517
cmpl $0x3, 0x1614(%r14)
jb 0x7f4be
movq 0xe6afc(%rip), %rdi     # 0x165f98
leaq 0x57e44(%rip), %rsi     # 0xd72e7
callq 0x289f0
movsd (%r13), %xmm0
movq %rax, %rdi
callq 0x290f0
movq %rax, %rdi
callq 0x284a0
movsd (%r13), %xmm0
movsd %xmm0, 0x70(%rsp)
movq 0x68(%rsp), %rdi
movq %r15, %rsi
callq 0x861e4
movl %r12d, %ecx
movq (%rax), %rax
movsd 0x70(%rsp), %xmm0
movsd %xmm0, (%rax,%rcx,8)
movsd (%r13), %xmm0
movq %rbx, %rdi
callq 0x9f57b
leaq 0x40(%rsp), %rdi
movq %rbx, %rsi
callq 0x5ec8c
movq %rbx, %rdi
callq 0x295a0
incl %r12d
addq $0x8, %r13
jmp 0x7f481
xorl %r13d, %r13d
movq 0x10(%rsp), %r12
movl %r13d, %eax
movq 0x15c8(%r14), %rdx
subq 0x15c0(%r14), %rdx
sarq $0x3, %rdx
cmpq %rax, %rdx
jbe 0x7f564
movl (%r15), %edi
movl %r13d, %esi
callq 0x9ec09
movq (%r14), %rdi
orl $-0x1, (%rsp)
xorl %esi, %esi
movl %eax, %edx
pushq $0x15
popq %rcx
xorl %r8d, %r8d
leaq 0x40(%rsp), %r9
callq 0x600c8
incl %r13d
jmp 0x7f51f
movq %r12, %rdi
leaq 0xc(%rsp), %rsi
callq 0x867c6
movl 0x1c(%rsp), %r12d
movq %rax, %rdi
movq %rbp, %rsi
callq 0x86878
movq %rax, %rbp
addq $0x4, %r15
incl %r12d
movl 0x1620(%r14), %eax
xorl %edx, %edx
divl 0x16fc(%r14)
movl %eax, %r13d
leaq 0x40(%rsp), %rdi
callq 0x3355a
cmpl %r13d, %r12d
jb 0x7f3d0
leaq 0x20(%rsp), %rdi
callq 0x5b268
addq $0x98, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x7f5d9
jmp 0x7f5d9
jmp 0x7f5d9
jmp 0x7f5d9
jmp 0x7f5f1
jmp 0x7f5d9
movq %rax, %rbx
jmp 0x7f5fe
jmp 0x7f5f1
movq %rax, %rbx
leaq 0x78(%rsp), %rdi
callq 0x295a0
jmp 0x7f5f4
jmp 0x7f5f1
movq %rax, %rbx
leaq 0x40(%rsp), %rdi
callq 0x3355a
leaq 0x20(%rsp), %rdi
callq 0x5b268
movq %rbx, %rdi
callq 0x292f0