// File: /workspace/github_cpp_makefile_star2_O1/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 %r13
pushq %r12
pushq %rbx
subq $0x328, %rsp            # imm = 0x328
movl %r8d, %ebp
movsd %xmm0, 0x20(%rsp)
movq %rcx, %r15
movq %rdi, %rbx
leaq 0x521dd(%rip), %rax     # 0x86418
movq %rax, (%rdi)
xorpd %xmm0, %xmm0
movupd %xmm0, 0x8(%rdi)
movq $0x0, 0x18(%rdi)
movabsq $0x3ff0000000000000, %r12 # imm = 0x3FF0000000000000
movq %r12, 0x28(%rdi)
movq %rsi, 0x30(%rdi)
movq %rdx, 0x38(%rdi)
leaq 0x40(%rdi), %r14
leaq 0x50(%rdi), %r13
movq %r13, 0x40(%rdi)
movq (%rcx), %rsi
movq 0x8(%rcx), %rdx
addq %rsi, %rdx
movq %r14, %rdi
callq 0xda94
movsd 0x20(%rsp), %xmm0
movsd %xmm0, 0x60(%rbx)
movb %bpl, 0x68(%rbx)
xorpd %xmm0, %xmm0
movupd %xmm0, 0x70(%rbx)
movq $0x0, 0x80(%rbx)
leaq 0x3bcee(%rip), %rsi     # 0x6ff9b
movq %r15, %rdi
callq 0x90e0
testl %eax, %eax
jne 0x3461b
leaq 0x10(%rsp), %rax
movq %rax, -0x10(%rax)
leaq 0x540f3(%rip), %rbp     # 0x883c0
movq (%rbp), %rsi
movq 0x8(%rbp), %rdx
addq %rsi, %rdx
movq %rsp, %rdi
callq 0xda94
movq (%rsp), %rsi
leaq 0x120(%rsp), %rdi
movl $0x8, %edx
callq 0x96c0
movq 0x120(%rsp), %rax
movq -0x18(%rax), %rax
cmpl $0x0, 0x140(%rsp,%rax)
je 0x343dd
movq 0x53ca9(%rip), %rdi     # 0x87fc0
leaq 0x3af04(%rip), %rsi     # 0x6f222
movl $0x2b, %edx
callq 0x93a0
movq 0x53ca9(%rip), %rdi     # 0x87fd8
movq %rsp, %rsi
callq 0x9400
leaq 0x58(%rsp), %r15
movq %r15, -0x10(%r15)
movq (%rsp), %rsi
movq 0x8(%rsp), %rdx
addq %rsi, %rdx
leaq 0x48(%rsp), %rdi
callq 0xda94
leaq 0x38(%rsp), %rbp
movq %rbp, -0x10(%rbp)
leaq 0x3aeba(%rip), %rsi     # 0x6f220
leaq 0x3aeb4(%rip), %rdx     # 0x6f221
leaq 0x28(%rsp), %rdi
callq 0xdb24
leaq 0xa8(%rsp), %rdi
leaq 0x48(%rsp), %rsi
leaq 0x28(%rsp), %rdx
callq 0xd66e
movq 0x28(%rsp), %rdi
cmpq %rbp, %rdi
je 0x343a5
movq 0x38(%rsp), %rsi
incq %rsi
callq 0x9340
movq 0x48(%rsp), %rdi
cmpq %r15, %rdi
je 0x343bc
movq 0x58(%rsp), %rsi
incq %rsi
callq 0x9340
leaq 0xe8(%rsp), %rdi
leaq 0xa8(%rsp), %rsi
xorl %edx, %edx
movl $0x2710, %ecx           # imm = 0x2710
callq 0x59450
jmp 0x3448c
leaq 0x98(%rsp), %r15
movq %r15, -0x10(%r15)
movq (%rbp), %rsi
movq 0x8(%rbp), %rdx
addq %rsi, %rdx
leaq 0x88(%rsp), %rdi
callq 0xda94
leaq 0x78(%rsp), %rbp
movq %rbp, -0x10(%rbp)
leaq 0x3ae0f(%rip), %rsi     # 0x6f220
leaq 0x3ae09(%rip), %rdx     # 0x6f221
leaq 0x68(%rsp), %rdi
callq 0xdb24
leaq 0xa8(%rsp), %rdi
leaq 0x88(%rsp), %rsi
leaq 0x68(%rsp), %rdx
callq 0xd66e
movq 0x68(%rsp), %rdi
cmpq %rbp, %rdi
je 0x34453
movq 0x78(%rsp), %rsi
incq %rsi
callq 0x9340
movq 0x88(%rsp), %rdi
cmpq %r15, %rdi
je 0x34470
movq 0x98(%rsp), %rsi
incq %rsi
callq 0x9340
leaq 0xe8(%rsp), %rdi
leaq 0xa8(%rsp), %rsi
xorl %edx, %edx
movl $0x2710, %ecx           # imm = 0x2710
callq 0x59450
xorpd %xmm0, %xmm0
leaq 0x100(%rsp), %rdi
movapd %xmm0, (%rdi)
movq $0x0, 0x10(%rdi)
movq 0x70(%rbx), %rax
movupd 0x78(%rbx), %xmm0
leaq 0xe8(%rsp), %r14
movq (%r14), %rcx
movq %rcx, 0x70(%rbx)
movq 0x8(%r14), %rcx
movq %rcx, 0x78(%rbx)
movq 0x10(%r14), %rcx
movq %rcx, 0x80(%rbx)
movq (%rdi), %rcx
movq 0x8(%rdi), %rdx
movq 0x10(%rdi), %rsi
movq %rax, (%rdi)
movupd %xmm0, 0x8(%rdi)
movq %rcx, (%r14)
movq %rdx, 0x8(%r14)
movq %rsi, 0x10(%r14)
callq 0x30124
movq %r14, %rdi
callq 0x30124
leaq 0xd8(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x3451b
movq 0xd8(%rsp), %rsi
incq %rsi
callq 0x9340
leaq 0xb8(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x3453c
movq 0xb8(%rsp), %rsi
incq %rsi
callq 0x9340
movq 0x70(%rbx), %rax
movq 0x78(%rbx), %rdx
subq %rax, %rdx
sarq $0x3, %rdx
movabsq $-0x5555555555555555, %rcx # imm = 0xAAAAAAAAAAAAAAAB
imulq %rdx, %rcx
movq 0x8(%rax), %rdx
subq (%rax), %rdx
movq %r12, 0x28(%rbx)
testl %ecx, %ecx
jle 0x34599
movl %ecx, %esi
andl $0x7fffffff, %esi       # imm = 0x7FFFFFFF
movsd 0x27e30(%rip), %xmm0    # 0x5c3a8
movq %rax, %rdi
movq (%rdi), %r8
movsd (%r8), %xmm1
maxsd %xmm0, %xmm1
movsd %xmm1, 0x28(%rbx)
addq $0x18, %rdi
movapd %xmm1, %xmm0
decq %rsi
jne 0x3457b
movsd 0x3ac4f(%rip), %xmm0    # 0x6f1f0
minsd 0x28(%rbx), %xmm0
movsd %xmm0, 0x28(%rbx)
testl %ecx, %ecx
jle 0x345f3
shrq $0x3, %rdx
movl $0x7fffffff, %edi       # imm = 0x7FFFFFFF
andq %rdi, %rcx
movq %rdx, %rsi
andq %rdi, %rsi
xorl %edi, %edi
testl %edx, %edx
jle 0x345eb
leaq (%rdi,%rdi,2), %r8
movq (%rax,%r8,8), %r8
xorl %r9d, %r9d
movsd (%r8,%r9,8), %xmm0
divsd 0x28(%rbx), %xmm0
movsd %xmm0, (%r8,%r9,8)
incq %r9
cmpq %r9, %rsi
jne 0x345d2
incq %rdi
cmpq %rcx, %rdi
jne 0x345c3
leaq 0x120(%rsp), %rdi
callq 0x90b0
movq (%rsp), %rdi
leaq 0x10(%rsp), %rax
cmpq %rax, %rdi
je 0x3461b
movq 0x10(%rsp), %rsi
incq %rsi
callq 0x9340
addq $0x328, %rsp            # imm = 0x328
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x34667
movq %rax, %r12
movq 0x68(%rsp), %rdi
cmpq %rbp, %rdi
je 0x3464e
movq 0x78(%rsp), %rsi
incq %rsi
callq 0x9340
jmp 0x3464e
movq %rax, %r12
movq 0x88(%rsp), %rdi
cmpq %r15, %rdi
je 0x346c0
movq 0x98(%rsp), %rsi
jmp 0x346a7
jmp 0x346bd
movq %rax, %r12
leaq 0xa8(%rsp), %rdi
callq 0xd790
jmp 0x346c0
movq %rax, %r12
movq 0x28(%rsp), %rdi
cmpq %rbp, %rdi
je 0x34698
movq 0x38(%rsp), %rsi
incq %rsi
callq 0x9340
jmp 0x34698
movq %rax, %r12
movq 0x48(%rsp), %rdi
cmpq %r15, %rdi
je 0x346c0
movq 0x58(%rsp), %rsi
incq %rsi
callq 0x9340
jmp 0x346c0
jmp 0x346bd
movq %rax, %r12
jmp 0x346cd
movq %rax, %r12
jmp 0x346e8
movq %rax, %r12
leaq 0x120(%rsp), %rdi
callq 0x90b0
movq (%rsp), %rdi
leaq 0x10(%rsp), %rax
cmpq %rax, %rdi
je 0x346e8
movq 0x10(%rsp), %rsi
incq %rsi
callq 0x9340
leaq 0x70(%rbx), %rdi
callq 0x30124
movq (%r14), %rdi
cmpq %r13, %rdi
je 0x3470a
movq (%r13), %rsi
incq %rsi
callq 0x9340
jmp 0x3470a
movq %rax, %r12
leaq 0x8(%rbx), %rax
movq (%rax), %rdi
testq %rdi, %rdi
je 0x34722
movq 0x18(%rbx), %rsi
subq %rdi, %rsi
callq 0x9340
movq %r12, %rdi
callq 0x9670