// File: /workspace/github_cpp_makefile_star2_O1/canzarlab[P]Trajan/src/BnG.cpp
// Function: GenericBnBSolver::SolveNode(BnBNode*, double, double)
bool GenericBnBSolver::SolveNode(BnBNode* node, double pgtol, double numtol)
{
    Vector x = (node->warm) ? *(node->warm) : Vector::Zero(nr_cols);

#if DEBUG == 1    
    size_t debug_node_genocnt  = 0;
    double debug_node_genotime = 0;
    debug_log << "id: " << node->debug_nodeid << endl;
    debug_log << "parent: " << node->debug_parent << endl;    
    debug_log << "depth: " << node->debug_depth << endl;
    debug_log << "best: " << -sys_ub << endl;
#endif

    if (!OnNodeStart(node)) return false;

    while(1)
    {
        SpMat A(node->rows, node->cols);
        A.setFromTriplets(node->Triplets.begin(), node->Triplets.end());
        Vector b = Vector::Ones(node->rows);       
        Vector y = Vector::Zero(node->rows);        
        Vector d = -c;                    

        BranchingJRF simpleJRF(A, b, d, x, y);
        simpleJRF.lo = node->var_lb;
        simpleJRF.hi = node->var_ub;
        AugmentedLagrangian solver(simpleJRF, 15);
        solver.setParameter("verbose", false);
        solver.setParameter("pgtol", pgtol); 
        solver.setParameter("constraintsTol", 1e-4);

        if (!OnNodeLP(node))
        { 
#if DEBUG == 1    
            debug_log << "ABORT" << endl << endl;
#endif
            return false;
        }
#if DEBUG == 1    
        Timer debug_T; debug_T.start();        
#endif      
        SolverStatus status = solver.solve();    
#if DEBUG == 1    
        debug_T.stop();
        debug_genocnt++;    
        debug_node_genocnt++;
        debug_node_genotime += debug_T.secs();
        debug_genotime += debug_T.secs();
        debug_genomin = min(debug_genomin, (double)debug_T.secs());
        debug_genomax = max(debug_genomax, (double)debug_T.secs());
        if (status == SUBOPTIMAL)
            debug_log << "SUBOPTIMAL(" << status << ")" << endl; 
        if (status == UNBOUNDED)
            debug_log << "UNBOUNDED(" << status << ")" << endl; 
        if (status == INFEASIBLE)
            debug_log << "INFEASIBLE(" << status << ")" << endl; 
        if (status == NUM_ERROR)
            debug_log << "NUM_ERROR(" << status << ")" << endl; 
#endif
        
        if (status == INFEASIBLE || CheckUB(solver.f(), numtol))
        {
#if DEBUG == 1    
            debug_log << "geno calls: " << debug_node_genocnt << endl;
            debug_log << "geno time: " << debug_node_genotime << endl;
            debug_log << "CUT: " << -solver.f() << endl << endl;
#endif
            return false;
        } 

        x = Vector::ConstMapType(solver.x(), node->cols);     

        if ((LP::cf == 1 && Add<1>(node->Triplets, x, node->rows)) || (LP::cf == 2 && (Add<1>(node->Triplets, x, node->rows) + Add<2>(node->Triplets, x, node->rows))))
            continue;
        
        node->obj = solver.f();        
        node->sol = x;

        if (!OnNodeFinish(node, true))
        {
#if DEBUG == 1    
            debug_log << "geno calls: " << debug_node_genocnt << endl;
            debug_log << "geno time: " << debug_node_genotime << endl;
            debug_log << "GREEDY CUT: " << -solver.f() << endl << endl;
#endif
            return false;
        }

        break;
    }

#if DEBUG == 1    
    debug_log << "geno calls: " << debug_node_genocnt << endl;
    debug_log << "geno time: " << debug_node_genotime << endl;
    debug_log << node->rows << " x " << node->cols << endl;
    debug_log << "lp: " << -node->obj << endl;
    size_t debug_fracs = 0;
    for (size_t i = 0; i < x.size(); ++i)
        debug_fracs += IsVarFrac(node->sol(i)) && !node->IsVarFixed(i);
    debug_log << "fracs: " << debug_fracs << endl << endl;
#endif

    return true;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x1d8, %rsp            # imm = 0x1D8
movsd %xmm1, 0x40(%rsp)
movsd %xmm0, 0x50(%rsp)
movq %rsi, %rbx
movq %rdi, %r14
movq 0x48(%rsi), %rsi
testq %rsi, %rsi
je 0x42df2
movq %rsp, %rdi
callq 0x1022e
jmp 0x42e26
movslq 0x10c(%r14), %rax
movq %rax, 0x128(%rsp)
movq $0x0, 0x138(%rsp)
testq %rax, %rax
js 0x43558
movq %rsp, %rdi
leaq 0x128(%rsp), %rsi
callq 0x377fc
movq (%r14), %rax
movq %r14, %rdi
movq %rbx, %rsi
callq *0xa0(%rax)
testb %al, %al
je 0x4351a
leaq 0x18(%rbx), %rax
movq %rax, 0x10(%rsp)
leaq 0xf8(%r14), %rax
movq %rax, 0x48(%rsp)
leaq 0x50(%rbx), %rax
movq %rax, 0x18(%rsp)
leaq 0x128(%rsp), %r12
movq 0x18(%rbx), %rsi
movq 0x20(%rbx), %rdx
movb $0x0, 0x190(%rsp)
leaq 0x198(%rsp), %rax
xorps %xmm0, %xmm0
movups %xmm0, 0x30(%rax)
movups %xmm0, 0x20(%rax)
movups %xmm0, 0x10(%rax)
movups %xmm0, (%rax)
leaq 0x190(%rsp), %r13
movq %r13, %rdi
callq 0x386d2
movq (%rbx), %rax
movq %rax, 0x128(%rsp)
movq 0x8(%rbx), %rax
movq %rax, 0x68(%rsp)
movq %r12, %rdi
leaq 0x68(%rsp), %rsi
movq %r13, %rdx
leaq 0x118(%rsp), %rbp
movq %rbp, %rcx
callq 0x387a4
movq 0x10(%rsp), %rax
movq (%rax), %rax
movq %rax, 0x128(%rsp)
movabsq $0x3ff0000000000000, %rcx # imm = 0x3FF0000000000000
movq %rcx, 0x138(%rsp)
testq %rax, %rax
js 0x43558
movq %rbp, %rdi
movq %r12, %rsi
callq 0x377fc
movq 0x10(%rsp), %rax
movq (%rax), %rax
movq %rax, 0x128(%rsp)
movq $0x0, 0x138(%rsp)
testq %rax, %rax
js 0x43558
leaq 0x58(%rsp), %rdi
movq %r12, %rsi
callq 0x377fc
movq 0x48(%rsp), %rax
movq %rax, 0x128(%rsp)
leaq 0x108(%rsp), %r15
movq %r15, %rdi
movq %r12, %rsi
callq 0x39b9e
leaq 0x68(%rsp), %rdi
movq %r13, %rsi
movq %rbp, %rdx
movq %r15, %rcx
movq %rsp, %r8
leaq 0x58(%rsp), %r9
callq 0x414e6
movq 0x28(%rbx), %r13
movq 0x30(%rbx), %rbp
cmpq %rbp, 0xc0(%rsp)
je 0x42fec
testq %rbp, %rbp
js 0x435a5
movq 0xb8(%rsp), %rdi
callq 0x93c0
testq %rbp, %rbp
je 0x42fda
movabsq $0x1fffffffffffffff, %rax # imm = 0x1FFFFFFFFFFFFFFF
cmpq %rax, %rbp
ja 0x43577
leaq (,%rbp,8), %rdi
callq 0x9440
cmpq $0x1, %rbp
setne %cl
testb $0xf, %al
setne %dl
testb %dl, %cl
jne 0x435c4
testq %rax, %rax
jne 0x42fdc
jmp 0x43577
xorl %eax, %eax
movq %rax, 0xb8(%rsp)
movq %rbp, 0xc0(%rsp)
movq 0xc0(%rsp), %rax
cmpq %rbp, %rax
jne 0x43539
movq 0xb8(%rsp), %rcx
movq %rax, %rdx
shrq $0x3f, %rdx
addq %rax, %rdx
andq $-0x2, %rdx
cmpq $0x2, %rax
jl 0x4302e
xorl %esi, %esi
movaps (%r13,%rsi,8), %xmm0
movaps %xmm0, (%rcx,%rsi,8)
addq $0x2, %rsi
cmpq %rdx, %rsi
jl 0x4301b
cmpq %rax, %rdx
jge 0x43047
movsd (%r13,%rdx,8), %xmm0
movsd %xmm0, (%rcx,%rdx,8)
incq %rdx
cmpq %rdx, %rax
jne 0x43033
movq 0x38(%rbx), %r13
movq 0x40(%rbx), %rbp
cmpq %rbp, 0xb0(%rsp)
je 0x430c4
testq %rbp, %rbp
js 0x435a5
movq 0xa8(%rsp), %rdi
callq 0x93c0
testq %rbp, %rbp
je 0x430b2
movabsq $0x1fffffffffffffff, %rax # imm = 0x1FFFFFFFFFFFFFFF
cmpq %rax, %rbp
ja 0x43577
leaq (,%rbp,8), %rdi
callq 0x9440
cmpq $0x1, %rbp
setne %cl
testb $0xf, %al
setne %dl
testb %dl, %cl
jne 0x435c4
testq %rax, %rax
jne 0x430b4
jmp 0x43577
xorl %eax, %eax
movq %rax, 0xa8(%rsp)
movq %rbp, 0xb0(%rsp)
movq 0xb0(%rsp), %rax
cmpq %rbp, %rax
jne 0x43539
movq 0xa8(%rsp), %rcx
movq %rax, %rdx
shrq $0x3f, %rdx
addq %rax, %rdx
andq $-0x2, %rdx
cmpq $0x2, %rax
leaq 0xf8(%rsp), %rbp
jl 0x4310e
xorl %esi, %esi
movaps (%r13,%rsi,8), %xmm0
movaps %xmm0, (%rcx,%rsi,8)
addq $0x2, %rsi
cmpq %rdx, %rsi
jl 0x430fb
cmpq %rax, %rdx
jge 0x43127
movsd (%r13,%rdx,8), %xmm0
movsd %xmm0, (%rcx,%rdx,8)
incq %rdx
cmpq %rdx, %rax
jne 0x43113
movl $0xf, %edx
movq %r12, %rdi
leaq 0x68(%rsp), %rsi
callq 0xdf90
movq %rbp, 0xe8(%rsp)
leaq 0xe8(%rsp), %r15
movq %r15, %rdi
leaq 0x192df(%rip), %rsi     # 0x5c432
leaq 0x192df(%rip), %rdx     # 0x5c439
callq 0xdb24
xorps %xmm0, %xmm0
movq %r12, %rdi
movq %r15, %rsi
callq 0xee5a
movq 0xe8(%rsp), %rdi
cmpq %rbp, %rdi
je 0x4318a
movq 0xf8(%rsp), %rsi
incq %rsi
callq 0x9340
leaq 0xd8(%rsp), %r13
movq %r13, 0xc8(%rsp)
leaq 0xc8(%rsp), %r15
movq %r15, %rdi
leaq 0x19264(%rip), %rsi     # 0x5c410
leaq 0x19262(%rip), %rdx     # 0x5c415
callq 0xdb24
leaq 0x20(%rsp), %rbp
movq %r12, %rdi
movq %r15, %rsi
movsd 0x50(%rsp), %xmm0
callq 0xee5a
movq 0xc8(%rsp), %rdi
cmpq %r13, %rdi
je 0x431eb
movq 0xd8(%rsp), %rsi
incq %rsi
callq 0x9340
leaq 0x30(%rsp), %rax
movq %rax, 0x20(%rsp)
movq %rbp, %rdi
leaq 0x19224(%rip), %rsi     # 0x5c423
leaq 0x1922b(%rip), %rdx     # 0x5c431
callq 0xdb24
movq %r12, %rdi
movq %rbp, %rsi
movsd 0x2cdb7(%rip), %xmm0    # 0x6ffd0
callq 0xee5a
movq 0x20(%rsp), %rdi
leaq 0x30(%rsp), %rax
cmpq %rax, %rdi
je 0x4323a
movq 0x30(%rsp), %rsi
incq %rsi
callq 0x9340
movq (%r14), %rax
movq %r14, %rdi
movq %rbx, %rsi
callq *0xa8(%rax)
movl $0x1, %ebp
testb %al, %al
je 0x4347d
movq %r12, %rdi
callq 0xe148
cmpl $0x3, %eax
je 0x4347d
movq %r12, %rdi
callq 0xee54
movq (%r14), %rax
movq %r14, %rdi
movsd 0x40(%rsp), %xmm1
callq *0x68(%rax)
testb %al, %al
jne 0x4347d
movq %r12, %rdi
callq 0xee48
movq 0x20(%rbx), %rbp
testq %rbp, %rbp
js 0x435e3
movq %rax, %r13
cmpq %rbp, 0x8(%rsp)
je 0x432fc
movq (%rsp), %rdi
callq 0x93c0
testq %rbp, %rbp
je 0x432f1
movabsq $0x1fffffffffffffff, %rax # imm = 0x1FFFFFFFFFFFFFFF
cmpq %rax, %rbp
ja 0x4361c
leaq (,%rbp,8), %rdi
callq 0x9440
cmpq $0x1, %rbp
setne %cl
testb $0xf, %al
setne %dl
testb %dl, %cl
jne 0x435c4
testq %rax, %rax
jne 0x432f3
jmp 0x4361c
xorl %eax, %eax
movq %rax, (%rsp)
movq %rbp, 0x8(%rsp)
movq 0x8(%rsp), %rax
cmpq %rbp, %rax
jne 0x43602
movq (%rsp), %rcx
movq %rax, %rdx
shrq $0x3f, %rdx
addq %rax, %rdx
andq $-0x2, %rdx
cmpq $0x2, %rax
jl 0x43337
xorl %esi, %esi
movups (%r13,%rsi,8), %xmm0
movaps %xmm0, (%rcx,%rsi,8)
addq $0x2, %rsi
cmpq %rdx, %rsi
jl 0x43324
cmpq %rax, %rdx
jge 0x43350
movsd (%r13,%rdx,8), %xmm0
movsd %xmm0, (%rcx,%rdx,8)
incq %rdx
cmpq %rdx, %rax
jne 0x4333c
leaq 0x450a9(%rip), %rax     # 0x88400
cmpl $0x1, (%rax)
jne 0x4337c
movq %r14, %rdi
movq %rbx, %rsi
movq %rsp, %rdx
movq 0x10(%rsp), %rcx
callq 0x45ec0
movl $0x2, %ebp
testl %eax, %eax
jne 0x4347d
leaq 0x4507d(%rip), %rax     # 0x88400
cmpl $0x2, (%rax)
jne 0x433d0
movq %r14, %rdi
movq %rbx, %rsi
movq %rsp, %rdx
movq 0x10(%rsp), %rcx
callq 0x45ec0
movl %eax, %r13d
cmpb $0x1, 0x68(%r14)
jne 0x433af
movq %r14, %rdi
callq 0x383ec
jmp 0x433c2
movq %r14, %rdi
movq %rbx, %rsi
movq %rsp, %rdx
movq 0x10(%rsp), %rcx
callq 0x46020
movl $0x2, %ebp
addl %eax, %r13d
jne 0x4347d
movq %r12, %rdi
callq 0xee54
movsd %xmm0, 0x60(%rbx)
movq (%rsp), %rbp
movq 0x8(%rsp), %r13
cmpq %r13, 0x58(%rbx)
je 0x4340a
testq %r13, %r13
js 0x435a5
movl $0x1, %ecx
movq 0x18(%rsp), %rdi
movq %r13, %rsi
movq %r13, %rdx
callq 0x10056
movq 0x58(%rbx), %rax
cmpq %r13, %rax
jne 0x43539
movq 0x18(%rsp), %rcx
movq (%rcx), %rcx
movq %rax, %rdx
shrq $0x3f, %rdx
addq %rax, %rdx
andq $-0x2, %rdx
cmpq $0x2, %rax
jl 0x43447
xorl %esi, %esi
movaps (%rbp,%rsi,8), %xmm0
movaps %xmm0, (%rcx,%rsi,8)
addq $0x2, %rsi
cmpq %rdx, %rsi
jl 0x43435
cmpq %rax, %rdx
jge 0x4345f
movsd (%rbp,%rdx,8), %xmm0
movsd %xmm0, (%rcx,%rdx,8)
incq %rdx
cmpq %rdx, %rax
jne 0x4344c
movq (%r14), %rax
movq %r14, %rdi
movq %rbx, %rsi
movl $0x1, %edx
callq *0xb0(%rax)
movzbl %al, %eax
leal 0x1(,%rax,2), %ebp
movq 0x160(%rsp), %rdi
callq 0x93c0
movq 0x150(%rsp), %rdi
callq 0x93c0
leaq 0x43302(%rip), %rax     # 0x867a0
movq %rax, 0x68(%rsp)
movq 0xb8(%rsp), %rdi
callq 0x93c0
movq 0xa8(%rsp), %rdi
callq 0x93c0
movq 0x108(%rsp), %rdi
callq 0x93c0
movq 0x58(%rsp), %rdi
callq 0x93c0
movq 0x118(%rsp), %rdi
callq 0x93c0
movq 0x1a8(%rsp), %rdi
callq 0x93c0
movq 0x1b0(%rsp), %rdi
callq 0x93c0
leaq 0x1b8(%rsp), %rdi
callq 0x38782
cmpl $0x2, %ebp
je 0x42e63
cmpl $0x3, %ebp
jne 0x4351a
movb $0x1, %bl
jmp 0x4351c
xorl %ebx, %ebx
movq (%rsp), %rdi
callq 0x93c0
movl %ebx, %eax
addq $0x1d8, %rsp            # imm = 0x1D8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x19b20(%rip), %rdi     # 0x5d060
leaq 0x18fd2(%rip), %rsi     # 0x5c519
leaq 0x19d9e(%rip), %rcx     # 0x5d2ec
movl $0x2d1, %edx            # imm = 0x2D1
callq 0x9200
leaq 0x18fdd(%rip), %rdi     # 0x5c53c
leaq 0x1906b(%rip), %rsi     # 0x5c5d1
leaq 0x19e5f(%rip), %rcx     # 0x5d3cc
movl $0x4a, %edx
callq 0x9200
movl $0x8, %edi
callq 0x9180
movq 0x44a28(%rip), %rcx     # 0x87fb0
addq $0x10, %rcx
movq %rcx, (%rax)
movq 0x44a32(%rip), %rsi     # 0x87fc8
movq 0x449f3(%rip), %rdx     # 0x87f90
movq %rax, %rdi
callq 0x9630
leaq 0x198ac(%rip), %rdi     # 0x5ce58
leaq 0x19704(%rip), %rsi     # 0x5ccb7
leaq 0x19a2d(%rip), %rcx     # 0x5cfe7
movl $0x11d, %edx            # imm = 0x11D
callq 0x9200
leaq 0x19781(%rip), %rdi     # 0x5cd4c
leaq 0x19834(%rip), %rsi     # 0x5ce06
leaq 0x1984c(%rip), %rcx     # 0x5ce25
movl $0xa1, %edx
callq 0x9200
leaq 0x1959d(%rip), %rdi     # 0x5cb87
leaq 0x19313(%rip), %rsi     # 0x5c904
leaq 0x1a146(%rip), %rcx     # 0x5d73e
movl $0xa3, %edx
callq 0x9200
leaq 0x19a57(%rip), %rdi     # 0x5d060
leaq 0x18f09(%rip), %rsi     # 0x5c519
leaq 0x1a1c9(%rip), %rcx     # 0x5d7e0
jmp 0x4354e
movl $0x8, %edi
callq 0x9180
movq 0x44983(%rip), %rcx     # 0x87fb0
addq $0x10, %rcx
movq %rcx, (%rax)
movq 0x4498d(%rip), %rsi     # 0x87fc8
movq 0x4494e(%rip), %rdx     # 0x87f90
movq %rax, %rdi
callq 0x9630
jmp 0x43701
movq %rax, %rbx
jmp 0x43775
jmp 0x43701
jmp 0x43701
jmp 0x43701
movq %rax, %rbx
movq 0x20(%rsp), %rdi
leaq 0x30(%rsp), %rax
cmpq %rax, %rdi
je 0x43704
movq 0x30(%rsp), %rsi
jmp 0x436f0
movq %rax, %rbx
movq 0xc8(%rsp), %rdi
cmpq %r13, %rdi
je 0x43704
movq 0xd8(%rsp), %rsi
jmp 0x436f0
movq %rax, %rbx
jmp 0x43744
movq %rax, %rbx
jmp 0x4375b
jmp 0x436bb
jmp 0x43701
jmp 0x43701
movq %rax, %rbx
jmp 0x43751
movq %rax, %rbx
jmp 0x43768
movq %rax, %rbx
leaq 0x1b8(%rsp), %rdi
callq 0x38782
jmp 0x43775
movq %rax, %rbx
movq 0xe8(%rsp), %rdi
cmpq %rbp, %rdi
je 0x43704
movq 0xf8(%rsp), %rsi
incq %rsi
callq 0x9340
jmp 0x43704
jmp 0x436fc
movq %rax, %rbx
jmp 0x4371e
movq %rax, %rbx
movq 0x160(%rsp), %rdi
callq 0x93c0
movq 0x150(%rsp), %rdi
callq 0x93c0
leaq 0x4307b(%rip), %rax     # 0x867a0
movq %rax, 0x68(%rsp)
movq 0xb8(%rsp), %rdi
callq 0x93c0
movq 0xa8(%rsp), %rdi
callq 0x93c0
movq 0x108(%rsp), %rdi
callq 0x93c0
movq 0x58(%rsp), %rdi
callq 0x93c0
movq 0x118(%rsp), %rdi
callq 0x93c0
leaq 0x190(%rsp), %rdi
callq 0x369fa
movq (%rsp), %rdi
callq 0x93c0
movq %rbx, %rdi
callq 0x9670