// File: /workspace/github_cpp_makefile_star2_O2/richardposner[P]BioNetFit2/src/code/Swarm.cpp
// Function: Swarm::runAPSO()
void Swarm::runAPSO() {
	if (options.verbosity >= 3) {
		cout << "Running an asynchronous PSO fit" << endl;
	}

	if (!checkIfFileExists(options.jobOutputDir + "1")) {
		string createDirCmd = "mkdir " + options.jobOutputDir + "1";
		runCommand(createDirCmd);
	}

	if (!resumingSavedSwarm) {
		// Generate all particles that will be present in the swarm
		populationTopology_ = generateTopology(options.swarmSize);

		// Run first flight
		initPSOswarm();
	}


	if (options.verbosity >= 0) {
		cout << "Generation (flock): " << toString(currentGeneration - 1 ) << endl;
	}
		vector<unsigned int> particlestoProcess;


	bool stopCriteria = false;
	while (!stopCriteria){
		if (options.verbosity >= 3) {
			cout << "RAQUEL: Started runasyncGeneration();" << endl;
		}
		runAsyncGeneration();
		if (options.verbosity >= 3) {
			cout << "RAQUEL: Finished runasyncGeneration();" << endl;

			cout << "RAQUEL: Started checkStopCriteria();" << endl;
		}

		if (options.verbosity >= 0) {
			cout << "Generation (flock): " << toString(currentGeneration - 1 ) << endl;
		}

		stopCriteria = checkStopCriteria();
		if (options.verbosity >= 3) {
			cout << "RAQUEL: Stop criteria value is " << stopCriteria << endl;

			cout << "RAQUEL: Finished checkStopCriteria();" << endl;
			cout << "RAQUEL: Started saveSwarmState();" << endl;
		}
		saveSwarmState();
		if (options.verbosity >= 3) {

			cout << "RAQUEL: Finished saveSwarmState();" << endl;
		}

		string currentDirectory = options.jobOutputDir + toString(currentGeneration);
		if (options.deleteOldFiles) {
			if (options.verbosity >= 3) {
				cout << "RAQUEL: Started cleanupFiles();" << endl;
			}
			cleanupFiles(currentDirectory.c_str());
			if (options.verbosity >= 3) {
				cout << "RAQUEL: Finished cleanupFiles();" << endl;
			}
		}

		string outputPath = options.jobOutputDir + toString(currentGeneration - 1 ) + "_summary.txt";
		if (options.verbosity >= 3) {
			cout << "RAQUEL: Started outputRunSummary();" << endl;
		}
		outputRunSummary(outputPath);
		if (options.verbosity >= 3) {
			cout << "RAQUEL: Finished outputRunSummary();" << endl;
		}

		if (!stopCriteria) {
			if (options.verbosity >= 3) {
				cout << "RAQUEL: started processParticlesPSO();" << endl;
			}
			particlestoProcess.clear();

			for(auto i = finishedParticles_.begin(); i!=finishedParticles_.end(); ++i){
				if (options.verbosity >= 3) {
					cout << "RAQUEL: processing particle number: " << *i << endl;
				}
				particlestoProcess.push_back(*i);
			}
			processParticlesPSO(particlestoProcess, true);

			if (options.verbosity >= 3) {
				cout << "RAQUEL: finished processParticlesPSO();" << endl;
			}
		}
	}
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x128, %rsp            # imm = 0x128
movq %rdi, %rbx
cmpl $0x3, 0x1614(%rdi)
jb 0x6feae
movq 0xf60fe(%rip), %rdi     # 0x165f98
leaq 0x6ed9c(%rip), %rsi     # 0xdec3d
callq 0x289f0
movq %rax, %rdi
callq 0x284a0
leaq 0x1520(%rbx), %rsi
leaq 0x704ef(%rip), %rdx     # 0xe03ab
leaq 0xa8(%rsp), %r14
movq %r14, %rdi
movq %rsi, 0x8(%rsp)
callq 0x334ed
movq %r14, %rdi
callq 0x9ec28
movl %eax, %ebp
leaq 0xa8(%rsp), %rdi
callq 0x295a0
testl %ebp, %ebp
jne 0x6ff59
leaq 0x65fa4(%rip), %rsi     # 0xd5e97
leaq 0x30(%rsp), %r14
movq %r14, %rdi
movq 0x8(%rsp), %rdx
callq 0x3338b
leaq 0x7049f(%rip), %rdx     # 0xe03ab
leaq 0x10(%rsp), %rdi
movq %r14, %rsi
callq 0x3336c
leaq 0x30(%rsp), %rdi
callq 0x295a0
leaq 0x88(%rsp), %rdi
leaq 0x10(%rsp), %rsi
callq 0x28dd0
leaq 0x88(%rsp), %rdi
callq 0x9f543
leaq 0x88(%rsp), %rdi
callq 0x295a0
leaq 0x10(%rsp), %rdi
callq 0x295a0
cmpb $0x0, 0x13f0(%rbx)
jne 0x6ff99
movl 0x1620(%rbx), %edx
leaq 0x10(%rsp), %r14
movq %r14, %rdi
movq %rbx, %rsi
callq 0x734e6
leaq 0x1a08(%rbx), %rdi
movq %r14, %rsi
callq 0x9ca60
movq %r14, %rdi
callq 0x85c60
movq %rbx, %rdi
xorl %esi, %esi
callq 0x7ed78
movq 0xf5ff8(%rip), %rdi     # 0x165f98
leaq 0x6ea1f(%rip), %rsi     # 0xde9c6
callq 0x289f0
movq %rax, %r14
movl 0x13e8(%rbx), %esi
decl %esi
leaq 0x10(%rsp), %r15
movq %r15, %rdi
callq 0x9f56b
movq %r14, %rdi
movq %r15, %rsi
callq 0x28910
movq %rax, %rdi
callq 0x284a0
leaq 0x10(%rsp), %rdi
callq 0x295a0
xorps %xmm0, %xmm0
leaq 0x50(%rsp), %r12
andq $0x0, 0x10(%r12)
movaps %xmm0, (%r12)
leaq 0x18c8(%rbx), %rbp
movq 0xf5f96(%rip), %r13     # 0x165f98
cmpl $0x3, 0x1614(%rbx)
jb 0x70022
movq %r13, %rdi
leaq 0x6ec48(%rip), %rsi     # 0xdec5d
callq 0x289f0
movq %rax, %rdi
callq 0x284a0
movq %rbx, %rdi
callq 0x78478
cmpl $0x3, 0x1614(%rbx)
jb 0x70061
movq %r13, %rdi
leaq 0x6ec46(%rip), %rsi     # 0xdec83
callq 0x289f0
movq %rax, %rdi
callq 0x284a0
movq %r13, %rdi
leaq 0x6eaad(%rip), %rsi     # 0xdeb01
callq 0x289f0
movq %rax, %rdi
callq 0x284a0
movq %r13, %rdi
leaq 0x6e95b(%rip), %rsi     # 0xde9c6
callq 0x289f0
movq %rax, %r15
movl 0x13e8(%rbx), %esi
decl %esi
leaq 0x10(%rsp), %r14
movq %r14, %rdi
callq 0x9f56b
movq %r15, %rdi
movq %r14, %rsi
callq 0x28910
movq %rax, %rdi
callq 0x284a0
leaq 0x10(%rsp), %rdi
callq 0x295a0
movq %rbx, %rdi
callq 0x72f2a
movb %al, 0x7(%rsp)
cmpl $0x3, 0x1614(%rbx)
jb 0x7010c
movq %r13, %rdi
leaq 0x6eac6(%rip), %rsi     # 0xdeb8a
callq 0x289f0
movzbl 0x7(%rsp), %esi
movq %rax, %rdi
callq 0x29180
movq %rax, %rdi
callq 0x284a0
movq %r13, %rdi
leaq 0x6eac2(%rip), %rsi     # 0xdebaa
callq 0x289f0
movq %rax, %rdi
callq 0x284a0
movq %r13, %rdi
leaq 0x6ead1(%rip), %rsi     # 0xdebd0
callq 0x289f0
movq %rax, %rdi
callq 0x284a0
movq %rbx, %rdi
callq 0x7ec70
cmpl $0x3, 0x1614(%rbx)
jb 0x70134
movq %r13, %rdi
leaq 0x6e9ff(%rip), %rsi     # 0xdeb26
callq 0x289f0
movq %rax, %rdi
callq 0x284a0
movl 0x13e8(%rbx), %esi
leaq 0x30(%rsp), %r14
movq %r14, %rdi
callq 0x9f56b
leaq 0x10(%rsp), %rdi
movq 0x8(%rsp), %rsi
movq %r14, %rdx
callq 0x5a115
movq %r14, %rdi
callq 0x295a0
cmpb $0x1, 0x1646(%rbx)
jne 0x701b4
cmpl $0x3, 0x1614(%rbx)
jb 0x7018a
movq %r13, %rdi
leaq 0x6e9cc(%rip), %rsi     # 0xdeb49
callq 0x289f0
movq %rax, %rdi
callq 0x284a0
movq 0x10(%rsp), %rsi
callq 0x791e0
cmpl $0x3, 0x1614(%rbx)
jb 0x701b4
movq %r13, %rdi
leaq 0x6e9c2(%rip), %rsi     # 0xdeb69
callq 0x289f0
movq %rax, %rdi
callq 0x284a0
movl 0x13e8(%rbx), %esi
decl %esi
leaq 0xe8(%rsp), %r14
movq %r14, %rdi
callq 0x9f56b
leaq 0x108(%rsp), %r15
movq %r15, %rdi
movq 0x8(%rsp), %rsi
movq %r14, %rdx
callq 0x5a115
leaq 0x30(%rsp), %rdi
movq %r15, %rsi
leaq 0x6e753(%rip), %rdx     # 0xde946
callq 0x3336c
movq %r15, %rdi
callq 0x295a0
movq %r14, %rdi
callq 0x295a0
cmpl $0x3, 0x1614(%rbx)
leaq 0xc8(%rsp), %r14
jb 0x70230
movq %r13, %rdi
leaq 0x6ea87(%rip), %rsi     # 0xdecaa
callq 0x289f0
movq %rax, %rdi
callq 0x284a0
movq %r14, %rdi
leaq 0x30(%rsp), %rsi
callq 0x28dd0
movq %rbx, %rdi
movq %r14, %rsi
callq 0x7942a
movq %r14, %rdi
callq 0x295a0
cmpl $0x3, 0x1614(%rbx)
jb 0x70270
movq %r13, %rdi
leaq 0x6ea6b(%rip), %rsi     # 0xdecce
callq 0x289f0
movq %rax, %rdi
callq 0x284a0
cmpb $0x0, 0x7(%rsp)
jne 0x7035d
cmpl $0x3, 0x1614(%rbx)
jb 0x7029b
movq %r13, %rdi
leaq 0x6ea65(%rip), %rsi     # 0xdecf3
callq 0x289f0
movq %rax, %rdi
callq 0x284a0
movq 0x50(%rsp), %rax
cmpq %rax, 0x58(%rsp)
je 0x702ac
movq %rax, 0x58(%rsp)
movq 0x18d8(%rbx), %r15
cmpq %rbp, %r15
je 0x702fd
cmpl $0x3, 0x1614(%rbx)
jb 0x702e4
movq %r13, %rdi
leaq 0x6ea4f(%rip), %rsi     # 0xded1a
callq 0x289f0
movl 0x20(%r15), %esi
movq %rax, %rdi
callq 0x286e0
movq %rax, %rdi
callq 0x284a0
leaq 0x20(%r15), %rsi
movq %r12, %rdi
callq 0x5a59e
movq %r15, %rdi
callq 0x28b60
movq %rax, %r15
jmp 0x702b3
leaq 0x70(%rsp), %rdi
movq %r12, %rsi
callq 0x8673e
movq %rbx, %rdi
leaq 0x70(%rsp), %r14
movq %r14, %rsi
xorl %edx, %edx
callq 0x73f2e
movq %r14, %rdi
callq 0x5b268
cmpl $0x3, 0x1614(%rbx)
jb 0x70344
movq %r13, %rdi
leaq 0x6ea08(%rip), %rsi     # 0xded3f
callq 0x289f0
movq %rax, %rdi
callq 0x284a0
leaq 0x30(%rsp), %rdi
callq 0x295a0
leaq 0x10(%rsp), %rdi
callq 0x295a0
jmp 0x70002
leaq 0x30(%rsp), %rdi
callq 0x295a0
leaq 0x10(%rsp), %rdi
callq 0x295a0
leaq 0x50(%rsp), %rdi
callq 0x5b268
addq $0x128, %rsp            # imm = 0x128
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
leaq 0x88(%rsp), %rdi
callq 0x295a0
jmp 0x703bb
jmp 0x703b8
movq %rax, %rbx
leaq 0x30(%rsp), %rdi
jmp 0x703c0
movq %rax, %rbx
leaq 0xa8(%rsp), %rdi
jmp 0x703c0
movq %rax, %rbx
leaq 0x10(%rsp), %rdi
callq 0x295a0
jmp 0x70446
movq %rax, %rbx
leaq 0x70(%rsp), %rdi
callq 0x5b268
jmp 0x70428
jmp 0x70419
movq %rax, %rbx
jmp 0x703ed
movq %rax, %rbx
leaq 0x108(%rsp), %rdi
callq 0x295a0
leaq 0xe8(%rsp), %rdi
jmp 0x7042d
movq %rax, %rbx
leaq 0xc8(%rsp), %rdi
callq 0x295a0
jmp 0x70428
jmp 0x70420
jmp 0x70420
movq %rax, %rbx
leaq 0x30(%rsp), %rdi
jmp 0x70437
jmp 0x70419
movq %rax, %rbx
jmp 0x70432
jmp 0x70425
movq %rax, %rbx
jmp 0x7043c
movq %rax, %rbx
leaq 0x30(%rsp), %rdi
callq 0x295a0
leaq 0x10(%rsp), %rdi
callq 0x295a0
leaq 0x50(%rsp), %rdi
callq 0x5b268
movq %rbx, %rdi
callq 0x292f0