// File: /workspace/github_cpp_makefile_star2_O2/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 0x67d8
movq %rsi, %r15
movl %edi, %ebp
movq 0x8(%rsi), %rsi
leaq 0x40(%rsp), %rdi
callq 0x35ac
movb $0x1, %al
movl %eax, 0x8(%rsp)
movl $0x3e8, %eax            # imm = 0x3E8
movq %rax, 0x28(%rsp)
pushq $0x32
popq %rax
movq %rax, 0x10(%rsp)
pushq $0x1e
popq %rax
movq %rax, 0x20(%rsp)
movq $0x0, 0x18(%rsp)
leaq 0xed8(%rip), %r13       # 0x73fd
leaq 0x4d14(%rip), %rbx      # 0xb240
leaq 0x3c(%rsp), %r12
leaq 0xe48(%rip), %r14       # 0x7380
movb $0x1, %al
movl %eax, 0xc(%rsp)
movq $0x0, 0x30(%rsp)
movl %ebp, %edi
movq %r15, %rsi
movq %r13, %rdx
movq %rbx, %rcx
movq %r12, %r8
callq 0x3380
leal -0x61(%rax), %ecx
cmpl $0x13, %ecx
ja 0x666e
movslq (%r14,%rcx,4), %rax
addq %r14, %rax
jmpq *%rax
movq 0x4a5a(%rip), %rdi      # 0xafd0
callq 0x3130
movq %rax, %rdi
leaq 0xe85(%rip), %rsi       # 0x740a
callq 0x3250
movq %rax, %rdi
pushq $0x1
popq %rsi
callq 0x3370
movb $0x1, %cl
movq %rcx, 0x18(%rsp)
movq %rax, %rdi
callq 0x3130
jmp 0x6547
movq 0x4a0b(%rip), %rax      # 0xafb8
movq (%rax), %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0x32c0
movq %rax, 0x28(%rsp)
jmp 0x6547
movq 0x49f1(%rip), %rax      # 0xafb8
movq (%rax), %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0x32c0
movq %rax, 0x10(%rsp)
movq 0x49f1(%rip), %rdi      # 0xafd0
callq 0x3130
movq %rax, %rdi
leaq 0xe2a(%rip), %rsi       # 0x7418
callq 0x3250
movq %rax, %rdi
movq 0x10(%rsp), %rsi
callq 0x33a0
movq %rax, %rdi
callq 0x3130
movq %rax, %rdi
callq 0x3130
jmp 0x6547
movl $0x0, 0x8(%rsp)
jmp 0x6547
movq 0x498f(%rip), %rax      # 0xafb8
movq (%rax), %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0x32c0
movq %rax, 0x20(%rsp)
jmp 0x6547
movb $0x1, %al
movl %eax, 0x8(%rsp)
jmp 0x6547
movb $0x1, %al
movl %eax, 0xc(%rsp)
jmp 0x6547
movb $0x1, %al
movq %rax, 0x30(%rsp)
jmp 0x6547
movl $0x0, 0xc(%rsp)
jmp 0x6547
cmpl $-0x1, %eax
jne 0x6547
testb $0x1, 0x30(%rsp)
je 0x672a
leaq 0x40(%rsp), %rdi
pushq $0x3a
popq %rsi
callq 0x3640
leaq 0x40(%rsp), %rdi
pushq $0x4
popq %rsi
callq 0x3640
leaq 0x40(%rsp), %rdi
pushq $0x19
popq %rsi
callq 0x3640
leaq 0x40(%rsp), %rdi
pushq $0x1a
popq %rsi
callq 0x3640
leaq 0x40(%rsp), %rdi
pushq $0x2b
popq %rsi
callq 0x3640
leaq 0x40(%rsp), %rdi
pushq $0x2e
popq %rsi
callq 0x3640
leaq 0x40(%rsp), %rdi
pushq $0x5d
popq %rsi
callq 0x3640
leaq 0x40(%rsp), %rdi
pushq $0x63
popq %rsi
callq 0x3640
xorl %r14d, %r14d
leaq 0xcdc(%rip), %r15       # 0x73d0
leaq 0x40(%rsp), %rbx
cmpq $0x10, %r14
je 0x679c
movl (%r14,%r15), %edi
movl $0x493e0, %esi          # imm = 0x493E0
movsd 0xc64(%rip), %xmm0      # 0x7378
callq 0x68ac
movq %rbx, %rdi
movq %rax, %rsi
callq 0x36b6
addq $0x4, %r14
jmp 0x66f9
leaq 0x40(%rsp), %rdi
callq 0x36a0
testb $0x1, 0xc(%rsp)
je 0x6758
pushq $0x10
popq %rdi
callq 0x3260
movq %rax, %r15
movzbl 0x8(%rsp), %esi
andl $0x1, %esi
movq %rax, %rdi
callq 0x68f0
jmp 0x678f
movl $0xb8, %edi
callq 0x3260
movq %rax, %r15
cvtsi2sdl 0x20(%rsp), %xmm0
movzbl 0x18(%rsp), %ecx
andl $0x1, %ecx
movzbl 0x8(%rsp), %r8d
andl $0x1, %r8d
movq %rax, %rdi
movq 0x10(%rsp), %rsi
movq 0x28(%rsp), %rdx
callq 0x6936
leaq 0x40(%rsp), %rdi
movq %r15, %rsi
callq 0x36b6
leaq 0x40(%rsp), %rdi
callq 0x36cc
leaq 0x40(%rsp), %rdi
callq 0x3f62
leaq 0x40(%rsp), %rdi
callq 0x4070
leaq 0x40(%rsp), %rdi
callq 0x699a
xorl %eax, %eax
addq $0xb8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
pushq $0x10
popq %rdi
callq 0x3140
movq %rax, %r15
leaq 0xbf6(%rip), %rsi       # 0x73e0
movq %rax, %rdi
callq 0x30e0
movq 0x47f7(%rip), %rsi      # 0xaff0
movq 0x47c8(%rip), %rdx      # 0xafc8
movq %r15, %rdi
callq 0x3390
movq %rdx, %r14
movq %rax, %rbx
movq %r15, %rdi
callq 0x3230
jmp 0x683c
jmp 0x682a
movq %rdx, %r14
movq %rax, %rbx
movq %r15, %rdi
callq 0x31c0
jmp 0x6846
movq %rdx, %r14
movq %rax, %rbx
jmp 0x6846
jmp 0x6836
jmp 0x6836
movq %rdx, %r14
movq %rax, %rbx
leaq 0x40(%rsp), %rdi
callq 0x699a
cmpl $0x1, %r14d
jne 0x689b
movq %rbx, %rdi
callq 0x3100
movq %rax, %rbx
movq 0x4772(%rip), %rdi      # 0xafd0
leaq 0xa0d(%rip), %rsi       # 0x7272
callq 0x3250
movq %rax, %r14
movq (%rbx), %rax
movq %rbx, %rdi
callq *0x10(%rax)
movq %r14, %rdi
movq %rax, %rsi
callq 0x3250
movq %rax, %rdi
callq 0x3130
callq 0x3360
jmp 0x67c4
movq %rax, %rbx
callq 0x3360
movq %rbx, %rdi
callq 0x33b0
movq %rax, %rdi
callq 0x4a0a
nop