// File: /workspace/github_cpp_makefile_star2_O2/richardposner[P]BioNetFit2/src/code/Swarm.cpp
// Function: Swarm::calcParticlePosPSO(unsigned int)
vector<double> Swarm::calcParticlePosPSO(unsigned int particle) {

	if (options.verbosity >= 3) {
		cout << "Calculating velocity and position of particle " << particle << endl;
	}

	// This vector holds the new positions to be sent to the particle
	vector<double> nextPositions(particleCurrParamSets_.at(particle).size());
	vector<double> nextVelocities(particleCurrParamSets_.at(particle).size());
	if (options.verbosity >= 4) {
		cout << "RAQUEL getting best neighbor inside calcParticlePosPSO" << endl;
	}
	// Get the best positions for particle's neighborhood
	vector<double> neighborhoodBestPositions = getNeighborhoodBestPositions(particle);
	if (options.verbosity >= 4) {
		cout << "RAQUEL done best neighbor inside calcParticlePosPSO" << endl;
	}

	int i = 0;

	//cout << "inertia: " << options.inertia << endl;
	//cout << "cognitive: " << options.cognitive << endl;
	//cout << "social: " << options.social << endl << endl;
	if (options.verbosity >= 4) {
		cout << "RAQUEL entering for loop particleCurrParamSets_ " << endl;
	}
	// For each parameter in the current parameter set
	for (auto param = particleCurrParamSets_.at(particle).begin(); param != particleCurrParamSets_.at(particle).end(); ++param) {
		if (options.verbosity >= 3) {
			cout << "before " << *param << endl;
		}
		// Set up formula variables
		double currVelocity = options.inertia * particleParamVelocities_.at(particle)[i];
		//cout << "cv: " << currVelocity << endl;
		double r1 = ((double) rand() / (RAND_MAX));
		//cout << "r1: " << r1 << endl;
		double r2 = ((double) rand() / (RAND_MAX));
		//cout << "r2: " << r2 << endl;
		double personalBestPos = particleBestParamSets_.at(particle)[i];
		//cout << "pb: " << personalBestPos << endl;
		double currPos = particleCurrParamSets_.at(particle)[i];
		if (options.verbosity >= 3) {
			cout << "cp: " << currPos << endl;
		}
		//cout << "nbp: " << neighborhoodBestPositions[i] << endl;
		// Set velocity

		// TODO: Look into constriction factor - Clerc
		// Also, according to Eberhart and Shi, constriction factor + velocity clamping
		// results in fastest convergence
		double nextVelocity = (options.inertia * currVelocity) + options.cognitive * r1 * (personalBestPos - currPos) + options.social * r2 * (neighborhoodBestPositions[i] - currPos);
		if (options.verbosity >= 3) {
			cout << "nv: " << nextVelocity << endl;
		}
		// Set velocity
		particleParamVelocities_.at(particle)[i] = nextVelocity;
		// Set position
		nextPositions[i] = currPos + nextVelocity;

		/*
		if (nextPosition <= 0) {
			cout << "NP less than 0. Setting to Very Small Number" << endl;
			nextPosition = 0.00000001;
			particleParamVelocities_.at(particle)[i] = 0;
		}
		 */
		if (options.verbosity >= 3) {
			cout << "after " << nextPositions[i] << endl << endl;
		}
		++i;
	}

	if (options.verbosity >= 3) {
		cout << "RAQUEL done for loop particleCurrParamSets_ " << endl;
	}

	return nextPositions;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x78, %rsp
movq %rsi, %r14
movq %rdi, 0x10(%rsp)
movl %edx, 0xc(%rsp)
cmpl $0x3, 0x1614(%rsi)
jb 0x74876
movl %edx, %ebx
movq 0xf1740(%rip), %rdi     # 0x165f98
leaq 0x6895a(%rip), %rsi     # 0xdd1b9
callq 0x289f0
movl %ebx, %esi
movq %rax, %rdi
callq 0x286e0
movq %rax, %rdi
callq 0x284a0
leaq 0x1400(%r14), %r15
leaq 0xc(%rsp), %rbx
movq %r15, %rdi
movq %rbx, %rsi
callq 0x861e4
movq 0x8(%rax), %rsi
subq (%rax), %rsi
sarq $0x3, %rsi
leaq 0x60(%rsp), %rdx
movq 0x10(%rsp), %rdi
callq 0x85f4a
movq %r15, 0x28(%rsp)
movq %r15, %rdi
movq %rbx, %rsi
callq 0x861e4
movq 0x8(%rax), %rsi
subq (%rax), %rsi
sarq $0x3, %rsi
leaq 0x60(%rsp), %rdi
leaq 0x48(%rsp), %rdx
callq 0x85f4a
cmpl $0x4, 0x1614(%r14)
jb 0x748f6
movq 0xf16b6(%rip), %rdi     # 0x165f98
leaq 0x688ff(%rip), %rsi     # 0xdd1e8
callq 0x289f0
movq %rax, %rdi
callq 0x284a0
movl 0xc(%rsp), %edx
leaq 0x48(%rsp), %rdi
movq %r14, %rsi
callq 0x752f0
cmpl $0x4, 0x1614(%r14)
jb 0x74951
movq 0xf1680(%rip), %rdi     # 0x165f98
leaq 0x68900(%rip), %rsi     # 0xdd21f
callq 0x289f0
movq %rax, %rdi
callq 0x284a0
cmpl $0x4, 0x1614(%r14)
jb 0x74951
movq 0xf165b(%rip), %rdi     # 0x165f98
leaq 0x6890f(%rip), %rsi     # 0xdd253
callq 0x289f0
movq %rax, %rdi
callq 0x284a0
leaq 0xc(%rsp), %rsi
movq 0x28(%rsp), %rdi
callq 0x861e4
movq (%rax), %rax
movq %rax, 0x38(%rsp)
leaq 0x1c90(%r14), %r12
leaq 0x1cc0(%r14), %rax
movq %rax, 0x30(%rsp)
xorl %r15d, %r15d
leaq 0xc(%rsp), %rbp
movq 0x28(%rsp), %rdi
movq %rbp, %rsi
callq 0x861e4
movq 0x38(%rsp), %rcx
leaq (%rcx,%r15), %rbx
movl 0x1614(%r14), %ecx
cmpq 0x8(%rax), %rbx
je 0x74bb0
cmpl $0x3, %ecx
jb 0x749d6
movq 0xf15e2(%rip), %rdi     # 0x165f98
leaq 0x688c7(%rip), %rsi     # 0xdd284
callq 0x289f0
movsd (%rbx), %xmm0
movq %rax, %rdi
callq 0x290f0
movq %rax, %rdi
callq 0x284a0
movss 0x1688(%r14), %xmm0
movss %xmm0, 0x18(%rsp)
movq %r12, %rdi
movq %rbp, %rsi
callq 0x861e4
cvtss2sd 0x18(%rsp), %xmm0
movq (%rax), %rax
mulsd (%rax,%r15), %xmm0
movsd %xmm0, 0x20(%rsp)
callq 0x28280
movl %eax, %ebx
callq 0x28280
movl %eax, %r13d
movq 0x30(%rsp), %rdi
movq %rbp, %rsi
callq 0x861e4
movq (%rax), %rax
movsd (%rax,%r15), %xmm0
movsd %xmm0, 0x40(%rsp)
movq 0x28(%rsp), %rdi
movq %rbp, %rsi
callq 0x861e4
movq (%rax), %rax
movsd (%rax,%r15), %xmm0
movsd %xmm0, 0x18(%rsp)
cmpl $0x3, 0x1614(%r14)
jb 0x74a8c
movq 0xf153b(%rip), %rdi     # 0x165f98
leaq 0x68828(%rip), %rsi     # 0xdd28c
callq 0x289f0
movq %rax, %rdi
movsd 0x18(%rsp), %xmm0
callq 0x290f0
movq %rax, %rdi
callq 0x284a0
cmpl $0x3, 0x1614(%r14)
setae %al
jmp 0x74a8e
xorl %eax, %eax
cvtsi2sd %ebx, %xmm0
cvtsi2sd %r13d, %xmm1
movsd 0x61761(%rip), %xmm2    # 0xd6200
divsd %xmm2, %xmm0
divsd %xmm2, %xmm1
cvtss2sd 0x1688(%r14), %xmm2
mulsd 0x20(%rsp), %xmm2
cvtss2sd 0x168c(%r14), %xmm3
mulsd %xmm0, %xmm3
movsd 0x18(%rsp), %xmm4
movsd 0x40(%rsp), %xmm5
subsd %xmm4, %xmm5
mulsd %xmm3, %xmm5
cvtss2sd 0x1690(%r14), %xmm0
addsd %xmm2, %xmm5
mulsd %xmm1, %xmm0
movq 0x48(%rsp), %rcx
movsd (%rcx,%r15), %xmm1
subsd %xmm4, %xmm1
mulsd %xmm0, %xmm1
addsd %xmm5, %xmm1
movsd %xmm1, 0x20(%rsp)
testb %al, %al
je 0x74b32
movq 0xf1488(%rip), %rdi     # 0x165f98
leaq 0x6877a(%rip), %rsi     # 0xdd291
callq 0x289f0
movq %rax, %rdi
movsd 0x20(%rsp), %xmm0
callq 0x290f0
movq %rax, %rdi
callq 0x284a0
movq %r12, %rdi
movq %rbp, %rsi
callq 0x861e4
movq (%rax), %rax
movsd 0x20(%rsp), %xmm1
movsd %xmm1, (%rax,%r15)
movsd 0x18(%rsp), %xmm0
addsd %xmm1, %xmm0
movq 0x10(%rsp), %rax
movq (%rax), %rax
movsd %xmm0, (%rax,%r15)
cmpl $0x3, 0x1614(%r14)
jb 0x74ba7
movq 0xf1423(%rip), %rdi     # 0x165f98
leaq 0x6871a(%rip), %rsi     # 0xdd296
callq 0x289f0
movq 0x10(%rsp), %rcx
movq (%rcx), %rcx
movsd (%rcx,%r15), %xmm0
movq %rax, %rdi
callq 0x290f0
movq %rax, %rdi
callq 0x284a0
movq %rax, %rdi
callq 0x284a0
addq $0x8, %r15
jmp 0x74983
cmpl $0x2, %ecx
jbe 0x74bd0
movq 0xf13dc(%rip), %rdi     # 0x165f98
leaq 0x686da(%rip), %rsi     # 0xdd29d
callq 0x289f0
movq %rax, %rdi
callq 0x284a0
leaq 0x48(%rsp), %rdi
callq 0x5c44e
leaq 0x60(%rsp), %rdi
callq 0x5c44e
movq 0x10(%rsp), %rax
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x74c16
jmp 0x74c16
jmp 0x74bfe
movq %rax, %rbx
jmp 0x74c23
jmp 0x74c05
movq %rax, %rbx
jmp 0x74c2d
jmp 0x74c16
jmp 0x74c16
jmp 0x74c16
jmp 0x74c16
jmp 0x74c16
jmp 0x74c16
movq %rax, %rbx
leaq 0x48(%rsp), %rdi
callq 0x5c44e
leaq 0x60(%rsp), %rdi
callq 0x5c44e
movq 0x10(%rsp), %rdi
callq 0x5c44e
movq %rbx, %rdi
callq 0x292f0
nop