// File: richardposner[P]BioNetFit2/src/code/Swarm.cpp
// Function: Swarm::Swarm()
Swarm::Swarm() {

	// Whether or not we are master
	isMaster = false;
	resumingSavedSwarm = false;
	swarmComm = 0;
	fitCompareTolerance = 1e-6;
	bootstrapCounter = 0;
	commInit = false;
	verbose = false;  //razi added for debugging

	options.jobName = "";
	options.fitType = "";
	options.outputDir = "";
	options.bngCommand = "";
	options.outputEvery = 100;

	options.models.clear();
	options.defaultModel = -1;
	sConf_.clear();

	options.synchronicity = 0;
	options.maxGenerations = 0;
	options.swarmSize = 0;
	options.minFit = 0;
	options.bootstrap = 0;
	options.parallelCount = 0;
	options.seed = 0;

	options.useCluster = false;
	options.saveClusterOutput = false;
	options.emailWhenFinished = false;
	options.emailAddress = "";

	options.usePipes = false;
	options.divideByInit = false;
	options.logTransformSimData = false;
	options.standardizeSimData = false;
	options.standardizeExpData = false;

	options.deleteOldFiles = true;
	options.objFunc = 1;
	options.extraWeight = 0;
	options.swapRate = 0.5;
	options.forceDifferentParents = true;
	options.maxRetryDifferentParents = 100;
	options.smoothing = 1;
	options.keepParents = 0;

	//options.maxFitTime = MAX_LONG;
	options.maxFitTime = std::string("700:00:00");
	options.maxNumSimulations = MAX_LONG;

	// PSO options
	options.inertia = 0.72; // 0.72
	options.cognitive = 1.49; // 1.49
	options.social = 1.49; // 1.49
	options.nmax = 0; // 20
	options.nmin = 80; // 80
	options.inertiaInit = 1; // 1
	options.inertiaFinal = 0.1; // 0.1
	options.absTolerance = 10e-4; // 10E-4
	options.relTolerance = 10e-4; // 10E-4
	options.mutateQPSO = false;
	options.betaMin = 0.5;
	options.betaMax = 1.0;

	options.topology = "fullyconnected"; // fullyconnected
	options.psoType = "pso"; // pso

	options.enhancedStop = false; // true
	options.enhancedInertia = false; // true

	options.numIslands = 0;

	options.minTemp = pow(10, -10);
	options.minRadius = pow(10, -6);
	options.localSearchProbability = 0.01;
	options.randParamsProbability = 0.1;

	options.verbosity = 1;
	hasMutate = false;

	currentGeneration = 0;

	/*
	std::map<int, double> particleBestFits_;
	std::map<int, std::vector<double> > particleBestParamSets_;
	std::map<int, std::vector<double> > particleCurrParamSets_;
	std::map<int, double> particleWeights_;
	std::map<double, int> particleBestFitsByFit_;
	 */

	permanenceCounter_ = 0; // 0
	flightCounter_ = 0; // 0
	weightedAvgPos_ = 0; // 0
	optimum_ = 0; // 0
	inertiaUpdateCounter_ = 0; // 0;
	beta_ = 0.7;
	cauchyMutator_ = 0.2;

	auto seed = chrono::high_resolution_clock::now().time_since_epoch().count();
	generalRand.seed(seed);
	generalRand.discard(700000);

	/*
	if (options.seed) {
		generalRand.seed(options.seed);
		generalRand.discard(700000);

		srand(options.seed);
	}
	else {
		// TODO: Make sure everything is being seeded properly and in the proper place. Also let's do away with rand()
		// Seed our random number engine
		auto seed = chrono::high_resolution_clock::now().time_since_epoch().count();
		generalRand.seed(seed);
		generalRand.discard(700000);

		srand (std::tr1::random_device{}());
	}
	 */

}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x1e0, %rsp            # imm = 0x1E0
movq %rdi, -0x8(%rbp)
movq -0x8(%rbp), %rdi
movq %rdi, -0x68(%rbp)
addq $0x8, %rdi
movq %rdi, -0x78(%rbp)
callq 0x120be0
movq -0x68(%rbp), %rdi
addq $0x38, %rdi
movq %rdi, -0x70(%rbp)
callq 0x44da0
movq -0x68(%rbp), %rdi
addq $0x58, %rdi
callq 0x120c00
jmp 0xe8db4
movq -0x68(%rbp), %rdi
addq $0xa20, %rdi            # imm = 0xA20
callq 0x120c00
jmp 0xe8dc6
movq -0x68(%rbp), %rdi
addq $0x1400, %rdi           # imm = 0x1400
movq %rdi, -0x1a8(%rbp)
callq 0xde640
movq -0x68(%rbp), %rdi
addq $0x1430, %rdi           # imm = 0x1430
movq %rdi, -0x1a0(%rbp)
callq 0xde640
movq -0x68(%rbp), %rdi
addq $0x1460, %rdi           # imm = 0x1460
movq %rdi, -0x198(%rbp)
callq 0x120c20
movq -0x68(%rbp), %rdi
addq $0x1490, %rdi           # imm = 0x1490
movq %rdi, -0x190(%rbp)
callq 0x120c20
movq -0x68(%rbp), %rdi
addq $0x14c0, %rdi           # imm = 0x14C0
movq %rdi, -0x188(%rbp)
callq 0x120c40
movq -0x68(%rbp), %rdi
addq $0x17e0, %rdi           # imm = 0x17E0
movq %rdi, -0x180(%rbp)
callq 0x2f880
movq -0x68(%rbp), %rdi
addq $0x1800, %rdi           # imm = 0x1800
movq %rdi, -0x178(%rbp)
callq 0x2f880
movq -0x68(%rbp), %rdi
addq $0x1820, %rdi           # imm = 0x1820
movq %rdi, -0x170(%rbp)
callq 0x120d70
movq -0x68(%rbp), %rdi
addq $0x1850, %rdi           # imm = 0x1850
callq 0x120d90
movq -0x68(%rbp), %rdi
addq $0x1858, %rdi           # imm = 0x1858
movq %rdi, -0x168(%rbp)
callq 0x120d70
movq -0x68(%rbp), %rdi
addq $0x1888, %rdi           # imm = 0x1888
callq 0x120d90
movq -0x68(%rbp), %rdi
addq $0x1890, %rdi           # imm = 0x1890
movq %rdi, -0x160(%rbp)
callq 0x120d70
movq -0x68(%rbp), %rdi
addq $0x18c0, %rdi           # imm = 0x18C0
movq %rdi, -0x158(%rbp)
callq 0x120d70
movq -0x68(%rbp), %rdi
addq $0x18f0, %rdi           # imm = 0x18F0
movq %rdi, -0x150(%rbp)
callq 0x120db0
movq -0x68(%rbp), %rdi
addq $0x1908, %rdi           # imm = 0x1908
movq %rdi, -0x148(%rbp)
callq 0x120dd0
movq -0x68(%rbp), %rdi
addq $0x1938, %rdi           # imm = 0x1938
movq %rdi, -0x140(%rbp)
callq 0x448b0
movq -0x68(%rbp), %rdi
addq $0x1950, %rdi           # imm = 0x1950
movq %rdi, -0x138(%rbp)
callq 0x120df0
movq -0x68(%rbp), %rdi
addq $0x1980, %rdi           # imm = 0x1980
movq %rdi, -0x130(%rbp)
callq 0x120e10
movq -0x68(%rbp), %rdi
addq $0x1998, %rdi           # imm = 0x1998
movq %rdi, -0x128(%rbp)
callq 0x120d70
movq -0x68(%rbp), %rdi
addq $0x19c8, %rdi           # imm = 0x19C8
callq 0x120d90
movq -0x68(%rbp), %rdi
addq $0x19d0, %rdi           # imm = 0x19D0
movq %rdi, -0x120(%rbp)
callq 0x120d70
movq -0x68(%rbp), %rdi
addq $0x1a00, %rdi           # imm = 0x1A00
callq 0x120d90
movq -0x68(%rbp), %rdi
addq $0x1a08, %rdi           # imm = 0x1A08
movq %rdi, -0x118(%rbp)
callq 0x120e30
movq -0x68(%rbp), %rdi
addq $0x1a20, %rdi           # imm = 0x1A20
movq %rdi, -0x110(%rbp)
callq 0x120e50
movq -0x68(%rbp), %rdi
addq $0x1a50, %rdi           # imm = 0x1A50
movq %rdi, -0x108(%rbp)
callq 0x120e50
movq -0x68(%rbp), %rdi
addq $0x1a80, %rdi           # imm = 0x1A80
movq %rdi, -0x100(%rbp)
callq 0x120e50
movq -0x68(%rbp), %rdi
addq $0x1ab0, %rdi           # imm = 0x1AB0
movq %rdi, -0xf8(%rbp)
callq 0x120e70
movq -0x68(%rbp), %rdi
addq $0x1ae0, %rdi           # imm = 0x1AE0
movq %rdi, -0xf0(%rbp)
callq 0x120e70
movq -0x68(%rbp), %rdi
addq $0x1b10, %rdi           # imm = 0x1B10
movq %rdi, -0xe8(%rbp)
callq 0x120e70
movq -0x68(%rbp), %rdi
addq $0x1b40, %rdi           # imm = 0x1B40
movq %rdi, -0xe0(%rbp)
callq 0x120e70
movq -0x68(%rbp), %rdi
addq $0x1b70, %rdi           # imm = 0x1B70
movq %rdi, -0xd8(%rbp)
callq 0x120e70
movq -0x68(%rbp), %rdi
addq $0x1ba0, %rdi           # imm = 0x1BA0
movq %rdi, -0xd0(%rbp)
callq 0x120e70
movq -0x68(%rbp), %rdi
addq $0x1bd0, %rdi           # imm = 0x1BD0
movq %rdi, -0xc8(%rbp)
callq 0x120e70
movq -0x68(%rbp), %rdi
addq $0x1c00, %rdi           # imm = 0x1C00
movq %rdi, -0xc0(%rbp)
callq 0x120e70
movq -0x68(%rbp), %rdi
addq $0x1c30, %rdi           # imm = 0x1C30
movq %rdi, -0xb8(%rbp)
callq 0x120e70
movq -0x68(%rbp), %rdi
addq $0x1c60, %rdi           # imm = 0x1C60
movq %rdi, -0xb0(%rbp)
callq 0x120e70
movq -0x68(%rbp), %rdi
addq $0x1c90, %rdi           # imm = 0x1C90
movq %rdi, -0xa8(%rbp)
callq 0xde640
movq -0x68(%rbp), %rdi
addq $0x1cc0, %rdi           # imm = 0x1CC0
movq %rdi, -0xa0(%rbp)
callq 0xde640
movq -0x68(%rbp), %rdi
addq $0x1cf0, %rdi           # imm = 0x1CF0
movq %rdi, -0x98(%rbp)
callq 0x120e50
movq -0x68(%rbp), %rdi
addq $0x1d20, %rdi           # imm = 0x1D20
movq %rdi, -0x90(%rbp)
callq 0xb2010
movq -0x68(%rbp), %rdi
addq $0x1d38, %rdi           # imm = 0x1D38
movq %rdi, -0x88(%rbp)
callq 0x120e30
movq -0x68(%rbp), %rdi
addq $0x1d50, %rdi           # imm = 0x1D50
movq %rdi, -0x80(%rbp)
callq 0xde640
movq -0x68(%rbp), %rdi
addq $0x1db0, %rdi           # imm = 0x1DB0
callq 0x120e90
jmp 0xe917f
movq -0x68(%rbp), %rdi
addq $0x1db8, %rdi           # imm = 0x1DB8
callq 0x120e90
jmp 0xe9191
movq -0x68(%rbp), %rdi
movb $0x0, 0x50(%rdi)
movb $0x0, 0x13f0(%rdi)
movq $0x0, (%rdi)
movl $0x358637bd, 0x13f4(%rdi) # imm = 0x358637BD
movl $0x0, 0x13ec(%rdi)
movb $0x0, 0x13f8(%rdi)
movb $0x0, 0x13f9(%rdi)
addq $0x14c0, %rdi           # imm = 0x14C0
leaq 0xf0329(%rip), %rsi     # 0x1d9500
callq 0x2f9d0
jmp 0xe91de
movq -0x68(%rbp), %rdi
addq $0x14e0, %rdi           # imm = 0x14E0
leaq 0xf0310(%rip), %rsi     # 0x1d9500
callq 0x2f9d0
jmp 0xe91f7
movq -0x68(%rbp), %rdi
addq $0x1500, %rdi           # imm = 0x1500
leaq 0xf02f7(%rip), %rsi     # 0x1d9500
callq 0x2f9d0
jmp 0xe9210
movq -0x68(%rbp), %rdi
addq $0x1540, %rdi           # imm = 0x1540
leaq 0xf02de(%rip), %rsi     # 0x1d9500
callq 0x2f9d0
jmp 0xe9229
movq -0x68(%rbp), %rdi
movl $0x64, 0x1728(%rdi)
addq $0x15c0, %rdi           # imm = 0x15C0
callq 0xb2070
movq -0x68(%rbp), %rdi
movl $0xffffffff, 0x15d8(%rdi) # imm = 0xFFFFFFFF
addq $0x1938, %rdi           # imm = 0x1938
callq 0x451d0
movq -0x68(%rbp), %rdi
movb $0x0, 0x1618(%rdi)
movl $0x0, 0x161c(%rdi)
movl $0x0, 0x1620(%rdi)
movl $0x0, 0x1624(%rdi)
movl $0x0, 0x1638(%rdi)
movl $0x0, 0x1628(%rdi)
movl $0x0, 0x1634(%rdi)
movb $0x0, 0x1631(%rdi)
movb $0x0, 0x1770(%rdi)
movb $0x0, 0x1798(%rdi)
addq $0x17a0, %rdi           # imm = 0x17A0
leaq 0xf0239(%rip), %rsi     # 0x1d9500
callq 0x2f9d0
jmp 0xe92ce
movq -0x68(%rbp), %rax
movb $0x0, 0x1630(%rax)
movb $0x0, 0x163c(%rax)
movl $0x0, 0x1640(%rax)
movb $0x0, 0x1644(%rax)
movb $0x0, 0x1645(%rax)
movb $0x1, 0x1646(%rax)
movl $0x1, 0x162c(%rax)
movl $0x0, 0x1648(%rax)
movl $0x3f000000, 0x164c(%rax) # imm = 0x3F000000
movb $0x1, 0x1650(%rax)
movl $0x64, 0x1654(%rax)
movl $0x1, 0x1658(%rax)
movl $0x0, 0x165c(%rax)
leaq -0x39(%rbp), %rdi
movq %rdi, -0x1b0(%rbp)
callq 0x30a70
movq -0x1b0(%rbp), %rdx
leaq 0xf7b74(%rip), %rsi     # 0x1e0ed4
leaq -0x38(%rbp), %rdi
callq 0x44470
jmp 0xe936b
movq -0x68(%rbp), %rdi
addq $0x1660, %rdi           # imm = 0x1660
leaq -0x38(%rbp), %rsi
movq %rsi, -0x1b8(%rbp)
callq 0x2fd80
movq -0x1b8(%rbp), %rdi
callq 0x311e8
leaq -0x39(%rbp), %rdi
callq 0x311c0
movq -0x68(%rbp), %rdi
movabsq $0x7fffffffffffffff, %rax # imm = 0x7FFFFFFFFFFFFFFF
movq %rax, 0x1680(%rdi)
movl $0x3f3851ec, 0x1688(%rdi) # imm = 0x3F3851EC
movl $0x3fbeb852, 0x168c(%rdi) # imm = 0x3FBEB852
movl $0x3fbeb852, 0x1690(%rdi) # imm = 0x3FBEB852
movl $0x0, 0x1694(%rdi)
movl $0x50, 0x1698(%rdi)
movl $0x3f800000, 0x169c(%rdi) # imm = 0x3F800000
movl $0x3dcccccd, 0x16a0(%rdi) # imm = 0x3DCCCCCD
movl $0x3a83126f, 0x16a4(%rdi) # imm = 0x3A83126F
movl $0x3a83126f, 0x16a8(%rdi) # imm = 0x3A83126F
movb $0x0, 0x16ac(%rdi)
movl $0x3f000000, 0x16b4(%rdi) # imm = 0x3F000000
movl $0x3f800000, 0x16b0(%rdi) # imm = 0x3F800000
addq $0x16b8, %rdi           # imm = 0x16B8
leaq 0xf7aab(%rip), %rsi     # 0x1e0ede
callq 0x2f9d0
jmp 0xe943a
movq -0x68(%rbp), %rdi
addq $0x16d8, %rdi           # imm = 0x16D8
leaq 0xf85f6(%rip), %rsi     # 0x1e1a42
callq 0x2f9d0
jmp 0xe9453
movq -0x68(%rbp), %rax
movb $0x0, 0x16f8(%rax)
movb $0x0, 0x16f9(%rax)
movl $0x0, 0x16fc(%rax)
movl $0xa, %edi
movl $0xfffffff6, %esi       # imm = 0xFFFFFFF6
callq 0xb3030
movsd %xmm0, -0x1c0(%rbp)
jmp 0xe9488
movq -0x68(%rbp), %rax
movsd -0x1c0(%rbp), %xmm0
movsd %xmm0, 0x1710(%rax)
movl $0xa, %edi
movl $0xfffffffa, %esi       # imm = 0xFFFFFFFA
callq 0xb3030
movsd %xmm0, -0x1c8(%rbp)
jmp 0xe94b5
movq -0x68(%rbp), %rax
movsd -0x1c8(%rbp), %xmm0
movsd %xmm0, 0x1718(%rax)
movl $0x3c23d70a, 0x1720(%rax) # imm = 0x3C23D70A
movl $0x3dcccccd, 0x1724(%rax) # imm = 0x3DCCCCCD
movl $0x1, 0x1614(%rax)
movb $0x0, 0x13f1(%rax)
movl $0x0, 0x13e8(%rax)
movl $0x0, 0x1d80(%rax)
movl $0x0, 0x1d84(%rax)
movq $0x0, 0x1d88(%rax)
movq $0x0, 0x1d90(%rax)
movl $0x0, 0x1d98(%rax)
movabsq $0x3fe6666666666666, %rcx # imm = 0x3FE6666666666666
movq %rcx, 0x1da0(%rax)
movabsq $0x3fc999999999999a, %rcx # imm = 0x3FC999999999999A
movq %rcx, 0x1da8(%rax)
callq 0x30330
movq %rax, -0x58(%rbp)
leaq -0x58(%rbp), %rdi
callq 0x120ec0
movq %rax, -0x1d0(%rbp)
jmp 0xe9569
movq -0x1d0(%rbp), %rax
movq %rax, -0x50(%rbp)
leaq -0x50(%rbp), %rdi
callq 0x120ee0
movq %rax, -0x1d8(%rbp)
jmp 0xe9586
movq -0x68(%rbp), %rdi
movq -0x1d8(%rbp), %rax
movq %rax, -0x48(%rbp)
addq $0x58, %rdi
movl -0x48(%rbp), %eax
movl %eax, -0x5c(%rbp)
leaq -0x5c(%rbp), %rsi
callq 0x120f00
jmp 0xe95aa
movq -0x68(%rbp), %rdi
addq $0x58, %rdi
movl $0xaae60, %esi          # imm = 0xAAE60
callq 0x120fc0
jmp 0xe95be
addq $0x1e0, %rsp            # imm = 0x1E0
popq %rbp
retq
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x10(%rbp)
movl %eax, -0x14(%rbp)
jmp 0xe97c0
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x10(%rbp)
movl %eax, -0x14(%rbp)
jmp 0xe95fb
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x10(%rbp)
movl %eax, -0x14(%rbp)
leaq -0x39(%rbp), %rdi
callq 0x311c0
movq -0x80(%rbp), %rdi
callq 0xdeb00
movq -0x88(%rbp), %rdi
callq 0x121030
movq -0x90(%rbp), %rdi
callq 0xb2400
movq -0x98(%rbp), %rdi
callq 0x121090
movq -0xa0(%rbp), %rdi
callq 0xdeb00
movq -0xa8(%rbp), %rdi
callq 0xdeb00
movq -0xb0(%rbp), %rdi
callq 0x1210b0
movq -0xb8(%rbp), %rdi
callq 0x1210b0
movq -0xc0(%rbp), %rdi
callq 0x1210b0
movq -0xc8(%rbp), %rdi
callq 0x1210b0
movq -0xd0(%rbp), %rdi
callq 0x1210b0
movq -0xd8(%rbp), %rdi
callq 0x1210b0
movq -0xe0(%rbp), %rdi
callq 0x1210b0
movq -0xe8(%rbp), %rdi
callq 0x1210b0
movq -0xf0(%rbp), %rdi
callq 0x1210b0
movq -0xf8(%rbp), %rdi
callq 0x1210b0
movq -0x100(%rbp), %rdi
callq 0x121090
movq -0x108(%rbp), %rdi
callq 0x121090
movq -0x110(%rbp), %rdi
callq 0x121090
movq -0x118(%rbp), %rdi
callq 0x121030
movq -0x120(%rbp), %rdi
callq 0x1210d0
movq -0x128(%rbp), %rdi
callq 0x1210d0
movq -0x130(%rbp), %rdi
callq 0x1210f0
movq -0x138(%rbp), %rdi
callq 0x121150
movq -0x140(%rbp), %rdi
callq 0x448d0
movq -0x148(%rbp), %rdi
callq 0x121170
movq -0x150(%rbp), %rdi
callq 0x121190
movq -0x158(%rbp), %rdi
callq 0x1210d0
movq -0x160(%rbp), %rdi
callq 0x1210d0
movq -0x168(%rbp), %rdi
callq 0x1210d0
movq -0x170(%rbp), %rdi
callq 0x1210d0
movq -0x178(%rbp), %rdi
callq 0x311e8
movq -0x180(%rbp), %rdi
callq 0x311e8
movq -0x188(%rbp), %rdi
callq 0x1211f0
movq -0x190(%rbp), %rdi
callq 0x121310
movq -0x198(%rbp), %rdi
callq 0x121310
movq -0x1a0(%rbp), %rdi
callq 0xdeb00
movq -0x1a8(%rbp), %rdi
callq 0xdeb00
movq -0x70(%rbp), %rdi
callq 0x45010
movq -0x78(%rbp), %rdi
callq 0x121330
movq -0x10(%rbp), %rdi
callq 0x30170
nopl (%rax,%rax)