// File: /workspace/github_cpp_makefile_star2_O2/canzarlab[P]Trajan/src/Solver.cpp
// Function: Solver::Solver(Graph&, Graph&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>, double, bool)
Solver::Solver(Graph& t1, Graph& t2, string d, double k, bool dag) : t1(t1), t2(t2), d(d), k(k), dag(dag)
{
    if (d == "e"){
        std::string fileName = costMatrixFileName;  // use file name from main function. 
        std::ifstream f(fileName.c_str());
        if (f.good())
        {
            CSVReader reader(costMatrixFileName);
            cost_matrix = reader.getDoubleData();
        }
        else
        {
            std::cout << "PLEASE INPUT WEIGHT(COST) MATRIX DIRECTORY:"; 
            std::cin >> fileName;
            CSVReader reader(fileName);
            cost_matrix = reader.getDoubleData();
        }
        // scale distance matrix 
        // std::cout << "Rescale distance matrix\n"; TODO: 
        int n = (int) cost_matrix.size();
        int m = (int) cost_matrix[0].size();
        scaleCoef = 1.0;
        for (int i=0; i < n; ++i)
            scaleCoef = max(scaleCoef, cost_matrix[i][0]);
        scaleCoef = min(scaleCoef, 100.0);
        for (int i=0; i < n; ++i){
            for (int j=0; j < m;++j)
            {
                cost_matrix[i][j] = cost_matrix[i][j]/scaleCoef;
            }
        }
        // std::cout << "scale coef: " << scaleCoef << m << n << endl;
    }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0x310, %rsp            # imm = 0x310
movl %r8d, %ebp
movsd %xmm0, 0x8(%rsp)
movq %rcx, %r15
movq %rdi, %rbx
leaq 0x63b67(%rip), %rax     # 0x954a0
movq %rax, (%rdi)
xorpd %xmm0, %xmm0
movupd %xmm0, 0x8(%rdi)
andq $0x0, 0x18(%rdi)
movabsq $0x3ff0000000000000, %r12 # imm = 0x3FF0000000000000
movq %r12, 0x28(%rdi)
movq %rsi, 0x30(%rdi)
movq %rdx, 0x38(%rdi)
leaq 0x40(%rdi), %r14
movq %r14, %rdi
movq %rcx, %rsi
callq 0x9470
movsd 0x8(%rsp), %xmm0
movsd %xmm0, 0x60(%rbx)
movb %bpl, 0x68(%rbx)
xorpd %xmm0, %xmm0
movupd %xmm0, 0x70(%rbx)
andq $0x0, 0x80(%rbx)
leaq 0x3c67d(%rip), %rsi     # 0x6e013
movq %r15, %rdi
callq 0xb7fa
testb %al, %al
je 0x31bd2
leaq 0x70(%rbx), %r15
leaq 0x659ff(%rip), %rsi     # 0x973b0
leaq 0x28(%rsp), %rdi
callq 0x9470
movq 0x28(%rsp), %rsi
leaq 0x108(%rsp), %rdi
pushq $0x8
popq %rdx
callq 0x9690
movq 0x108(%rsp), %rax
movq -0x18(%rax), %rax
cmpl $0x0, 0x128(%rsp,%rax)
je 0x31a79
movq 0x655bf(%rip), %rdi     # 0x96fb0
leaq 0x3af3a(%rip), %rsi     # 0x6c932
callq 0x9330
movq 0x655d4(%rip), %rdi     # 0x96fd8
leaq 0x28(%rsp), %rsi
callq 0x9400
leaq 0x68(%rsp), %rdi
leaq 0x28(%rsp), %rsi
callq 0x9470
leaq 0x3af0c(%rip), %rsi     # 0x6c930
leaq 0x48(%rsp), %rdi
leaq 0x10(%rsp), %rdx
callq 0xb7a6
leaq 0xc8(%rsp), %rdi
leaq 0x68(%rsp), %rsi
leaq 0x48(%rsp), %rdx
callq 0xb826
leaq 0x48(%rsp), %rdi
callq 0x9708
leaq 0x68(%rsp), %rdi
callq 0x9708
leaq 0x10(%rsp), %rdi
leaq 0xc8(%rsp), %rsi
xorl %edx, %edx
movl $0x2710, %ecx           # imm = 0x2710
callq 0x4eae6
jmp 0x31af6
leaq 0x65930(%rip), %rsi     # 0x973b0
leaq 0xa8(%rsp), %rdi
callq 0x9470
leaq 0x3ae9c(%rip), %rsi     # 0x6c930
leaq 0x88(%rsp), %rdi
leaq 0x10(%rsp), %rdx
callq 0xb7a6
leaq 0xc8(%rsp), %rdi
leaq 0xa8(%rsp), %rsi
leaq 0x88(%rsp), %rdx
callq 0xb826
leaq 0x88(%rsp), %rdi
callq 0x9708
leaq 0xa8(%rsp), %rdi
callq 0x9708
leaq 0x10(%rsp), %rdi
leaq 0xc8(%rsp), %rsi
xorl %edx, %edx
movl $0x2710, %ecx           # imm = 0x2710
callq 0x4eae6
leaq 0x10(%rsp), %r14
movq %r15, %rdi
movq %r14, %rsi
callq 0x321f8
movq %r14, %rdi
callq 0x2dd00
leaq 0xc8(%rsp), %rdi
callq 0xb9e8
movq 0x70(%rbx), %rcx
movq 0x78(%rbx), %rax
subq %rcx, %rax
pushq $0x18
popq %rsi
cqto
idivq %rsi
movq 0x8(%rcx), %rdx
subq (%rcx), %rdx
shrq $0x3, %rdx
movq %r12, 0x28(%rbx)
xorl %esi, %esi
testl %eax, %eax
cmovlel %esi, %eax
imulq $0x18, %rax, %rdi
movsd 0x21cd0(%rip), %xmm0    # 0x53820
cmpq %rsi, %rdi
je 0x31b71
movq (%rcx,%rsi), %r8
movsd (%r8), %xmm1
maxsd %xmm0, %xmm1
movsd %xmm1, 0x28(%rbx)
addq $0x18, %rsi
movapd %xmm1, %xmm0
jmp 0x31b50
movsd 0x3ad87(%rip), %xmm1    # 0x6c900
minsd %xmm0, %xmm1
movsd %xmm1, 0x28(%rbx)
xorl %esi, %esi
testl %edx, %edx
cmovlel %esi, %edx
cmpq %rax, %rsi
je 0x31bbb
imulq $0x18, %rsi, %rdi
addq %rcx, %rdi
xorl %r8d, %r8d
cmpq %r8, %rdx
je 0x31bb6
movq (%rdi), %r9
movsd (%r9,%r8,8), %xmm0
divsd 0x28(%rbx), %xmm0
movsd %xmm0, (%r9,%r8,8)
incq %r8
jmp 0x31b98
incq %rsi
jmp 0x31b89
leaq 0x108(%rsp), %rdi
callq 0x90c0
leaq 0x28(%rsp), %rdi
callq 0x9708
addq $0x310, %rsp            # imm = 0x310
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
jmp 0x31c05
movq %rax, %r12
leaq 0x88(%rsp), %rdi
callq 0x9708
jmp 0x31bf9
movq %rax, %r12
leaq 0xa8(%rsp), %rdi
jmp 0x31c2e
jmp 0x31c41
movq %rax, %r12
leaq 0xc8(%rsp), %rdi
callq 0xb9e8
jmp 0x31c44
movq %rax, %r12
leaq 0x48(%rsp), %rdi
callq 0x9708
jmp 0x31c29
movq %rax, %r12
leaq 0x68(%rsp), %rdi
callq 0x9708
jmp 0x31c44
jmp 0x31c41
movq %rax, %r12
jmp 0x31c51
movq %rax, %r12
jmp 0x31c5b
movq %rax, %r12
leaq 0x108(%rsp), %rdi
callq 0x90c0
leaq 0x28(%rsp), %rdi
callq 0x9708
movq %r15, %rdi
callq 0x2dd00
movq %r14, %rdi
callq 0x9708
jmp 0x31c70
movq %rax, %r12
addq $0x8, %rbx
movq %rbx, %rdi
callq 0x3137c
movq %r12, %rdi
callq 0x9640