// File: /workspace/github_cpp_makefile_star2_O3/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, 0x20(%rsp)
movsd %xmm0, 0x30(%rsp)
movq %rsi, %rbx
movq %rdi, %r14
movq 0x48(%rsi), %rsi
testq %rsi, %rsi
je 0x42698
movq %rsp, %rdi
callq 0x10120
jmp 0x426cc
movslq 0x10c(%r14), %rax
movq %rax, 0x128(%rsp)
movq $0x0, 0x138(%rsp)
testq %rax, %rax
js 0x42daa
movq %rsp, %rdi
leaq 0x128(%rsp), %rsi
callq 0x36fea
movq (%r14), %rax
movq %r14, %rdi
movq %rbx, %rsi
callq *0xa0(%rax)
testb %al, %al
je 0x42d8b
leaq 0x18(%rbx), %rax
movq %rax, 0x10(%rsp)
leaq 0xf8(%r14), %rax
movq %rax, 0x28(%rsp)
leaq 0x50(%rbx), %rax
movq %rax, 0x18(%rsp)
leaq 0x128(%rsp), %r13
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), %r12
movq %r12, %rdi
callq 0x37f02
movq (%rbx), %rax
movq %rax, 0x128(%rsp)
movq 0x8(%rbx), %rax
movq %rax, 0xa8(%rsp)
movq %r13, %rdi
leaq 0xa8(%rsp), %rsi
movq %r12, %rdx
leaq 0x118(%rsp), %rbp
movq %rbp, %rcx
callq 0x37fd4
movq 0x10(%rsp), %rax
movq (%rax), %rax
movq %rax, 0x128(%rsp)
movabsq $0x3ff0000000000000, %rcx # imm = 0x3FF0000000000000
movq %rcx, 0x138(%rsp)
testq %rax, %rax
js 0x42daa
movq %rbp, %rdi
movq %r13, %rsi
callq 0x36fea
movq 0x10(%rsp), %rax
movq (%rax), %rax
movq %rax, 0x128(%rsp)
movq $0x0, 0x138(%rsp)
testq %rax, %rax
js 0x42daa
leaq 0x38(%rsp), %rdi
movq %r13, %rsi
callq 0x36fea
movq 0x28(%rsp), %rax
movq %rax, 0x128(%rsp)
leaq 0x108(%rsp), %r15
movq %r15, %rdi
movq %r13, %rsi
callq 0x393be
leaq 0xa8(%rsp), %rdi
movq %r12, %rsi
movq %rbp, %rdx
movq %r15, %rcx
movq %rsp, %r8
leaq 0x38(%rsp), %r9
callq 0x40b08
movq 0x28(%rbx), %r12
movq 0x30(%rbx), %rbp
cmpq %rbp, 0x100(%rsp)
jne 0x4283a
movq 0xf8(%rsp), %rax
jmp 0x428a5
testq %rbp, %rbp
js 0x42df7
movq 0xf8(%rsp), %rdi
callq 0x93d0
testq %rbp, %rbp
je 0x42893
movabsq $0x1fffffffffffffff, %rax # imm = 0x1FFFFFFFFFFFFFFF
cmpq %rax, %rbp
ja 0x42dc9
leaq (,%rbp,8), %rdi
callq 0x9450
cmpq $0x1, %rbp
setne %cl
testb $0xf, %al
setne %dl
testb %dl, %cl
jne 0x42e16
testq %rax, %rax
jne 0x42895
jmp 0x42dc9
xorl %eax, %eax
movq %rax, 0xf8(%rsp)
movq %rbp, 0x100(%rsp)
movq %rbp, %rcx
shrq $0x3f, %rcx
addq %rbp, %rcx
andq $-0x2, %rcx
cmpq $0x2, %rbp
jl 0x428cd
xorl %edx, %edx
movaps (%r12,%rdx,8), %xmm0
movaps %xmm0, (%rax,%rdx,8)
addq $0x2, %rdx
cmpq %rcx, %rdx
jl 0x428bb
cmpq %rbp, %rcx
jge 0x428e5
movsd (%r12,%rcx,8), %xmm0
movsd %xmm0, (%rax,%rcx,8)
incq %rcx
cmpq %rcx, %rbp
jne 0x428d2
movq 0x38(%rbx), %r12
movq 0x40(%rbx), %rbp
cmpq %rbp, 0xf0(%rsp)
jne 0x42901
movq 0xe8(%rsp), %rax
jmp 0x4296c
testq %rbp, %rbp
js 0x42df7
movq 0xe8(%rsp), %rdi
callq 0x93d0
testq %rbp, %rbp
je 0x4295a
movabsq $0x1fffffffffffffff, %rax # imm = 0x1FFFFFFFFFFFFFFF
cmpq %rax, %rbp
ja 0x42dc9
leaq (,%rbp,8), %rdi
callq 0x9450
cmpq $0x1, %rbp
setne %cl
testb $0xf, %al
setne %dl
testb %dl, %cl
jne 0x42e16
testq %rax, %rax
jne 0x4295c
jmp 0x42dc9
xorl %eax, %eax
movq %rax, 0xe8(%rsp)
movq %rbp, 0xf0(%rsp)
movq %rbp, %rcx
shrq $0x3f, %rcx
addq %rbp, %rcx
andq $-0x2, %rcx
cmpq $0x2, %rbp
jl 0x42994
xorl %edx, %edx
movaps (%r12,%rdx,8), %xmm0
movaps %xmm0, (%rax,%rdx,8)
addq $0x2, %rdx
cmpq %rcx, %rdx
jl 0x42982
cmpq %rbp, %rcx
jge 0x429ac
movsd (%r12,%rcx,8), %xmm0
movsd %xmm0, (%rax,%rcx,8)
incq %rcx
cmpq %rcx, %rbp
jne 0x42999
movl $0xf, %edx
movq %r13, %rdi
leaq 0xa8(%rsp), %rsi
callq 0xdf50
leaq 0x98(%rsp), %r12
movq %r12, 0x88(%rsp)
leaq 0x88(%rsp), %r15
movq %r15, %rdi
leaq 0x19a6f(%rip), %rsi     # 0x5c452
leaq 0x19a6f(%rip), %rdx     # 0x5c459
callq 0xdadc
leaq 0x78(%rsp), %rbp
xorps %xmm0, %xmm0
movq %r13, %rdi
movq %r15, %rsi
callq 0xed94
movq 0x88(%rsp), %rdi
cmpq %r12, %rdi
je 0x42a1f
movq 0x98(%rsp), %rsi
incq %rsi
callq 0x9350
movq %rbp, 0x68(%rsp)
leaq 0x68(%rsp), %r15
movq %r15, %rdi
leaq 0x199fd(%rip), %rsi     # 0x5c430
leaq 0x199fb(%rip), %rdx     # 0x5c435
callq 0xdadc
movq %r13, %rdi
movq %r15, %rsi
movsd 0x30(%rsp), %xmm0
callq 0xed94
movq 0x68(%rsp), %rdi
cmpq %rbp, %rdi
je 0x42a67
movq 0x78(%rsp), %rsi
incq %rsi
callq 0x9350
leaq 0x58(%rsp), %r12
movq %r12, 0x48(%rsp)
leaq 0x48(%rsp), %r15
movq %r15, %rdi
leaq 0x199c3(%rip), %rsi     # 0x5c443
leaq 0x199ca(%rip), %rdx     # 0x5c451
callq 0xdadc
movq %r13, %rdi
movq %r15, %rsi
movsd 0x2c1d6(%rip), %xmm0    # 0x6ec70
callq 0xed94
movq 0x48(%rsp), %rdi
cmpq %r12, %rdi
je 0x42ab6
movq 0x58(%rsp), %rsi
incq %rsi
callq 0x9350
movq (%r14), %rax
movq %r14, %rdi
movq %rbx, %rsi
callq *0xa8(%rax)
movl $0x1, %ebp
testb %al, %al
je 0x42ceb
movq %r13, %rdi
callq 0xe0ee
cmpl $0x3, %eax
je 0x42ceb
movq %r13, %rdi
callq 0xed8e
movq (%r14), %rax
movq %r14, %rdi
movsd 0x20(%rsp), %xmm1
callq *0x68(%rax)
testb %al, %al
jne 0x42ceb
movq %r13, %rdi
callq 0xed82
movq 0x20(%rbx), %rbp
testq %rbp, %rbp
js 0x42e35
movq %rax, %r12
movq (%rsp), %rax
cmpq %rbp, 0x8(%rsp)
je 0x42b7b
movq %rax, %rdi
callq 0x93d0
testq %rbp, %rbp
je 0x42b70
movabsq $0x1fffffffffffffff, %rax # imm = 0x1FFFFFFFFFFFFFFF
cmpq %rax, %rbp
ja 0x42e54
leaq (,%rbp,8), %rdi
callq 0x9450
cmpq $0x1, %rbp
setne %cl
testb $0xf, %al
setne %dl
testb %dl, %cl
jne 0x42e16
testq %rax, %rax
jne 0x42b72
jmp 0x42e54
xorl %eax, %eax
movq %rax, (%rsp)
movq %rbp, 0x8(%rsp)
movq %rbp, %rcx
movabsq $0x7ffffffffffffffe, %rdx # imm = 0x7FFFFFFFFFFFFFFE
andq %rdx, %rcx
cmpq $0x2, %rbp
jb 0x42ba5
xorl %edx, %edx
movups (%r12,%rdx,8), %xmm0
movaps %xmm0, (%rax,%rdx,8)
addq $0x2, %rdx
cmpq %rcx, %rdx
jb 0x42b93
cmpq %rbp, %rcx
jge 0x42bbd
movsd (%r12,%rcx,8), %xmm0
movsd %xmm0, (%rax,%rcx,8)
incq %rcx
cmpq %rcx, %rbp
jne 0x42baa
leaq 0x43844(%rip), %rax     # 0x86408
movl (%rax), %eax
cmpl $0x1, %eax
jne 0x42bf4
movq %r14, %rdi
movq %rbx, %rsi
movq %rsp, %rdx
movq 0x10(%rsp), %rcx
callq 0x45662
movl $0x2, %ebp
testl %eax, %eax
jne 0x42ceb
leaq 0x43816(%rip), %rax     # 0x86408
movl (%rax), %eax
cmpl $0x2, %eax
jne 0x42c41
movq %r14, %rdi
movq %rbx, %rsi
movq %rsp, %rdx
movq 0x10(%rsp), %rcx
callq 0x45662
movl %eax, %r12d
cmpb $0x1, 0x68(%r14)
jne 0x42c20
movq %r14, %rdi
callq 0x37c6c
jmp 0x42c33
movq %r14, %rdi
movq %rbx, %rsi
movq %rsp, %rdx
movq 0x10(%rsp), %rcx
callq 0x457c2
movl $0x2, %ebp
addl %eax, %r12d
jne 0x42ceb
movq %r13, %rdi
callq 0xed8e
movsd %xmm0, 0x60(%rbx)
movq (%rsp), %rbp
movq 0x8(%rsp), %r12
cmpq %r12, 0x58(%rbx)
je 0x42c85
testq %r12, %r12
js 0x42df7
movl $0x1, %ecx
movq 0x18(%rsp), %rdi
movq %r12, %rsi
movq %r12, %rdx
callq 0xff4c
cmpq %r12, 0x58(%rbx)
jne 0x42e82
movq 0x18(%rsp), %rax
movq (%rax), %rax
movq %r12, %rcx
shrq $0x3f, %rcx
addq %r12, %rcx
andq $-0x2, %rcx
cmpq $0x2, %r12
jl 0x42cb5
xorl %edx, %edx
movaps (%rbp,%rdx,8), %xmm0
movaps %xmm0, (%rax,%rdx,8)
addq $0x2, %rdx
cmpq %rcx, %rdx
jl 0x42ca3
cmpq %r12, %rcx
jge 0x42ccd
movsd (%rbp,%rcx,8), %xmm0
movsd %xmm0, (%rax,%rcx,8)
incq %rcx
cmpq %rcx, %r12
jne 0x42cba
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 0x93d0
movq 0x150(%rsp), %rdi
callq 0x93d0
leaq 0x41a94(%rip), %rax     # 0x847a0
movq %rax, 0xa8(%rsp)
movq 0xf8(%rsp), %rdi
callq 0x93d0
movq 0xe8(%rsp), %rdi
callq 0x93d0
movq 0x108(%rsp), %rdi
callq 0x93d0
movq 0x38(%rsp), %rdi
callq 0x93d0
movq 0x118(%rsp), %rdi
callq 0x93d0
movq 0x1a8(%rsp), %rdi
callq 0x93d0
movq 0x1b0(%rsp), %rdi
callq 0x93d0
leaq 0x1b8(%rsp), %rdi
callq 0x37fb2
cmpl $0x2, %ebp
je 0x42709
cmpl $0x3, %ebp
jne 0x42d8b
movb $0x1, %bl
jmp 0x42d8d
xorl %ebx, %ebx
movq (%rsp), %rdi
callq 0x93d0
movl %ebx, %eax
addq $0x1d8, %rsp            # imm = 0x1D8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x197ab(%rip), %rdi     # 0x5c55c
leaq 0x19839(%rip), %rsi     # 0x5c5f1
leaq 0x1a62d(%rip), %rcx     # 0x5d3ec
movl $0x4a, %edx
callq 0x9200
movl $0x8, %edi
callq 0x9180
movq 0x431d6(%rip), %rcx     # 0x85fb0
addq $0x10, %rcx
movq %rcx, (%rax)
movq 0x431e0(%rip), %rsi     # 0x85fc8
movq 0x431a1(%rip), %rdx     # 0x85f90
movq %rax, %rdi
callq 0x9640
leaq 0x1a07a(%rip), %rdi     # 0x5ce78
leaq 0x19ed2(%rip), %rsi     # 0x5ccd7
leaq 0x1a1fb(%rip), %rcx     # 0x5d007
movl $0x11d, %edx            # imm = 0x11D
callq 0x9200
leaq 0x19f4f(%rip), %rdi     # 0x5cd6c
leaq 0x1a002(%rip), %rsi     # 0x5ce26
leaq 0x1a01a(%rip), %rcx     # 0x5ce45
movl $0xa1, %edx
callq 0x9200
leaq 0x19d6b(%rip), %rdi     # 0x5cba7
leaq 0x19ae1(%rip), %rsi     # 0x5c924
leaq 0x1a914(%rip), %rcx     # 0x5d75e
movl $0xa3, %edx
callq 0x9200
movl $0x8, %edi
callq 0x9180
movq 0x4314b(%rip), %rcx     # 0x85fb0
addq $0x10, %rcx
movq %rcx, (%rax)
movq 0x43155(%rip), %rsi     # 0x85fc8
movq 0x43116(%rip), %rdx     # 0x85f90
movq %rax, %rdi
callq 0x9640
leaq 0x1a1f7(%rip), %rdi     # 0x5d080
leaq 0x196a9(%rip), %rsi     # 0x5c539
leaq 0x1a475(%rip), %rcx     # 0x5d30c
movl $0x2d1, %edx            # imm = 0x2D1
callq 0x9200
jmp 0x42f4a
movq %rax, %rbx
jmp 0x42fc1
jmp 0x42f4a
jmp 0x42f4a
movq %rax, %rbx
movq 0x48(%rsp), %rdi
cmpq %r12, %rdi
je 0x42f4d
movq 0x58(%rsp), %rsi
jmp 0x42f39
movq %rax, %rbx
jmp 0x42f90
movq %rax, %rbx
jmp 0x42fa7
jmp 0x42f4a
jmp 0x42ef0
jmp 0x42f4a
jmp 0x42f4a
movq %rax, %rbx
jmp 0x42f9d
movq %rax, %rbx
jmp 0x42fb4
movq %rax, %rbx
movq 0x68(%rsp), %rdi
cmpq %rbp, %rdi
je 0x42f4d
movq 0x78(%rsp), %rsi
jmp 0x42f39
movq %rax, %rbx
leaq 0x1b8(%rsp), %rdi
callq 0x37fb2
jmp 0x42fc1
movq %rax, %rbx
movq 0x88(%rsp), %rdi
cmpq %r12, %rdi
je 0x42f4d
movq 0x98(%rsp), %rsi
incq %rsi
callq 0x9350
jmp 0x42f4d
jmp 0x42f45
movq %rax, %rbx
jmp 0x42f67
movq %rax, %rbx
movq 0x160(%rsp), %rdi
callq 0x93d0
movq 0x150(%rsp), %rdi
callq 0x93d0
leaq 0x41832(%rip), %rax     # 0x847a0
movq %rax, 0xa8(%rsp)
movq 0xf8(%rsp), %rdi
callq 0x93d0
movq 0xe8(%rsp), %rdi
callq 0x93d0
movq 0x108(%rsp), %rdi
callq 0x93d0
movq 0x38(%rsp), %rdi
callq 0x93d0
movq 0x118(%rsp), %rdi
callq 0x93d0
leaq 0x190(%rsp), %rdi
callq 0x35fc8
movq (%rsp), %rdi
callq 0x93d0
movq %rbx, %rdi
callq 0x9680