// File: 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:
subq $0x1f8, %rsp            # imm = 0x1F8
movq %rdi, 0xc8(%rsp)
movq %rdi, %rax
movq %rax, 0xd0(%rsp)
movq %rdi, 0x1f0(%rsp)
movq %rsi, 0x1e8(%rsp)
movb $0x0, 0x1e7(%rsp)
callq 0x19220
leaq 0x1c8(%rsp), %rdi
callq 0x19220
jmp 0xcbd6
leaq 0x1a0(%rsp), %rdi
callq 0xfdf0
movq 0x1e8(%rsp), %rdi
callq 0x19230
movq %rax, 0xc0(%rsp)
jmp 0xcbfa
movq 0xc0(%rsp), %rdi
callq 0xfc20
movq %rax, 0x198(%rsp)
movq 0x1e8(%rsp), %rdi
callq 0x19230
movq %rax, 0xb8(%rsp)
jmp 0xcc26
movq 0xb8(%rsp), %rdi
callq 0xfc50
movq %rax, 0x190(%rsp)
movq 0x198(%rsp), %rdi
movq 0x190(%rsp), %rsi
callq 0xcb50
jmp 0xcc52
movl $0x0, 0x188(%rsp)
movl 0x188(%rsp), %eax
movl %eax, 0xb4(%rsp)
leaq 0x8fd8e(%rip), %rax     # 0x9ca00
movl (%rax), %eax
movl $0xa, %ecx
xorl %edx, %edx
divl %ecx
movl %eax, %ecx
movl 0xb4(%rsp), %eax
cmpl %ecx, %eax
jae 0xceb9
movq 0x1e8(%rsp), %rdi
callq 0x19230
movq %rax, 0xa8(%rsp)
jmp 0xcca5
movq 0xa8(%rsp), %rdi
movl 0x188(%rsp), %eax
movl %eax, %esi
callq 0x10230
movq %rax, %rsi
leaq 0x1a0(%rsp), %rdi
callq 0x10250
jmp 0xcccd
movl $0x0, 0x184(%rsp)
movl 0x184(%rsp), %eax
leaq 0x8fd1a(%rip), %rcx     # 0x9ca00
cmpl (%rcx), %eax
jae 0xce73
movl 0x188(%rsp), %eax
cmpl 0x184(%rsp), %eax
je 0xce5b
movq 0x1e8(%rsp), %rdi
callq 0x19230
movq %rax, 0xa0(%rsp)
jmp 0xcd19
movq 0xa0(%rsp), %rdi
movl 0x184(%rsp), %eax
movl %eax, %esi
callq 0x10230
movq %rax, %rsi
leaq 0x150(%rsp), %rdi
callq 0xfcd0
jmp 0xcd41
leaq 0x138(%rsp), %rdi
leaq 0x1a0(%rsp), %rsi
callq 0xfcd0
jmp 0xcd58
leaq 0x168(%rsp), %rdi
leaq 0x150(%rsp), %rsi
leaq 0x138(%rsp), %rdx
callq 0x5dd80
jmp 0xcd77
leaq 0x138(%rsp), %rdi
callq 0x9af0
leaq 0x150(%rsp), %rdi
callq 0x9af0
leaq 0x1a0(%rsp), %rdi
leaq 0x168(%rsp), %rsi
callq 0x10250
jmp 0xcda8
leaq 0x168(%rsp), %rdi
callq 0x9af0
jmp 0xce5b
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x1c0(%rsp)
movl %eax, 0x1bc(%rsp)
jmp 0xd1d5
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x1c0(%rsp)
movl %eax, 0x1bc(%rsp)
jmp 0xd19c
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x1c0(%rsp)
movl %eax, 0x1bc(%rsp)
jmp 0xce23
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x1c0(%rsp)
movl %eax, 0x1bc(%rsp)
leaq 0x138(%rsp), %rdi
callq 0x9af0
leaq 0x150(%rsp), %rdi
callq 0x9af0
jmp 0xd19c
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x1c0(%rsp)
movl %eax, 0x1bc(%rsp)
leaq 0x168(%rsp), %rdi
callq 0x9af0
jmp 0xd19c
jmp 0xce5d
movl 0x184(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x184(%rsp)
jmp 0xccd8
movq 0xc8(%rsp), %rdi
callq 0x19230
movq %rax, 0x98(%rsp)
jmp 0xce8a
movq 0x98(%rsp), %rdi
leaq 0x1a0(%rsp), %rsi
callq 0x10190
jmp 0xcea1
jmp 0xcea3
movl 0x188(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x188(%rsp)
jmp 0xcc5d
movq 0xc8(%rsp), %rdi
leaq 0x8fb38(%rip), %rax     # 0x9ca00
movl (%rax), %eax
cvtsi2sd %rax, %xmm0
leaq 0x8fa1a(%rip), %rax     # 0x9c8f0
movsd (%rax), %xmm1
mulsd %xmm1, %xmm0
cvttsd2si %xmm0, %rax
movl %eax, %esi
callq 0xaaf0
jmp 0xceec
movq 0xc8(%rsp), %rdi
callq 0x19230
movq %rax, 0x90(%rsp)
jmp 0xcf03
movq 0x90(%rsp), %rdi
callq 0xfc20
movq 0xc8(%rsp), %rdi
movq %rax, 0x130(%rsp)
callq 0x19230
movq %rax, 0x88(%rsp)
jmp 0xcf2f
movq 0x88(%rsp), %rdi
callq 0xfc50
movq %rax, 0x128(%rsp)
movq 0x130(%rsp), %rdi
movq 0x128(%rsp), %rsi
callq 0xcb50
jmp 0xcf5b
movq 0x8f036(%rip), %rdi     # 0x9bf98
leaq 0x673d7(%rip), %rsi     # 0x74340
callq 0x64a0
movq %rax, 0x80(%rsp)
jmp 0xcf78
movq 0xc8(%rsp), %rdi
callq 0x19330
movq %rax, 0x78(%rsp)
jmp 0xcf8c
movq 0x78(%rsp), %rdi
callq 0x1b240
movl %eax, 0x74(%rsp)
jmp 0xcf9c
movl 0x74(%rsp), %esi
movq 0x80(%rsp), %rdi
callq 0x6820
movq %rax, 0x68(%rsp)
jmp 0xcfb4
movq 0x68(%rsp), %rdi
movq 0x8ef90(%rip), %rsi     # 0x9bf50
callq 0x6500
jmp 0xcfc7
movq 0xc8(%rsp), %rdi
leaq 0x8fa2a(%rip), %rax     # 0x9ca00
movl (%rax), %eax
movq %rax, 0x58(%rsp)
callq 0x19230
movq %rax, 0x60(%rsp)
jmp 0xcfe9
movq 0x60(%rsp), %rdi
callq 0x10510
movq 0x58(%rsp), %rcx
movl %ecx, %edx
subl %eax, %edx
leaq 0x108(%rsp), %rdi
leaq 0x107(%rsp), %rsi
callq 0x4ff30
jmp 0xd013
leaq 0x1c8(%rsp), %rdi
leaq 0x108(%rsp), %rsi
movq %rsi, 0x48(%rsp)
callq 0x9410
movq 0x48(%rsp), %rdi
callq 0x9440
movq 0xc8(%rsp), %rdi
callq 0x19230
movq %rax, 0x50(%rsp)
jmp 0xd04b
movq 0xc8(%rsp), %rdi
callq 0x19230
movq %rax, 0x40(%rsp)
jmp 0xd05f
movq 0x40(%rsp), %rdi
callq 0xfc50
movq %rax, 0xf0(%rsp)
leaq 0xf8(%rsp), %rdi
leaq 0xf0(%rsp), %rsi
callq 0x105f0
leaq 0x1c8(%rsp), %rdi
callq 0x19230
movq %rax, 0x38(%rsp)
jmp 0xd09a
movq 0x38(%rsp), %rdi
callq 0xfc20
movq %rax, 0xe8(%rsp)
leaq 0x1c8(%rsp), %rdi
callq 0x19230
movq %rax, 0x30(%rsp)
jmp 0xd0c0
movq 0x30(%rsp), %rdi
callq 0xfc50
movq 0x50(%rsp), %rdi
movq %rax, 0xe0(%rsp)
movq 0xf8(%rsp), %rsi
movq 0xe8(%rsp), %rdx
movq 0xe0(%rsp), %rcx
callq 0x10530
movq %rax, 0x28(%rsp)
jmp 0xd0fb
movq 0x28(%rsp), %rax
movq %rax, 0xd8(%rsp)
movq 0x8ee89(%rip), %rdi     # 0x9bf98
leaq 0x67240(%rip), %rsi     # 0x74356
callq 0x64a0
movq %rax, 0x20(%rsp)
jmp 0xd122
movq 0xc8(%rsp), %rdi
callq 0x19330
movq %rax, 0x18(%rsp)
jmp 0xd136
movq 0x18(%rsp), %rdi
callq 0x1b240
movl %eax, 0x14(%rsp)
jmp 0xd146
movl 0x14(%rsp), %esi
movq 0x20(%rsp), %rdi
callq 0x6820
movq %rax, 0x8(%rsp)
jmp 0xd15b
movq 0x8(%rsp), %rdi
movq 0x8ede9(%rip), %rsi     # 0x9bf50
callq 0x6500
jmp 0xd16e
movb $0x1, 0x1e7(%rsp)
leaq 0x1a0(%rsp), %rdi
callq 0x9af0
leaq 0x1c8(%rsp), %rdi
callq 0x9440
testb $0x1, 0x1e7(%rsp)
jne 0xd1c5
jmp 0xd1b8
leaq 0x1a0(%rsp), %rdi
callq 0x9af0
leaq 0x1c8(%rsp), %rdi
callq 0x9440
jmp 0xd1d5
movq 0xc8(%rsp), %rdi
callq 0x9440
movq 0xd0(%rsp), %rax
addq $0x1f8, %rsp            # imm = 0x1F8
retq
movq 0xc8(%rsp), %rdi
callq 0x9440
movq 0x1c0(%rsp), %rdi
callq 0x6850
nop