// File: samuel500[P]NEAT/individual.cpp
// Function: Individual::activate(std::vector<double, std::allocator<double>>)
bool Individual::activate(vector<double> input){

	if(input.size() != inputs.size()){
		cout << "invalid input size" << endl;
		return false;
	}

	for(int i=0; i<inputs.size(); i++){
		inputs[i]->firing = input[i];
		inputs[i]->activated = true;
	}

	// messy, but it looks like it's the way to go 
	// (see FAQ: https://www.cs.ucf.edu/~kstanley/neat.html#FAQ1)
	int max_loops = 20; 
	int loops = 0;
	bool outputs_activated = false;
	while(!outputs_activated || loops<max_loops){
		outputs_activated = true;
		for(int i=*in_size; i<nodes.size(); i++){
			nodes[i]->activate();
			
			if(nodes[i]->node_type==OUTPUT && !nodes[i]->activated){
				outputs_activated = false;
			}
		}
		loops++;

	}

	if(!outputs_activated) {
		cout<<"activation pb" << endl;
		return false;
	}
	else return true;

}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x70, %rsp
movq %rsi, -0x50(%rbp)
movq %rdi, %rax
movq -0x50(%rbp), %rdi
movq %rdi, -0x48(%rbp)
movq %rax, -0x10(%rbp)
movq %rdi, -0x18(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x40(%rbp)
callq 0x6a50
movq -0x40(%rbp), %rdi
movq %rax, -0x38(%rbp)
addq $0x30, %rdi
callq 0x4070
movq %rax, %rcx
movq -0x38(%rbp), %rax
cmpq %rcx, %rax
je 0x11c54
movq 0xc3a8(%rip), %rdi      # 0x1dfd8
leaq 0x3649(%rip), %rsi      # 0x15280
callq 0x10d0
movq %rax, %rdi
movq 0xc382(%rip), %rsi      # 0x1dfc8
callq 0x1100
movb $0x0, -0x1(%rbp)
jmp 0x11dda
movl $0x0, -0x1c(%rbp)
movq -0x40(%rbp), %rdi
movslq -0x1c(%rbp), %rax
movq %rax, -0x58(%rbp)
addq $0x30, %rdi
callq 0x4070
movq %rax, %rcx
movq -0x58(%rbp), %rax
cmpq %rcx, %rax
jae 0x11cd3
movq -0x48(%rbp), %rdi
movslq -0x1c(%rbp), %rsi
callq 0x4100
movq -0x40(%rbp), %rdi
movsd (%rax), %xmm0
movsd %xmm0, -0x60(%rbp)
addq $0x30, %rdi
movslq -0x1c(%rbp), %rsi
callq 0xdfe0
movsd -0x60(%rbp), %xmm0
movq -0x40(%rbp), %rdi
movq (%rax), %rax
movsd %xmm0, 0x10(%rax)
addq $0x30, %rdi
movslq -0x1c(%rbp), %rsi
callq 0xdfe0
movq (%rax), %rax
movb $0x1, 0xc(%rax)
movl -0x1c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1c(%rbp)
jmp 0x11c5b
movl $0x14, -0x20(%rbp)
movl $0x0, -0x24(%rbp)
movb $0x0, -0x25(%rbp)
movb $0x1, %al
testb $0x1, -0x25(%rbp)
movb %al, -0x61(%rbp)
je 0x11cfc
movl -0x24(%rbp), %eax
cmpl -0x20(%rbp), %eax
setl %al
movb %al, -0x61(%rbp)
movb -0x61(%rbp), %al
testb $0x1, %al
jne 0x11d08
jmp 0x11da8
movq -0x40(%rbp), %rax
movb $0x1, -0x25(%rbp)
movq 0x80(%rax), %rax
movl (%rax), %eax
movl %eax, -0x2c(%rbp)
movq -0x40(%rbp), %rdi
movslq -0x2c(%rbp), %rax
movq %rax, -0x70(%rbp)
addq $0x18, %rdi
callq 0x4070
movq %rax, %rcx
movq -0x70(%rbp), %rax
cmpq %rcx, %rax
jae 0x11d9a
movq -0x40(%rbp), %rdi
addq $0x18, %rdi
movslq -0x2c(%rbp), %rsi
callq 0xdfe0
movq (%rax), %rdi
callq 0x13910
movq -0x40(%rbp), %rdi
addq $0x18, %rdi
movslq -0x2c(%rbp), %rsi
callq 0xdfe0
movq (%rax), %rax
cmpl $0x1, (%rax)
jne 0x11d8d
movq -0x40(%rbp), %rdi
addq $0x18, %rdi
movslq -0x2c(%rbp), %rsi
callq 0xdfe0
movq (%rax), %rax
testb $0x1, 0xc(%rax)
jne 0x11d8d
movb $0x0, -0x25(%rbp)
jmp 0x11d8f
movl -0x2c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2c(%rbp)
jmp 0x11d1c
movl -0x24(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x24(%rbp)
jmp 0x11ce5
testb $0x1, -0x25(%rbp)
jne 0x11dd6
movq 0xc223(%rip), %rdi      # 0x1dfd8
leaq 0x34d7(%rip), %rsi      # 0x15293
callq 0x10d0
movq %rax, %rdi
movq 0xc1fd(%rip), %rsi      # 0x1dfc8
callq 0x1100
movb $0x0, -0x1(%rbp)
jmp 0x11dda
movb $0x1, -0x1(%rbp)
movb -0x1(%rbp), %al
andb $0x1, %al
addq $0x70, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)