// File: richardposner[P]BioNetFit2/src/code/Swarm.cpp
// Function: Swarm::calcParticlePosBBPSO(unsigned int, bool)
vector<double> Swarm::calcParticlePosBBPSO(unsigned int particle, bool exp) {

	if (options.verbosity >= 3) {
		cout << "Calculating BBPSO for particle " << particle << endl;
	}

	// Get the best positions for particle's neighborhood
	vector<double> neighborhoodBestPositions = getNeighborhoodBestPositions(particle);

	/*
	cout << "nbps:" << endl;
	for (auto p = neighborhoodBestPositions.begin(); p != neighborhoodBestPositions.end(); ++p) {
		cout << "nbp: " << *p << endl;
	}
	 */

	if (options.verbosity >= 4) {
		cout << "RAQUEL before nextPositions" << endl;
	}
	// This vector holds the new positions to be sent to the particle
	vector<double> nextPositions(particleCurrParamSets_.size());
	if (options.verbosity >= 4) {
		cout << "RAQUEL after nextPositions" << endl;
	}
	bool usePersonalBest = false;
	if (options.verbosity >= 3) {
		cout << "RAQUEL: entering for" << endl;
	}
	// For each parameter in the current parameter set
	int i = 0;
	for (auto param = particleBestParamSets_.at(particle).begin(); param != particleBestParamSets_.at(particle).end(); ++param) {
		if (exp) {
			if ( ((float) rand() / (RAND_MAX)) < 0.5 ) {
				usePersonalBest = true;
			}
		}

		double personalBestPos = particleBestParamSets_.at(particle)[i];

		if (usePersonalBest) {
			nextPositions[i] = personalBestPos;
			usePersonalBest = false;
		}
		else {
			// Calculate our mean and std
			if (options.verbosity >= 3) {
				cout << "personalbest: " << personalBestPos << " neighborbest: " << neighborhoodBestPositions[i] << endl;
			}
			double mean = (abs(personalBestPos) + abs(neighborhoodBestPositions[i])) / 2;
			if (options.verbosity >= 3) {
				cout << "mean: " << mean << endl;
			}
			double std = abs(abs(personalBestPos) - abs(neighborhoodBestPositions[i]));
			if (options.verbosity >= 3) {
				cout << "std: " << std << endl;
			}
			// Create the gaussian distribution
			boost::random::normal_distribution<double> dist(mean, std);

			// Pick our next position randomly from distribution
			nextPositions[i] = dist(generalRand);
			if (options.verbosity >= 3) {
				cout << "picked: " << nextPositions[i] << endl;
			}
		}
		++i;
	}
	if (options.verbosity >= 4) {
		cout << "RAQUEL: exiting for" << endl;
	}

	return nextPositions;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x170, %rsp            # imm = 0x170
movq %rdi, -0x98(%rbp)
movb %cl, %al
movq %rdi, %rcx
movq %rcx, -0x90(%rbp)
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movl %edx, -0x14(%rbp)
andb $0x1, %al
movb %al, -0x15(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x88(%rbp)
cmpl $0x3, 0x1614(%rax)
jb 0xfd4ff
movq 0x1d7a77(%rip), %rdi    # 0x2d4f50
leaq 0xe475a(%rip), %rsi     # 0x1e1c3a
callq 0x2ff50
movq %rax, %rdi
movl -0x14(%rbp), %esi
callq 0x30640
movq %rax, %rdi
movq 0x1d7ace(%rip), %rsi    # 0x2d4fc8
callq 0x30c10
movq -0x88(%rbp), %rsi
movl -0x14(%rbp), %edx
leaq -0x30(%rbp), %rdi
callq 0xfe010
movq -0x88(%rbp), %rax
cmpl $0x4, 0x1614(%rax)
jb 0xfd566
movq 0x1d7a27(%rip), %rdi    # 0x2d4f50
leaq 0xe472a(%rip), %rsi     # 0x1e1c5a
callq 0x2ff50
movq %rax, -0xa0(%rbp)
jmp 0xfd53e
movq -0xa0(%rbp), %rdi
movq 0x1d7a7c(%rip), %rsi    # 0x2d4fc8
callq 0x30c10
jmp 0xfd553
jmp 0xfd566
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
jmp 0xfdafc
movq -0x88(%rbp), %rdi
movb $0x0, -0x3d(%rbp)
addq $0x1400, %rdi           # imm = 0x1400
callq 0x122f60
movq %rax, -0xb0(%rbp)
leaq -0x3e(%rbp), %rdi
movq %rdi, -0xa8(%rbp)
callq 0xb5b80
movq -0x98(%rbp), %rdi
movq -0xb0(%rbp), %rsi
movq -0xa8(%rbp), %rdx
callq 0x121bc0
jmp 0xfd5b0
leaq -0x3e(%rbp), %rdi
callq 0xbefe0
movq -0x88(%rbp), %rax
cmpl $0x4, 0x1614(%rax)
jb 0xfd633
movq 0x1d7980(%rip), %rdi    # 0x2d4f50
leaq 0xe469f(%rip), %rsi     # 0x1e1c76
callq 0x2ff50
movq %rax, -0xb8(%rbp)
jmp 0xfd5e5
movq -0xb8(%rbp), %rdi
movq 0x1d79d5(%rip), %rsi    # 0x2d4fc8
callq 0x30c10
jmp 0xfd5fa
jmp 0xfd633
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
leaq -0x3e(%rbp), %rdi
callq 0xbefe0
jmp 0xfdafc
movq -0x98(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
callq 0xb2660
jmp 0xfdafc
movq -0x88(%rbp), %rax
movb $0x0, -0x3f(%rbp)
cmpl $0x3, 0x1614(%rax)
jb 0xfd67a
movq 0x1d7902(%rip), %rdi    # 0x2d4f50
leaq 0xe463c(%rip), %rsi     # 0x1e1c91
callq 0x2ff50
movq %rax, -0xc0(%rbp)
jmp 0xfd663
movq -0xc0(%rbp), %rdi
movq 0x1d7957(%rip), %rsi    # 0x2d4fc8
callq 0x30c10
jmp 0xfd678
jmp 0xfd67a
movq -0x88(%rbp), %rdi
movl $0x0, -0x44(%rbp)
addq $0x1cc0, %rdi           # imm = 0x1CC0
leaq -0x14(%rbp), %rsi
callq 0x122470
movq %rax, -0xc8(%rbp)
jmp 0xfd6a1
movq -0xc8(%rbp), %rdi
callq 0xb2ea0
movq %rax, -0x50(%rbp)
movq -0x88(%rbp), %rdi
addq $0x1cc0, %rdi           # imm = 0x1CC0
leaq -0x14(%rbp), %rsi
callq 0x122470
movq %rax, -0xd0(%rbp)
jmp 0xfd6d1
movq -0xd0(%rbp), %rdi
callq 0xbdfd0
movq %rax, -0x58(%rbp)
leaq -0x50(%rbp), %rdi
leaq -0x58(%rbp), %rsi
callq 0x122510
testb $0x1, %al
jne 0xfd6f7
jmp 0xfda8a
testb $0x1, -0x15(%rbp)
je 0xfd72a
callq 0x30b00
cvtsi2ss %eax, %xmm0
movss 0xe344a(%rip), %xmm1    # 0x1e0b58
divss %xmm1, %xmm0
cvtss2sd %xmm0, %xmm1
movsd 0xdbad2(%rip), %xmm0    # 0x1d91f0
ucomisd %xmm1, %xmm0
jbe 0xfd728
movb $0x1, -0x3f(%rbp)
jmp 0xfd72a
movq -0x88(%rbp), %rdi
addq $0x1cc0, %rdi           # imm = 0x1CC0
leaq -0x14(%rbp), %rsi
callq 0x122470
movq %rax, -0xd8(%rbp)
jmp 0xfd74a
movq -0xd8(%rbp), %rdi
movslq -0x44(%rbp), %rsi
callq 0xb2610
movsd (%rax), %xmm0
movsd %xmm0, -0x60(%rbp)
testb $0x1, -0x3f(%rbp)
je 0xfd79b
movq -0x98(%rbp), %rdi
movsd -0x60(%rbp), %xmm0
movsd %xmm0, -0xe0(%rbp)
movslq -0x44(%rbp), %rsi
callq 0xb2610
movsd -0xe0(%rbp), %xmm0
movsd %xmm0, (%rax)
movb $0x0, -0x3f(%rbp)
jmp 0xfda73
movq -0x88(%rbp), %rax
cmpl $0x3, 0x1614(%rax)
jb 0xfd83e
movq 0x1d779a(%rip), %rdi    # 0x2d4f50
leaq 0xe44e9(%rip), %rsi     # 0x1e1ca6
callq 0x2ff50
movq %rax, -0xe8(%rbp)
jmp 0xfd7cb
movq -0xe8(%rbp), %rdi
movsd -0x60(%rbp), %xmm0
callq 0x30710
movq %rax, -0xf0(%rbp)
jmp 0xfd7e5
movq -0xf0(%rbp), %rdi
leaq 0xe44c2(%rip), %rsi     # 0x1e1cb5
callq 0x2ff50
movq %rax, -0xf8(%rbp)
jmp 0xfd801
movslq -0x44(%rbp), %rsi
leaq -0x30(%rbp), %rdi
callq 0xb2610
movq -0xf8(%rbp), %rdi
movsd (%rax), %xmm0
callq 0x30710
movq %rax, -0x100(%rbp)
jmp 0xfd827
movq -0x100(%rbp), %rdi
movq 0x1d7793(%rip), %rsi    # 0x2d4fc8
callq 0x30c10
jmp 0xfd83c
jmp 0xfd83e
movsd -0x60(%rbp), %xmm0
callq 0x9c8a0
movsd %xmm0, -0x108(%rbp)
jmp 0xfd852
movslq -0x44(%rbp), %rsi
leaq -0x30(%rbp), %rdi
callq 0xb2610
movsd (%rax), %xmm0
callq 0x9c8a0
movsd %xmm0, -0x110(%rbp)
jmp 0xfd872
movq -0x88(%rbp), %rax
movsd -0x110(%rbp), %xmm1
movsd -0x108(%rbp), %xmm0
addsd %xmm1, %xmm0
movsd 0xe3293(%rip), %xmm1    # 0x1e0b28
divsd %xmm1, %xmm0
movsd %xmm0, -0x68(%rbp)
cmpl $0x3, 0x1614(%rax)
jb 0xfd8f4
movq 0x1d76a2(%rip), %rdi    # 0x2d4f50
leaq 0xe4410(%rip), %rsi     # 0x1e1cc5
callq 0x2ff50
movq %rax, -0x118(%rbp)
jmp 0xfd8c3
movq -0x118(%rbp), %rdi
movsd -0x68(%rbp), %xmm0
callq 0x30710
movq %rax, -0x120(%rbp)
jmp 0xfd8dd
movq -0x120(%rbp), %rdi
movq 0x1d76dd(%rip), %rsi    # 0x2d4fc8
callq 0x30c10
jmp 0xfd8f2
jmp 0xfd8f4
movsd -0x60(%rbp), %xmm0
callq 0x9c8a0
movsd %xmm0, -0x128(%rbp)
jmp 0xfd908
movslq -0x44(%rbp), %rsi
leaq -0x30(%rbp), %rdi
callq 0xb2610
movsd (%rax), %xmm0
callq 0x9c8a0
movsd %xmm0, -0x130(%rbp)
jmp 0xfd928
movsd -0x130(%rbp), %xmm1
movsd -0x128(%rbp), %xmm0
subsd %xmm1, %xmm0
callq 0x9c8a0
movsd %xmm0, -0x138(%rbp)
jmp 0xfd94b
movq -0x88(%rbp), %rax
movsd -0x138(%rbp), %xmm0
movsd %xmm0, -0x70(%rbp)
cmpl $0x3, 0x1614(%rax)
jb 0xfd9b5
movq 0x1d75e1(%rip), %rdi    # 0x2d4f50
leaq 0xe4356(%rip), %rsi     # 0x1e1ccc
callq 0x2ff50
movq %rax, -0x140(%rbp)
jmp 0xfd984
movq -0x140(%rbp), %rdi
movsd -0x70(%rbp), %xmm0
callq 0x30710
movq %rax, -0x148(%rbp)
jmp 0xfd99e
movq -0x148(%rbp), %rdi
movq 0x1d761c(%rip), %rsi    # 0x2d4fc8
callq 0x30c10
jmp 0xfd9b3
jmp 0xfd9b5
leaq -0x80(%rbp), %rdi
leaq -0x68(%rbp), %rsi
leaq -0x70(%rbp), %rdx
callq 0x122f80
jmp 0xfd9c8
movq -0x88(%rbp), %rsi
addq $0x58, %rsi
leaq -0x80(%rbp), %rdi
callq 0x122ff0
movsd %xmm0, -0x150(%rbp)
jmp 0xfd9e6
movq -0x98(%rbp), %rdi
movslq -0x44(%rbp), %rsi
callq 0xb2610
movsd -0x150(%rbp), %xmm0
movq %rax, %rcx
movq -0x88(%rbp), %rax
movsd %xmm0, (%rcx)
cmpl $0x3, 0x1614(%rax)
jb 0xfda71
movq 0x1d7534(%rip), %rdi    # 0x2d4f50
leaq 0xe42af(%rip), %rsi     # 0x1e1cd2
callq 0x2ff50
movq %rax, -0x158(%rbp)
jmp 0xfda31
movq -0x98(%rbp), %rdi
movslq -0x44(%rbp), %rsi
callq 0xb2610
movq -0x158(%rbp), %rdi
movsd (%rax), %xmm0
callq 0x30710
movq %rax, -0x160(%rbp)
jmp 0xfda5a
movq -0x160(%rbp), %rdi
movq 0x1d7560(%rip), %rsi    # 0x2d4fc8
callq 0x30c10
jmp 0xfda6f
jmp 0xfda71
jmp 0xfda73
movl -0x44(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x44(%rbp)
leaq -0x50(%rbp), %rdi
callq 0xb2ef0
jmp 0xfd6b1
movq -0x88(%rbp), %rax
cmpl $0x4, 0x1614(%rax)
jb 0xfdacd
movq 0x1d74af(%rip), %rdi    # 0x2d4f50
leaq 0xe4233(%rip), %rsi     # 0x1e1cdb
callq 0x2ff50
movq %rax, -0x168(%rbp)
jmp 0xfdab6
movq -0x168(%rbp), %rdi
movq 0x1d7504(%rip), %rsi    # 0x2d4fc8
callq 0x30c10
jmp 0xfdacb
jmp 0xfdacd
movb $0x1, -0x3d(%rbp)
testb $0x1, -0x3d(%rbp)
jne 0xfdae3
movq -0x98(%rbp), %rdi
callq 0xb2660
leaq -0x30(%rbp), %rdi
callq 0xb2660
movq -0x90(%rbp), %rax
addq $0x170, %rsp            # imm = 0x170
popq %rbp
retq
leaq -0x30(%rbp), %rdi
callq 0xb2660
movq -0x38(%rbp), %rdi
callq 0x30170
nop