// File: richardposner[P]BioNetFit2/src/code/Swarm.cpp
// Function: Swarm::crossoverParticleDE(unsigned int, std::vector<double, std::allocator<double>>, float, bool)
vector<double> Swarm::crossoverParticleDE(unsigned int particle, vector<double> mutationSet, float crossoverRate, bool normalize) {
	if (options.verbosity >= 3) {
		cout << "Crossing over particle " << particle << endl;
	}

	// Uses binomial crossover
	boost::random::uniform_int_distribution<int> intDist(0, this->getNumFreeParams() - 1);//boost::random::uniform_int_distribution<int> intDist(0, options.model->getNumFreeParams() - 1);
	unsigned int randParam = intDist(generalRand);
	boost::random::uniform_real_distribution<float> floatDist(0, 1);

	float cr;
	if (crossoverRate) {
		cr = crossoverRate;
	}
	else {
		cr = options.cr;
	}

	//cout << "crossing over particle " << particle << ". randParam is " << randParam << endl;
	vector<double> newParamSet;
	unsigned int p = 0;
	for (auto param = this->getFreeParams_().begin(); param != this->getFreeParams_().end(); ++param) { //for (auto param = options.model->getFreeParams_().begin(); param != options.model->getFreeParams_().end(); ++param) {
		//for (unsigned int p = 0; p < options.model->getNumFreeParams(); ++p) {
		float rand = floatDist(generalRand);
		//cout << "p: " << p << ". rand: " << rand << endl;

		if (rand < cr || p == randParam) {
			newParamSet.push_back(mutationSet[p]);
			//cout << "pushing back " << mutationSet[p] << " from mutation set" << endl;
		}
		else {
			if (normalize) {
				newParamSet.push_back(normalizeParam(particleCurrParamSets_.at(particle)[p], param->second->getGenMin(), param->second->getGenMax(), param->second->getIsLog()));
			}
			else {
				newParamSet.push_back(particleCurrParamSets_.at(particle)[p]);
			}
			//cout << "pushing back " << particleCurrParamSets_.at(particle)[p] << " from current set" << endl;
		}
		++p;
	}

	return newParamSet;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xf0, %rsp
movq %rcx, -0x98(%rbp)
movq %rdi, -0x90(%rbp)
movb %r8b, %al
movq %rdi, %r8
movq %r8, -0x88(%rbp)
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movl %edx, -0x14(%rbp)
movq %rcx, -0x20(%rbp)
movss %xmm0, -0x24(%rbp)
andb $0x1, %al
movb %al, -0x25(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x80(%rbp)
cmpl $0x3, 0x1614(%rax)
jb 0x115ecd
movq 0x1bf0a9(%rip), %rdi    # 0x2d4f50
leaq 0xce640(%rip), %rsi     # 0x1e44ee
callq 0x2ff50
movq %rax, %rdi
movl -0x14(%rbp), %esi
callq 0x30640
movq %rax, %rdi
movq 0x1bf100(%rip), %rsi    # 0x2d4fc8
callq 0x30c10
movq -0x80(%rbp), %rdi
callq 0x121af0
movl %eax, %edx
subl $0x1, %edx
leaq -0x30(%rbp), %rdi
xorl %esi, %esi
callq 0x123cd0
movq -0x80(%rbp), %rsi
addq $0x58, %rsi
leaq -0x30(%rbp), %rdi
callq 0x123e00
movl %eax, -0x34(%rbp)
leaq -0x3c(%rbp), %rdi
xorps %xmm0, %xmm0
movss 0xbd0fb(%rip), %xmm1    # 0x1d3004
callq 0x125bd0
movss -0x24(%rbp), %xmm0
xorps %xmm1, %xmm1
ucomiss %xmm1, %xmm0
jne 0x115f1f
jp 0x115f1f
jmp 0x115f2b
movss -0x24(%rbp), %xmm0
movss %xmm0, -0x40(%rbp)
jmp 0x115f3c
movq -0x80(%rbp), %rax
movss 0x1704(%rax), %xmm0
movss %xmm0, -0x40(%rbp)
movq -0x90(%rbp), %rdi
movb $0x0, -0x41(%rbp)
callq 0xb2580
movq -0x80(%rbp), %rdi
movl $0x0, -0x48(%rbp)
callq 0x125110
movq %rax, -0xa0(%rbp)
jmp 0x115f65
movq -0xa0(%rbp), %rdi
callq 0xb3200
movq %rax, -0x50(%rbp)
movq -0x80(%rbp), %rdi
callq 0x125110
movq %rax, -0xa8(%rbp)
jmp 0x115f87
movq -0xa8(%rbp), %rdi
callq 0xb3310
movq %rax, -0x68(%rbp)
leaq -0x50(%rbp), %rdi
leaq -0x68(%rbp), %rsi
callq 0xb32e0
testb $0x1, %al
jne 0x115fad
jmp 0x11618e
movq -0x80(%rbp), %rsi
addq $0x58, %rsi
leaq -0x3c(%rbp), %rdi
callq 0x125c40
movss %xmm0, -0xac(%rbp)
jmp 0x115fc8
movss -0xac(%rbp), %xmm0
movss %xmm0, -0x6c(%rbp)
movss -0x6c(%rbp), %xmm1
movss -0x40(%rbp), %xmm0
ucomiss %xmm1, %xmm0
ja 0x115fec
movl -0x48(%rbp), %eax
cmpl -0x34(%rbp), %eax
jne 0x116030
movq -0x98(%rbp), %rdi
movl -0x48(%rbp), %eax
movl %eax, %esi
callq 0xb2610
movq -0x90(%rbp), %rdi
movq %rax, %rsi
callq 0xb2e30
jmp 0x11600e
jmp 0x116177
movq -0x90(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x58(%rbp)
movl %eax, -0x5c(%rbp)
callq 0xb2660
jmp 0x1161b4
testb $0x1, -0x25(%rbp)
je 0x116134
movq -0x80(%rbp), %rdi
addq $0x1400, %rdi           # imm = 0x1400
leaq -0x14(%rbp), %rsi
callq 0x122470
movq %rax, -0xb8(%rbp)
jmp 0x116057
movq -0xb8(%rbp), %rdi
movl -0x48(%rbp), %eax
movl %eax, %esi
callq 0xb2610
movsd (%rax), %xmm0
movsd %xmm0, -0xc8(%rbp)
leaq -0x50(%rbp), %rdi
callq 0xb3230
movq 0x20(%rax), %rdi
callq 0xb26f0
movss %xmm0, -0xbc(%rbp)
jmp 0x116090
movss -0xbc(%rbp), %xmm0
cvtss2sd %xmm0, %xmm0
movsd %xmm0, -0xd8(%rbp)
leaq -0x50(%rbp), %rdi
callq 0xb3230
movq 0x20(%rax), %rdi
callq 0xb2710
movss %xmm0, -0xcc(%rbp)
jmp 0x1160c0
movss -0xcc(%rbp), %xmm0
cvtss2sd %xmm0, %xmm0
movsd %xmm0, -0xe8(%rbp)
leaq -0x50(%rbp), %rdi
callq 0xb3230
movq 0x20(%rax), %rdi
callq 0x125bb0
movb %al, -0xd9(%rbp)
jmp 0x1160ee
movsd -0xe8(%rbp), %xmm2
movsd -0xd8(%rbp), %xmm1
movsd -0xc8(%rbp), %xmm0
movq -0x80(%rbp), %rdi
movb -0xd9(%rbp), %al
movzbl %al, %esi
andl $0x1, %esi
callq 0xe9940
movq -0x90(%rbp), %rdi
movsd %xmm0, -0x78(%rbp)
leaq -0x78(%rbp), %rsi
callq 0xb2630
jmp 0x116132
jmp 0x116175
movq -0x80(%rbp), %rdi
addq $0x1400, %rdi           # imm = 0x1400
leaq -0x14(%rbp), %rsi
callq 0x122470
movq %rax, -0xf0(%rbp)
jmp 0x116151
movq -0xf0(%rbp), %rdi
movl -0x48(%rbp), %eax
movl %eax, %esi
callq 0xb2610
movq -0x90(%rbp), %rdi
movq %rax, %rsi
callq 0xb2e30
jmp 0x116173
jmp 0x116175
jmp 0x116177
movl -0x48(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x48(%rbp)
leaq -0x50(%rbp), %rdi
callq 0xb3260
jmp 0x115f75
movb $0x1, -0x41(%rbp)
testb $0x1, -0x41(%rbp)
jne 0x1161a4
movq -0x90(%rbp), %rdi
callq 0xb2660
movq -0x88(%rbp), %rax
addq $0xf0, %rsp
popq %rbp
retq
movq -0x58(%rbp), %rdi
callq 0x30170
nopl (%rax)