// File: /workspace/github_cpp_makefile_star2_O2/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, 0x24(%rsp)
movl %edx, %r15d
movq %rsi, %r14
movq %rdi, 0x8(%rsp)
movl %edx, 0x14(%rsp)
cmpl $0x3, 0x1614(%rsi)
jb 0x74c90
movq 0xf1327(%rip), %rdi     # 0x165f98
leaq 0x68652(%rip), %rsi     # 0xdd2ca
callq 0x289f0
movl %r15d, %esi
movq %rax, %rdi
callq 0x286e0
movq %rax, %rdi
callq 0x284a0
leaq 0x50(%rsp), %rdi
movq %r14, %rsi
movl %r15d, %edx
callq 0x752f0
cmpl $0x4, 0x1614(%r14)
jb 0x74cc5
movq 0xf12e7(%rip), %rdi     # 0x165f98
leaq 0x68632(%rip), %rsi     # 0xdd2ea
callq 0x289f0
movq %rax, %rdi
callq 0x284a0
movq 0x1428(%r14), %rsi
leaq 0x68(%rsp), %rdx
movq 0x8(%rsp), %rdi
callq 0x85f4a
movl 0x1614(%r14), %eax
cmpl $0x4, %eax
jb 0x74d09
movq 0xf12aa(%rip), %rdi     # 0x165f98
leaq 0x68611(%rip), %rsi     # 0xdd306
callq 0x289f0
movq %rax, %rdi
callq 0x284a0
movl 0x1614(%r14), %eax
cmpl $0x3, %eax
jb 0x74d29
movq 0xf1283(%rip), %rdi     # 0x165f98
leaq 0x68605(%rip), %rsi     # 0xdd321
callq 0x289f0
movq %rax, %rdi
callq 0x284a0
leaq 0x1cc0(%r14), %r15
leaq 0x14(%rsp), %rsi
movq %r15, %rdi
callq 0x861e4
movq (%rax), %r12
leaq 0x58(%r14), %rax
movq %rax, 0x48(%rsp)
xorl %ebp, %ebp
leaq 0x14(%rsp), %r13
movq %r15, %rdi
movq %r13, %rsi
callq 0x861e4
leaq (%r12,%rbp), %rcx
cmpq 0x8(%rax), %rcx
je 0x74f77
cmpb $0x0, 0x24(%rsp)
je 0x74d92
callq 0x28280
cvtsi2ss %eax, %xmm0
mulss 0x67447(%rip), %xmm0    # 0xdc1c8
movss 0x67443(%rip), %xmm1    # 0xdc1cc
ucomiss %xmm0, %xmm1
jbe 0x74d92
movb $0x1, %bl
jmp 0x74d94
xorl %ebx, %ebx
movq %r15, %rdi
movq %r13, %rsi
callq 0x861e4
movq (%rax), %rax
movsd (%rax,%rbp), %xmm0
testb %bl, %bl
je 0x74dbd
movq 0x8(%rsp), %rax
movq (%rax), %rax
movsd %xmm0, (%rax,%rbp)
jmp 0x74f6e
movaps %xmm0, 0x30(%rsp)
cmpl $0x3, 0x1614(%r14)
jb 0x74e22
movq 0xf11c5(%rip), %rdi     # 0x165f98
leaq 0x6855c(%rip), %rsi     # 0xdd336
callq 0x289f0
movq %rax, %rdi
movaps 0x30(%rsp), %xmm0
callq 0x290f0
movq %rax, %rdi
leaq 0x6854f(%rip), %rsi     # 0xdd345
callq 0x289f0
movq 0x50(%rsp), %rcx
movsd (%rcx,%rbp), %xmm0
movq %rax, %rdi
callq 0x290f0
movq %rax, %rdi
callq 0x284a0
cmpl $0x3, 0x1614(%r14)
setae %al
jmp 0x74e24
xorl %eax, %eax
movapd 0x60d74(%rip), %xmm1    # 0xd5ba0
movapd 0x30(%rsp), %xmm2
andpd %xmm1, %xmm2
movq 0x50(%rsp), %rcx
movsd (%rcx,%rbp), %xmm0
andpd %xmm1, %xmm0
addsd %xmm2, %xmm0
mulsd 0x5fc38(%rip), %xmm0    # 0xd4a88
movsd %xmm0, 0x28(%rsp)
testb %al, %al
je 0x74eec
movapd %xmm2, 0x30(%rsp)
movq 0xf112d(%rip), %rdi     # 0x165f98
leaq 0x684e3(%rip), %rsi     # 0xdd355
callq 0x289f0
movsd 0x28(%rsp), %xmm0
movq %rax, %rdi
callq 0x290f0
movq %rax, %rdi
callq 0x284a0
movq 0x50(%rsp), %rax
cmpl $0x2, 0x1614(%r14)
movsd (%rax,%rbp), %xmm0
movapd 0x60cf9(%rip), %xmm1    # 0xd5ba0
andpd %xmm1, %xmm0
movapd 0x30(%rsp), %xmm2
subsd %xmm0, %xmm2
andpd %xmm1, %xmm2
movlpd %xmm2, 0x18(%rsp)
jbe 0x74f03
movq 0xf10d0(%rip), %rdi     # 0x165f98
leaq 0x6848d(%rip), %rsi     # 0xdd35c
callq 0x289f0
movsd 0x18(%rsp), %xmm0
movq %rax, %rdi
callq 0x290f0
movq %rax, %rdi
callq 0x284a0
jmp 0x74f03
movsd (%rcx,%rbp), %xmm0
andpd %xmm1, %xmm0
subsd %xmm0, %xmm2
andpd %xmm1, %xmm2
movlpd %xmm2, 0x18(%rsp)
leaq 0x68(%rsp), %rbx
movq %rbx, %rdi
leaq 0x28(%rsp), %rsi
leaq 0x18(%rsp), %rdx
callq 0x8659e
movq %rbx, %rdi
movq 0x48(%rsp), %rsi
callq 0x865da
movq 0x8(%rsp), %rax
movq (%rax), %rax
movsd %xmm0, (%rax,%rbp)
cmpl $0x3, 0x1614(%r14)
jb 0x74f6e
movq 0xf1053(%rip), %rdi     # 0x165f98
leaq 0x68416(%rip), %rsi     # 0xdd362
callq 0x289f0
movq 0x8(%rsp), %rcx
movq (%rcx), %rcx
movsd (%rcx,%rbp), %xmm0
movq %rax, %rdi
callq 0x290f0
movq %rax, %rdi
callq 0x284a0
addq $0x8, %rbp
jmp 0x74d50
cmpl $0x3, 0x1614(%r14)
jbe 0x74f9c
movq 0xf1010(%rip), %rdi     # 0x165f98
leaq 0x683dc(%rip), %rsi     # 0xdd36b
callq 0x289f0
movq %rax, %rdi
callq 0x284a0
leaq 0x50(%rsp), %rdi
callq 0x5c44e
movq 0x8(%rsp), %rax
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x74fd1
jmp 0x74fd1
jmp 0x74fd1
jmp 0x74fd1
jmp 0x74fc4
movq %rax, %r14
jmp 0x74fde
jmp 0x74fd1
jmp 0x74fd1
jmp 0x74fd1
jmp 0x74fd1
movq %rax, %r14
movq 0x8(%rsp), %rdi
callq 0x5c44e
leaq 0x50(%rsp), %rdi
callq 0x5c44e
movq %r14, %rdi
callq 0x292f0