// File: 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
movq %rsp, %rbp
subq $0x230, %rsp            # imm = 0x230
movq %rdi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
movq %rdx, -0x18(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x110(%rbp)
movq -0x18(%rbp), %rdi
leaq -0xc(%rbp), %rsi
callq 0x123fd0
movq %rax, -0x20(%rbp)
movq -0x18(%rbp), %rdi
callq 0x124000
movq %rax, -0x28(%rbp)
leaq -0x20(%rbp), %rdi
leaq -0x28(%rbp), %rsi
callq 0x123fa0
movb %al, %cl
xorl %eax, %eax
testb $0x1, %cl
movb %al, -0x105(%rbp)
jne 0x10fc1d
jmp 0x10fc3f
movq -0x18(%rbp), %rdi
leaq -0xc(%rbp), %rsi
callq 0x124030
movq %rax, %rdi
callq 0xb25e0
cmpq $0x0, %rax
setne %al
movb %al, -0x105(%rbp)
movb -0x105(%rbp), %al
testb $0x1, %al
jne 0x10fc4e
jmp 0x1104ef
movq -0x110(%rbp), %rax
cmpl $0x3, 0x1614(%rax)
jb 0x10fcc5
movq 0x1c52eb(%rip), %rdi    # 0x2d4f50
leaq 0xd363b(%rip), %rsi     # 0x1e32a7
callq 0x2ff50
movq %rax, -0x118(%rbp)
movq -0x18(%rbp), %rdi
leaq -0xc(%rbp), %rsi
callq 0x124030
movq %rax, %rdi
callq 0xb25e0
movq -0x118(%rbp), %rdi
movq %rax, %rsi
callq 0x30cf0
movq %rax, %rdi
leaq 0xd360c(%rip), %rsi     # 0x1e32b2
callq 0x2ff50
movq %rax, %rdi
movl -0xc(%rbp), %esi
callq 0x30640
movq %rax, %rdi
movq 0x1c5308(%rip), %rsi    # 0x2d4fc8
callq 0x30c10
leaq -0x40(%rbp), %rdi
callq 0xb2010
movq -0x110(%rbp), %rdi
movl $0x0, -0x44(%rbp)
addq $0x14c0, %rdi           # imm = 0x14C0
addq $0x120, %rdi            # imm = 0x120
callq 0x123030
cmpq $0x0, %rax
jbe 0x10fe5b
movq -0x110(%rbp), %rsi
addq $0x18f0, %rsi           # imm = 0x18F0
leaq -0x50(%rbp), %rdi
callq 0x1240d0
movq -0x110(%rbp), %rsi
addq $0x18f0, %rsi           # imm = 0x18F0
leaq -0x58(%rbp), %rdi
movq %rdi, -0x128(%rbp)
callq 0x124150
movq -0x128(%rbp), %rsi
leaq -0x50(%rbp), %rdi
callq 0x124120
movb %al, -0x119(%rbp)
jmp 0x10fd46
movb -0x119(%rbp), %al
testb $0x1, %al
jne 0x10fd55
jmp 0x10fe56
movq -0x110(%rbp), %rax
cmpl $0x3, 0x1614(%rax)
jb 0x10fdbd
leaq -0x50(%rbp), %rdi
callq 0x1241a0
movq %rax, -0x130(%rbp)
jmp 0x10fd77
movq -0x130(%rbp), %rax
movl (%rax), %esi
movq 0x1c51c9(%rip), %rdi    # 0x2d4f50
callq 0x2f800
movq %rax, -0x138(%rbp)
jmp 0x10fd95
movq -0x138(%rbp), %rdi
movq 0x1c5225(%rip), %rsi    # 0x2d4fc8
callq 0x30c10
jmp 0x10fdaa
jmp 0x10fdbd
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x60(%rbp)
movl %eax, -0x64(%rbp)
jmp 0x1104e4
leaq -0x50(%rbp), %rdi
callq 0x1241a0
movq %rax, -0x140(%rbp)
jmp 0x10fdcf
movq -0x110(%rbp), %rdi
movq -0x140(%rbp), %rax
movl (%rax), %eax
movl %eax, -0x148(%rbp)
addq $0x15c0, %rdi           # imm = 0x15C0
callq 0x45170
movl -0x148(%rbp), %edi
movl %eax, %esi
callq 0x17d3f0
movl %eax, -0x144(%rbp)
jmp 0x10fe06
movq -0x110(%rbp), %rdi
movl -0x144(%rbp), %eax
movl %eax, -0x44(%rbp)
addq $0x1d20, %rdi           # imm = 0x1D20
movslq -0x44(%rbp), %rsi
callq 0xccc10
movl (%rax), %eax
cmpl -0xc(%rbp), %eax
jne 0x10fe44
movl -0x44(%rbp), %eax
movl %eax, -0x68(%rbp)
leaq -0x40(%rbp), %rdi
leaq -0x68(%rbp), %rsi
callq 0x122310
jmp 0x10fe42
jmp 0x10fe44
jmp 0x10fe46
leaq -0x50(%rbp), %rdi
callq 0x1241e0
jmp 0x10fe51
jmp 0x10fd10
jmp 0x10ff92
movq -0x110(%rbp), %rsi
addq $0x1ab0, %rsi           # imm = 0x1AB0
leaq -0x70(%rbp), %rdi
callq 0x1239e0
movq -0x110(%rbp), %rsi
addq $0x1ab0, %rsi           # imm = 0x1AB0
leaq -0x78(%rbp), %rdi
movq %rdi, -0x158(%rbp)
callq 0x123a40
movq -0x158(%rbp), %rsi
leaq -0x70(%rbp), %rdi
callq 0x123a10
movb %al, -0x149(%rbp)
jmp 0x10fea8
movb -0x149(%rbp), %al
testb $0x1, %al
jne 0x10feb7
jmp 0x10ff90
movq -0x110(%rbp), %rax
cmpl $0x3, 0x1614(%rax)
jb 0x10ff0f
leaq -0x70(%rbp), %rdi
callq 0x123a70
movq %rax, -0x160(%rbp)
jmp 0x10fed9
movq -0x160(%rbp), %rax
movl 0x8(%rax), %esi
movq 0x1c5066(%rip), %rdi    # 0x2d4f50
callq 0x30640
movq %rax, -0x168(%rbp)
jmp 0x10fef8
movq -0x168(%rbp), %rdi
movq 0x1c50c2(%rip), %rsi    # 0x2d4fc8
callq 0x30c10
jmp 0x10ff0d
jmp 0x10ff0f
movq -0x110(%rbp), %rax
addq $0x1d20, %rax           # imm = 0x1D20
movq %rax, -0x178(%rbp)
leaq -0x70(%rbp), %rdi
callq 0x123a70
movq %rax, -0x170(%rbp)
jmp 0x10ff35
movq -0x178(%rbp), %rdi
movq -0x170(%rbp), %rax
movl 0x8(%rax), %eax
movl %eax, %esi
callq 0xccc10
movl (%rax), %eax
cmpl -0xc(%rbp), %eax
jne 0x10ff7e
leaq -0x70(%rbp), %rdi
callq 0x123a70
movq %rax, -0x180(%rbp)
jmp 0x10ff66
movq -0x180(%rbp), %rsi
addq $0x8, %rsi
leaq -0x40(%rbp), %rdi
callq 0xb4640
jmp 0x10ff7c
jmp 0x10ff7e
jmp 0x10ff80
leaq -0x70(%rbp), %rdi
callq 0x123ab0
jmp 0x10ff8b
jmp 0x10fe72
jmp 0x10ff92
leaq -0x40(%rbp), %rdi
callq 0xcc840
movq %rax, -0x80(%rbp)
movl $0x0, -0x84(%rbp)
movl $0x0, -0x88(%rbp)
movq -0x18(%rbp), %rdi
leaq -0xc(%rbp), %rsi
callq 0x123e30
movq %rax, -0x188(%rbp)
jmp 0x10ffc9
movq -0x188(%rbp), %rdi
callq 0xbf930
movq %rax, -0x90(%rbp)
movq -0x18(%rbp), %rdi
leaq -0xc(%rbp), %rsi
callq 0x123e30
movq %rax, -0x190(%rbp)
jmp 0x10fff2
movq -0x190(%rbp), %rdi
callq 0xbf660
movq %rax, -0x98(%rbp)
leaq -0x90(%rbp), %rdi
leaq -0x98(%rbp), %rsi
callq 0x124210
testb $0x1, %al
jne 0x110021
jmp 0x1104d9
movq -0x110(%rbp), %rax
cmpl $0x3, 0x1614(%rax)
jb 0x110141
movq 0x1c4f14(%rip), %rdi    # 0x2d4f50
leaq 0xd328b(%rip), %rsi     # 0x1e32ce
callq 0x2ff50
movq %rax, -0x198(%rbp)
jmp 0x110051
leaq -0x90(%rbp), %rdi
callq 0x124250
movq %rax, %rdi
callq 0xb25c0
movq -0x198(%rbp), %rdi
movq %rax, %rsi
callq 0x30cf0
movq %rax, -0x1a0(%rbp)
jmp 0x11007d
movq -0x1a0(%rbp), %rdi
leaq 0xd1ced(%rip), %rsi     # 0x1e1d78
callq 0x2ff50
movq %rax, -0x1a8(%rbp)
jmp 0x110099
leaq -0x80(%rbp), %rdi
callq 0xd0d10
movq -0x1a8(%rbp), %rdi
movl (%rax), %esi
callq 0x30640
movq %rax, -0x1b0(%rbp)
jmp 0x1100b9
movq -0x1b0(%rbp), %rdi
leaq 0xd3212(%rip), %rsi     # 0x1e32d9
callq 0x2ff50
movq %rax, -0x1b8(%rbp)
jmp 0x1100d5
movq -0x110(%rbp), %rax
addq $0x1a20, %rax           # imm = 0x1A20
movq %rax, -0x1c8(%rbp)
leaq -0x80(%rbp), %rdi
callq 0xd0d10
movq -0x1c8(%rbp), %rdi
movq %rax, %rsi
callq 0x1226a0
movq %rax, -0x1c0(%rbp)
jmp 0x11010a
movq -0x1b8(%rbp), %rdi
movq -0x1c0(%rbp), %rax
movsd (%rax), %xmm0
callq 0x30710
movq %rax, -0x1d0(%rbp)
jmp 0x11012a
movq -0x1d0(%rbp), %rdi
movq 0x1c4e90(%rip), %rsi    # 0x2d4fc8
callq 0x30c10
jmp 0x11013f
jmp 0x110141
leaq -0xb0(%rbp), %rdi
callq 0x448b0
movl $0x0, -0xb4(%rbp)
leaq -0x90(%rbp), %rdi
callq 0x124250
movq %rax, %rdi
callq 0xb2ea0
movq %rax, -0xc0(%rbp)
leaq -0x90(%rbp), %rdi
callq 0x124250
movq %rax, %rdi
callq 0xbdfd0
movq %rax, -0xc8(%rbp)
leaq -0xc0(%rbp), %rdi
leaq -0xc8(%rbp), %rsi
callq 0x122510
testb $0x1, %al
jne 0x1101a9
jmp 0x11030e
movq -0x110(%rbp), %rax
cmpl $0x3, 0x1614(%rax)
jb 0x110222
movq 0x1c4d90(%rip), %rdi    # 0x2d4f50
leaq 0xcba7b(%rip), %rsi     # 0x1dbc42
callq 0x2ff50
movq %rax, -0x1d8(%rbp)
jmp 0x1101d5
leaq -0xc0(%rbp), %rdi
callq 0xb2ed0
movq -0x1d8(%rbp), %rdi
movsd (%rax), %xmm0
callq 0x30710
movq %rax, -0x1e0(%rbp)
jmp 0x1101fa
movq -0x1e0(%rbp), %rdi
movq 0x1c4dc0(%rip), %rsi    # 0x2d4fc8
callq 0x30c10
jmp 0x11020f
jmp 0x110222
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x60(%rbp)
movl %eax, -0x64(%rbp)
jmp 0x1104cb
leaq -0xc0(%rbp), %rdi
callq 0xb2ed0
movq %rax, %rcx
movq -0x110(%rbp), %rax
movsd (%rcx), %xmm0
movsd %xmm0, -0x1f8(%rbp)
addq $0x1400, %rax           # imm = 0x1400
movq %rax, -0x1f0(%rbp)
leaq -0x80(%rbp), %rdi
callq 0xd0d10
movq -0x1f0(%rbp), %rdi
movq %rax, %rsi
callq 0x122470
movq %rax, -0x1e8(%rbp)
jmp 0x110272
movq -0x1e8(%rbp), %rdi
movl -0xb4(%rbp), %eax
movl %eax, %esi
callq 0xb2610
movsd -0x1f8(%rbp), %xmm0
movsd %xmm0, (%rax)
leaq -0xc0(%rbp), %rdi
callq 0xb2ed0
movsd (%rax), %xmm0
leaq -0xe8(%rbp), %rdi
callq 0x17e490
jmp 0x1102b0
leaq -0xb0(%rbp), %rdi
leaq -0xe8(%rbp), %rsi
callq 0xb39c0
jmp 0x1102c5
leaq -0xe8(%rbp), %rdi
callq 0x311e8
movl -0xb4(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xb4(%rbp)
leaq -0xc0(%rbp), %rdi
callq 0xb2ef0
jmp 0x110172
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x60(%rbp)
movl %eax, -0x64(%rbp)
leaq -0xe8(%rbp), %rdi
callq 0x311e8
jmp 0x1104cb
movl $0x0, -0xec(%rbp)
movq -0x110(%rbp), %rdi
movl -0xec(%rbp), %eax
movq %rax, -0x200(%rbp)
addq $0x14c0, %rdi           # imm = 0x14C0
addq $0x100, %rdi            # imm = 0x100
callq 0x45170
movq %rax, %rcx
movq -0x200(%rbp), %rax
cmpq %rcx, %rax
jae 0x1103f1
leaq -0x80(%rbp), %rdi
callq 0xd0d10
movq -0x110(%rbp), %rdi
movl (%rax), %eax
movl %eax, -0x20c(%rbp)
movl -0xec(%rbp), %eax
movl %eax, -0x208(%rbp)
addq $0x15c0, %rdi           # imm = 0x15C0
callq 0x45170
movl -0x20c(%rbp), %edi
movl -0x208(%rbp), %esi
movl %eax, %edx
callq 0x17d3a0
movl %eax, -0x204(%rbp)
jmp 0x11039d
movq -0x110(%rbp), %rax
movl -0x204(%rbp), %ecx
movl %ecx, -0x88(%rbp)
movq (%rax), %rdi
movl -0x88(%rbp), %edx
movq %rsp, %rax
movl $0xffffffff, (%rax)     # imm = 0xFFFFFFFF
movl $0x15, %ecx
xorl %r8d, %r8d
leaq -0xb0(%rbp), %r9
movl %r8d, %esi
callq 0xcd520
jmp 0x1103db
jmp 0x1103dd
movl -0xec(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xec(%rbp)
jmp 0x110318
leaq -0x80(%rbp), %rdi
callq 0xd0f50
movl -0x84(%rbp), %eax
incl %eax
movl %eax, -0x84(%rbp)
movq -0x18(%rbp), %rdi
leaq -0xc(%rbp), %rsi
callq 0x123e30
movq %rax, -0x218(%rbp)
jmp 0x11041e
leaq -0x100(%rbp), %rdi
leaq -0x90(%rbp), %rsi
callq 0x1242e0
movq -0x218(%rbp), %rdi
movq -0x100(%rbp), %rsi
callq 0x124270
movq %rax, -0x220(%rbp)
jmp 0x11044d
movq -0x110(%rbp), %rcx
movq -0x220(%rbp), %rax
movq %rax, -0xf8(%rbp)
movq -0xf8(%rbp), %rax
movq %rax, -0x90(%rbp)
movl -0x84(%rbp), %eax
movl %eax, -0x224(%rbp)
movl 0x1620(%rcx), %eax
xorl %edx, %edx
divl 0x16fc(%rcx)
movl %eax, %ecx
movl -0x224(%rbp), %eax
cmpl %ecx, %eax
jb 0x1104a2
movl $0x8, -0x104(%rbp)
jmp 0x1104ac
movl $0x0, -0x104(%rbp)
leaq -0xb0(%rbp), %rdi
callq 0x448d0
movl -0x104(%rbp), %eax
testl %eax, %eax
je 0x1104c6
jmp 0x1104c4
jmp 0x1104d9
jmp 0x10ffdc
leaq -0xb0(%rbp), %rdi
callq 0x448d0
jmp 0x1104e4
leaq -0x40(%rbp), %rdi
callq 0xb2400
jmp 0x1104ef
leaq -0x40(%rbp), %rdi
callq 0xb2400
jmp 0x1104f8
addq $0x230, %rsp            # imm = 0x230
popq %rbp
retq
movq -0x60(%rbp), %rdi
callq 0x30170
nopw %cs:(%rax,%rax)