// File: /workspace/github_cpp_makefile_star2_O2/EduBic[P]TSP-MetaheuristicSolvers/solversexecutor.cpp
// Function: SolversExecutor::execute()
void SolversExecutor::execute() {

    // name log file with actual date
    time_t rawtime;
    struct tm* timeinfo;
    char buffer[80];

    time(&rawtime);
    timeinfo = localtime(&rawtime);

    strftime(buffer, sizeof(buffer),"%d-%m-%Y %I:%M:%S", timeinfo);
    string nowTime(buffer);

    string fileNameStr = string(mFilename);
    fileNameStr.erase(0, 5);

    ofstream outputLog("Log/" + fileNameStr + "-outputLog-" + nowTime + ".txt");
    ofstream latexLog("Log/" + fileNameStr + "-latexLog-" + nowTime + ".txt");
    //ofstream csvLog("Log/" + fileNameStr + "-csvLog-" + nowTime + ".csv");

    //csvLog << "Length, Avg. Value, Avg. Time, Best Value found, Total time" << endl;

    latexLog << "Solver, Avg Value, Best Value found, Avg. Time, Total time, Avg Iter" << endl;


    for (std::vector<Solver*>::iterator it = mSolvers.begin(); it != mSolvers.end(); ++it) {

        latexLog << endl;

        int i = 0;
        double values[mInitSolutions.size()];
        double times[mInitSolutions.size()];
        uint iterations[mInitSolutions.size()];
        double bestOfBestvalue = 1e10;

        for (std::vector<TSPSolution*>::iterator inIt = mInitSolutions.begin(); inIt != mInitSolutions.end(); ++inIt) {

            TSPSolution* bestSolution = new TSPSolution(mTspInstance);
            executeAndMeasureTime(*(*it), **inIt, *bestSolution);

            mBestSolutions.push_back(bestSolution);


            // print solution into log file
            double value = bestSolution->evaluateObjectiveFunction(mTspInstance);

            if (value < bestOfBestvalue) {
                bestOfBestvalue = value;
            }

            // print logconsole result of init solution solved
            outputLog << std::endl << "----------------------------------------------------------------------" << std::endl
                      << std::endl << bestSolution->solveBy << std::endl;

            //bestSolution->print(outputLog);

            outputLog << "(value : " << value << ")\t"
                      << "sec. (user time) " << bestSolution->userTime << "\t"
                      << "sec. (CPU time) " << bestSolution->cpuTime << "\t"
                      << "Max iterations " << bestSolution->iterations << endl;

            // print latex result of init solution solved
            latexLog << bestSolution->solveBy << ", " << value << ", " << bestSolution->cpuTime << endl;

            // for compute average
            values[i] = value;
            times[i] = bestSolution->cpuTime;
            iterations[i] = bestSolution->iterations;

            i++;
        }


        double sumValue = 0;
        double sumTime = 0;
        uint sumIter = 0;
        for (unsigned int j = 0; j < mInitSolutions.size(); j++) {
            sumValue += values[j];
            sumTime += times[j];
            sumIter += iterations[j];
        }

        double avgValue = sumValue / mInitSolutions.size();
        double avgTime = sumTime / mInitSolutions.size();
        double avgIter = sumIter / mInitSolutions.size();

        //latexLog << endl;
        //latexLog << "Solver, Avg Value, Avg. Time, Best Value found, Total time, Avg Iter" << endl;
        latexLog << (*it)->getSolverName()
                 << ", " << avgValue
                 << ", " << bestOfBestvalue
                 << ", " << avgTime
                 << ", " << sumTime
                 << ", " << avgIter;
        latexLog << endl;


        // Print result for Calibration of TS
        TabuSearchSolver* tsSolver = dynamic_cast<TabuSearchSolver*>(*it);
        if (tsSolver != NULL) {
            //csvLog << tsSolver->mTabuLength << ", " << avgValue << ", " << ", " << bestOfBestvalue << ", " << avgTime << ", " << sumTime << endl;
        }

        // Print result
        // csvLog << (*it)->getSolverName() << ", " << bestOfBestvalue << ", " << sumTime << endl;
    }

    //csvLog.close();
    latexLog.close();
    outputLog.close();
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x568, %rsp            # imm = 0x568
movq %rdi, %rbx
leaq -0x140(%rbp), %r14
movq %r14, %rdi
callq 0x3220
movq %r14, %rdi
callq 0x31d0
leaq 0x3937(%rip), %rdx      # 0x7038
leaq -0x590(%rbp), %r14
pushq $0x50
popq %rsi
movq %r14, %rdi
movq %rax, %rcx
callq 0x31f0
leaq -0x118(%rbp), %rdi
leaq -0x540(%rbp), %rdx
movq %r14, %rsi
callq 0x30f0
movq %rbx, -0x38(%rbp)
movq (%rbx), %rsi
leaq -0xf8(%rbp), %rdi
leaq -0x540(%rbp), %rdx
callq 0x30f0
leaq -0xf8(%rbp), %rdi
pushq $0x5
popq %rdx
xorl %esi, %esi
callq 0x3090
leaq 0x38ec(%rip), %rsi      # 0x704a
leaq -0xb8(%rbp), %rdi
leaq -0xf8(%rbp), %rdx
callq 0x46f5
leaq 0x38d7(%rip), %rdx      # 0x704f
leaq -0xd8(%rbp), %rdi
leaq -0xb8(%rbp), %rsi
callq 0x46b7
leaq -0x68(%rbp), %rdi
leaq -0xd8(%rbp), %rsi
leaq -0x118(%rbp), %rdx
callq 0x46d6
leaq 0x38b2(%rip), %rdx      # 0x705b
leaq -0x340(%rbp), %rdi
leaq -0x68(%rbp), %rsi
callq 0x46b7
leaq -0x540(%rbp), %rdi
leaq -0x340(%rbp), %rsi
pushq $0x10
popq %rdx
callq 0x33f0
leaq -0x340(%rbp), %rdi
callq 0x3120
leaq -0x68(%rbp), %rdi
callq 0x3120
leaq -0xd8(%rbp), %rdi
callq 0x3120
leaq -0xb8(%rbp), %rdi
callq 0x3120
leaq 0x3847(%rip), %rsi      # 0x704a
leaq -0x138(%rbp), %rdi
leaq -0xf8(%rbp), %rdx
callq 0x46f5
leaq 0x3843(%rip), %rdx      # 0x7060
leaq -0xb8(%rbp), %rdi
leaq -0x138(%rbp), %rsi
callq 0x46b7
leaq -0xd8(%rbp), %rdi
leaq -0xb8(%rbp), %rsi
leaq -0x118(%rbp), %rdx
callq 0x46d6
leaq 0x380a(%rip), %rdx      # 0x705b
leaq -0x68(%rbp), %rdi
leaq -0xd8(%rbp), %rsi
callq 0x46b7
leaq -0x340(%rbp), %rdi
leaq -0x68(%rbp), %rsi
pushq $0x10
popq %rdx
callq 0x33f0
leaq -0x68(%rbp), %rdi
callq 0x3120
leaq -0xd8(%rbp), %rdi
callq 0x3120
leaq -0xb8(%rbp), %rdi
callq 0x3120
leaq -0x138(%rbp), %rdi
callq 0x3120
leaq 0x37c3(%rip), %rsi      # 0x706b
leaq -0x340(%rbp), %rdi
callq 0x3250
movq %rax, %rdi
callq 0x3130
movq -0x38(%rbp), %rax
movq 0x30(%rax), %rbx
leaq 0x8(%rax), %rcx
movq %rcx, -0x80(%rbp)
addq $0x48, %rax
movq %rax, -0x98(%rbp)
movq -0x38(%rbp), %rax
cmpq 0x38(%rax), %rbx
je 0x3ca1
movq %rbx, -0x78(%rbp)
leaq -0x340(%rbp), %rdi
callq 0x3130
movq %rsp, -0x88(%rbp)
movq -0x38(%rbp), %rcx
movq 0x68(%rcx), %rax
subq 0x60(%rcx), %rax
addq $0xf, %rax
andq $-0x10, %rax
movq %rsp, %rdx
subq %rax, %rdx
movq %rdx, -0x48(%rbp)
movq %rdx, %rsp
movq 0x60(%rcx), %rdx
movq 0x68(%rcx), %r13
movq %r13, %rax
movq %rdx, -0x40(%rbp)
subq %rdx, %rax
movq %rsp, %r15
leaq 0xf(%rax), %rcx
andq $-0x10, %rcx
subq %rcx, %r15
movq %r15, %rsp
movq %rsp, %r14
sarq %rax
addq $0xf, %rax
andq $-0x10, %rax
subq %rax, %r14
movq %r14, %rsp
xorl %ebx, %ebx
movq %r14, -0x90(%rbp)
movsd 0x36bb(%rip), %xmm0     # 0x7020
movsd %xmm0, -0x70(%rbp)
movq -0x40(%rbp), %rax
leaq (%rax,%rbx), %r12
cmpq %r13, %r12
je 0x3b5e
pushq $0x50
popq %rdi
callq 0x3260
movq %rax, %r13
movq %rax, %rdi
movq -0x80(%rbp), %rsi
callq 0x44e6
movq %r13, -0x68(%rbp)
movq -0x78(%rbp), %rax
movq (%rax), %rsi
movq (%r12), %rdx
movq -0x38(%rbp), %rdi
movq %r13, %rcx
callq 0x3df2
movq -0x98(%rbp), %rdi
leaq -0x68(%rbp), %rsi
callq 0x467c
movq -0x68(%rbp), %rdi
movq -0x80(%rbp), %rsi
callq 0x476c
movsd %xmm0, -0x30(%rbp)
leaq -0x540(%rbp), %rdi
callq 0x3130
movq %rax, %rdi
leaq 0x36cb(%rip), %rsi      # 0x70b0
callq 0x3250
movq %rax, %rdi
callq 0x3130
movq %rax, %rdi
callq 0x3130
movq -0x68(%rbp), %rsi
addq $0x18, %rsi
movq %rax, %rdi
callq 0x3210
movq %rax, %rdi
callq 0x3130
leaq -0x540(%rbp), %rdi
leaq 0x36d7(%rip), %rsi      # 0x70f7
callq 0x3250
movq %rax, %rdi
movsd -0x30(%rbp), %xmm0
callq 0x3320
movq %rax, %rdi
leaq 0x36c5(%rip), %rsi      # 0x7101
callq 0x3250
movq %rax, %rdi
leaq 0x36b9(%rip), %rsi      # 0x7104
callq 0x3250
movq -0x68(%rbp), %rcx
movsd 0x38(%rcx), %xmm0
movq %rax, %rdi
callq 0x3320
movq %rax, %rdi
leaq 0x3697(%rip), %rsi      # 0x7102
callq 0x3250
movq %rax, %rdi
leaq 0x369c(%rip), %rsi      # 0x7116
callq 0x3250
movq -0x68(%rbp), %rcx
movsd 0x40(%rcx), %xmm0
movq %rax, %rdi
callq 0x3320
movq %rax, %rdi
leaq 0x3668(%rip), %rsi      # 0x7102
callq 0x3250
movq %rax, %rdi
leaq 0x367e(%rip), %rsi      # 0x7127
callq 0x3250
movq -0x68(%rbp), %rcx
movl 0x48(%rcx), %esi
movq %rax, %rdi
callq 0x31b0
movq %rax, %rdi
callq 0x3130
movq -0x68(%rbp), %rsi
addq $0x18, %rsi
leaq -0x340(%rbp), %rdi
callq 0x3210
movq %rax, %rdi
leaq 0x378c(%rip), %rsi      # 0x726f
callq 0x3250
movq %rax, %rdi
movsd -0x30(%rbp), %xmm0
callq 0x3320
movq %rax, %rdi
leaq 0x3770(%rip), %rsi      # 0x726f
callq 0x3250
movq -0x68(%rbp), %rcx
movsd 0x40(%rcx), %xmm0
movq %rax, %rdi
callq 0x3320
movq %rax, %rdi
callq 0x3130
movsd -0x30(%rbp), %xmm1
movapd %xmm1, %xmm0
minsd -0x70(%rbp), %xmm0
movq -0x48(%rbp), %rax
movsd %xmm1, (%rax,%rbx)
movq -0x68(%rbp), %rax
movsd 0x40(%rax), %xmm1
movsd %xmm1, (%r15,%rbx)
movl 0x48(%rax), %eax
movl %eax, (%r14)
movq -0x38(%rbp), %rax
movq 0x68(%rax), %r13
addq $0x4, %r14
addq $0x8, %rbx
jmp 0x3965
movq -0x38(%rbp), %rax
subq 0x60(%rax), %r13
sarq $0x3, %r13
xorl %eax, %eax
xorpd %xmm0, %xmm0
movsd %xmm0, -0x40(%rbp)
movsd %xmm0, -0x30(%rbp)
xorl %ecx, %ecx
movq -0x90(%rbp), %rsi
movl %ecx, %ecx
cmpq %rcx, %r13
jbe 0x3bb4
movq -0x48(%rbp), %rdx
movsd -0x40(%rbp), %xmm0
addsd (%rdx,%rcx,8), %xmm0
movsd %xmm0, -0x40(%rbp)
movsd -0x30(%rbp), %xmm0
addsd (%r15,%rcx,8), %xmm0
movsd %xmm0, -0x30(%rbp)
addl (%rsi,%rcx,4), %eax
incl %ecx
jmp 0x3b83
xorl %edx, %edx
divl %r13d
movl %eax, %r15d
movq -0x78(%rbp), %rbx
movq (%rbx), %rsi
movq (%rsi), %rax
leaq -0x68(%rbp), %r14
movq %r14, %rdi
callq *(%rax)
leaq -0x340(%rbp), %rdi
movq %r14, %rsi
callq 0x3210
movq %rax, %rdi
leaq 0x3687(%rip), %rsi      # 0x726f
callq 0x3250
cvtsi2sd %r13, %xmm1
movsd -0x40(%rbp), %xmm0
movsd %xmm1, -0x48(%rbp)
divsd %xmm1, %xmm0
movq %rax, %rdi
callq 0x3320
movq %rax, %rdi
leaq 0x365d(%rip), %rsi      # 0x726f
callq 0x3250
movq %rax, %rdi
movsd -0x70(%rbp), %xmm0
callq 0x3320
movq %rax, %rdi
leaq 0x3641(%rip), %rsi      # 0x726f
callq 0x3250
movsd -0x30(%rbp), %xmm0
divsd -0x48(%rbp), %xmm0
movq %rax, %rdi
callq 0x3320
movq %rax, %rdi
leaq 0x3620(%rip), %rsi      # 0x726f
callq 0x3250
movq %rax, %rdi
movsd -0x30(%rbp), %xmm0
callq 0x3320
movq %rax, %rdi
leaq 0x3604(%rip), %rsi      # 0x726f
callq 0x3250
cvtsi2sd %r15, %xmm0
movq %rax, %rdi
callq 0x3320
movq %r14, %rdi
callq 0x3120
leaq -0x340(%rbp), %rdi
callq 0x3130
movq -0x88(%rbp), %rsp
addq $0x8, %rbx
jmp 0x38d7
leaq -0x340(%rbp), %rdi
callq 0x32d0
leaq -0x540(%rbp), %rdi
callq 0x32d0
leaq -0x340(%rbp), %rdi
callq 0x32f0
leaq -0x540(%rbp), %rdi
callq 0x32f0
leaq -0xf8(%rbp), %rdi
callq 0x3120
leaq -0x118(%rbp), %rdi
callq 0x3120
leaq -0x28(%rbp), %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
leaq -0x68(%rbp), %rdi
callq 0x3120
jmp 0x3d09
movq %rax, %rbx
leaq -0xd8(%rbp), %rdi
callq 0x3120
jmp 0x3d1a
movq %rax, %rbx
leaq -0xb8(%rbp), %rdi
callq 0x3120
jmp 0x3d2b
movq %rax, %rbx
leaq -0x138(%rbp), %rdi
callq 0x3120
jmp 0x3dc5
movq %rax, %rbx
jmp 0x3dc5
movq %rax, %rbx
leaq -0x340(%rbp), %rdi
callq 0x3120
jmp 0x3d58
movq %rax, %rbx
leaq -0x68(%rbp), %rdi
callq 0x3120
jmp 0x3d66
movq %rax, %rbx
leaq -0xd8(%rbp), %rdi
callq 0x3120
jmp 0x3d77
movq %rax, %rbx
leaq -0xb8(%rbp), %rdi
callq 0x3120
jmp 0x3dd1
jmp 0x3d87
movq %rax, %rbx
jmp 0x3dd1
movq %rax, %rbx
jmp 0x3ddd
jmp 0x3db6
jmp 0x3db6
jmp 0x3db6
jmp 0x3db6
movq %rax, %rbx
leaq -0x68(%rbp), %rdi
callq 0x3120
jmp 0x3db9
movq %rax, %rbx
movq %r13, %rdi
callq 0x3230
jmp 0x3db9
jmp 0x3db6
movq %rax, %rbx
leaq -0x340(%rbp), %rdi
callq 0x32f0
leaq -0x540(%rbp), %rdi
callq 0x32f0
leaq -0xf8(%rbp), %rdi
callq 0x3120
leaq -0x118(%rbp), %rdi
callq 0x3120
movq %rbx, %rdi
callq 0x33b0
nop