// File: 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
subq $0x170, %rsp            # imm = 0x170
movq %rdi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
movl %edx, -0x10(%rbp)
movl %ecx, -0x14(%rbp)
movq -0x8(%rbp), %rdi
movq %rdi, -0xf8(%rbp)
movq %rdi, %rax
movq %rax, -0x118(%rbp)
callq 0x3930
movq -0xf8(%rbp), %rdi
addq $0x18, %rdi
movq %rdi, -0x110(%rbp)
callq 0x3950
movq -0xf8(%rbp), %rdi
addq $0x30, %rdi
movq %rdi, -0x108(%rbp)
callq 0x3970
movq -0xf8(%rbp), %rdi
addq $0x50, %rdi
movq %rdi, -0x100(%rbp)
callq 0x3990
movq -0xf8(%rbp), %rax
movl -0xc(%rbp), %ecx
movl %ecx, 0x68(%rax)
movl -0x10(%rbp), %ecx
movl %ecx, 0x6c(%rax)
movl -0x14(%rbp), %ecx
movl %ecx, 0x70(%rax)
movl $0x0, 0x74(%rax)
movq $0x0, 0x80(%rax)
movl $0x4, %edi
callq 0x10e0
movq %rax, -0xf0(%rbp)
jmp 0x1a45
movq -0x118(%rbp), %rax
movq -0xf0(%rbp), %rcx
movq %rcx, 0x78(%rax)
movl 0x6c(%rax), %ecx
movl 0x70(%rax), %edx
addl %edx, %ecx
movq 0x78(%rax), %rax
movl %ecx, (%rax)
movq 0x1c56c(%rip), %rdi     # 0x1dfd8
leaq 0x135c9(%rip), %rsi     # 0x1503c
callq 0x10d0
movq %rax, -0x120(%rbp)
jmp 0x1a81
movq -0x120(%rbp), %rdi
movq -0x118(%rbp), %rax
movl 0x68(%rax), %esi
callq 0x1160
movq %rax, -0x128(%rbp)
jmp 0x1aa0
movq -0x128(%rbp), %rdi
movq 0x1c51a(%rip), %rsi     # 0x1dfc8
callq 0x1100
jmp 0x1ab5
movq 0x1c51c(%rip), %rdi     # 0x1dfd8
leaq 0x13560(%rip), %rsi     # 0x15023
callq 0x10d0
movq %rax, -0x130(%rbp)
jmp 0x1ad1
movq -0x130(%rbp), %rdi
movq -0x118(%rbp), %rax
movq 0x78(%rax), %rax
movl (%rax), %esi
callq 0x1160
movq %rax, -0x138(%rbp)
jmp 0x1af3
movq -0x138(%rbp), %rdi
movq 0x1c4c7(%rip), %rsi     # 0x1dfc8
callq 0x1100
jmp 0x1b08
movl $0x0, -0x40(%rbp)
movq -0x118(%rbp), %rcx
movl -0x40(%rbp), %eax
cmpl 0x68(%rcx), %eax
jge 0x1ea5
movb $0x0, -0x39(%rbp)
movl $0x98, %edi
callq 0x10e0
movq %rax, -0x140(%rbp)
jmp 0x1b39
movq -0x140(%rbp), %rdi
movq -0x118(%rbp), %rax
movq %rax, %rsi
addq $0x6c, %rsi
movq %rax, %rdx
addq $0x70, %rdx
movq %rax, %rcx
addq $0x74, %rcx
movq 0x78(%rax), %r8
callq 0x11330
jmp 0x1b67
movq -0x118(%rbp), %rdx
movq -0x140(%rbp), %rax
movq %rax, -0x30(%rbp)
movq -0x30(%rbp), %rdi
movq %rdx, %rsi
addq $0x18, %rsi
addq $0x30, %rdx
callq 0x12570
jmp 0x1b8f
movq -0x118(%rbp), %rdx
movq -0x30(%rbp), %rdi
movq %rdx, %rsi
addq $0x18, %rsi
addq $0x30, %rdx
callq 0x120b0
jmp 0x1bac
leaq -0x48(%rbp), %rdi
callq 0x1800
leaq -0x50(%rbp), %rdi
callq 0x39b0
movq -0x30(%rbp), %rdi
addq $0x60, %rdi
callq 0x1820
movq %rax, -0x58(%rbp)
movq -0x58(%rbp), %rax
movq %rax, -0x48(%rbp)
movq -0x30(%rbp), %rdi
addq $0x60, %rdi
callq 0x1890
movq %rax, -0x60(%rbp)
leaq -0x48(%rbp), %rdi
leaq -0x60(%rbp), %rsi
callq 0x1850
testb $0x1, %al
jne 0x1bfb
jmp 0x1c67
movq -0x118(%rbp), %rax
addq $0x30, %rax
movq %rax, -0x148(%rbp)
leaq -0x48(%rbp), %rdi
callq 0x18c0
movq -0x148(%rbp), %rdi
movq %rax, %rsi
callq 0x39d0
jmp 0x1c27
jmp 0x1c29
leaq -0x48(%rbp), %rdi
callq 0x18e0
jmp 0x1bd7
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x20(%rbp)
movl %eax, -0x24(%rbp)
jmp 0x1eae
movq -0x140(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x20(%rbp)
movl %eax, -0x24(%rbp)
movl $0x98, %esi
callq 0x10f0
jmp 0x1eae
movq -0x30(%rbp), %rdi
addq $0x18, %rdi
callq 0x3a40
movq %rax, -0x68(%rbp)
movq -0x68(%rbp), %rax
movq %rax, -0x50(%rbp)
movq -0x30(%rbp), %rdi
addq $0x18, %rdi
callq 0x3ab0
movq %rax, -0x70(%rbp)
leaq -0x50(%rbp), %rdi
leaq -0x70(%rbp), %rsi
callq 0x3a70
testb $0x1, %al
jne 0x1ca4
jmp 0x1cdd
movq -0x118(%rbp), %rax
addq $0x18, %rax
movq %rax, -0x150(%rbp)
leaq -0x50(%rbp), %rdi
callq 0x3b50
movq -0x150(%rbp), %rdi
movq %rax, %rsi
callq 0x3ae0
jmp 0x1cd0
jmp 0x1cd2
leaq -0x50(%rbp), %rdi
callq 0x3b70
jmp 0x1c80
movups 0x1345c(%rip), %xmm0    # 0x15140
movaps %xmm0, -0xb0(%rbp)
movabsq $0x3fb999999999999a, %rax # imm = 0x3FB999999999999A
movq %rax, -0xa0(%rbp)
leaq -0xb0(%rbp), %rax
movq %rax, -0x98(%rbp)
movq $0x3, -0x90(%rbp)
leaq -0xb1(%rbp), %rdi
movq %rdi, -0x158(%rbp)
callq 0x3b90
movq -0x158(%rbp), %rcx
movq -0x98(%rbp), %rsi
movq -0x90(%rbp), %rdx
leaq -0x88(%rbp), %rdi
callq 0x3bb0
jmp 0x1d4b
leaq -0xb1(%rbp), %rdi
callq 0x3c30
movq -0x30(%rbp), %rax
movq %rax, -0x160(%rbp)
leaq -0xd0(%rbp), %rdi
leaq -0x88(%rbp), %rsi
callq 0x3c50
jmp 0x1d77
movq -0x160(%rbp), %rdi
leaq -0xd0(%rbp), %rsi
callq 0x11be0
movb %al, -0x161(%rbp)
jmp 0x1d92
movb -0x161(%rbp), %al
andb $0x1, %al
movb %al, -0x39(%rbp)
leaq -0xd0(%rbp), %rdi
callq 0x3d40
testb $0x1, -0x39(%rbp)
jne 0x1e2a
movq 0x1c222(%rip), %rdi     # 0x1dfd8
leaq 0x132e3(%rip), %rsi     # 0x150a0
callq 0x10d0
movq %rax, -0x170(%rbp)
jmp 0x1dcb
movq -0x170(%rbp), %rdi
movq 0x1c1ef(%rip), %rsi     # 0x1dfc8
callq 0x1100
jmp 0x1de0
jmp 0x1e2a
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x20(%rbp)
movl %eax, -0x24(%rbp)
leaq -0xb1(%rbp), %rdi
callq 0x3c30
jmp 0x1eae
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x20(%rbp)
movl %eax, -0x24(%rbp)
jmp 0x1e97
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x20(%rbp)
movl %eax, -0x24(%rbp)
leaq -0xd0(%rbp), %rdi
callq 0x3d40
jmp 0x1e97
movq -0x30(%rbp), %rsi
leaq -0xe8(%rbp), %rdi
callq 0x11df0
jmp 0x1e3c
movq -0x30(%rbp), %rdi
callq 0x11ed0
jmp 0x1e47
movq -0x118(%rbp), %rdi
leaq -0x30(%rbp), %rsi
callq 0x3da0
jmp 0x1e59
leaq -0xe8(%rbp), %rdi
callq 0x3d40
leaq -0x88(%rbp), %rdi
callq 0x3d40
movl -0x40(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x40(%rbp)
jmp 0x1b0f
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x20(%rbp)
movl %eax, -0x24(%rbp)
leaq -0xe8(%rbp), %rdi
callq 0x3d40
leaq -0x88(%rbp), %rdi
callq 0x3d40
jmp 0x1eae
addq $0x170, %rsp            # imm = 0x170
popq %rbp
retq
movq -0x100(%rbp), %rdi
callq 0x3e10
movq -0x108(%rbp), %rdi
callq 0x3e70
movq -0x110(%rbp), %rdi
callq 0x3ed0
movq -0xf8(%rbp), %rdi
callq 0x3f30
movq -0x20(%rbp), %rdi
callq 0x1180
nopw (%rax,%rax)