// File: /workspace/github_cpp_makefile_star2_O1/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, 0x38(%rsp)
movl %esi, %ebp
movq %rdi, %r15
cmpl $0x3, 0x1614(%rdi)
movl %esi, %r14d
jb 0x9cce1
movq 0xd92f8(%rip), %rbx     # 0x175f90
leaq 0x639c7(%rip), %rsi     # 0x100666
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 0x38(%rsp), %rax
movq (%rax), %rax
leaq (%r14,%r14,2), %rcx
movq 0x8(%rax,%rcx,8), %r12
movq %rcx, 0x40(%rsp)
subq (%rax,%rcx,8), %r12
shrq $0x2, %r12
decl %r12d
js 0x9d06f
movq %r14, 0x50(%rsp)
xorps %xmm0, %xmm0
movaps %xmm0, (%rsp)
movq $0x0, 0x10(%rsp)
cmpq $0x0, 0x1608(%r15)
je 0x9cdc3
movq 0x18f0(%r15), %rbx
cmpq 0x18f8(%r15), %rbx
je 0x9ce37
movq %rsp, %r14
leaq 0x20(%rsp), %r13
movl (%rbx), %edi
movq 0x15c8(%r15), %rsi
subq 0x15c0(%r15), %rsi
shrq $0x3, %rsi
callq 0xbf2b8
movslq %eax, %rcx
movq 0x1d20(%r15), %rdx
cmpl %ebp, (%rdx,%rcx,4)
jne 0x9cdb4
movl %eax, 0x20(%rsp)
movq 0x8(%rsp), %rsi
cmpq 0x10(%rsp), %rsi
je 0x9cd8c
movl %eax, (%rsi)
addq $0x4, %rsi
movq %rsi, 0x8(%rsp)
jmp 0x9cd97
movq %r14, %rdi
movq %r13, %rdx
callq 0xaf698
movq 0x8(%rsp), %rax
subq (%rsp), %rax
sarq $0x2, %rax
movl 0x170c(%r15), %ecx
cmpq %rcx, %rax
je 0x9ce37
addq $0x8, %rbx
cmpq 0x18f8(%r15), %rbx
jne 0x9cd47
jmp 0x9ce37
movq 0x1ac8(%r15), %r13
leaq 0x1ab8(%r15), %rbx
cmpq %rbx, %r13
je 0x9ce37
movq %rsp, %r14
movl 0x28(%r13), %eax
movq 0x1d20(%r15), %rcx
cmpl %ebp, (%rcx,%rax,4)
jne 0x9ce27
movq 0x8(%rsp), %rsi
cmpq 0x10(%rsp), %rsi
je 0x9ce02
movl %eax, (%rsi)
addq $0x4, %rsi
movq %rsi, 0x8(%rsp)
jmp 0x9ce0e
leaq 0x28(%r13), %rdx
movq %r14, %rdi
callq 0x6b5ce
movq 0x8(%rsp), %rax
subq (%rsp), %rax
sarq $0x2, %rax
movl 0x170c(%r15), %ecx
cmpq %rcx, %rax
je 0x9ce37
movq %r13, %rdi
callq 0x22670
movq %rax, %r13
cmpq %rbx, %rax
jne 0x9cdd9
leaq 0x58(%r15), %rdi
xorl %esi, %esi
movl %r12d, %edx
callq 0xbc645
xorps %xmm0, %xmm0
movaps %xmm0, 0x20(%rsp)
movq $0x0, 0x30(%rsp)
cmpl $0x0, 0x170c(%r15)
je 0x9d033
leaq 0x1400(%r15), %r13
movl %eax, %eax
xorl %ebp, %ebp
movq %rax, 0x48(%rsp)
leaq (,%rax,4), %rax
movq %rax, 0x58(%rsp)
leaq 0x20(%rsp), %r12
cmpl $0x3, 0x1614(%r15)
jb 0x9cf08
movl $0xc, %edx
movq 0xd90f4(%rip), %rdi     # 0x175f90
leaq 0x637e6(%rip), %rsi     # 0x100689
callq 0x22ab0
leaq 0x1(%rbp), %rsi
movq 0xd90dd(%rip), %rdi     # 0x175f90
callq 0x22650
movq %rax, %rbx
movl $0xf, %edx
movq %rax, %rdi
leaq 0x637cc(%rip), %rsi     # 0x100696
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 0xa873a
movq (%rax), %rbx
movq (%rsp), %rsi
addq %r14, %rsi
movq %r13, %rdi
callq 0xa873a
cmpq 0x8(%rax), %rbx
je 0x9cf67
movq 0x28(%rsp), %rsi
cmpq 0x30(%rsp), %rsi
je 0x9cf56
movsd (%rbx), %xmm0
movsd %xmm0, (%rsi)
addq $0x8, %rsi
movq %rsi, 0x28(%rsp)
jmp 0x9cf61
movq %r12, %rdi
movq %rbx, %rdx
callq 0x68992
addq $0x8, %rbx
jmp 0x9cf22
movq 0x38(%rsp), %rax
movq (%rax), %rax
movq 0x40(%rsp), %rcx
movq (%rax,%rcx,8), %rsi
addq 0x58(%rsp), %rsi
movq 0x60(%rsp), %rdi
callq 0xa89b4
movq %rax, %rdi
movq %r12, %rsi
callq 0xa8a18
movq 0x20(%rsp), %rax
cmpq %rax, 0x28(%rsp)
je 0x9cfa3
movq %rax, 0x28(%rsp)
cmpl $0x3, 0x1614(%r15)
jb 0x9d020
movq 0xd8fdc(%rip), %rdi     # 0x175f90
movq 0x50(%rsp), %rsi
callq 0x22650
movq %rax, %rbx
movl $0x21, %edx
movq %rax, %rdi
leaq 0x636d6(%rip), %rsi     # 0x1006a6
callq 0x22ab0
movq 0x38(%rsp), %rax
movq (%rax), %rax
movq 0x40(%rsp), %rcx
movq (%rax,%rcx,8), %rax
movq 0x48(%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 0x9ce86
movq 0x20(%rsp), %rdi
testq %rdi, %rdi
je 0x9d04a
movq 0x30(%rsp), %rsi
subq %rdi, %rsi
callq 0x229c0
movq (%rsp), %rdi
testq %rdi, %rdi
je 0x9d060
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 0x79ef2(%rip), %rdi     # 0x116f68
leaq 0x79efe(%rip), %rsi     # 0x116f7b
leaq 0x79f2e(%rip), %rcx     # 0x116fb2
movl $0x151, %edx            # imm = 0x151
callq 0x22610
jmp 0x9d094
jmp 0x9d094
jmp 0x9d094
movq %rax, %rbx
jmp 0x9d0b9
jmp 0x9d09f
jmp 0x9d09f
jmp 0x9d09f
movq %rax, %rbx
movq 0x20(%rsp), %rdi
testq %rdi, %rdi
je 0x9d0b9
movq 0x30(%rsp), %rsi
subq %rdi, %rsi
callq 0x229c0
movq (%rsp), %rdi
testq %rdi, %rdi
je 0x9d0cf
movq 0x10(%rsp), %rsi
subq %rdi, %rsi
callq 0x229c0
movq %rbx, %rdi
callq 0x23240
nop