// File: 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
movq %rsp, %rbp
subq $0x1b0, %rsp            # imm = 0x1B0
movq %rdi, -0xc0(%rbp)
movq %rdi, %rax
movq %rax, -0xb8(%rbp)
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movl %edx, -0x14(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0xb0(%rbp)
cmpl $0x3, 0x1614(%rax)
jb 0xfcd58
movq 0x1d821e(%rip), %rdi    # 0x2d4f50
leaq 0xe4df0(%rip), %rsi     # 0x1e1b29
callq 0x2ff50
movq %rax, %rdi
movl -0x14(%rbp), %esi
callq 0x30640
movq %rax, %rdi
movq 0x1d8275(%rip), %rsi    # 0x2d4fc8
callq 0x30c10
movq -0xb0(%rbp), %rdi
movb $0x0, -0x15(%rbp)
addq $0x1400, %rdi           # imm = 0x1400
leaq -0x14(%rbp), %rsi
callq 0x122470
movq %rax, %rdi
callq 0xb25c0
movq %rax, -0xd0(%rbp)
leaq -0x16(%rbp), %rdi
movq %rdi, -0xc8(%rbp)
callq 0xb5b80
movq -0xc0(%rbp), %rdi
movq -0xd0(%rbp), %rsi
movq -0xc8(%rbp), %rdx
callq 0x121bc0
jmp 0xfcdae
leaq -0x16(%rbp), %rdi
callq 0xbefe0
movq -0xb0(%rbp), %rdi
addq $0x1400, %rdi           # imm = 0x1400
leaq -0x14(%rbp), %rsi
callq 0x122470
movq %rax, -0xd8(%rbp)
jmp 0xfcdd7
movq -0xd8(%rbp), %rdi
callq 0xb25c0
movq %rax, -0xe8(%rbp)
leaq -0x41(%rbp), %rdi
movq %rdi, -0xe0(%rbp)
callq 0xb5b80
movq -0xe8(%rbp), %rsi
movq -0xe0(%rbp), %rdx
leaq -0x40(%rbp), %rdi
callq 0x121bc0
jmp 0xfce13
leaq -0x41(%rbp), %rdi
callq 0xbefe0
movq -0xb0(%rbp), %rax
cmpl $0x4, 0x1614(%rax)
jb 0xfceb9
movq 0x1d8119(%rip), %rdi    # 0x2d4f50
leaq 0xe4d1a(%rip), %rsi     # 0x1e1b58
callq 0x2ff50
movq %rax, -0xf0(%rbp)
jmp 0xfce4c
movq -0xf0(%rbp), %rdi
movq 0x1d816e(%rip), %rsi    # 0x2d4fc8
callq 0x30c10
jmp 0xfce61
jmp 0xfceb9
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x20(%rbp)
movl %eax, -0x24(%rbp)
leaq -0x16(%rbp), %rdi
callq 0xbefe0
jmp 0xfd484
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x20(%rbp)
movl %eax, -0x24(%rbp)
jmp 0xfd478
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x20(%rbp)
movl %eax, -0x24(%rbp)
leaq -0x41(%rbp), %rdi
callq 0xbefe0
jmp 0xfd478
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x20(%rbp)
movl %eax, -0x24(%rbp)
jmp 0xfd451
movq -0xb0(%rbp), %rsi
movl -0x14(%rbp), %edx
leaq -0x60(%rbp), %rdi
callq 0xfe010
jmp 0xfcece
movq -0xb0(%rbp), %rax
cmpl $0x4, 0x1614(%rax)
jb 0xfcf2b
movq 0x1d806b(%rip), %rdi    # 0x2d4f50
leaq 0xe4ca3(%rip), %rsi     # 0x1e1b8f
callq 0x2ff50
movq %rax, -0xf8(%rbp)
jmp 0xfcefa
movq -0xf8(%rbp), %rdi
movq 0x1d80c0(%rip), %rsi    # 0x2d4fc8
callq 0x30c10
jmp 0xfcf0f
jmp 0xfcf2b
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x20(%rbp)
movl %eax, -0x24(%rbp)
leaq -0x60(%rbp), %rdi
callq 0xb2660
jmp 0xfd451
movq -0xb0(%rbp), %rax
movl $0x0, -0x64(%rbp)
cmpl $0x4, 0x1614(%rax)
jb 0xfcf75
movq 0x1d8007(%rip), %rdi    # 0x2d4f50
leaq 0xe4c73(%rip), %rsi     # 0x1e1bc3
callq 0x2ff50
movq %rax, -0x100(%rbp)
jmp 0xfcf5e
movq -0x100(%rbp), %rdi
movq 0x1d805c(%rip), %rsi    # 0x2d4fc8
callq 0x30c10
jmp 0xfcf73
jmp 0xfcf75
movq -0xb0(%rbp), %rdi
addq $0x1400, %rdi           # imm = 0x1400
leaq -0x14(%rbp), %rsi
callq 0x122470
movq %rax, -0x108(%rbp)
jmp 0xfcf95
movq -0x108(%rbp), %rdi
callq 0xb2ea0
movq %rax, -0x70(%rbp)
movq -0xb0(%rbp), %rdi
addq $0x1400, %rdi           # imm = 0x1400
leaq -0x14(%rbp), %rsi
callq 0x122470
movq %rax, -0x110(%rbp)
jmp 0xfcfc5
movq -0x110(%rbp), %rdi
callq 0xbdfd0
movq %rax, -0x78(%rbp)
leaq -0x70(%rbp), %rdi
leaq -0x78(%rbp), %rsi
callq 0x122510
testb $0x1, %al
jne 0xfcfeb
jmp 0xfd3f0
movq -0xb0(%rbp), %rax
cmpl $0x3, 0x1614(%rax)
jb 0xfd050
movq 0x1d7f4e(%rip), %rdi    # 0x2d4f50
leaq 0xe4beb(%rip), %rsi     # 0x1e1bf4
callq 0x2ff50
movq %rax, -0x118(%rbp)
jmp 0xfd017
leaq -0x70(%rbp), %rdi
callq 0xb2ed0
movq -0x118(%rbp), %rdi
movsd (%rax), %xmm0
callq 0x30710
movq %rax, -0x120(%rbp)
jmp 0xfd039
movq -0x120(%rbp), %rdi
movq 0x1d7f81(%rip), %rsi    # 0x2d4fc8
callq 0x30c10
jmp 0xfd04e
jmp 0xfd050
movq -0xb0(%rbp), %rdi
movss 0x1688(%rdi), %xmm0
cvtss2sd %xmm0, %xmm0
movsd %xmm0, -0x130(%rbp)
addq $0x1c90, %rdi           # imm = 0x1C90
leaq -0x14(%rbp), %rsi
callq 0x122470
movq %rax, -0x128(%rbp)
jmp 0xfd084
movq -0x128(%rbp), %rdi
movslq -0x64(%rbp), %rsi
callq 0xb2610
movsd -0x130(%rbp), %xmm0
movsd (%rax), %xmm1
mulsd %xmm1, %xmm0
movsd %xmm0, -0x80(%rbp)
callq 0x30b00
cvtsi2sd %eax, %xmm0
movsd 0xdda66(%rip), %xmm1    # 0x1dab20
movsd %xmm1, -0x140(%rbp)
divsd %xmm1, %xmm0
movsd %xmm0, -0x88(%rbp)
callq 0x30b00
movsd -0x140(%rbp), %xmm1
movq -0xb0(%rbp), %rdi
cvtsi2sd %eax, %xmm0
divsd %xmm1, %xmm0
movsd %xmm0, -0x90(%rbp)
addq $0x1cc0, %rdi           # imm = 0x1CC0
leaq -0x14(%rbp), %rsi
callq 0x122470
movq %rax, -0x138(%rbp)
jmp 0xfd10b
movq -0x138(%rbp), %rdi
movslq -0x64(%rbp), %rsi
callq 0xb2610
movq -0xb0(%rbp), %rdi
movsd (%rax), %xmm0
movsd %xmm0, -0x98(%rbp)
addq $0x1400, %rdi           # imm = 0x1400
leaq -0x14(%rbp), %rsi
callq 0x122470
movq %rax, -0x148(%rbp)
jmp 0xfd147
movq -0x148(%rbp), %rdi
movslq -0x64(%rbp), %rsi
callq 0xb2610
movq %rax, %rcx
movq -0xb0(%rbp), %rax
movsd (%rcx), %xmm0
movsd %xmm0, -0xa0(%rbp)
cmpl $0x3, 0x1614(%rax)
jb 0xfd1c6
movq 0x1d7dd3(%rip), %rdi    # 0x2d4f50
leaq 0xe4a78(%rip), %rsi     # 0x1e1bfc
callq 0x2ff50
movq %rax, -0x150(%rbp)
jmp 0xfd192
movq -0x150(%rbp), %rdi
movsd -0xa0(%rbp), %xmm0
callq 0x30710
movq %rax, -0x158(%rbp)
jmp 0xfd1af
movq -0x158(%rbp), %rdi
movq 0x1d7e0b(%rip), %rsi    # 0x2d4fc8
callq 0x30c10
jmp 0xfd1c4
jmp 0xfd1c6
movq -0xb0(%rbp), %rax
movss 0x1688(%rax), %xmm0
cvtss2sd %xmm0, %xmm0
movsd -0x80(%rbp), %xmm2
movss 0x168c(%rax), %xmm1
cvtss2sd %xmm1, %xmm1
mulsd -0x88(%rbp), %xmm1
movsd -0x98(%rbp), %xmm3
subsd -0xa0(%rbp), %xmm3
mulsd %xmm3, %xmm1
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, -0x160(%rbp)
movss 0x1690(%rax), %xmm0
cvtss2sd %xmm0, %xmm0
mulsd -0x90(%rbp), %xmm0
movsd %xmm0, -0x168(%rbp)
movslq -0x64(%rbp), %rsi
leaq -0x60(%rbp), %rdi
callq 0xb2610
movsd -0x168(%rbp), %xmm0
movsd -0x160(%rbp), %xmm1
movq %rax, %rcx
movq -0xb0(%rbp), %rax
movsd (%rcx), %xmm2
subsd -0xa0(%rbp), %xmm2
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, -0xa8(%rbp)
cmpl $0x3, 0x1614(%rax)
jb 0xfd2ce
movq 0x1d7ccb(%rip), %rdi    # 0x2d4f50
leaq 0xe4975(%rip), %rsi     # 0x1e1c01
callq 0x2ff50
movq %rax, -0x170(%rbp)
jmp 0xfd29a
movq -0x170(%rbp), %rdi
movsd -0xa8(%rbp), %xmm0
callq 0x30710
movq %rax, -0x178(%rbp)
jmp 0xfd2b7
movq -0x178(%rbp), %rdi
movq 0x1d7d03(%rip), %rsi    # 0x2d4fc8
callq 0x30c10
jmp 0xfd2cc
jmp 0xfd2ce
movq -0xb0(%rbp), %rdi
movsd -0xa8(%rbp), %xmm0
movsd %xmm0, -0x188(%rbp)
addq $0x1c90, %rdi           # imm = 0x1C90
leaq -0x14(%rbp), %rsi
callq 0x122470
movq %rax, -0x180(%rbp)
jmp 0xfd2fe
movq -0x180(%rbp), %rdi
movslq -0x64(%rbp), %rsi
callq 0xb2610
movsd -0x188(%rbp), %xmm0
movq -0xc0(%rbp), %rdi
movsd %xmm0, (%rax)
movsd -0xa0(%rbp), %xmm0
addsd -0xa8(%rbp), %xmm0
movsd %xmm0, -0x190(%rbp)
movslq -0x64(%rbp), %rsi
callq 0xb2610
movsd -0x190(%rbp), %xmm0
movq %rax, %rcx
movq -0xb0(%rbp), %rax
movsd %xmm0, (%rcx)
cmpl $0x3, 0x1614(%rax)
jb 0xfd3d9
movq 0x1d7be8(%rip), %rdi    # 0x2d4f50
leaq 0xe4897(%rip), %rsi     # 0x1e1c06
callq 0x2ff50
movq %rax, -0x198(%rbp)
jmp 0xfd37d
movq -0xc0(%rbp), %rdi
movslq -0x64(%rbp), %rsi
callq 0xb2610
movq -0x198(%rbp), %rdi
movsd (%rax), %xmm0
callq 0x30710
movq %rax, -0x1a0(%rbp)
jmp 0xfd3a6
movq -0x1a0(%rbp), %rdi
movq 0x1d7c14(%rip), %rsi    # 0x2d4fc8
callq 0x30c10
movq %rax, -0x1a8(%rbp)
jmp 0xfd3c2
movq -0x1a8(%rbp), %rdi
movq 0x1d7bf8(%rip), %rsi    # 0x2d4fc8
callq 0x30c10
jmp 0xfd3d7
jmp 0xfd3d9
movl -0x64(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x64(%rbp)
leaq -0x70(%rbp), %rdi
callq 0xb2ef0
jmp 0xfcfa5
movq -0xb0(%rbp), %rax
cmpl $0x3, 0x1614(%rax)
jb 0xfd433
movq 0x1d7b49(%rip), %rdi    # 0x2d4f50
leaq 0xe47ff(%rip), %rsi     # 0x1e1c0d
callq 0x2ff50
movq %rax, -0x1b0(%rbp)
jmp 0xfd41c
movq -0x1b0(%rbp), %rdi
movq 0x1d7b9e(%rip), %rsi    # 0x2d4fc8
callq 0x30c10
jmp 0xfd431
jmp 0xfd433
movb $0x1, -0x15(%rbp)
leaq -0x60(%rbp), %rdi
callq 0xb2660
leaq -0x40(%rbp), %rdi
callq 0xb2660
testb $0x1, -0x15(%rbp)
jne 0xfd468
jmp 0xfd45c
leaq -0x40(%rbp), %rdi
callq 0xb2660
jmp 0xfd478
movq -0xc0(%rbp), %rdi
callq 0xb2660
movq -0xb8(%rbp), %rax
addq $0x1b0, %rsp            # imm = 0x1B0
popq %rbp
retq
movq -0xc0(%rbp), %rdi
callq 0xb2660
movq -0x20(%rbp), %rdi
callq 0x30170
nopl (%rax)