// File: /workspace/github_cpp_makefile_star2_O1/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 0x8a15c
movq 0xebe7e(%rip), %rbx     # 0x175f90
leaq 0x74ed0(%rip), %rsi     # 0xfefe9
movl $0x2e, %edx
movq %rbx, %rdi
callq 0x22ab0
movl 0x4(%rsp), %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 0x1400(%r12), %r15
leaq 0x4(%rsp), %rbx
movq %r15, %rdi
movq %rbx, %rsi
callq 0xa837c
movq 0x8(%rax), %rsi
subq (%rax), %rsi
sarq $0x3, %rsi
leaq 0x60(%rsp), %rdx
movq %rbp, %rdi
callq 0xa800e
movq %r15, 0x20(%rsp)
movq %r15, %rdi
movq %rbx, %rsi
callq 0xa837c
movq 0x8(%rax), %rsi
subq (%rax), %rsi
sarq $0x3, %rsi
leaq 0x60(%rsp), %rdi
leaq 0x30(%rsp), %rdx
callq 0xa800e
cmpl $0x4, 0x1614(%r12)
jb 0x8a207
movq 0xebdc8(%rip), %rbx     # 0x175f90
leaq 0x74e49(%rip), %rsi     # 0xff018
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 0xebd96(%rip), %rdi     # 0x175f90
callq 0x22050
movq %rax, %rdi
callq 0x22660
movl 0x4(%rsp), %edx
leaq 0x30(%rsp), %rdi
movq %r12, %rsi
callq 0x8b016
cmpl $0x4, 0x1614(%r12)
jb 0x8a269
movq 0xebd66(%rip), %rbx     # 0x175f90
leaq 0x74e1e(%rip), %rsi     # 0xff04f
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 0xebd34(%rip), %rdi     # 0x175f90
callq 0x22050
movq %rax, %rdi
callq 0x22660
cmpl $0x4, 0x1614(%r12)
jb 0x8a2ba
movq 0xebd15(%rip), %rbx     # 0x175f90
leaq 0x74e01(%rip), %rsi     # 0xff083
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 0xebce3(%rip), %rdi     # 0x175f90
callq 0x22050
movq %rax, %rdi
callq 0x22660
leaq 0x4(%rsp), %rsi
movq 0x20(%rsp), %rdi
callq 0xa837c
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 0xa837c
movq 0x50(%rsp), %rcx
leaq (%rcx,%rbx), %r15
movl 0x1614(%r12), %ecx
cmpq 0x8(%rax), %r15
je 0x8a622
movq %rbx, 0x28(%rsp)
cmpl $0x3, %ecx
jb 0x8a377
movl $0x7, %edx
movq 0xebc60(%rip), %rdi     # 0x175f90
leaq 0x74d7d(%rip), %rsi     # 0xff0b4
callq 0x22ab0
movsd (%r15), %xmm0
movq 0xebc48(%rip), %rdi     # 0x175f90
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 0xa837c
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 0xa837c
movq (%rax), %rax
movsd (%rax,%r12), %xmm0
movsd %xmm0, 0x58(%rsp)
movq 0x20(%rsp), %rdi
movq %rbx, %rsi
callq 0xa837c
movq (%rax), %rax
movq 0x28(%rsp), %rcx
movsd (%rax,%rcx), %xmm0
movsd %xmm0, 0x8(%rsp)
cmpl $0x3, 0x1614(%r14)
jb 0x8a464
movl $0x4, %edx
movq 0xebb74(%rip), %rdi     # 0x175f90
leaq 0x74c99(%rip), %rsi     # 0xff0bc
callq 0x22ab0
movq 0xebb61(%rip), %rdi     # 0x175f90
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
xorps %xmm0, %xmm0
cvtsi2sd %r13d, %xmm0
movsd 0x6de8c(%rip), %xmm2    # 0xf8300
divsd %xmm2, %xmm0
cvtsi2sd %r15d, %xmm1
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
addsd %xmm2, %xmm5
xorps %xmm0, %xmm0
cvtss2sd 0x1690(%r14), %xmm0
mulsd %xmm1, %xmm0
movq 0x30(%rsp), %rax
movq 0x28(%rsp), %rcx
movsd (%rax,%rcx), %xmm1
subsd %xmm4, %xmm1
mulsd %xmm0, %xmm1
addsd %xmm5, %xmm1
movsd %xmm1, 0x18(%rsp)
cmpl $0x3, 0x1614(%r14)
movq 0x10(%rsp), %rax
movq %rbp, %r13
movq %rax, %rbp
movq %rcx, %rbx
movq %r14, %r12
leaq 0x4(%rsp), %r14
jb 0x8a55d
movl $0x4, %edx
movq 0xeba7b(%rip), %rdi     # 0x175f90
leaq 0x74ba5(%rip), %rsi     # 0xff0c1
callq 0x22ab0
movq 0xeba68(%rip), %rdi     # 0x175f90
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 0xa837c
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 0x8a619
movl $0x6, %edx
movq 0xeb9ec(%rip), %rdi     # 0x175f90
leaq 0x74b1b(%rip), %rsi     # 0xff0c6
callq 0x22ab0
movq (%rbp), %rax
movsd (%rax,%rbx), %xmm0
movq 0xeb9d0(%rip), %rdi     # 0x175f90
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 0x8a2f2
cmpl $0x2, %ecx
jbe 0x8a66d
movq 0xeb962(%rip), %rbx     # 0x175f90
leaq 0x74a98(%rip), %rsi     # 0xff0cd
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 0xeb930(%rip), %rdi     # 0x175f90
callq 0x22050
movq %rax, %rdi
callq 0x22660
movq 0x30(%rsp), %rdi
testq %rdi, %rdi
je 0x8a684
movq 0x40(%rsp), %rsi
subq %rdi, %rsi
callq 0x229c0
movq 0x60(%rsp), %rdi
testq %rdi, %rdi
je 0x8a69b
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 0x8a6d3
jmp 0x8a6ba
jmp 0x8a6b3
movq %rax, %rbx
jmp 0x8a704
jmp 0x8a6d3
movq %rax, %rbx
jmp 0x8a6ed
jmp 0x8a6d3
jmp 0x8a6c9
jmp 0x8a6c9
jmp 0x8a6d3
jmp 0x8a6d3
movq %rax, %rbx
movq 0x10(%rsp), %rbp
jmp 0x8a6d6
movq %rax, %rbx
movq 0x30(%rsp), %rdi
testq %rdi, %rdi
je 0x8a6ed
movq 0x40(%rsp), %rsi
subq %rdi, %rsi
callq 0x229c0
movq 0x60(%rsp), %rdi
testq %rdi, %rdi
je 0x8a704
movq 0x70(%rsp), %rsi
subq %rdi, %rsi
callq 0x229c0
movq (%rbp), %rdi
testq %rdi, %rdi
je 0x8a719
movq 0x10(%rbp), %rsi
subq %rdi, %rsi
callq 0x229c0
movq %rbx, %rdi
callq 0x23240
nop