// File: /workspace/github_cpp_makefile_star2_O3/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, %rbx
movl %edx, 0xc(%rsp)
cmpl $0x3, 0x1614(%rsi)
jb 0x89e5c
movq 0xec195(%rip), %r12     # 0x175fa8
leaq 0x75350(%rip), %rsi     # 0xff16a
movl $0x1f, %edx
movq %r12, %rdi
callq 0x22ab0
movl %r15d, %esi
movq %r12, %rdi
callq 0x22650
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
leaq 0x28(%rsp), %rdi
movq %r14, %rsi
movl %r15d, %edx
callq 0x8a700
cmpl $0x4, 0x1614(%r14)
jb 0x89ebc
movq 0xec12b(%rip), %r15     # 0x175fa8
leaq 0x75306(%rip), %rsi     # 0xff18a
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 0xec0f9(%rip), %rdi     # 0x175fa8
callq 0x22050
movq %rax, %rdi
callq 0x22660
movq 0x1428(%r14), %rsi
leaq 0xb(%rsp), %rdx
movq %rbx, %rdi
callq 0xa75c2
movl 0x1614(%r14), %eax
cmpl $0x4, %eax
jb 0x89f29
movq 0xec0c5(%rip), %r15     # 0x175fa8
leaq 0x752bc(%rip), %rsi     # 0xff1a6
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 0xec093(%rip), %rdi     # 0x175fa8
callq 0x22050
movq %rax, %rdi
callq 0x22660
movl 0x1614(%r14), %eax
cmpl $0x3, %eax
jb 0x89f74
movq 0xec073(%rip), %r15     # 0x175fa8
leaq 0x75285(%rip), %rsi     # 0xff1c1
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 0xec041(%rip), %rdi     # 0x175fa8
callq 0x22050
movq %rax, %rdi
callq 0x22660
leaq 0x1cc0(%r14), %r15
leaq 0xc(%rsp), %rsi
movq %r15, %rdi
callq 0xa7a46
movq (%rax), %r13
leaq 0x58(%r14), %rax
movq %rax, 0x58(%rsp)
xorl %r12d, %r12d
movq %r15, %rdi
leaq 0xc(%rsp), %rsi
callq 0xa7a46
leaq (%r12,%r13), %rcx
cmpq 0x8(%rax), %rcx
je 0x8a289
cmpb $0x0, 0x24(%rsp)
je 0x89fdf
callq 0x22230
xorps %xmm0, %xmm0
cvtsi2ss %eax, %xmm0
mulss 0x7409b(%rip), %xmm0    # 0xfe068
movss 0x74097(%rip), %xmm1    # 0xfe06c
ucomiss %xmm0, %xmm1
jbe 0x89fdf
movb $0x1, %bpl
jmp 0x89fe1
xorl %ebp, %ebp
movq %r15, %rdi
leaq 0xc(%rsp), %rsi
callq 0xa7a46
movq (%rax), %rax
movsd (%rax,%r12), %xmm0
testb %bpl, %bpl
je 0x8a00a
movq (%rbx), %rax
movsd %xmm0, (%rax,%r12)
jmp 0x8a280
movaps %xmm0, 0x10(%rsp)
cmpl $0x3, 0x1614(%r14)
jb 0x8a0a7
movl $0xe, %edx
movq 0xebf7f(%rip), %rdi     # 0x175fa8
leaq 0x751a6(%rip), %rsi     # 0xff1d6
callq 0x22ab0
movq 0xebf6c(%rip), %rdi     # 0x175fa8
movaps 0x10(%rsp), %xmm0
callq 0x23060
movq %rax, %rbp
movl $0xf, %edx
movq %rax, %rdi
leaq 0x7518d(%rip), %rsi     # 0xff1e5
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
cmpl $0x3, 0x1614(%r14)
setae %al
jmp 0x8a0a9
xorl %eax, %eax
movapd 0x6db9f(%rip), %xmm1    # 0xf7c50
movapd 0x10(%rsp), %xmm2
andpd %xmm1, %xmm2
movq 0x28(%rsp), %rcx
movsd (%rcx,%r12), %xmm0
andpd %xmm1, %xmm0
movapd %xmm2, %xmm1
addsd %xmm0, %xmm1
mulsd 0x6ca1e(%rip), %xmm1    # 0xf6af8
movapd %xmm1, 0x60(%rsp)
testb %al, %al
je 0x8a1d3
movapd %xmm2, 0x10(%rsp)
movl $0x6, %edx
movq 0xebeae(%rip), %rdi     # 0x175fa8
leaq 0x750f4(%rip), %rsi     # 0xff1f5
callq 0x22ab0
movq 0xebe9b(%rip), %rdi     # 0x175fa8
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
cmpl $0x3, 0x1614(%r14)
movq 0x28(%rsp), %rax
movsd (%rax,%r12), %xmm0
movapd 0x6daf3(%rip), %xmm1    # 0xf7c50
andpd %xmm1, %xmm0
movapd 0x10(%rsp), %xmm2
subsd %xmm0, %xmm2
movapd %xmm2, 0x10(%rsp)
andpd %xmm1, %xmm2
movapd %xmm2, 0x40(%rsp)
jb 0x8a1eb
movl $0x5, %edx
movq 0xebe1f(%rip), %rdi     # 0x175fa8
leaq 0x7506c(%rip), %rsi     # 0xff1fc
callq 0x22ab0
movq 0xebe0c(%rip), %rdi     # 0x175fa8
movapd 0x40(%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
jmp 0x8a1eb
subsd %xmm0, %xmm2
movapd %xmm2, 0x10(%rsp)
andpd 0x6da6b(%rip), %xmm2    # 0xf7c50
movapd %xmm2, 0x40(%rsp)
movapd 0x10(%rsp), %xmm0
ucomisd %xmm0, %xmm0
jp 0x8a302
leaq 0xb(%rsp), %rdi
movq 0x58(%rsp), %rsi
callq 0xaf442
mulsd 0x40(%rsp), %xmm0
addsd 0x60(%rsp), %xmm0
movq (%rbx), %rax
movsd %xmm0, (%rax,%r12)
cmpl $0x3, 0x1614(%r14)
jb 0x8a280
movl $0x8, %edx
movq 0xebd73(%rip), %rdi     # 0x175fa8
leaq 0x74fc6(%rip), %rsi     # 0xff202
callq 0x22ab0
movq (%rbx), %rax
movsd (%rax,%r12), %xmm0
movq 0xebd57(%rip), %rdi     # 0x175fa8
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 0x89f97
cmpl $0x3, 0x1614(%r14)
jbe 0x8a2d9
movq 0xebd0e(%rip), %r14     # 0x175fa8
leaq 0x74f6a(%rip), %rsi     # 0xff20b
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 0xebcdc(%rip), %rdi     # 0x175fa8
callq 0x22050
movq %rax, %rdi
callq 0x22660
movq 0x28(%rsp), %rdi
testq %rdi, %rdi
je 0x8a2f0
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 0x77cbc(%rip), %rdi     # 0x101fc5
leaq 0x77ccb(%rip), %rsi     # 0x101fdb
leaq 0x77cf6(%rip), %rcx     # 0x10200d
movl $0x11a, %edx            # imm = 0x11A
callq 0x22610
jmp 0x8a338
jmp 0x8a32b
jmp 0x8a338
jmp 0x8a338
jmp 0x8a338
movq %rax, %r14
jmp 0x8a34f
jmp 0x8a338
jmp 0x8a338
jmp 0x8a338
jmp 0x8a338
movq %rax, %r14
movq (%rbx), %rdi
testq %rdi, %rdi
je 0x8a34f
movq 0x10(%rbx), %rsi
subq %rdi, %rsi
callq 0x229c0
movq 0x28(%rsp), %rdi
testq %rdi, %rdi
je 0x8a366
movq 0x38(%rsp), %rsi
subq %rdi, %rsi
callq 0x229c0
movq %r14, %rdi
callq 0x23240