// File: GAStudyGroup[P]GPX2/src/cross/gpx/sources/GPX2.cpp
// Function: GPX2::crossover(std::vector<int, std::allocator<int>>, std::vector<int, std::allocator<int>>)
vector<int> GPX2::crossover(vector<int> redT, vector<int> blueT)
{
    GPX2 obj;
    // Step 1
    obj.convertParentsToMap(redT,blueT);

    // Step 2
    obj.createGhosts();

    // Step 3
    obj.joinGraphs();

    // Step 4
    obj.cutCommonEdges();

    // Step 5
    obj.findAllPartitions();

    //the tours are equal if 0, or one of them is better if 
    if (obj.candidatePartitions.size() < 2) {
        return ((getFitness(redT) < getFitness(blueT)) ? redT : blueT);
    }

    // Step 6
    obj.checkAllPartitions();

    // Fusion
    // It's needed to have more than one unfeasible partition to fuse them
    if (obj.unfeasiblePartitions.size() > 1) {
        obj.fusion();
    }

    if (obj.feasiblePartitions.size() < 1) {
        return ((getFitness(redT) < getFitness(blueT)) ? redT : blueT);
    }

    // Step 7
    obj.choose();

    // Step 8
    obj.buildOffspring();


    // Step 9
    //return obj.convertChoosenChild();
    vector<int> offspring{obj.convertChoosenChild()};
    if(getFitness(redT) > getFitness(offspring) && getFitness(blueT) > getFitness(offspring) ){
        Log::printTourFile(redT,"red");
        Log::printTourFile(blueT,"blue");
        Log::printTourFile(offspring,"off");
    }
    return offspring;
}

