// File: /workspace/github_cpp_makefile_star2_O3/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 0x783b
movq %rsi, %r15
movl %edi, %ebp
movq 0x8(%rsi), %rsi
leaq 0x40(%rsp), %rdi
callq 0x369c
movb $0x1, %al
movl %eax, 0x8(%rsp)
movl $0x3e8, %eax            # imm = 0x3E8
movq %rax, 0x28(%rsp)
movl $0x32, %eax
movq %rax, 0x10(%rsp)
movl $0x1e, %eax
movq %rax, 0x20(%rsp)
movq $0x0, 0x18(%rsp)
leaq 0x3e6b(%rip), %rbx      # 0xb260
leaq 0x3c(%rsp), %r12
leaq 0xf9f(%rip), %r13       # 0x83a0
movb $0x1, %al
movl %eax, 0xc(%rsp)
movq $0x0, 0x30(%rsp)
movl %ebp, %edi
movq %r15, %rsi
leaq 0x1001(%rip), %rdx      # 0x841d
movq %rbx, %rcx
movq %r12, %r8
callq 0x33e0
leal -0x61(%rax), %ecx
cmpl $0x13, %ecx
ja 0x7606
movslq (%r13,%rcx,4), %rax
addq %r13, %rax
jmpq *%rax
movq 0x3b8c(%rip), %rcx      # 0xafd0
movq (%rcx), %rax
movq -0x18(%rax), %rdi
addq %rcx, %rdi
movl $0xa, %esi
callq 0x32b0
movsbl %al, %esi
movq 0x3b6e(%rip), %rdi      # 0xafd0
callq 0x3030
movq %rax, %rdi
callq 0x31f0
movq %rax, %r14
movl $0xd, %edx
movq %rax, %rdi
leaq 0xfa9(%rip), %rsi       # 0x842a
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 0x7410
movq 0x3ae0(%rip), %rax      # 0xafb0
movq (%rax), %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0x3320
movq %rax, 0x28(%rsp)
jmp 0x7410
movq 0x3ac3(%rip), %rax      # 0xafb0
movq (%rax), %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0x3320
movq %rax, 0x10(%rsp)
movq 0x3acb(%rip), %rcx      # 0xafd0
movq (%rcx), %rax
movq -0x18(%rax), %rdi
addq %rcx, %rdi
movl $0xa, %esi
callq 0x32b0
movsbl %al, %esi
movq 0x3aad(%rip), %rdi      # 0xafd0
callq 0x3030
movq %rax, %rdi
callq 0x31f0
movq %rax, %r14
movl $0x8, %edx
movq %rax, %rdi
leaq 0xef6(%rip), %rsi       # 0x8438
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 0x7410
movl $0x0, 0x8(%rsp)
jmp 0x7410
movq 0x39ef(%rip), %rax      # 0xafb0
movq (%rax), %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0x3320
movq %rax, 0x20(%rsp)
jmp 0x7410
movb $0x1, %al
movl %eax, 0x8(%rsp)
jmp 0x7410
movb $0x1, %al
movl %eax, 0xc(%rsp)
jmp 0x7410
movb $0x1, %al
movq %rax, 0x30(%rsp)
jmp 0x7410
movl $0x0, 0xc(%rsp)
jmp 0x7410
cmpl $-0x1, %eax
jne 0x7410
testb $0x1, 0x30(%rsp)
je 0x76d1
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 0xd54(%rip), %r15       # 0x83f0
leaq 0x40(%rsp), %rbx
movl (%r14,%r15), %edi
movl $0x493e0, %esi          # imm = 0x493E0
movsd 0xce6(%rip), %xmm0      # 0x8398
callq 0x7916
movq %rbx, %rdi
movq %rax, %rsi
callq 0x37be
addq $0x4, %r14
cmpq $0x10, %r14
jne 0x76a1
jmp 0x77cc
leaq 0x40(%rsp), %rdi
callq 0x37a8
testb $0x1, 0xc(%rsp)
je 0x772e
movl $0x10, %edi
callq 0x32d0
movq %rax, %r15
leaq 0x35a2(%rip), %rax      # 0xac98
addq $0x10, %rax
movq %rax, (%r15)
movl $0x8, %edi
callq 0x32d0
leaq 0x360a(%rip), %rcx      # 0xad18
leaq 0x364b(%rip), %rdx      # 0xad60
testb $0x1, 0x8(%rsp)
cmovneq %rcx, %rdx
addq $0x10, %rdx
movq %rdx, (%rax)
movq %rax, 0x8(%r15)
jmp 0x77bf
movl $0xb8, %edi
callq 0x32d0
movq %rax, %r15
cvtsi2sdl 0x20(%rsp), %xmm0
leaq 0x3598(%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 0x37be
leaq 0x40(%rsp), %rdi
callq 0x37e8
leaq 0x40(%rsp), %rdi
callq 0x4694
leaq 0x40(%rsp), %rdi
callq 0x4868
movq 0xa0(%rsp), %rdi
testq %rdi, %rdi
je 0x77fc
callq 0x3290
movq 0x88(%rsp), %rdi
testq %rdi, %rdi
je 0x780e
callq 0x3290
movq 0x70(%rsp), %rdi
testq %rdi, %rdi
je 0x781d
callq 0x3290
leaq 0x50(%rsp), %rdi
callq 0x5722
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 0xbb1(%rip), %rsi       # 0x8400
movq %rax, %rdi
callq 0x3110
movq 0x3792(%rip), %rsi      # 0xaff0
movq 0x3763(%rip), %rdx      # 0xafc8
movq %r15, %rdi
callq 0x33f0
movq %rdx, %r14
movq %rax, %rbx
movq %r15, %rdi
callq 0x3290
jmp 0x78a1
jmp 0x788f
movq %rdx, %r14
movq %rax, %rbx
movq %r15, %rdi
callq 0x3210
jmp 0x78ab
movq %rdx, %r14
movq %rax, %rbx
jmp 0x78ab
jmp 0x789b
jmp 0x789b
movq %rdx, %r14
movq %rax, %rbx
leaq 0x40(%rsp), %rdi
callq 0x7998
cmpl $0x1, %r14d
jne 0x7906
movq %rbx, %rdi
callq 0x3130
movq %rax, %rbx
movq 0x370d(%rip), %rdi      # 0xafd0
leaq 0x9d2(%rip), %rsi       # 0x829c
movl $0xe, %edx
callq 0x32f0
movq (%rbx), %rax
movq %rbx, %rdi
callq *0x10(%rax)
movq 0x36ec(%rip), %rdi      # 0xafd0
movq %rax, %rsi
callq 0x32c0
movq %rax, %rdi
callq 0x3150
callq 0x33c0
jmp 0x7827
movq %rax, %rbx
callq 0x33c0
movq %rbx, %rdi
callq 0x3410
movq %rax, %rdi
callq 0x62e8