// File: /workspace/github_cpp_makefile_star2_O3/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, %r12
movq %rdi, %rbp
movl %edx, 0x4(%rsp)
cmpl $0x3, 0x1614(%rsi)
jb 0x8980e
movl %edx, %ebx
movq 0xec7e2(%rip), %r15     # 0x175fa8
leaq 0x7588c(%rip), %rsi     # 0xff059
movl $0x2e, %edx
movq %r15, %rdi
callq 0x22ab0
movl %ebx, %esi
movq %r15, %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 0x1400(%r12), %r15
leaq 0x4(%rsp), %rbx
movq %r15, %rdi
movq %rbx, %rsi
callq 0xa7a46
movq 0x8(%rax), %rsi
subq (%rax), %rsi
sarq $0x3, %rsi
leaq 0x60(%rsp), %rdx
movq %rbp, %rdi
callq 0xa75c2
movq %r15, 0x20(%rsp)
movq %r15, %rdi
movq %rbx, %rsi
callq 0xa7a46
movq 0x8(%rax), %rsi
subq (%rax), %rsi
sarq $0x3, %rsi
leaq 0x60(%rsp), %rdi
leaq 0x30(%rsp), %rdx
callq 0xa75c2
cmpl $0x4, 0x1614(%r12)
jb 0x898b9
movq 0xec72e(%rip), %rbx     # 0x175fa8
leaq 0x75807(%rip), %rsi     # 0xff088
movl $0x36, %edx
movq %rbx, %rdi
callq 0x22ab0
movq (%rbx), %rax
addq -0x18(%rax), %rbx
movq %rbx, %rdi
movl $0xa, %esi
callq 0x22940
movsbl %al, %esi
movq 0xec6fc(%rip), %rdi     # 0x175fa8
callq 0x22050
movq %rax, %rdi
callq 0x22660
movl 0x4(%rsp), %edx
leaq 0x30(%rsp), %rdi
movq %r12, %rsi
callq 0x8a700
cmpl $0x4, 0x1614(%r12)
jb 0x89970
movq 0xec6c8(%rip), %rbx     # 0x175fa8
leaq 0x757d8(%rip), %rsi     # 0xff0bf
movl $0x33, %edx
movq %rbx, %rdi
callq 0x22ab0
movq (%rbx), %rax
addq -0x18(%rax), %rbx
movq %rbx, %rdi
movl $0xa, %esi
callq 0x22940
movsbl %al, %esi
movq 0xec696(%rip), %rdi     # 0x175fa8
callq 0x22050
movq %rax, %rdi
callq 0x22660
cmpl $0x4, 0x1614(%r12)
jb 0x89970
movq 0xec677(%rip), %rbx     # 0x175fa8
leaq 0x757bb(%rip), %rsi     # 0xff0f3
movl $0x30, %edx
movq %rbx, %rdi
callq 0x22ab0
movq (%rbx), %rax
addq -0x18(%rax), %rbx
movq %rbx, %rdi
movl $0xa, %esi
callq 0x22940
movsbl %al, %esi
movq 0xec645(%rip), %rdi     # 0x175fa8
callq 0x22050
movq %rax, %rdi
callq 0x22660
leaq 0x4(%rsp), %rsi
movq 0x20(%rsp), %rdi
callq 0xa7a46
movq (%rax), %rax
movq %rax, 0x50(%rsp)
leaq 0x1c90(%r12), %r13
leaq 0x1cc0(%r12), %rax
movq %rax, 0x48(%rsp)
xorl %ebx, %ebx
leaq 0x4(%rsp), %r14
movq %rbp, 0x10(%rsp)
movq 0x20(%rsp), %rdi
movq %r14, %rsi
callq 0xa7a46
movq 0x50(%rsp), %rcx
leaq (%rcx,%rbx), %r15
movl 0x1614(%r12), %ecx
cmpq 0x8(%rax), %r15
je 0x89ce4
movq %rbx, 0x28(%rsp)
cmpl $0x3, %ecx
jb 0x89a2d
movl $0x7, %edx
movq 0xec5c2(%rip), %rdi     # 0x175fa8
leaq 0x75737(%rip), %rsi     # 0xff124
callq 0x22ab0
movsd (%r15), %xmm0
movq 0xec5aa(%rip), %rdi     # 0x175fa8
callq 0x23060
movq %rax, %r15
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r15, %rdi
movl $0xa, %esi
callq 0x22940
movsbl %al, %esi
movq %r15, %rdi
callq 0x22050
movq %rax, %rdi
callq 0x22660
movq %r12, %r14
movss 0x1688(%r12), %xmm0
movss %xmm0, 0x8(%rsp)
movq %r13, %rbp
movq %r13, %rdi
leaq 0x4(%rsp), %rbx
movq %rbx, %rsi
callq 0xa7a46
xorps %xmm0, %xmm0
cvtss2sd 0x8(%rsp), %xmm0
movq (%rax), %rax
movq 0x28(%rsp), %r12
mulsd (%rax,%r12), %xmm0
movsd %xmm0, 0x18(%rsp)
callq 0x22230
movl %eax, %r13d
callq 0x22230
movl %eax, %r15d
movq 0x48(%rsp), %rdi
movq %rbx, %rsi
callq 0xa7a46
movq (%rax), %rax
movsd (%rax,%r12), %xmm0
movsd %xmm0, 0x58(%rsp)
movq 0x20(%rsp), %rdi
movq %rbx, %rsi
callq 0xa7a46
movq (%rax), %rax
movq 0x28(%rsp), %rcx
movsd (%rax,%rcx), %xmm0
movsd %xmm0, 0x8(%rsp)
cmpl $0x3, 0x1614(%r14)
jb 0x89b27
movl $0x4, %edx
movq 0xec4d6(%rip), %rdi     # 0x175fa8
leaq 0x75653(%rip), %rsi     # 0xff12c
callq 0x22ab0
movq 0xec4c3(%rip), %rdi     # 0x175fa8
movsd 0x8(%rsp), %xmm0
callq 0x23060
movq %rax, %r12
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r12, %rdi
movl $0xa, %esi
callq 0x22940
movsbl %al, %esi
movq %r12, %rdi
callq 0x22050
movq %rax, %rdi
callq 0x22660
cmpl $0x3, 0x1614(%r14)
setae %al
jmp 0x89b29
xorl %eax, %eax
xorps %xmm0, %xmm0
cvtsi2sd %r13d, %xmm0
xorps %xmm1, %xmm1
cvtsi2sd %r15d, %xmm1
movsd 0x6e79f(%rip), %xmm2    # 0xf82e0
divsd %xmm2, %xmm0
divsd %xmm2, %xmm1
xorps %xmm2, %xmm2
cvtss2sd 0x1688(%r14), %xmm2
mulsd 0x18(%rsp), %xmm2
cvtss2sd 0x168c(%r14), %xmm3
mulsd %xmm0, %xmm3
movsd 0x8(%rsp), %xmm4
movsd 0x58(%rsp), %xmm5
subsd %xmm4, %xmm5
mulsd %xmm3, %xmm5
xorps %xmm0, %xmm0
cvtss2sd 0x1690(%r14), %xmm0
addsd %xmm2, %xmm5
mulsd %xmm1, %xmm0
movq 0x30(%rsp), %rcx
movq 0x28(%rsp), %rdx
movsd (%rcx,%rdx), %xmm1
subsd %xmm4, %xmm1
mulsd %xmm0, %xmm1
addsd %xmm5, %xmm1
movsd %xmm1, 0x18(%rsp)
testb %al, %al
movq 0x10(%rsp), %rax
movq %rbp, %r13
movq %rax, %rbp
movq %rdx, %rbx
movq %r14, %r12
leaq 0x4(%rsp), %r14
je 0x89c1f
movl $0x4, %edx
movq 0xec3d1(%rip), %rdi     # 0x175fa8
leaq 0x75553(%rip), %rsi     # 0xff131
callq 0x22ab0
movq 0xec3be(%rip), %rdi     # 0x175fa8
movsd 0x18(%rsp), %xmm0
callq 0x23060
movq %rax, %r15
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r15, %rdi
movl $0xa, %esi
callq 0x22940
movsbl %al, %esi
movq %r15, %rdi
callq 0x22050
movq %rax, %rdi
callq 0x22660
movq %r13, %rdi
movq %r14, %rsi
callq 0xa7a46
movq (%rax), %rax
movsd 0x18(%rsp), %xmm1
movsd %xmm1, (%rax,%rbx)
movsd 0x8(%rsp), %xmm0
addsd %xmm1, %xmm0
movq (%rbp), %rax
movsd %xmm0, (%rax,%rbx)
cmpl $0x3, 0x1614(%r12)
jb 0x89cdb
movl $0x6, %edx
movq 0xec342(%rip), %rdi     # 0x175fa8
leaq 0x754c9(%rip), %rsi     # 0xff136
callq 0x22ab0
movq (%rbp), %rax
movsd (%rax,%rbx), %xmm0
movq 0xec326(%rip), %rdi     # 0x175fa8
callq 0x23060
movq %rax, %r15
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r15, %rdi
movl $0xa, %esi
callq 0x22940
movsbl %al, %esi
movq %r15, %rdi
callq 0x22050
movq %rax, %rdi
callq 0x22660
movq %rax, %r15
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r15, %rdi
movl $0xa, %esi
callq 0x22940
movsbl %al, %esi
movq %r15, %rdi
callq 0x22050
movq %rax, %rdi
callq 0x22660
addq $0x8, %rbx
jmp 0x899a8
cmpl $0x2, %ecx
jbe 0x89d2f
movq 0xec2b8(%rip), %rbx     # 0x175fa8
leaq 0x75446(%rip), %rsi     # 0xff13d
movl $0x2c, %edx
movq %rbx, %rdi
callq 0x22ab0
movq (%rbx), %rax
addq -0x18(%rax), %rbx
movq %rbx, %rdi
movl $0xa, %esi
callq 0x22940
movsbl %al, %esi
movq 0xec286(%rip), %rdi     # 0x175fa8
callq 0x22050
movq %rax, %rdi
callq 0x22660
movq 0x30(%rsp), %rdi
testq %rdi, %rdi
je 0x89d46
movq 0x40(%rsp), %rsi
subq %rdi, %rsi
callq 0x229c0
movq 0x60(%rsp), %rdi
testq %rdi, %rdi
je 0x89d5d
movq 0x70(%rsp), %rsi
subq %rdi, %rsi
callq 0x229c0
movq %rbp, %rax
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x89d95
jmp 0x89d7c
jmp 0x89d75
movq %rax, %rbx
jmp 0x89dc6
jmp 0x89d95
movq %rax, %rbx
jmp 0x89daf
jmp 0x89d95
jmp 0x89d8b
jmp 0x89d8b
jmp 0x89d95
jmp 0x89d95
movq %rax, %rbx
movq 0x10(%rsp), %rbp
jmp 0x89d98
movq %rax, %rbx
movq 0x30(%rsp), %rdi
testq %rdi, %rdi
je 0x89daf
movq 0x40(%rsp), %rsi
subq %rdi, %rsi
callq 0x229c0
movq 0x60(%rsp), %rdi
testq %rdi, %rdi
je 0x89dc6
movq 0x70(%rsp), %rsi
subq %rdi, %rsi
callq 0x229c0
movq (%rbp), %rdi
testq %rdi, %rdi
je 0x89ddb
movq 0x10(%rbp), %rsi
subq %rdi, %rsi
callq 0x229c0
movq %rbx, %rdi
callq 0x23240
nop