// Assembly:
subq $0x278, %rsp            # imm = 0x278
movq %rdx, 0x70(%rsp)
movq %rsi, 0x68(%rsp)
movq %rdi, 0x50(%rsp)
movq %rdi, %rax
movq %rax, 0x58(%rsp)
movq %rdi, 0x270(%rsp)
movq %rsi, 0x268(%rsp)
movq %rdx, 0x260(%rsp)
leaq 0x108(%rsp), %rdi
movq %rdi, 0x60(%rsp)
callq 0x609a0
movq 0x60(%rsp), %rdi
movq 0x68(%rsp), %rsi
movq 0x70(%rsp), %rdx
callq 0x5e260
jmp 0x5ddde
leaq 0x108(%rsp), %rdi
callq 0x5e2f0
jmp 0x5dded
leaq 0x108(%rsp), %rdi
callq 0x5e850
jmp 0x5ddfc
leaq 0x108(%rsp), %rdi
callq 0x5f080
jmp 0x5de0b
leaq 0x108(%rsp), %rdi
callq 0x5f230
jmp 0x5de1a
leaq 0x108(%rsp), %rdi
callq 0x60b50
cmpq $0x2, %rax
jae 0x5deab
movq 0x68(%rsp), %rdi
callq 0x1b240
movl %eax, 0x4c(%rsp)
jmp 0x5de3d
movq 0x70(%rsp), %rdi
callq 0x1b240
movl %eax, 0x48(%rsp)
jmp 0x5de4d
movl 0x4c(%rsp), %eax
movl 0x48(%rsp), %ecx
cmpl %ecx, %eax
jge 0x5de65
movq 0x68(%rsp), %rax
movq %rax, 0x40(%rsp)
jmp 0x5de71
movq 0x70(%rsp), %rax
movq %rax, 0x40(%rsp)
jmp 0x5de71
movq 0x50(%rsp), %rdi
movq 0x40(%rsp), %rsi
callq 0xfcd0
jmp 0x5de82
movl $0x1, 0xf8(%rsp)
jmp 0x5e228
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x100(%rsp)
movl %eax, 0xfc(%rsp)
jmp 0x5e242
leaq 0x108(%rsp), %rdi
callq 0x5f9e0
jmp 0x5deba
leaq 0x108(%rsp), %rdi
addq $0x60, %rdi
callq 0x60b50
cmpq $0x1, %rax
jbe 0x5dee2
leaq 0x108(%rsp), %rdi
callq 0x5fb40
jmp 0x5dee0
jmp 0x5dee2
leaq 0x108(%rsp), %rdi
addq $0x30, %rdi
callq 0x60b50
cmpq $0x1, %rax
jae 0x5df5e
movq 0x68(%rsp), %rdi
callq 0x1b240
movl %eax, 0x3c(%rsp)
jmp 0x5df09
movq 0x70(%rsp), %rdi
callq 0x1b240
movl %eax, 0x38(%rsp)
jmp 0x5df19
movl 0x3c(%rsp), %eax
movl 0x38(%rsp), %ecx
cmpl %ecx, %eax
jge 0x5df31
movq 0x68(%rsp), %rax
movq %rax, 0x30(%rsp)
jmp 0x5df3d
movq 0x70(%rsp), %rax
movq %rax, 0x30(%rsp)
jmp 0x5df3d
movq 0x50(%rsp), %rdi
movq 0x30(%rsp), %rsi
callq 0xfcd0
jmp 0x5df4e
movl $0x1, 0xf8(%rsp)
jmp 0x5e228
leaq 0x108(%rsp), %rdi
callq 0x5fcc0
jmp 0x5df6d
leaq 0x108(%rsp), %rdi
callq 0x60110
jmp 0x5df7c
movq 0x50(%rsp), %rdi
movb $0x0, 0xf7(%rsp)
leaq 0x108(%rsp), %rsi
callq 0x60910
jmp 0x5df98
movq 0x68(%rsp), %rdi
callq 0x1b240
movl %eax, 0x2c(%rsp)
jmp 0x5dfa8
movq 0x50(%rsp), %rdi
callq 0x1b240
movl %eax, 0x28(%rsp)
jmp 0x5dfb8
movl 0x2c(%rsp), %eax
movl 0x28(%rsp), %ecx
cmpl %ecx, %eax
jle 0x5e1f3
movq 0x70(%rsp), %rdi
callq 0x1b240
movl %eax, 0x24(%rsp)
jmp 0x5dfd8
movq 0x50(%rsp), %rdi
callq 0x1b240
movl %eax, 0x20(%rsp)
jmp 0x5dfe8
movl 0x24(%rsp), %eax
movl 0x20(%rsp), %ecx
cmpl %ecx, %eax
jle 0x5e1f3
leaq 0xcf(%rsp), %rdi
movq %rdi, 0x18(%rsp)
callq 0x6860
movq 0x18(%rsp), %rdx
leaq 0x178ec(%rip), %rsi     # 0x75902
leaq 0xd0(%rsp), %rdi
callq 0x92b0
jmp 0x5e025
movq 0x68(%rsp), %rdi
leaq 0xd0(%rsp), %rsi
callq 0x171c0
jmp 0x5e039
leaq 0xd0(%rsp), %rdi
callq 0x6988
leaq 0xcf(%rsp), %rdi
callq 0x6520
leaq 0xa7(%rsp), %rdi
movq %rdi, 0x10(%rsp)
callq 0x6860
movq 0x10(%rsp), %rdx
leaq 0x17895(%rip), %rsi     # 0x75906
leaq 0xa8(%rsp), %rdi
callq 0x92b0
jmp 0x5e080
movq 0x70(%rsp), %rdi
leaq 0xa8(%rsp), %rsi
callq 0x171c0
jmp 0x5e094
leaq 0xa8(%rsp), %rdi
callq 0x6988
leaq 0xa7(%rsp), %rdi
callq 0x6520
leaq 0x7f(%rsp), %rdi
movq %rdi, 0x8(%rsp)
callq 0x6860
movq 0x8(%rsp), %rdx
leaq 0x17842(%rip), %rsi     # 0x7590b
leaq 0x80(%rsp), %rdi
callq 0x92b0
jmp 0x5e0d8
movq 0x50(%rsp), %rdi
leaq 0x80(%rsp), %rsi
callq 0x171c0
jmp 0x5e0ec
leaq 0x80(%rsp), %rdi
callq 0x6988
leaq 0x7f(%rsp), %rdi
callq 0x6520
jmp 0x5e1f3
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x100(%rsp)
movl %eax, 0xfc(%rsp)
jmp 0x5e21c
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x100(%rsp)
movl %eax, 0xfc(%rsp)
jmp 0x5e158
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x100(%rsp)
movl %eax, 0xfc(%rsp)
leaq 0xd0(%rsp), %rdi
callq 0x6988
leaq 0xcf(%rsp), %rdi
callq 0x6520
jmp 0x5e21c
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x100(%rsp)
movl %eax, 0xfc(%rsp)
jmp 0x5e1a1
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x100(%rsp)
movl %eax, 0xfc(%rsp)
leaq 0xa8(%rsp), %rdi
callq 0x6988
leaq 0xa7(%rsp), %rdi
callq 0x6520
jmp 0x5e21c
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x100(%rsp)
movl %eax, 0xfc(%rsp)
jmp 0x5e1e7
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x100(%rsp)
movl %eax, 0xfc(%rsp)
leaq 0x80(%rsp), %rdi
callq 0x6988
leaq 0x7f(%rsp), %rdi
callq 0x6520
jmp 0x5e21c
movb $0x1, 0xf7(%rsp)
movl $0x1, 0xf8(%rsp)
testb $0x1, 0xf7(%rsp)
jne 0x5e21a
movq 0x50(%rsp), %rdi
callq 0x9af0
jmp 0x5e228
movq 0x50(%rsp), %rdi
callq 0x9af0
jmp 0x5e242
leaq 0x108(%rsp), %rdi
callq 0x60a30
movq 0x58(%rsp), %rax
addq $0x278, %rsp            # imm = 0x278
retq
leaq 0x108(%rsp), %rdi
callq 0x60a30
movq 0x100(%rsp), %rdi
callq 0x6850
nopl (%rax)