// File: /workspace/github_cpp_makefile_star2_O2/GAStudyGroup[P]GPX2/src/base/sources/GAUtils.cpp
// Function: GAUtils::crossGPX2WithAntColonyAndReset(Population&)
Population GAUtils::crossGPX2WithAntColonyAndReset(Population &pop){
    Population newPop, tmpPop;
    vector<int> currentTour;

    sort(pop.getPopulation().begin(), pop.getPopulation().end(),sortPopulation);

    for (unsigned i = 0; i < Config::POP_SIZE/10; i++) {
        currentTour = pop.getPopulation()[i];
        for (unsigned j = 0; j < Config::POP_SIZE; j++) {
            if (i != j) {
                vector<int> t = GPX2::crossover(pop.getPopulation()[j], currentTour);
                currentTour = t;
            }
        }

        newPop.getPopulation().push_back(currentTour);
    }

    fillPopulationWithReset(newPop, Config::POP_SIZE*Config::RESET_PERCENTAGE);

    sort(newPop.getPopulation().begin(), newPop.getPopulation().end(),sortPopulation);
    cout<<"Best tour from GPX2: "<<getFitness(newPop.getBestTour())<<endl;
    // cout<<newPop<<endl;

    // AntMap::updatePheromoneMap(newPop.getBestTour());

    tmpPop = AntColony().run(Config::POP_SIZE-(newPop.getPopulation().size()));

    // cout<<tmpPop<<endl;

    newPop.getPopulation().insert(newPop.getPopulation().end(),tmpPop.getPopulation().begin(),tmpPop.getPopulation().end());

    cout<<"Best tour after AntColony: "<<getFitness(newPop.getBestTour())<<endl;
    // cout<<newPop<<endl;

    // cin.get();

    return newPop;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xa8, %rsp
movq %rsi, %r14
movq %rdi, 0x8(%rsp)
callq 0xb97c
leaq 0x48(%rsp), %rdi
callq 0xb97c
xorpd %xmm0, %xmm0
movapd %xmm0, 0x20(%rsp)
andq $0x0, 0x30(%rsp)
movq %r14, %rdi
callq 0xb988
movq (%rax), %r15
movq %r14, %rdi
callq 0xb988
movq 0x8(%rax), %rsi
movq %r15, %rdi
callq 0x8442
xorl %ebx, %ebx
leaq 0x90(%rsp), %r12
leaq 0x78(%rsp), %r13
leaq 0x60(%rsp), %rbp
xorl %r15d, %r15d
movq %r14, 0x18(%rsp)
leaq 0x3438d(%rip), %rax     # 0x3c8c0
movl (%rax), %ecx
movl %ecx, %eax
xorl %edx, %edx
pushq $0xa
popq %rsi
divl %esi
cmpq %rax, %r15
jae 0x8617
movq %r14, %rdi
callq 0xb988
imulq $0x18, %r15, %rsi
addq (%rax), %rsi
leaq 0x20(%rsp), %rdi
callq 0x93b6
movq %r15, 0x40(%rsp)
leaq 0x34354(%rip), %rax     # 0x3c8c0
movl (%rax), %eax
xorl %r14d, %r14d
xorl %r15d, %r15d
movl %eax, %ecx
cmpq %rcx, %r15
jae 0x85ea
cmpq %r14, %rbx
je 0x85e1
movq 0x18(%rsp), %rdi
callq 0xb988
movq (%rax), %rsi
addq %r14, %rsi
movq %r12, %rdi
callq 0x9210
movq %r13, %rdi
leaq 0x20(%rsp), %rsi
callq 0x9210
movq %rbp, %rdi
movq %r12, %rsi
movq %r13, %rdx
callq 0x1f198
movq %r13, %rdi
callq 0x6e4c
movq %r12, %rdi
callq 0x6e4c
leaq 0x20(%rsp), %rdi
movq %rbp, %rsi
callq 0x93b6
movq %rbp, %rdi
callq 0x6e4c
leaq 0x342e1(%rip), %rax     # 0x3c8c0
movl (%rax), %eax
incq %r15
addq $0x18, %r14
jmp 0x8574
movq 0x8(%rsp), %rdi
callq 0xb988
movq 0x40(%rsp), %r15
movq %rax, %rdi
leaq 0x20(%rsp), %rsi
callq 0x938a
incq %r15
addq $0x18, %rbx
movq 0x18(%rsp), %r14
jmp 0x852c
movl %ecx, %eax
cvtsi2sd %rax, %xmm0
leaq 0x3418b(%rip), %rax     # 0x3c7b0
mulsd (%rax), %xmm0
cvttsd2si %xmm0, %rsi
movq 0x8(%rsp), %rdi
callq 0x730d
movq 0x8(%rsp), %rdi
callq 0xb988
movq (%rax), %r14
movq 0x8(%rsp), %rdi
callq 0xb988
movq 0x8(%rax), %rsi
movq %r14, %rdi
callq 0x8442
movq 0x3393e(%rip), %rdi     # 0x3bfa0
leaq 0x1eceb(%rip), %rsi     # 0x27354
callq 0x5370
movq %rax, %r14
movq 0x8(%rsp), %rdi
callq 0xb9f0
movq %rax, %rdi
callq 0xc060
movq %r14, %rdi
movl %eax, %esi
callq 0x55e0
movq %rax, %rdi
callq 0x51c0
leaq 0x34224(%rip), %rax     # 0x3c8c0
movl (%rax), %ebp
movq 0x8(%rsp), %rdi
callq 0xb988
movq 0x8(%rax), %rcx
subq (%rax), %rcx
pushq $-0x18
popq %rsi
movq %rcx, %rax
cqto
idivq %rsi
addl %eax, %ebp
leaq 0x60(%rsp), %rdi
leaq 0x17(%rsp), %rsi
movl %ebp, %edx
callq 0x1bee4
leaq 0x48(%rsp), %rdi
leaq 0x60(%rsp), %r14
movq %r14, %rsi
callq 0x6d8c
movq %r14, %rdi
callq 0x6dde
movq 0x8(%rsp), %rdi
callq 0xb988
movq %rax, %r14
movq 0x8(%rsp), %rdi
callq 0xb988
movq 0x8(%rax), %r15
leaq 0x48(%rsp), %rdi
callq 0xb988
movq (%rax), %r12
leaq 0x48(%rsp), %rdi
callq 0xb988
movq 0x8(%rax), %rcx
movq %r14, %rdi
movq %r15, %rsi
movq %r12, %rdx
callq 0x9480
movq 0x3386e(%rip), %rdi     # 0x3bfa0
leaq 0x1ec31(%rip), %rsi     # 0x2736a
callq 0x5370
movq %rax, %r14
movq 0x8(%rsp), %rdi
callq 0xb9f0
movq %rax, %rdi
callq 0xc060
movq %r14, %rdi
movl %eax, %esi
callq 0x55e0
movq %rax, %rdi
callq 0x51c0
leaq 0x20(%rsp), %rdi
callq 0x6e4c
leaq 0x48(%rsp), %rdi
callq 0x6dde
movq 0x8(%rsp), %rax
addq $0xa8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %r14
jmp 0x87df
jmp 0x87c8
jmp 0x87c8
jmp 0x87c8
jmp 0x87c8
movq %rax, %r14
leaq 0x60(%rsp), %rdi
jmp 0x87c1
movq %rax, %r14
leaq 0x78(%rsp), %rdi
callq 0x6e4c
jmp 0x87b9
movq %rax, %r14
leaq 0x90(%rsp), %rdi
callq 0x6e4c
jmp 0x87cb
movq %rax, %r14
leaq 0x20(%rsp), %rdi
callq 0x6e4c
leaq 0x48(%rsp), %rdi
callq 0x6dde
movq 0x8(%rsp), %rdi
callq 0x6dde
movq %r14, %rdi
callq 0x5610