// File: /workspace/github_cpp_makefile_star2_O2/samuel500[P]NEAT/population.cpp
// Function: Population::Population(int, int, int)
Population::Population(int popsize, int insize, int outsize): pop_size(popsize), in_size(insize), out_size(outsize){

	generation = 0;

	max_fitness = 0;

	innov_num = new int;
	*innov_num = in_size+out_size;


	cout << "pop size " << pop_size << endl;

	cout << "innov_num " << *innov_num << endl;

	Individual *new_individual;

	Individual *cp_ind;

	bool activated;

	for(int i=0; i<pop_size; ++i){

		activated = false;

		new_individual = new Individual(&in_size, &out_size, &generation, innov_num); //, &all_nodes, &all_connections);
		// cout << "p1" << endl;

		new_individual->mutate_add_connection(&all_nodes, &all_connections);
		new_individual->mutate_add_node(&all_nodes, &all_connections);


		vector<Connection*>::iterator conPtr;
		vector<Node*>::iterator nodePtr;
		// cout << "p2" << endl;

		for(conPtr=new_individual->connections.begin(); conPtr!=new_individual->connections.end(); ++conPtr){
			all_connections.push_back((*conPtr));
		}
		// cout << "p3" << endl;

		for(nodePtr=new_individual->nodes.begin(); nodePtr!=new_individual->nodes.end(); ++nodePtr){
			all_nodes.push_back((*nodePtr));
		}


		// testing

		vector<double> inp = {1., 0.5, 0.1}; 

		activated = new_individual->activate(inp);
		// cout << "p4" << endl;

		if(!activated) cout<<"error, individual failed to activate"<<endl;

		vector<double> out = new_individual->get_outputs();
		// cout<<  "or"<<out[0]<<endl;

		new_individual->reset_activations();


		// cout << "p4" << endl;


		individuals.push_back(new_individual);

	}


}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x88, %rsp
movl %ecx, %r12d
movl %edx, %r13d
movq %rdi, %r15
leaq 0x18(%rdi), %rax
movq %rax, -0x40(%rbp)
xorps %xmm0, %xmm0
movups %xmm0, 0x50(%rdi)
andq $0x0, 0x60(%rdi)
movups %xmm0, (%rdi)
movups %xmm0, 0x10(%rdi)
andq $0x0, 0x40(%rdi)
movups %xmm0, 0x20(%rdi)
movups %xmm0, 0x30(%rdi)
movl %esi, 0x68(%rdi)
movl %edx, 0x6c(%rdi)
movl %ecx, 0x70(%rdi)
andl $0x0, 0x74(%rdi)
leaq 0x30(%rdi), %rax
movq %rax, -0x48(%rbp)
andq $0x0, 0x80(%rdi)
pushq $0x4
popq %rdi
callq 0x10f0
movq %rax, 0x78(%r15)
addl %r13d, %r12d
movl %r12d, (%rax)
movq 0x9995(%rip), %rdi      # 0xafd8
leaq 0x59f2(%rip), %rsi      # 0x703c
callq 0x10e0
movl 0x68(%r15), %esi
movq %rax, %rdi
callq 0x1170
movq %rax, %rdi
callq 0x1070
movq 0x996e(%rip), %rdi      # 0xafd8
leaq 0x59b2(%rip), %rsi      # 0x7023
callq 0x10e0
movq 0x78(%r15), %rcx
movl (%rcx), %esi
movq %rax, %rdi
callq 0x1170
movq %rax, %rdi
callq 0x1070
leaq 0x6c(%r15), %rax
movq %rax, -0x78(%rbp)
leaq 0x70(%r15), %rax
movq %rax, -0x70(%rbp)
leaq 0x74(%r15), %rax
movq %rax, -0x68(%rbp)
xorl %r13d, %r13d
leaq -0xa8(%rbp), %r14
cmpl 0x68(%r15), %r13d
jge 0x17fd
movl $0x98, %edi
callq 0x10f0
movq %rax, %r12
movq 0x78(%r15), %r8
movq %rax, %rdi
movq -0x78(%rbp), %rsi
movq -0x70(%rbp), %rdx
movq -0x68(%rbp), %rcx
callq 0x536c
movq %r12, -0x30(%rbp)
movq %r12, %rdi
movq -0x40(%rbp), %rsi
movq -0x48(%rbp), %rdx
callq 0x5c24
movq -0x30(%rbp), %rdi
movq -0x40(%rbp), %rsi
movq -0x48(%rbp), %rdx
callq 0x59d6
movq -0x30(%rbp), %rax
movq 0x60(%rax), %r12
cmpq 0x68(%rax), %r12
je 0x1726
movq -0x48(%rbp), %rdi
movq %r12, %rsi
callq 0x2248
addq $0x8, %r12
movq -0x30(%rbp), %rax
jmp 0x170a
movq 0x18(%rax), %r12
cmpq 0x20(%rax), %r12
je 0x1746
movq -0x40(%rbp), %rdi
movq %r12, %rsi
callq 0x226c
addq $0x8, %r12
movq -0x30(%rbp), %rax
jmp 0x172a
movups 0x59f3(%rip), %xmm0     # 0x7140
movaps %xmm0, -0x60(%rbp)
movabsq $0x3fb999999999999a, %rax # imm = 0x3FB999999999999A
movq %rax, -0x50(%rbp)
leaq -0x90(%rbp), %rbx
movq %rbx, %rdi
leaq -0x60(%rbp), %rsi
pushq $0x3
popq %rdx
leaq -0x31(%rbp), %rcx
callq 0x2290
movq -0x30(%rbp), %r12
movq %r14, %rdi
movq %rbx, %rsi
callq 0x22c6
movq %r12, %rdi
movq %r14, %rsi
callq 0x5788
movl %eax, %r12d
movq %r14, %rdi
callq 0x2914
testb %r12b, %r12b
jne 0x17be
movq 0x982e(%rip), %rdi      # 0xafd8
leaq 0x58ef(%rip), %rsi      # 0x70a0
callq 0x10e0
movq %rax, %rdi
callq 0x1070
movq -0x30(%rbp), %rsi
leaq -0x60(%rbp), %rdi
callq 0x5864
movq -0x30(%rbp), %rdi
callq 0x58c0
movq %r15, %rdi
leaq -0x30(%rbp), %rsi
callq 0x231e
leaq -0x60(%rbp), %rdi
callq 0x2914
leaq -0x90(%rbp), %rdi
callq 0x2914
incl %r13d
jmp 0x16ae
addq $0x88, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x1856
movq %rax, %r14
leaq -0xa8(%rbp), %rdi
jmp 0x183f
jmp 0x1856
jmp 0x1833
movq %rax, %r14
movl $0x98, %esi
movq %r12, %rdi
callq 0x1100
jmp 0x1859
movq %rax, %r14
jmp 0x1844
movq %rax, %r14
leaq -0x60(%rbp), %rdi
callq 0x2914
leaq -0x90(%rbp), %rdi
callq 0x2914
jmp 0x1859
jmp 0x1856
jmp 0x1856
movq %rax, %r14
leaq 0x50(%r15), %rdi
callq 0x25c2
movq -0x48(%rbp), %rdi
callq 0x2584
movq -0x40(%rbp), %rdi
callq 0x2546
movq %r15, %rdi
callq 0x2508
movq %r14, %rdi
callq 0x1180