// File: 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
movq %rsp, %rbp
subq $0x430, %rsp            # imm = 0x430
movq %rcx, -0x3d8(%rbp)
movb %r8b, %al
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
movsd %xmm0, -0x28(%rbp)
andb $0x1, %al
movb %al, -0x29(%rbp)
movq -0x8(%rbp), %rdi
movq %rdi, -0x3e0(%rbp)
leaq 0xf35af(%rip), %rax     # 0x19f3f0
movq %rax, (%rdi)
addq $0x8, %rdi
movq %rdi, -0x3e8(%rbp)
callq 0xacd60
movq -0x3e0(%rbp), %rdi
movq -0x3d8(%rbp), %rsi
movabsq $0x3ff0000000000000, %rax # imm = 0x3FF0000000000000
movq %rax, 0x28(%rdi)
movq -0x10(%rbp), %rax
movq %rax, 0x30(%rdi)
movq -0x18(%rbp), %rax
movq %rax, 0x38(%rdi)
addq $0x40, %rdi
movq %rdi, -0x3d0(%rbp)
callq 0xa190
jmp 0xabe92
movq -0x3e0(%rbp), %rdi
movsd -0x28(%rbp), %xmm0
movsd %xmm0, 0x60(%rdi)
movb -0x29(%rbp), %al
andb $0x1, %al
movb %al, 0x68(%rdi)
addq $0x70, %rdi
movq %rdi, -0x3f8(%rbp)
callq 0x99120
movq -0x3d8(%rbp), %rdi
leaq 0x7fbb2(%rip), %rsi     # 0x12ba7b
callq 0xeaa0
movb %al, -0x3e9(%rbp)
jmp 0xabed6
movb -0x3e9(%rbp), %al
testb $0x1, %al
jne 0xabee5
jmp 0xac427
leaq 0xf55b4(%rip), %rsi     # 0x1a14a0
leaq -0x60(%rbp), %rdi
callq 0xa190
jmp 0xabef7
leaq -0x60(%rbp), %rdi
callq 0xa170
movq %rax, %rsi
leaq -0x268(%rbp), %rdi
movl $0x8, %edx
callq 0xa820
jmp 0xabf16
movq -0x268(%rbp), %rax
movq -0x18(%rax), %rax
leaq -0x268(%rbp,%rax), %rdi
callq 0xa750
movb %al, -0x3f9(%rbp)
jmp 0xabf36
movb -0x3f9(%rbp), %al
testb $0x1, %al
jne 0xabf45
jmp 0xac0bd
leaq 0xf5554(%rip), %rsi     # 0x1a14a0
leaq -0x2c8(%rbp), %rdi
callq 0xa190
jmp 0xabf5a
leaq -0x2e9(%rbp), %rdi
movq %rdi, -0x408(%rbp)
callq 0xa7d0
movq -0x408(%rbp), %rdx
leaq 0x7e1f5(%rip), %rsi     # 0x12a170
leaq -0x2e8(%rbp), %rdi
callq 0xe9b0
jmp 0xabf89
leaq -0x2a8(%rbp), %rdi
leaq -0x2c8(%rbp), %rsi
leaq -0x2e8(%rbp), %rdx
callq 0xeba0
jmp 0xabfa5
leaq -0x2e8(%rbp), %rdi
callq 0xa8d8
leaq -0x2e9(%rbp), %rdi
callq 0xa4c0
leaq -0x2c8(%rbp), %rdi
callq 0xa8d8
leaq -0x308(%rbp), %rdi
leaq -0x2a8(%rbp), %rsi
xorl %edx, %edx
movl $0x2710, %ecx           # imm = 0x2710
callq 0x104400
jmp 0xabfe5
movq -0x3e0(%rbp), %rdi
addq $0x70, %rdi
leaq -0x308(%rbp), %rsi
callq 0xacd80
leaq -0x308(%rbp), %rdi
callq 0x994d0
leaq -0x2a8(%rbp), %rdi
callq 0xf2c0
jmp 0xac212
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
jmp 0xac448
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
jmp 0xac430
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
jmp 0xac41c
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
jmp 0xac410
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
jmp 0xac083
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
leaq -0x2e8(%rbp), %rdi
callq 0xa8d8
leaq -0x2e9(%rbp), %rdi
callq 0xa4c0
leaq -0x2c8(%rbp), %rdi
callq 0xa8d8
jmp 0xac410
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
leaq -0x2a8(%rbp), %rdi
callq 0xf2c0
jmp 0xac410
movq 0xf4eec(%rip), %rdi     # 0x1a0fb0
leaq 0x7e0a7(%rip), %rsi     # 0x12a172
callq 0xa440
jmp 0xac0d2
movq 0xf4eff(%rip), %rdi     # 0x1a0fd8
leaq -0x60(%rbp), %rsi
callq 0xa590
jmp 0xac0e4
leaq -0x368(%rbp), %rdi
leaq -0x60(%rbp), %rsi
callq 0xa190
jmp 0xac0f6
leaq -0x389(%rbp), %rdi
movq %rdi, -0x410(%rbp)
callq 0xa7d0
movq -0x410(%rbp), %rdx
leaq 0x7e059(%rip), %rsi     # 0x12a170
leaq -0x388(%rbp), %rdi
callq 0xe9b0
jmp 0xac125
leaq -0x348(%rbp), %rdi
leaq -0x368(%rbp), %rsi
leaq -0x388(%rbp), %rdx
callq 0xeba0
jmp 0xac141
leaq -0x388(%rbp), %rdi
callq 0xa8d8
leaq -0x389(%rbp), %rdi
callq 0xa4c0
leaq -0x368(%rbp), %rdi
callq 0xa8d8
leaq -0x3a8(%rbp), %rdi
leaq -0x348(%rbp), %rsi
xorl %edx, %edx
movl $0x2710, %ecx           # imm = 0x2710
callq 0x104400
jmp 0xac181
movq -0x3e0(%rbp), %rdi
addq $0x70, %rdi
leaq -0x3a8(%rbp), %rsi
callq 0xacd80
leaq -0x3a8(%rbp), %rdi
callq 0x994d0
leaq -0x348(%rbp), %rdi
callq 0xf2c0
jmp 0xac212
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
jmp 0xac1d8
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
leaq -0x388(%rbp), %rdi
callq 0xa8d8
leaq -0x389(%rbp), %rdi
callq 0xa4c0
leaq -0x368(%rbp), %rdi
callq 0xa8d8
jmp 0xac410
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
leaq -0x348(%rbp), %rdi
callq 0xf2c0
jmp 0xac410
movq -0x3e0(%rbp), %rdi
addq $0x70, %rdi
callq 0x9c200
movq -0x3e0(%rbp), %rdi
movl %eax, -0x3ac(%rbp)
addq $0x70, %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x9a070
movq %rax, %rdi
callq 0x9ce20
movq %rax, %rcx
movq -0x3e0(%rbp), %rax
movl %ecx, -0x3b0(%rbp)
movsd 0x61a0c(%rip), %xmm0    # 0x10dc68
movsd %xmm0, 0x28(%rax)
movl $0x0, -0x3b4(%rbp)
movl -0x3b4(%rbp), %eax
cmpl -0x3ac(%rbp), %eax
jge 0xac2ea
movq -0x3e0(%rbp), %rdi
movq %rdi, %rax
addq $0x28, %rax
movq %rax, -0x420(%rbp)
addq $0x70, %rdi
movslq -0x3b4(%rbp), %rsi
callq 0x9a070
movq %rax, %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x9a090
movq -0x420(%rbp), %rdi
movq %rax, %rsi
callq 0x14920
movq %rax, -0x418(%rbp)
jmp 0xac2c2
movq -0x3e0(%rbp), %rax
movq -0x418(%rbp), %rcx
movsd (%rcx), %xmm0
movsd %xmm0, 0x28(%rax)
movl -0x3b4(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x3b4(%rbp)
jmp 0xac26b
movq -0x3e0(%rbp), %rdi
addq $0x28, %rdi
movabsq $0x4059000000000000, %rax # imm = 0x4059000000000000
movq %rax, -0x3c0(%rbp)
leaq -0x3c0(%rbp), %rsi
callq 0x148e0
movq %rax, -0x428(%rbp)
jmp 0xac31b
movq -0x3e0(%rbp), %rax
movq -0x428(%rbp), %rcx
movsd (%rcx), %xmm0
movsd %xmm0, 0x28(%rax)
movl $0x0, -0x3c4(%rbp)
movl -0x3c4(%rbp), %eax
cmpl -0x3ac(%rbp), %eax
jge 0xac3f9
movl $0x0, -0x3c8(%rbp)
movl -0x3c8(%rbp), %eax
cmpl -0x3b0(%rbp), %eax
jge 0xac3e3
movq -0x3e0(%rbp), %rdi
addq $0x70, %rdi
movslq -0x3c4(%rbp), %rsi
callq 0x9a070
movq %rax, %rdi
movslq -0x3c8(%rbp), %rsi
callq 0x9a090
movq -0x3e0(%rbp), %rdi
movsd (%rax), %xmm0
divsd 0x28(%rdi), %xmm0
movsd %xmm0, -0x430(%rbp)
addq $0x70, %rdi
movslq -0x3c4(%rbp), %rsi
callq 0x9a070
movq %rax, %rdi
movslq -0x3c8(%rbp), %rsi
callq 0x9a090
movsd -0x430(%rbp), %xmm0
movsd %xmm0, (%rax)
movl -0x3c8(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x3c8(%rbp)
jmp 0xac358
jmp 0xac3e5
movl -0x3c4(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x3c4(%rbp)
jmp 0xac33c
leaq -0x268(%rbp), %rdi
callq 0xa0f0
leaq -0x60(%rbp), %rdi
callq 0xa8d8
jmp 0xac427
leaq -0x268(%rbp), %rdi
callq 0xa0f0
leaq -0x60(%rbp), %rdi
callq 0xa8d8
jmp 0xac430
addq $0x430, %rsp            # imm = 0x430
popq %rbp
retq
movq -0x3f8(%rbp), %rdi
callq 0x994d0
movq -0x3d0(%rbp), %rdi
callq 0xa8d8
movq -0x3e8(%rbp), %rdi
callq 0xa9390
movq -0x38(%rbp), %rdi
callq 0xa7c0
nopl (%rax)