// File: /workspace/github_cpp_makefile_star2_O1/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x78, %rsp
movl %ecx, 0xc(%rsp)
movq %rsi, %r14
movq %rdi, %rbx
movl %edx, 0x8(%rsp)
cmpl $0x3, 0x1614(%rsi)
jb 0x8a798
movq 0xeb842(%rip), %r15     # 0x175f90
leaq 0x749a5(%rip), %rsi     # 0xff0fa
movl $0x1f, %edx
movq %r15, %rdi
callq 0x22ab0
movl 0x8(%rsp), %esi
movq %r15, %rdi
callq 0x22650
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
movl 0x8(%rsp), %edx
leaq 0x28(%rsp), %rdi
movq %r14, %rsi
callq 0x8b016
cmpl $0x4, 0x1614(%r14)
jb 0x8a7f9
movq 0xeb7d6(%rip), %r15     # 0x175f90
leaq 0x74959(%rip), %rsi     # 0xff11a
movl $0x1b, %edx
movq %r15, %rdi
callq 0x22ab0
movq (%r15), %rax
addq -0x18(%rax), %r15
movq %r15, %rdi
movl $0xa, %esi
callq 0x22940
movsbl %al, %esi
movq 0xeb7a4(%rip), %rdi     # 0x175f90
callq 0x22050
movq %rax, %rdi
callq 0x22660
movq 0x1428(%r14), %rsi
leaq 0x7(%rsp), %rdx
movq %rbx, %rdi
callq 0xa800e
cmpl $0x4, 0x1614(%r14)
jb 0x8a85d
movq 0xeb772(%rip), %r15     # 0x175f90
leaq 0x74911(%rip), %rsi     # 0xff136
movl $0x1a, %edx
movq %r15, %rdi
callq 0x22ab0
movq (%r15), %rax
addq -0x18(%rax), %r15
movq %r15, %rdi
movl $0xa, %esi
callq 0x22940
movsbl %al, %esi
movq 0xeb740(%rip), %rdi     # 0x175f90
callq 0x22050
movq %rax, %rdi
callq 0x22660
cmpl $0x3, 0x1614(%r14)
jb 0x8a8ad
movq 0xeb722(%rip), %r15     # 0x175f90
leaq 0x748dc(%rip), %rsi     # 0xff151
movl $0x14, %edx
movq %r15, %rdi
callq 0x22ab0
movq (%r15), %rax
addq -0x18(%rax), %r15
movq %r15, %rdi
movl $0xa, %esi
callq 0x22940
movsbl %al, %esi
movq 0xeb6f0(%rip), %rdi     # 0x175f90
callq 0x22050
movq %rax, %rdi
callq 0x22660
leaq 0x1cc0(%r14), %r15
leaq 0x8(%rsp), %rsi
movq %r15, %rdi
callq 0xa837c
movq (%rax), %rax
movq %rax, 0x48(%rsp)
leaq 0x58(%r14), %rax
movq %rax, 0x40(%rsp)
xorl %r12d, %r12d
xorl %r13d, %r13d
movq %r15, %rdi
leaq 0x8(%rsp), %rsi
callq 0xa837c
movq 0x48(%rsp), %rcx
addq %r12, %rcx
cmpq 0x8(%rax), %rcx
je 0x8ab9f
cmpb $0x0, 0xc(%rsp)
je 0x8a922
callq 0x22230
xorps %xmm0, %xmm0
cvtsi2ss %eax, %xmm0
mulss 0x736e6(%rip), %xmm0    # 0xfdff8
movss 0x736e2(%rip), %xmm1    # 0xfdffc
ucomiss %xmm0, %xmm1
jbe 0x8a922
movb $0x1, %r13b
movq %r15, %rdi
leaq 0x8(%rsp), %rsi
callq 0xa837c
movq (%rax), %rax
movsd (%rax,%r12), %xmm0
testb $0x1, %r13b
je 0x8a94f
movq (%rbx), %rax
movsd %xmm0, (%rax,%r12)
xorl %r13d, %r13d
jmp 0x8ab96
movaps %xmm0, 0x10(%rsp)
cmpl $0x3, 0x1614(%r14)
jb 0x8a9db
movl $0xe, %edx
movq 0xeb626(%rip), %rdi     # 0x175f90
leaq 0x747f5(%rip), %rsi     # 0xff166
callq 0x22ab0
movq 0xeb613(%rip), %rdi     # 0x175f90
movaps 0x10(%rsp), %xmm0
callq 0x23060
movq %rax, %rbp
movl $0xf, %edx
movq %rax, %rdi
leaq 0x747dc(%rip), %rsi     # 0xff175
callq 0x22ab0
movq 0x28(%rsp), %rax
movsd (%rax,%r12), %xmm0
movq %rbp, %rdi
callq 0x23060
movq %rax, %rbp
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %rbp, %rdi
movl $0xa, %esi
callq 0x22940
movsbl %al, %esi
movq %rbp, %rdi
callq 0x22050
movq %rax, %rdi
callq 0x22660
movapd 0x6d2bd(%rip), %xmm0    # 0xf7ca0
movapd 0x10(%rsp), %xmm1
andpd %xmm0, %xmm1
movq 0x28(%rsp), %rax
movsd (%rax,%r12), %xmm2
andpd %xmm0, %xmm2
movapd %xmm1, 0x10(%rsp)
addsd %xmm1, %xmm2
mulsd 0x6c13a(%rip), %xmm2    # 0xf6b48
movapd %xmm2, 0x60(%rsp)
cmpl $0x3, 0x1614(%r14)
jb 0x8aa72
movl $0x6, %edx
movq 0xeb566(%rip), %rdi     # 0x175f90
leaq 0x74754(%rip), %rsi     # 0xff185
callq 0x22ab0
movq 0xeb553(%rip), %rdi     # 0x175f90
movapd 0x60(%rsp), %xmm0
callq 0x23060
movq %rax, %rbp
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %rbp, %rdi
movl $0xa, %esi
callq 0x22940
movsbl %al, %esi
movq %rbp, %rdi
callq 0x22050
movq %rax, %rdi
callq 0x22660
movq 0x28(%rsp), %rax
movsd (%rax,%r12), %xmm0
movapd 0x6d21b(%rip), %xmm1    # 0xf7ca0
andpd %xmm1, %xmm0
movapd 0x10(%rsp), %xmm2
subsd %xmm0, %xmm2
movapd %xmm2, 0x10(%rsp)
andpd %xmm1, %xmm2
movapd %xmm2, 0x50(%rsp)
cmpl $0x3, 0x1614(%r14)
jb 0x8ab01
movl $0x5, %edx
movq 0xeb4d7(%rip), %rdi     # 0x175f90
leaq 0x746cc(%rip), %rsi     # 0xff18c
callq 0x22ab0
movq 0xeb4c4(%rip), %rdi     # 0x175f90
movapd 0x50(%rsp), %xmm0
callq 0x23060
movq %rax, %rbp
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %rbp, %rdi
movl $0xa, %esi
callq 0x22940
movsbl %al, %esi
movq %rbp, %rdi
callq 0x22050
movq %rax, %rdi
callq 0x22660
movapd 0x10(%rsp), %xmm0
ucomisd %xmm0, %xmm0
jp 0x8ac18
leaq 0x7(%rsp), %rdi
movq 0x40(%rsp), %rsi
callq 0xafc6a
mulsd 0x50(%rsp), %xmm0
addsd 0x60(%rsp), %xmm0
movq (%rbx), %rax
movsd %xmm0, (%rax,%r12)
cmpl $0x3, 0x1614(%r14)
jb 0x8ab96
movl $0x8, %edx
movq 0xeb445(%rip), %rdi     # 0x175f90
leaq 0x74640(%rip), %rsi     # 0xff192
callq 0x22ab0
movq (%rbx), %rax
movsd (%rax,%r12), %xmm0
movq 0xeb429(%rip), %rdi     # 0x175f90
callq 0x23060
movq %rax, %rbp
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %rbp, %rdi
movl $0xa, %esi
callq 0x22940
movsbl %al, %esi
movq %rbp, %rdi
callq 0x22050
movq %rax, %rdi
callq 0x22660
addq $0x8, %r12
jmp 0x8a8d8
cmpl $0x3, 0x1614(%r14)
jbe 0x8abef
movq 0xeb3e0(%rip), %r14     # 0x175f90
leaq 0x745e4(%rip), %rsi     # 0xff19b
movl $0x13, %edx
movq %r14, %rdi
callq 0x22ab0
movq (%r14), %rax
addq -0x18(%rax), %r14
movq %r14, %rdi
movl $0xa, %esi
callq 0x22940
movsbl %al, %esi
movq 0xeb3ae(%rip), %rdi     # 0x175f90
callq 0x22050
movq %rax, %rdi
callq 0x22660
movq 0x28(%rsp), %rdi
testq %rdi, %rdi
je 0x8ac06
movq 0x38(%rsp), %rsi
subq %rdi, %rsi
callq 0x229c0
movq %rbx, %rax
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x773bf(%rip), %rdi     # 0x101fde
leaq 0x773ce(%rip), %rsi     # 0x101ff4
leaq 0x773f9(%rip), %rcx     # 0x102026
movl $0x11a, %edx            # imm = 0x11A
callq 0x22610
jmp 0x8ac4e
jmp 0x8ac41
jmp 0x8ac4e
jmp 0x8ac4e
jmp 0x8ac4e
movq %rax, %r14
jmp 0x8ac65
jmp 0x8ac4e
jmp 0x8ac4e
jmp 0x8ac4e
jmp 0x8ac4e
movq %rax, %r14
movq (%rbx), %rdi
testq %rdi, %rdi
je 0x8ac65
movq 0x10(%rbx), %rsi
subq %rdi, %rsi
callq 0x229c0
movq 0x28(%rsp), %rdi
testq %rdi, %rdi
je 0x8ac7c
movq 0x38(%rsp), %rsi
subq %rdi, %rsi
callq 0x229c0
movq %r14, %rdi
callq 0x23240