// File: richardposner[P]BioNetFit2/src/code/Swarm.cpp
// Function: Swarm::runSGA()
void Swarm::runSGA() {
	if (options.verbosity >= 3) {
		cout << "Running synchronous genetic fit" << endl;
	}

	if (!checkIfFileExists(options.jobOutputDir + "1")) {
		string createDirCmd = "mkdir " + options.jobOutputDir + "1";
		if (runCommand(createDirCmd) != 0) {
			outputError("Error: Couldn't create first generation output directory with command: " + createDirCmd + ". Quitting.");
		}
	}

	bool stopCriteria = false;
	while (!stopCriteria){
		//cout << "RAQUEL: starting runGeneration" << endl;
		runGeneration();
		//cout << "RAQUEL: finished runGeneration" << endl;
		//cout << "RAQUEL: starting checkStopCriteria" << endl;
		//cout << "RAQUEL: STOP CRITERIA value" << stopCriteria << endl;
		//cout << "RAQUEL: starting saveSwarmState" << endl;

		saveSwarmState();
		//cout << "RAQUEL: finished saveSwarmState" << endl;

		string currentDirectory = options.jobOutputDir + toString(currentGeneration);
		if (options.deleteOldFiles) {
			//cout << "RAQUEL: starting cleanupFiles" << endl;

			cleanupFiles(currentDirectory.c_str());
			//cout << "RAQUEL: finished cleanupFiles" << endl;

		}

		string outputPath = options.jobOutputDir + toString(currentGeneration - 1 ) + "_summary.txt";
		cout << "Generation: " << toString(currentGeneration - 1 ) << endl;
		//cout << "RAQUEL: starting outputRunSummary from runSGA" << endl;

		outputRunSummary(outputPath);
		if(options.verbosity>=3){
			cout << "RAQUEL: finished outputRunSummary from runSGA" << endl;
			//cout << "RAQUEL: starting breedGenerationGA from runSGA" << endl;
		}
		stopCriteria = checkStopCriteria();

		if (!stopCriteria) {

			breedGenerationGA();
			if(options.verbosity>=3){

				cout << "Finished breedGenerationGA from runSGA" << endl;
			}
		}
	}
	//cout << "RAQUEL: got out from WHILE STOP CRITERIA" << endl;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x260, %rsp            # imm = 0x260
movq %rdi, -0x8(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x1e8(%rbp)
cmpl $0x3, 0x1614(%rax)
jb 0xf0235
movq 0x1e4d36(%rip), %rdi    # 0x2d4f50
leaq 0xf30cc(%rip), %rsi     # 0x1e32ed
callq 0x2ff50
movq %rax, %rdi
movq 0x1e4d98(%rip), %rsi    # 0x2d4fc8
callq 0x30c10
movq -0x1e8(%rbp), %rsi
addq $0x1520, %rsi           # imm = 0x1520
leaq 0xf4c34(%rip), %rdx     # 0x1e4e7e
leaq -0x28(%rbp), %rdi
movq %rdi, -0x1f8(%rbp)
callq 0x447b0
movq -0x1f8(%rbp), %rdi
callq 0x17d410
movl %eax, -0x1ec(%rbp)
jmp 0xf026e
movl -0x1ec(%rbp), %eax
cmpl $0x0, %eax
setne %al
xorb $-0x1, %al
movb %al, -0x1f9(%rbp)
leaq -0x28(%rbp), %rdi
callq 0x311e8
movb -0x1f9(%rbp), %al
testb $0x1, %al
jne 0xf029a
jmp 0xf0432
movq -0x1e8(%rbp), %rdx
addq $0x1520, %rdx           # imm = 0x1520
leaq 0xea4e8(%rip), %rsi     # 0x1da797
leaq -0x78(%rbp), %rdi
movq %rdi, -0x208(%rbp)
callq 0x44240
movq -0x208(%rbp), %rsi
leaq 0xf4bb1(%rip), %rdx     # 0x1e4e7e
leaq -0x58(%rbp), %rdi
callq 0x441f0
jmp 0xf02d8
leaq -0x78(%rbp), %rdi
callq 0x311e8
leaq -0x98(%rbp), %rdi
leaq -0x58(%rbp), %rsi
callq 0x2f300
jmp 0xf02f3
leaq -0x98(%rbp), %rdi
callq 0x17e3f0
movl %eax, -0x20c(%rbp)
jmp 0xf0307
leaq -0x98(%rbp), %rdi
callq 0x311e8
movl -0x20c(%rbp), %eax
cmpl $0x0, %eax
je 0xf0419
leaq 0xf2fe4(%rip), %rsi     # 0x1e330d
leaq -0xd8(%rbp), %rdi
leaq -0x58(%rbp), %rdx
callq 0x44240
jmp 0xf033b
leaq 0xf4322(%rip), %rdx     # 0x1e4664
leaq -0xb8(%rbp), %rdi
leaq -0xd8(%rbp), %rsi
callq 0x441f0
jmp 0xf0357
movq -0x1e8(%rbp), %rdi
leaq -0xb8(%rbp), %rsi
callq 0xeada0
jmp 0xf036c
leaq -0xb8(%rbp), %rdi
callq 0x311e8
leaq -0xd8(%rbp), %rdi
callq 0x311e8
jmp 0xf0419
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x30(%rbp)
movl %eax, -0x34(%rbp)
leaq -0x28(%rbp), %rdi
callq 0x311e8
jmp 0xf0825
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x30(%rbp)
movl %eax, -0x34(%rbp)
leaq -0x78(%rbp), %rdi
callq 0x311e8
jmp 0xf0825
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x30(%rbp)
movl %eax, -0x34(%rbp)
jmp 0xf0424
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x30(%rbp)
movl %eax, -0x34(%rbp)
leaq -0x98(%rbp), %rdi
callq 0x311e8
jmp 0xf0424
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x30(%rbp)
movl %eax, -0x34(%rbp)
jmp 0xf040b
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x30(%rbp)
movl %eax, -0x34(%rbp)
leaq -0xb8(%rbp), %rdi
callq 0x311e8
leaq -0xd8(%rbp), %rdi
callq 0x311e8
jmp 0xf0424
leaq -0x58(%rbp), %rdi
callq 0x311e8
jmp 0xf0432
leaq -0x58(%rbp), %rdi
callq 0x311e8
jmp 0xf0825
movb $0x0, -0xd9(%rbp)
movb -0xd9(%rbp), %al
xorb $-0x1, %al
testb $0x1, %al
jne 0xf044a
jmp 0xf081c
movq -0x1e8(%rbp), %rdi
callq 0x100a10
movq -0x1e8(%rbp), %rdi
callq 0x10f2c0
movq -0x1e8(%rbp), %rax
movq %rax, %rcx
addq $0x1520, %rcx           # imm = 0x1520
movq %rcx, -0x220(%rbp)
movl 0x13e8(%rax), %esi
leaq -0x120(%rbp), %rdi
movq %rdi, -0x218(%rbp)
callq 0x17e460
movq -0x220(%rbp), %rsi
movq -0x218(%rbp), %rdx
leaq -0x100(%rbp), %rdi
callq 0xb3380
jmp 0xf04af
leaq -0x120(%rbp), %rdi
callq 0x311e8
movq -0x1e8(%rbp), %rax
testb $0x1, 0x1646(%rax)
je 0xf0518
leaq -0x100(%rbp), %rdi
callq 0x2f290
movq -0x1e8(%rbp), %rdi
movq %rax, %rsi
callq 0x105080
jmp 0xf04e8
jmp 0xf0518
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x30(%rbp)
movl %eax, -0x34(%rbp)
leaq -0x120(%rbp), %rdi
callq 0x311e8
jmp 0xf0825
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x30(%rbp)
movl %eax, -0x34(%rbp)
jmp 0xf080e
movq -0x1e8(%rbp), %rax
movq %rax, %rcx
addq $0x1520, %rcx           # imm = 0x1520
movq %rcx, -0x228(%rbp)
movl 0x13e8(%rax), %esi
decl %esi
leaq -0x180(%rbp), %rdi
callq 0x17e460
jmp 0xf0546
movq -0x228(%rbp), %rsi
leaq -0x160(%rbp), %rdi
leaq -0x180(%rbp), %rdx
callq 0xb3380
jmp 0xf0562
leaq 0xf2dec(%rip), %rdx     # 0x1e3355
leaq -0x140(%rbp), %rdi
leaq -0x160(%rbp), %rsi
callq 0x441f0
jmp 0xf057e
leaq -0x160(%rbp), %rdi
callq 0x311e8
leaq -0x180(%rbp), %rdi
callq 0x311e8
movq 0x1e49b3(%rip), %rdi    # 0x2d4f50
leaq 0xf188e(%rip), %rsi     # 0x1e1e32
callq 0x2ff50
movq %rax, -0x230(%rbp)
jmp 0xf05b2
movq -0x1e8(%rbp), %rax
movl 0x13e8(%rax), %esi
decl %esi
leaq -0x1a0(%rbp), %rdi
callq 0x17e460
jmp 0xf05cf
movq -0x230(%rbp), %rdi
leaq -0x1a0(%rbp), %rsi
callq 0x2f780
movq %rax, -0x238(%rbp)
jmp 0xf05eb
movq -0x238(%rbp), %rdi
movq 0x1e49cf(%rip), %rsi    # 0x2d4fc8
callq 0x30c10
jmp 0xf0600
leaq -0x1a0(%rbp), %rdi
callq 0x311e8
leaq -0x1c0(%rbp), %rdi
leaq -0x140(%rbp), %rsi
callq 0x2f300
jmp 0xf0621
movq -0x1e8(%rbp), %rdi
leaq -0x1c0(%rbp), %rsi
callq 0x105530
jmp 0xf0636
leaq -0x1c0(%rbp), %rdi
callq 0x311e8
movq -0x1e8(%rbp), %rax
cmpl $0x3, 0x1614(%rax)
jb 0xf070e
movq 0x1e48f3(%rip), %rdi    # 0x2d4f50
leaq 0xf2cfe(%rip), %rsi     # 0x1e3362
callq 0x2ff50
movq %rax, -0x240(%rbp)
jmp 0xf0672
movq -0x240(%rbp), %rdi
movq 0x1e4948(%rip), %rsi    # 0x2d4fc8
callq 0x30c10
jmp 0xf0687
jmp 0xf070e
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x30(%rbp)
movl %eax, -0x34(%rbp)
jmp 0xf06b2
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x30(%rbp)
movl %eax, -0x34(%rbp)
leaq -0x160(%rbp), %rdi
callq 0x311e8
leaq -0x180(%rbp), %rdi
callq 0x311e8
jmp 0xf080e
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x30(%rbp)
movl %eax, -0x34(%rbp)
jmp 0xf0802
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x30(%rbp)
movl %eax, -0x34(%rbp)
leaq -0x1a0(%rbp), %rdi
callq 0x311e8
jmp 0xf0802
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x30(%rbp)
movl %eax, -0x34(%rbp)
leaq -0x1c0(%rbp), %rdi
callq 0x311e8
jmp 0xf0802
movq -0x1e8(%rbp), %rdi
callq 0xf99b0
movb %al, -0x241(%rbp)
jmp 0xf0722
movb -0x241(%rbp), %al
andb $0x1, %al
movb %al, -0xd9(%rbp)
testb $0x1, -0xd9(%rbp)
jne 0xf07e5
xorps %xmm0, %xmm0
movaps %xmm0, -0x1e0(%rbp)
movq $0x0, -0x1d0(%rbp)
leaq -0x1e0(%rbp), %rdi
movq %rdi, -0x250(%rbp)
callq 0xb2010
movq -0x1e8(%rbp), %rdi
movq -0x250(%rbp), %rsi
callq 0x110510
jmp 0xf077a
leaq -0x1e0(%rbp), %rdi
callq 0xb2400
movq -0x1e8(%rbp), %rax
cmpl $0x3, 0x1614(%rax)
jb 0xf07e3
movq 0x1e47b3(%rip), %rdi    # 0x2d4f50
leaq 0xf2bec(%rip), %rsi     # 0x1e3390
callq 0x2ff50
movq %rax, -0x258(%rbp)
jmp 0xf07b2
movq -0x258(%rbp), %rdi
movq 0x1e4808(%rip), %rsi    # 0x2d4fc8
callq 0x30c10
jmp 0xf07c7
jmp 0xf07e3
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x30(%rbp)
movl %eax, -0x34(%rbp)
leaq -0x1e0(%rbp), %rdi
callq 0xb2400
jmp 0xf0802
jmp 0xf07e5
leaq -0x140(%rbp), %rdi
callq 0x311e8
leaq -0x100(%rbp), %rdi
callq 0x311e8
jmp 0xf0439
leaq -0x140(%rbp), %rdi
callq 0x311e8
leaq -0x100(%rbp), %rdi
callq 0x311e8
jmp 0xf0825
addq $0x260, %rsp            # imm = 0x260
popq %rbp
retq
movq -0x30(%rbp), %rdi
callq 0x30170
nop