// File: /workspace/github_cpp_makefile_star2_O3/richardposner[P]BioNetFit2/src/code/Swarm.cpp
// Function: Swarm::sendMigrationSetDE(unsigned int, std::vector<std::vector<unsigned int, std::allocator<unsigned int>>, std::allocator<std::vector<unsigned int, std::allocator<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::sendMigrationSetDE(unsigned int island, vector<vector<unsigned int> > islandTopology, map<unsigned int, vector<vector<double> > > &migrationSets) {
	if (options.verbosity >= 3) {
		cout << "Sending migration set from island " << island << endl;
	}

	// Generate a random number between 1 and the number of neighbors
	// in the island topology
	boost::random::uniform_int_distribution<int> unif(0, islandTopology[island].size() - 1);
	int parID = 0;
	// Fill a vector with particles from this island, starting with best fits and ending with worst
	vector<unsigned int> particlesToSend;
	//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){

		//the ranks are sorted from the best particle to the worst, so the for loop will stop in the first time it finds a particle that belongs to the current iland
		for (auto fitIt = subParRankFinal.begin(); fitIt != subParRankFinal.end(); ++fitIt) {
			parID = fcalcParID(fitIt->first, options.models.size());

			if (particleToIsland_[parID] == island) {
				particlesToSend.push_back(parID);
				if (particlesToSend.size() == options.numToMigrate) {
					break;
				}
			}
		}

	}else{

		for (auto fitIt = particleBestFitsByFit_.begin(); fitIt != particleBestFitsByFit_.end(); ++fitIt) {
			if (particleToIsland_[fitIt->second] == island) {
				particlesToSend.push_back(fitIt->second);
				if (particlesToSend.size() == options.numToMigrate) {
					break;
				}
			}
		}

	}

	// Choose the index of our receiver
	unsigned int receivingIslandIndex = unif(generalRand);

	// Loop through particles to send
	vector<double> migrationSet;
	//for (auto particle = particlesToSend.begin(); particle != particlesToSend.end(); ++particle) {
	for (unsigned int i = 0; i < options.numToMigrate; ++i) {
		if (options.verbosity >= 3) {
			cout << "sending set " << i + 1 << " from particle " << particlesToSend[i] << endl;
		}
		// Fill migrationSet with this particles current parameters
		for (auto param = particleCurrParamSets_[particlesToSend[i]].begin(); param != particleCurrParamSets_[particlesToSend[i]].end(); ++param) {
			migrationSet.push_back(*param);
		}
		// Add that migration set to the list of the receiving island's
		// migration sets
		migrationSets[islandTopology[island][receivingIslandIndex]].push_back(migrationSet);
		migrationSet.clear();
		if (options.verbosity >= 3) {
			cout << island << " sending migration set to island " << islandTopology[island][receivingIslandIndex] << endl;
		}
	}
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x68, %rsp
movq %rcx, 0x60(%rsp)
movq %rdx, 0x40(%rsp)
movl %esi, %ebp
movq %rdi, %r15
cmpl $0x2, 0x1614(%rdi)
movl %esi, %r14d
jbe 0x9c237
movq 0xd9dba(%rip), %rbx     # 0x175fa8
leaq 0x64458(%rip), %rsi     # 0x10064d
movl $0x22, %edx
movq %rbx, %rdi
callq 0x22ab0
movq %rbx, %rdi
movq %r14, %rsi
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 0x40(%rsp), %rax
movq (%rax), %rax
leaq (%r14,%r14,2), %rcx
movq 0x8(%rax,%rcx,8), %rdx
movq %rcx, 0x48(%rsp)
subq (%rax,%rcx,8), %rdx
shrq $0x2, %rdx
decl %edx
js 0x9c5d1
movq %r14, 0x58(%rsp)
xorps %xmm0, %xmm0
movaps %xmm0, (%rsp)
movq $0x0, 0x10(%rsp)
cmpq $0x0, 0x1608(%r15)
movq %rdx, 0x38(%rsp)
je 0x9c31d
movq 0x18f0(%r15), %rbx
cmpq 0x18f8(%r15), %rbx
je 0x9c397
movq %rsp, %r14
leaq 0x20(%rsp), %r13
movl (%rbx), %edi
movq 0x15c8(%r15), %rsi
subq 0x15c0(%r15), %rsi
shrq $0x3, %rsi
callq 0xbe99e
movslq %eax, %rcx
movq 0x1d20(%r15), %rdx
cmpl %ebp, (%rdx,%rcx,4)
jne 0x9c30e
movl %eax, 0x20(%rsp)
movq 0x8(%rsp), %rsi
cmpq 0x10(%rsp), %rsi
je 0x9c2e6
movl %eax, (%rsi)
addq $0x4, %rsi
movq %rsi, 0x8(%rsp)
jmp 0x9c2f6
movq %r14, %rdi
movq %r13, %rdx
callq 0xaeef8
movq 0x8(%rsp), %rsi
subq (%rsp), %rsi
sarq $0x2, %rsi
movl 0x170c(%r15), %eax
cmpq %rax, %rsi
je 0x9c397
addq $0x8, %rbx
cmpq 0x18f8(%r15), %rbx
jne 0x9c2a1
jmp 0x9c397
movq 0x1ac8(%r15), %r13
leaq 0x1ab8(%r15), %r14
cmpq %r14, %r13
je 0x9c397
xorl %r12d, %r12d
xorl %ebx, %ebx
movl 0x28(%r13), %eax
movq 0x1d20(%r15), %rcx
cmpl %ebp, (%rcx,%rax,4)
jne 0x9c387
cmpq 0x10(%rsp), %rbx
je 0x9c359
movl %eax, (%rbx)
addq $0x4, %rbx
movq %rbx, 0x8(%rsp)
jmp 0x9c371
leaq 0x28(%r13), %rdx
movq %rsp, %rdi
movq %rbx, %rsi
callq 0x6b0da
movq (%rsp), %r12
movq 0x8(%rsp), %rbx
movq %rbx, %rax
subq %r12, %rax
sarq $0x2, %rax
movl 0x170c(%r15), %ecx
cmpq %rcx, %rax
je 0x9c397
movq %r13, %rdi
callq 0x22670
movq %rax, %r13
cmpq %r14, %rax
jne 0x9c335
leaq 0x58(%r15), %rdi
xorl %esi, %esi
movq 0x38(%rsp), %rdx
callq 0xbbd9b
xorps %xmm0, %xmm0
movaps %xmm0, 0x20(%rsp)
movq $0x0, 0x30(%rsp)
cmpl $0x0, 0x170c(%r15)
je 0x9c5ac
leaq 0x1400(%r15), %r13
movl %eax, %eax
xorl %ebp, %ebp
movq %rax, 0x50(%rsp)
leaq (,%rax,4), %rax
movq %rax, 0x38(%rsp)
leaq 0x20(%rsp), %r12
cmpl $0x3, 0x1614(%r15)
jb 0x9c46a
movl $0xc, %edx
movq 0xd9baa(%rip), %rdi     # 0x175fa8
leaq 0x6426b(%rip), %rsi     # 0x100670
callq 0x22ab0
leaq 0x1(%rbp), %rsi
movq 0xd9b93(%rip), %rdi     # 0x175fa8
callq 0x22650
movq %rax, %rbx
movl $0xf, %edx
movq %rax, %rdi
leaq 0x64251(%rip), %rsi     # 0x10067d
callq 0x22ab0
movq (%rsp), %rax
movl (%rax,%rbp,4), %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
leaq (,%rbp,4), %r14
movq (%rsp), %rsi
addq %r14, %rsi
movq %r13, %rdi
callq 0xa7e00
movq (%rax), %rbx
movq (%rsp), %rsi
addq %r14, %rsi
movq %r13, %rdi
callq 0xa7e00
cmpq 0x8(%rax), %rbx
je 0x9c4c9
movq 0x28(%rsp), %rsi
cmpq 0x30(%rsp), %rsi
je 0x9c4b8
movsd (%rbx), %xmm0
movsd %xmm0, (%rsi)
addq $0x8, %rsi
movq %rsi, 0x28(%rsp)
jmp 0x9c4c3
movq %r12, %rdi
movq %rbx, %rdx
callq 0x684d4
addq $0x8, %rbx
jmp 0x9c484
movq 0x40(%rsp), %rax
movq (%rax), %rax
movq 0x48(%rsp), %rcx
movq (%rax,%rcx,8), %rsi
addq 0x38(%rsp), %rsi
movq 0x60(%rsp), %rdi
callq 0xa8082
movq %rax, %rdi
movq %r12, %rsi
callq 0xa80e8
movq 0x20(%rsp), %rax
cmpq %rax, 0x28(%rsp)
je 0x9c505
movq %rax, 0x28(%rsp)
cmpl $0x3, 0x1614(%r15)
jb 0x9c582
movq 0xd9a92(%rip), %rdi     # 0x175fa8
movq 0x58(%rsp), %rsi
callq 0x22650
movq %rax, %rbx
movl $0x21, %edx
movq %rax, %rdi
leaq 0x6415b(%rip), %rsi     # 0x10068d
callq 0x22ab0
movq 0x40(%rsp), %rax
movq (%rax), %rax
movq 0x48(%rsp), %rcx
movq (%rax,%rcx,8), %rax
movq 0x50(%rsp), %rcx
movl (%rax,%rcx,4), %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
incq %rbp
movl 0x170c(%r15), %eax
cmpq %rax, %rbp
jb 0x9c3e8
movq 0x20(%rsp), %rdi
testq %rdi, %rdi
je 0x9c5ac
movq 0x30(%rsp), %rsi
subq %rdi, %rsi
callq 0x229c0
movq (%rsp), %rdi
testq %rdi, %rdi
je 0x9c5c2
movq 0x10(%rsp), %rsi
subq %rdi, %rsi
callq 0x229c0
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x7a977(%rip), %rdi     # 0x116f4f
leaq 0x7a983(%rip), %rsi     # 0x116f62
leaq 0x7a9b3(%rip), %rcx     # 0x116f99
movl $0x151, %edx            # imm = 0x151
callq 0x22610
jmp 0x9c5f6
jmp 0x9c5f6
jmp 0x9c5f6
movq %rax, %rbx
jmp 0x9c61b
jmp 0x9c601
jmp 0x9c601
jmp 0x9c601
movq %rax, %rbx
movq 0x20(%rsp), %rdi
testq %rdi, %rdi
je 0x9c61b
movq 0x30(%rsp), %rsi
subq %rdi, %rsi
callq 0x229c0
movq (%rsp), %rdi
testq %rdi, %rdi
je 0x9c631
movq 0x10(%rsp), %rsi
subq %rdi, %rsi
callq 0x229c0
movq %rbx, %rdi
callq 0x23240
nop