// File: /workspace/github_cpp_makefile_star2_O1/EduBic[P]TSP-MetaheuristicSolvers/main.cpp
// Function: main
int main (int argc, char *argv[]) {
    try {

        if (argc < 2) {
            throw std::runtime_error("usage: ./main <filename>.dat");
        }

        SolversExecutor solversExe(argv[1]);

        bool benchmark = false;

        // Solver option    default = LocalSearch
        bool localSearch = true;

        // Solvers features     default = BI
        bool bestImprove = true;
        bool aspCriteria = false;   // only for TabuSearch

        // Tabu options
        int seconds = 30;
        int tenure = 50;
        int maxIterations = 1000;

        int c;
        int option_index;

        while((c = getopt_long(argc, argv, "lfbtae:i:s:m", long_options, &option_index)) != EOF) {
            switch(c) {
                case 'l': {
                    localSearch = true;
                    break;
                }
                case 't': {
                    localSearch = false;
                    break;
                }
                case 'b': {
                    bestImprove = true;
                    break;
                }
                case 'f': {
                    bestImprove = false;
                    break;
                }
                case 'a': {
                    aspCriteria = true;
                    cout << endl << "AspCriteria: " << aspCriteria << endl;
                    break;
                }
                case 'e': {
                    tenure = strtol(optarg, NULL, 0);
                    cout << endl << "Tenure: " << tenure << endl << endl;
                    break;
                }
                case 'i': {
                    maxIterations = (int)strtol(optarg, NULL, 0);
                    break;
                }
                case 's': {
                    seconds = (int)strtol(optarg, NULL, 0);
                    break;
                }
                case 'm': {
                    benchmark = true;
                    break;
                }
            }
        }

        if (benchmark) {

            // Test initial solutions
            solversExe.addRandomSeedInitSolution(58);
            solversExe.addRandomSeedInitSolution(4);
            solversExe.addRandomSeedInitSolution(25);
            solversExe.addRandomSeedInitSolution(26);
            solversExe.addRandomSeedInitSolution(43);
            solversExe.addRandomSeedInitSolution(46);
            solversExe.addRandomSeedInitSolution(93);
            solversExe.addRandomSeedInitSolution(99);

            //solversExe.addSolver(new LocalSearchSolver());
            //solversExe.addSolver(new LocalSearchSolver(false));


            int maxIteration = 300000;
            double maxSeconds = 10;
            //int tabuLenght = 600;
            int tabuLengths[4] = {0, 20, 180, 480};

            //solversExe.addSolver(TabuSearchSolver::buildTS_BI(tabuLenght, maxIteration, maxSeconds));

            for (int i = 0; i < 4; i++) {
                solversExe.addSolver(TabuSearchSolver::buildTS_BI(tabuLengths[i], maxIteration, maxSeconds));
                //solversExe.addSolver(TabuSearchSolver::buildTS_BI_AC(tabuLengths[i], maxIteration, maxSeconds));
                //solversExe.addSolver(TabuSearchSolver::buildTS_FI(tabuLengths[i], maxIteration, maxSeconds));
                //solversExe.addSolver(TabuSearchSolver::buildTS_FI_AC(tabuLengths[i], maxIteration, maxSeconds));
            }

        } else {
            // Command line program
            solversExe.addRandomInitSolution();

            if (localSearch) {
                solversExe.addSolver(new LocalSearchSolver(bestImprove));
            } else { // tabu search
                solversExe.addSolver(new TabuSearchSolver(tenure, maxIterations, aspCriteria, bestImprove, seconds));
            }
        }

        solversExe.execute();

        solversExe.printInitSolutions();
        solversExe.printResults();

    }
    catch (std::exception& e) {
        std::cout << ">>>EXCEPTION: " << e.what() << std::endl;
    }

    return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xb8, %rsp
cmpl $0x1, %edi
jle 0x7925
movq %rsi, %r15
movl %edi, %ebp
movq 0x8(%rsi), %rsi
leaq 0x40(%rsp), %rdi
callq 0x369c
movl $0x3e8, %eax            # imm = 0x3E8
movq %rax, 0x28(%rsp)
movl $0x32, %eax
movq %rax, 0x10(%rsp)
movl $0x1e, %eax
movq %rax, 0x20(%rsp)
movb $0x1, %al
movl %eax, 0x8(%rsp)
movq $0x0, 0x18(%rsp)
leaq 0x3d57(%rip), %rbx      # 0xb260
leaq 0x3c(%rsp), %r12
leaq 0xeab(%rip), %r13       # 0x83c0
movb $0x1, %al
movl %eax, 0xc(%rsp)
movq $0x0, 0x30(%rsp)
movl %ebp, %edi
movq %r15, %rsi
leaq 0xf0d(%rip), %rdx       # 0x843d
movq %rbx, %rcx
movq %r12, %r8
callq 0x33e0
leal -0x61(%rax), %ecx
cmpl $0x13, %ecx
ja 0x771a
movslq (%r13,%rcx,4), %rax
addq %r13, %rax
jmpq *%rax
movq 0x3a78(%rip), %rcx      # 0xafd0
movq (%rcx), %rax
movq -0x18(%rax), %rdi
addq %rcx, %rdi
movl $0xa, %esi
callq 0x32b0
movsbl %al, %esi
movq 0x3a5a(%rip), %rdi      # 0xafd0
callq 0x3030
movq %rax, %rdi
callq 0x31f0
movq %rax, %r14
movl $0xd, %edx
movq %rax, %rdi
leaq 0xeb5(%rip), %rsi       # 0x844a
callq 0x32f0
movq %r14, %rdi
movl $0x1, %esi
callq 0x33d0
movq %rax, %r14
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r14, %rdi
movl $0xa, %esi
callq 0x32b0
movsbl %al, %esi
movq %r14, %rdi
callq 0x3030
movb $0x1, %cl
movq %rcx, 0x18(%rsp)
movq %rax, %rdi
callq 0x31f0
jmp 0x7524
movq 0x39cc(%rip), %rax      # 0xafb0
movq (%rax), %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0x3320
movq %rax, 0x28(%rsp)
jmp 0x7524
movq 0x39af(%rip), %rax      # 0xafb0
movq (%rax), %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0x3320
movq %rax, 0x10(%rsp)
movq 0x39b7(%rip), %rcx      # 0xafd0
movq (%rcx), %rax
movq -0x18(%rax), %rdi
addq %rcx, %rdi
movl $0xa, %esi
callq 0x32b0
movsbl %al, %esi
movq 0x3999(%rip), %rdi      # 0xafd0
callq 0x3030
movq %rax, %rdi
callq 0x31f0
movq %rax, %r14
movl $0x8, %edx
movq %rax, %rdi
leaq 0xe02(%rip), %rsi       # 0x8458
callq 0x32f0
movq %r14, %rdi
movq 0x10(%rsp), %rsi
callq 0x3400
movq %rax, %r14
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r14, %rdi
movl $0xa, %esi
callq 0x32b0
movsbl %al, %esi
movq %r14, %rdi
callq 0x3030
movq %rax, %rdi
callq 0x31f0
movq %rax, %r14
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r14, %rdi
movl $0xa, %esi
callq 0x32b0
movsbl %al, %esi
movq %r14, %rdi
callq 0x3030
movq %rax, %rdi
callq 0x31f0
jmp 0x7524
movl $0x0, 0x8(%rsp)
jmp 0x7524
movq 0x38db(%rip), %rax      # 0xafb0
movq (%rax), %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0x3320
movq %rax, 0x20(%rsp)
jmp 0x7524
movb $0x1, %al
movl %eax, 0x8(%rsp)
jmp 0x7524
movb $0x1, %al
movl %eax, 0xc(%rsp)
jmp 0x7524
movb $0x1, %al
movq %rax, 0x30(%rsp)
jmp 0x7524
movl $0x0, 0xc(%rsp)
jmp 0x7524
cmpl $-0x1, %eax
jne 0x7524
testb $0x1, 0x30(%rsp)
je 0x77e5
leaq 0x40(%rsp), %rdi
movl $0x3a, %esi
callq 0x3732
leaq 0x40(%rsp), %rdi
movl $0x4, %esi
callq 0x3732
leaq 0x40(%rsp), %rdi
movl $0x19, %esi
callq 0x3732
leaq 0x40(%rsp), %rdi
movl $0x1a, %esi
callq 0x3732
leaq 0x40(%rsp), %rdi
movl $0x2b, %esi
callq 0x3732
leaq 0x40(%rsp), %rdi
movl $0x2e, %esi
callq 0x3732
leaq 0x40(%rsp), %rdi
movl $0x5d, %esi
callq 0x3732
leaq 0x40(%rsp), %rdi
movl $0x63, %esi
callq 0x3732
xorl %r14d, %r14d
leaq 0xc60(%rip), %r15       # 0x8410
leaq 0x40(%rsp), %rbx
movl (%r14,%r15), %edi
movl $0x493e0, %esi          # imm = 0x493E0
movsd 0xbf2(%rip), %xmm0      # 0x83b8
callq 0x7a00
movq %rbx, %rdi
movq %rax, %rsi
callq 0x37c4
addq $0x4, %r14
cmpq $0x10, %r14
jne 0x77b5
jmp 0x78b6
leaq 0x40(%rsp), %rdi
callq 0x37ae
testb $0x1, 0xc(%rsp)
je 0x7818
movl $0x10, %edi
callq 0x32d0
movq %rax, %r15
movzbl 0x8(%rsp), %esi
andl $0x1, %esi
movq %rax, %rdi
callq 0x7a82
jmp 0x78a9
movl $0xb8, %edi
callq 0x32d0
movq %rax, %r15
cvtsi2sdl 0x20(%rsp), %xmm0
leaq 0x34ae(%rip), %rax      # 0xace0
addq $0x10, %rax
movq %rax, (%r15)
movq 0x10(%rsp), %rax
movl %eax, 0x8(%r15)
movq 0x28(%rsp), %rax
movl %eax, 0xc(%r15)
movsd %xmm0, 0x10(%r15)
leaq 0x18(%r15), %rax
movq %rax, 0x20(%r15)
movq %rax, 0x18(%r15)
xorl %eax, %eax
movq %rax, 0x28(%r15)
leaq 0x30(%r15), %rcx
movq %rcx, 0x38(%r15)
movq %rcx, 0x30(%r15)
movq %rax, 0x40(%r15)
movq %r15, %rcx
addq $0x50, %rcx
movl $0x0, 0x50(%r15)
movq %rax, 0x58(%r15)
movq %rcx, 0x60(%r15)
movq %rcx, 0x68(%r15)
movq %rax, 0x70(%r15)
movq 0x18(%rsp), %rax
movb %al, 0x80(%r15)
movl 0x8(%rsp), %eax
movb %al, 0x81(%r15)
leaq 0x40(%rsp), %rdi
movq %r15, %rsi
callq 0x37c4
leaq 0x40(%rsp), %rdi
callq 0x37ee
leaq 0x40(%rsp), %rdi
callq 0x46c0
leaq 0x40(%rsp), %rdi
callq 0x48ce
movq 0xa0(%rsp), %rdi
testq %rdi, %rdi
je 0x78e6
callq 0x3290
movq 0x88(%rsp), %rdi
testq %rdi, %rdi
je 0x78f8
callq 0x3290
movq 0x70(%rsp), %rdi
testq %rdi, %rdi
je 0x7907
callq 0x3290
leaq 0x50(%rsp), %rdi
callq 0x57a0
xorl %eax, %eax
addq $0xb8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl $0x10, %edi
callq 0x3160
movq %rax, %r15
leaq 0xae7(%rip), %rsi       # 0x8420
movq %rax, %rdi
callq 0x3110
movq 0x36a8(%rip), %rsi      # 0xaff0
movq 0x3679(%rip), %rdx      # 0xafc8
movq %r15, %rdi
callq 0x33f0
movq %rdx, %r14
movq %rax, %rbx
movq %r15, %rdi
callq 0x3290
jmp 0x798b
jmp 0x7979
movq %rdx, %r14
movq %rax, %rbx
movq %r15, %rdi
callq 0x3210
jmp 0x7995
movq %rdx, %r14
movq %rax, %rbx
jmp 0x7995
jmp 0x7985
jmp 0x7985
movq %rdx, %r14
movq %rax, %rbx
leaq 0x40(%rsp), %rdi
callq 0x7aca
cmpl $0x1, %r14d
jne 0x79f0
movq %rbx, %rdi
callq 0x3130
movq %rax, %rbx
movq 0x3623(%rip), %rdi      # 0xafd0
leaq 0x908(%rip), %rsi       # 0x82bc
movl $0xe, %edx
callq 0x32f0
movq (%rbx), %rax
movq %rbx, %rdi
callq *0x10(%rax)
movq 0x3602(%rip), %rdi      # 0xafd0
movq %rax, %rsi
callq 0x32c0
movq %rax, %rdi
callq 0x3150
callq 0x33c0
jmp 0x7911
movq %rax, %rbx
callq 0x33c0
movq %rbx, %rdi
callq 0x3410
movq %rax, %rdi
callq 0x6356