// File: richardposner[P]BioNetFit2/src/code/Swarm.cpp
// Function: Swarm::initPSOswarm(bool)
void Swarm::initPSOswarm(bool resumeFit) {
	vector<unsigned int> finishedParticles;
	//unsigned int numFinishedParticles = 0;

	if (options.verbosity >= 3) {
		cout << "Launching swarm" << endl;
	}

	// Launch all particles
	//for (unsigned int p = 1; p <= options.swarmSize; ++p) {
	//	launchParticle(p);
	//}

	//if (options.verbosity >= 3) {
	//	cout << "Waiting for particles to finish" << endl;
	//}

	// Wait until they are all finished so we can initialize
	// stuff for subsequent iterations
	/*while(numFinishedParticles < options.swarmSize) {
		// Check for our finished particles

		cout << "RAQUEL swarm size is " << options.swarmSize << " finished: " << numFinishedParticles << endl;
		finishedParticles = checkMasterMessages();
		numFinishedParticles += finishedParticles.size();

		// Sleep for a second
		usleep(1000000);
	}

	*/
	//Raquel replaced the loop above by a synchronous generation
	runGeneration();



	// Fill a vector with all pID's to send for processing
	vector<unsigned int> allParticles;
	for (int p = 1; p <= options.swarmSize; ++p) {
		allParticles.push_back(p);
	}

	// Send all pID's in for processing (update velocities and positions)
	processParticlesPSO(allParticles, false);

	// Set our optimum
	optimum_ = particleBestFitsByFit_.begin()->first;

	// If we're using enhanced stop criteria, update the enhanced stop variables
	if (options.enhancedStop) {
		// Initialize our particle weights and weighted average position
		updateEnhancedStop();
	}


}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x90, %rsp
movb %sil, %al
movq %rdi, -0x8(%rbp)
andb $0x1, %al
movb %al, -0x9(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x80(%rbp)
leaq -0x28(%rbp), %rdi
callq 0xb2010
movq -0x80(%rbp), %rax
cmpl $0x3, 0x1614(%rax)
jb 0x10f4d9
movq 0x1c5ab4(%rip), %rdi    # 0x2d4f50
leaq 0xd3d92(%rip), %rsi     # 0x1e3235
callq 0x2ff50
movq %rax, -0x88(%rbp)
jmp 0x10f4b1
movq -0x88(%rbp), %rdi
movq 0x1c5b09(%rip), %rsi    # 0x2d4fc8
callq 0x30c10
jmp 0x10f4c6
jmp 0x10f4d9
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x30(%rbp)
movl %eax, -0x34(%rbp)
jmp 0x10f5e0
movq -0x80(%rbp), %rdi
callq 0x100a10
jmp 0x10f4e4
leaq -0x50(%rbp), %rdi
callq 0xb2010
movl $0x1, -0x54(%rbp)
movq -0x80(%rbp), %rcx
movl -0x54(%rbp), %eax
cmpl 0x1620(%rcx), %eax
jg 0x10f536
movl -0x54(%rbp), %eax
movl %eax, -0x58(%rbp)
leaq -0x50(%rbp), %rdi
leaq -0x58(%rbp), %rsi
callq 0x122310
jmp 0x10f518
jmp 0x10f51a
movl -0x54(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x54(%rbp)
jmp 0x10f4f4
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x30(%rbp)
movl %eax, -0x34(%rbp)
jmp 0x10f5d7
leaq -0x70(%rbp), %rdi
leaq -0x50(%rbp), %rsi
callq 0x123be0
jmp 0x10f545
movq -0x80(%rbp), %rdi
leaq -0x70(%rbp), %rsi
xorl %edx, %edx
callq 0xfbb20
jmp 0x10f556
leaq -0x70(%rbp), %rdi
callq 0xb2400
movq -0x80(%rbp), %rdi
addq $0x1ab0, %rdi           # imm = 0x1AB0
callq 0x122630
movq %rax, -0x78(%rbp)
leaq -0x78(%rbp), %rdi
callq 0x122660
movq %rax, %rcx
movq -0x80(%rbp), %rax
movsd (%rcx), %xmm0
movsd %xmm0, 0x1d90(%rax)
testb $0x1, 0x16f8(%rax)
je 0x10f5bc
movq -0x80(%rbp), %rdi
callq 0xf9f80
jmp 0x10f5a3
jmp 0x10f5bc
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x30(%rbp)
movl %eax, -0x34(%rbp)
leaq -0x70(%rbp), %rdi
callq 0xb2400
jmp 0x10f5d7
leaq -0x50(%rbp), %rdi
callq 0xb2400
leaq -0x28(%rbp), %rdi
callq 0xb2400
addq $0x90, %rsp
popq %rbp
retq
leaq -0x50(%rbp), %rdi
callq 0xb2400
leaq -0x28(%rbp), %rdi
callq 0xb2400
movq -0x30(%rbp), %rdi
callq 0x30170
nopw %cs:(%rax,%rax)