// File: /workspace/github_cpp_makefile_star2_O2/canzarlab[P]Trajan/src/LPCP.cpp
// Function: LPCP::SolveLP()
bool LPCP::SolveLP()
{
    clog << "nr_rows = " << nr_rows << " and nr_cols = " << nr_cols << endl;
    warm_y.conservativeResizeLike(Vector::Zero(nr_rows)); // resizes y with 0's, but keeping old values intact.

    SpMat A(nr_rows, nr_cols);
    A.setFromTriplets(Triplets.begin(), Triplets.end());
    SpMat A_t = A.transpose();
    Vector b = Vector::Ones(nr_rows);

    //x = Vector::Zero(nr_cols);
    //y = Vector::Zero(nr_rows);

    CoveringJRF simpleJRF(A_t, c, b, warm_y, warm_x);

    Vector c1 = -c;
//        PackingJRF simpleJRF(A, b, c1, x, y);
    AugmentedLagrangian solver(simpleJRF, 15);
    solver.setParameter("verbose", false);
    solver.setParameter("pgtol", 1e-1); // should influence running time a lot
    solver.setParameter("constraintsTol", 1e-3);
    Timer timeGeno;
    timeGeno.start();
    solver.solve();
    timeGeno.stop();

    clog << "f = " << solver.f() << " computed in time: " << timeGeno.secs() << " secs" << endl;

    /* when Packing: x->x, y->y, when Covering: -y -> x, x -> y */
    x = -Vector::ConstMapType(solver.y(), nr_cols);
    y = Vector::ConstMapType(solver.x(), nr_rows);

    warm_x = Vector::ConstMapType(solver.y(), nr_cols);
    warm_y = Vector::ConstMapType(solver.x(), nr_rows);


    Vector t = A_t*y-c;
    int nr_tight_constr =  nr_cols - (t.array() > 0.1).count();
    clog << "Number of tight constraints in the dual: " << nr_tight_constr << endl;
    //idea, truncate matrix A for columns that correspond to non-tight constraints in dual
    SpMat truncA(nr_rows, nr_tight_constr);
    Vector truncc(nr_tight_constr);
    Vector truncx(nr_tight_constr);
    int truncA_col = 0;
    for (int i=0; i<nr_cols; i++)
        if (t(i)> 0.1)
            x(i) = 0.0;
        else {
            for (SpMat::InnerIterator it(A,i); it; ++it)
            {
                truncA.coeffRef(it.row(), truncA_col) = it.value();
            }
            truncc(truncA_col) = - c(i);
            truncx(truncA_col) = x(i);
            truncA_col ++;
        }

    assert(truncA_col == nr_tight_constr);

    clog << "Truncated matrix formed ... resolve" << endl;
    Vector expy = Vector::Zero(truncA.rows() + truncA.cols());
    IntegerPackingJRF simpleJRF1(truncA, b, truncc, truncx, expy);
    //PackingJRF simpleJRF1(truncA, b, truncc, truncx, y);
    AugmentedLagrangian solver1(simpleJRF1, 15);
    solver1.setParameter("verbose", false);
    solver1.setParameter("pgtol", 1e-1); // should influence running time a lot
    solver1.setParameter("constraintsTol", 1e-5);
    Timer timeGeno1;
    timeGeno1.start();
    solver1.solve();
    timeGeno1.stop();
    clog << "trunc f = " << solver1.f() << " computed in time: " << timeGeno1.secs() << " secs" << endl;

    // map the solution back to vector x
    truncx = Vector::ConstMapType(solver1.x(), nr_tight_constr);
    clog <<"MAX INTEGER PACKING VALUE: " <<  truncx.maxCoeff() << endl;
    truncA_col = 0;
    for (int i=0; i<nr_cols; i++)
        if (t(i)<= 0.1){
            x(i) = truncx(truncA_col);
            truncA_col++;
        }

    assert(truncA_col == nr_tight_constr);
    return true;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x428, %rsp            # imm = 0x428
movq %rdi, %rbx
movq 0x54f33(%rip), %rdi     # 0x96f70
leaq 0x2a9b8(%rip), %rsi     # 0x6c9fc
callq 0x9330
movl 0x108(%rbx), %esi
movq %rax, %rdi
callq 0x9610
leaq 0x2a9a9(%rip), %rsi     # 0x6ca07
movq %rax, %rdi
callq 0x9330
movl 0x10c(%rbx), %esi
movq %rax, %rdi
callq 0x9610
movq %rax, %rdi
callq 0x9170
leaq 0xb0(%rbx), %r13
movslq 0x108(%rbx), %rsi
leaq 0x150(%rsp), %r15
movq %r15, %rdi
callq 0xced2
movq %r13, %rdi
movq %r15, %rsi
callq 0x3c2be
movslq 0x108(%rbx), %rsi
movslq 0x10c(%rbx), %rdx
leaq 0x2b8(%rsp), %r14
movq %r14, %rdi
callq 0x3331e
movq 0x88(%rbx), %rax
movq %rax, (%r15)
movq 0x90(%rbx), %rax
leaq 0x60(%rsp), %rdx
movq %rax, (%rdx)
leaq 0x150(%rsp), %rsi
movq %r14, %rdi
callq 0x33360
leaq 0x150(%rsp), %rsi
movb $0x0, (%rsi)
movq %r14, 0x8(%rsi)
leaq 0x358(%rsp), %r14
movq %r14, %rdi
callq 0x3337a
movslq 0x108(%rbx), %rsi
leaq 0x150(%rsp), %rdi
callq 0x333bc
leaq 0xd8(%rsp), %r15
leaq 0x150(%rsp), %rsi
movq %r15, %rdi
callq 0x34154
leaq 0xf8(%rbx), %rcx
leaq 0xa0(%rbx), %rbp
movq %r14, 0x280(%rsp)
movq %rcx, 0x288(%rsp)
movq %r15, 0x290(%rsp)
movq %r13, 0x298(%rsp)
movq %rbp, 0x2a0(%rsp)
movups 0x360(%rsp), %xmm0
movups %xmm0, 0x2a8(%rsp)
leaq 0x53c04(%rip), %rax     # 0x95d88
movq %rax, 0x278(%rsp)
leaq 0x150(%rsp), %rsi
movq %rcx, 0x38(%rsp)
movq %rcx, (%rsi)
leaq 0xf8(%rsp), %rdi
callq 0x35f66
leaq 0x150(%rsp), %rdi
leaq 0x278(%rsp), %rsi
pushq $0xf
popq %rdx
callq 0xc424
leaq 0xf272(%rip), %rsi      # 0x5143a
leaq 0x258(%rsp), %rdi
leaq 0x60(%rsp), %rdx
callq 0xb7a6
leaq 0x150(%rsp), %rdi
leaq 0x258(%rsp), %rsi
xorps %xmm0, %xmm0
callq 0xcdfc
leaq 0x258(%rsp), %rdi
callq 0x9708
leaq 0xf212(%rip), %rsi      # 0x51418
leaq 0x238(%rsp), %rdi
leaq 0x60(%rsp), %rdx
callq 0xb7a6
leaq 0x150(%rsp), %rdi
leaq 0x238(%rsp), %rsi
movsd 0x11610(%rip), %xmm0    # 0x53840
callq 0xcdfc
leaq 0x238(%rsp), %rdi
callq 0x9708
leaq 0xf1e2(%rip), %rsi      # 0x5142b
leaq 0x218(%rsp), %rdi
leaq 0x60(%rsp), %rdx
callq 0xb7a6
leaq 0x150(%rsp), %rdi
leaq 0x218(%rsp), %rsi
movsd 0x115bd(%rip), %xmm0    # 0x53830
callq 0xcdfc
leaq 0x218(%rsp), %rdi
callq 0x9708
leaq 0x3a0(%rsp), %rdi
movb $0x0, 0x38(%rdi)
xorps %xmm0, %xmm0
movaps %xmm0, (%rdi)
callq 0xb808
leaq 0x150(%rsp), %rdi
callq 0xc4b2
leaq 0x3a0(%rsp), %rdi
callq 0xba34
movq 0x54cb3(%rip), %rdi     # 0x96f70
leaq 0x2de00(%rip), %rsi     # 0x700c4
callq 0x9330
movq %rax, %r14
leaq 0x150(%rsp), %rdi
callq 0xcdf6
movq %r14, %rdi
callq 0x9540
leaq 0x2a72f(%rip), %rsi     # 0x6ca17
movq %rax, %rdi
callq 0x9330
cvtsi2sdq 0x3a0(%rsp), %xmm0
divsd 0xed26(%rip), %xmm0     # 0x51028
cvtsd2ss %xmm0, %xmm0
movq %rax, %rdi
callq 0x9270
leaq 0xef77(%rip), %rsi      # 0x5128c
movq %rax, %rdi
callq 0x9330
movq %rax, %rdi
callq 0x9170
leaq 0x150(%rsp), %rdi
callq 0xcdf0
movslq 0x10c(%rbx), %rdx
leaq 0x108(%rsp), %rdi
movq %rax, %rsi
callq 0xebcc
movups 0x108(%rsp), %xmm0
leaq 0x60(%rsp), %rsi
movaps %xmm0, (%rsi)
leaq 0xc0(%rbx), %r14
movq %r14, %rdi
callq 0x42d86
leaq 0x150(%rsp), %rdi
callq 0xcdea
movslq 0x108(%rbx), %rdx
leaq 0x60(%rsp), %rdi
movq %rax, %rsi
callq 0xebcc
leaq 0xd0(%rbx), %r15
leaq 0x60(%rsp), %rsi
movq %r15, %rdi
callq 0xebf9
leaq 0x150(%rsp), %rdi
callq 0xcdf0
movslq 0x10c(%rbx), %rdx
leaq 0x60(%rsp), %rdi
movq %rax, %rsi
callq 0xebcc
leaq 0x60(%rsp), %rsi
movq %rbp, %rdi
callq 0xebf9
leaq 0x150(%rsp), %rdi
callq 0xcdea
movslq 0x108(%rbx), %rdx
leaq 0x60(%rsp), %rdi
movq %rax, %rsi
callq 0xebcc
leaq 0x60(%rsp), %rsi
movq %r13, %rdi
callq 0xebf9
leaq 0x358(%rsp), %rdi
movq %r15, %rsi
callq 0x42b4a
leaq 0x108(%rsp), %rsi
movq %rax, (%rsi)
movq %rdx, 0x8(%rsi)
leaq 0x60(%rsp), %rdi
movq 0x38(%rsp), %rdx
callq 0x42b6e
leaq 0x40(%rsp), %r15
leaq 0x60(%rsp), %rsi
movq %r15, %rdi
callq 0x42f14
movq %rbx, 0x30(%rsp)
movl 0x10c(%rbx), %ebx
leaq 0x108(%rsp), %rsi
movq %r15, (%rsi)
movabsq $0x3fb999999999999a, %rax # imm = 0x3FB999999999999A
leaq 0x3e8(%rsp), %rdx
movq %rax, (%rdx)
leaq 0x60(%rsp), %rdi
callq 0x42b8a
leaq 0x60(%rsp), %rdi
callq 0x42bce
subl %eax, %ebx
movl %ebx, 0x8(%rsp)
movq 0x54aeb(%rip), %rdi     # 0x96f70
leaq 0x2db9c(%rip), %rsi     # 0x70028
callq 0x9330
movl 0x8(%rsp), %esi
movq %rax, %rdi
callq 0x9610
movq %rax, %rdi
callq 0x9170
movq 0x30(%rsp), %rbx
movslq 0x108(%rbx), %rsi
movslq 0x8(%rsp), %rdx
leaq 0x108(%rsp), %rdi
callq 0x3331e
leaq 0x50(%rsp), %rdi
leaq 0x8(%rsp), %rsi
callq 0x3324c
leaq 0x20(%rsp), %rdi
leaq 0x8(%rsp), %rsi
callq 0x3324c
xorl %r12d, %r12d
leaq 0x40(%rsp), %r15
movl $0x0, 0xc(%rsp)
movq %r14, 0xd0(%rsp)
movslq 0x10c(%rbx), %rax
cmpq %rax, %r12
jge 0x42622
movq %r15, %rdi
movq %r12, %rsi
callq 0xd27a
movsd (%rax), %xmm0
ucomisd 0x11320(%rip), %xmm0    # 0x53840
jbe 0x42536
movq %r14, %rdi
movq %r12, %rsi
callq 0xd27a
andq $0x0, (%rax)
jmp 0x4261a
movq 0x2d0(%rsp), %rax
movq 0x2d8(%rsp), %rcx
movslq (%rax,%r12,4), %rbx
testq %rcx, %rcx
je 0x42558
movslq (%rcx,%r12,4), %r13
addq %rbx, %r13
jmp 0x4255d
movslq 0x4(%rax,%r12,4), %r13
movq 0x2e0(%rsp), %r14
movq 0x2e8(%rsp), %r15
movslq 0xc(%rsp), %rbp
cmpq %r13, %rbx
jge 0x425a6
movsd (%r14,%rbx,8), %xmm0
movsd %xmm0, 0x10(%rsp)
movslq (%r15,%rbx,4), %rsi
leaq 0x108(%rsp), %rdi
movq %rbp, %rdx
callq 0x42bfe
movsd 0x10(%rsp), %xmm0
movsd %xmm0, (%rax)
incq %rbx
jmp 0x42572
movq 0x38(%rsp), %rdi
movq %r12, %rsi
callq 0xd27a
movq 0x30(%rsp), %rbx
movq 0xd0(%rsp), %r14
leaq 0x40(%rsp), %r15
movsd (%rax), %xmm0
movaps %xmm0, 0x10(%rsp)
leaq 0x50(%rsp), %rdi
movq %rbp, %rsi
callq 0xd27a
movaps 0x10(%rsp), %xmm0
xorps 0xedd9(%rip), %xmm0     # 0x513c0
movlps %xmm0, (%rax)
movq %r14, %rdi
movq %r12, %rsi
callq 0xd27a
movsd (%rax), %xmm0
movsd %xmm0, 0x10(%rsp)
leaq 0x20(%rsp), %rdi
movq %rbp, %rsi
callq 0xd27a
movsd 0x10(%rsp), %xmm0
movsd %xmm0, (%rax)
incl 0xc(%rsp)
incq %r12
jmp 0x424f9
movl 0xc(%rsp), %eax
cmpl 0x8(%rsp), %eax
jne 0x429a4
movq 0x54939(%rip), %rdi     # 0x96f70
leaq 0x2da5c(%rip), %rsi     # 0x7009a
callq 0x9330
movq %rax, %rdi
callq 0x9170
movq 0x110(%rsp), %rsi
addq 0x118(%rsp), %rsi
leaq 0x60(%rsp), %rdi
callq 0xced2
leaq 0xe8(%rsp), %r12
leaq 0x60(%rsp), %rsi
movq %r12, %rdi
callq 0x34154
leaq 0x3e8(%rsp), %rsi
leaq 0x108(%rsp), %rax
movq %rax, 0x8(%rsi)
leaq 0xd8(%rsp), %rax
movq %rax, 0x10(%rsi)
leaq 0x50(%rsp), %rax
movq %rax, 0x18(%rsi)
leaq 0x20(%rsp), %rax
movq %rax, 0x20(%rsi)
movq %r12, 0x28(%rsi)
movq 0x110(%rsp), %rax
movq %rax, 0x30(%rsi)
leaq 0x535cd(%rip), %rcx     # 0x95c90
movq %rcx, (%rsi)
addq 0x118(%rsp), %rax
movq %rax, 0x38(%rsi)
leaq 0x60(%rsp), %rdi
pushq $0xf
popq %rdx
callq 0xc424
leaq 0xed54(%rip), %rsi      # 0x5143a
leaq 0x1f8(%rsp), %rdi
leaq 0x300(%rsp), %rdx
callq 0xb7a6
leaq 0x60(%rsp), %rdi
leaq 0x1f8(%rsp), %rsi
xorps %xmm0, %xmm0
callq 0xcdfc
leaq 0x1f8(%rsp), %rdi
callq 0x9708
leaq 0xecf4(%rip), %rsi      # 0x51418
leaq 0x1d8(%rsp), %rdi
leaq 0x300(%rsp), %rdx
callq 0xb7a6
leaq 0x60(%rsp), %rdi
leaq 0x1d8(%rsp), %rsi
movsd 0x110f2(%rip), %xmm0    # 0x53840
callq 0xcdfc
leaq 0x1d8(%rsp), %rdi
callq 0x9708
leaq 0xecc4(%rip), %rsi      # 0x5142b
leaq 0x1b8(%rsp), %rdi
leaq 0x300(%rsp), %rdx
callq 0xb7a6
leaq 0x60(%rsp), %rdi
leaq 0x1b8(%rsp), %rsi
movsd 0x2d88f(%rip), %xmm0    # 0x70020
callq 0xcdfc
leaq 0x1b8(%rsp), %rdi
callq 0x9708
leaq 0x300(%rsp), %rdi
movb $0x0, 0x38(%rdi)
xorps %xmm0, %xmm0
movaps %xmm0, (%rdi)
callq 0xb808
leaq 0x60(%rsp), %rdi
callq 0xc4b2
leaq 0x300(%rsp), %rdi
callq 0xba34
movq 0x54798(%rip), %rdi     # 0x96f70
leaq 0x2d8df(%rip), %rsi     # 0x700be
callq 0x9330
movq %rax, %r15
leaq 0x60(%rsp), %rdi
callq 0xcdf6
movq %r15, %rdi
callq 0x9540
leaq 0x2a217(%rip), %rsi     # 0x6ca17
movq %rax, %rdi
callq 0x9330
cvtsi2sdq 0x300(%rsp), %xmm0
divsd 0xe80e(%rip), %xmm0     # 0x51028
cvtsd2ss %xmm0, %xmm0
movq %rax, %rdi
callq 0x9270
leaq 0xea5f(%rip), %rsi      # 0x5128c
movq %rax, %rdi
callq 0x9330
movq %rax, %rdi
callq 0x9170
leaq 0x60(%rsp), %rdi
callq 0xcdea
movslq 0x8(%rsp), %rdx
leaq 0x340(%rsp), %rdi
movq %rax, %rsi
callq 0xebcc
leaq 0x20(%rsp), %rdi
leaq 0x340(%rsp), %rsi
callq 0xebf9
movq 0x546fb(%rip), %rdi     # 0x96f70
leaq 0x2d84d(%rip), %rsi     # 0x700c9
callq 0x9330
movq %rax, %r15
leaq 0x20(%rsp), %rdi
callq 0x42ce2
movq %r15, %rdi
callq 0x9540
movq %rax, %rdi
callq 0x9170
xorl %r15d, %r15d
leaq 0x40(%rsp), %r12
leaq 0x20(%rsp), %r13
xorl %ebp, %ebp
movslq 0x10c(%rbx), %rax
cmpq %rax, %r15
jge 0x42903
movq %r12, %rdi
movq %r15, %rsi
callq 0xd27a
movsd 0x10f74(%rip), %xmm0    # 0x53840
ucomisd (%rax), %xmm0
jb 0x428fe
movslq %ebp, %rsi
movq %r13, %rdi
callq 0xd27a
movsd (%rax), %xmm0
movsd %xmm0, 0x10(%rsp)
movq %r14, %rdi
movq %r15, %rsi
callq 0xd27a
movsd 0x10(%rsp), %xmm0
movsd %xmm0, (%rax)
incl %ebp
incq %r15
jmp 0x428ad
cmpl 0x8(%rsp), %ebp
jne 0x429bd
leaq 0x60(%rsp), %rdi
callq 0x333e4
movq 0xe8(%rsp), %rdi
callq 0x93c0
movq 0x20(%rsp), %rdi
callq 0x93c0
movq 0x50(%rsp), %rdi
callq 0x93c0
leaq 0x108(%rsp), %rdi
callq 0x33400
movq 0x40(%rsp), %rdi
callq 0x93c0
leaq 0x150(%rsp), %rdi
callq 0x333e4
movq 0xf8(%rsp), %rdi
callq 0x93c0
movq 0xd8(%rsp), %rdi
callq 0x93c0
leaq 0x358(%rsp), %rdi
callq 0x33400
leaq 0x2b8(%rsp), %rdi
callq 0x33400
movb $0x1, %al
addq $0x428, %rsp            # imm = 0x428
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x2d6a7(%rip), %rdi     # 0x70052
leaq 0x2d6be(%rip), %rsi     # 0x70070
leaq 0x2d6c4(%rip), %rcx     # 0x7007d
pushq $0x42
jmp 0x429d4
leaq 0x2d68e(%rip), %rdi     # 0x70052
leaq 0x2d6a5(%rip), %rsi     # 0x70070
leaq 0x2d6ab(%rip), %rcx     # 0x7007d
pushq $0x5c
popq %rdx
callq 0x9210
jmp 0x42ab4
movq %rax, %rbx
leaq 0x1b8(%rsp), %rdi
jmp 0x42a0e
jmp 0x42ab4
movq %rax, %rbx
leaq 0x1d8(%rsp), %rdi
jmp 0x42a0e
jmp 0x42ab4
movq %rax, %rbx
leaq 0x1f8(%rsp), %rdi
callq 0x9708
jmp 0x42ab7
jmp 0x42ab4
movq %rax, %rbx
jmp 0x42ac1
movq %rax, %rbx
jmp 0x42adf
movq %rax, %rbx
jmp 0x42ae9
jmp 0x42aa6
jmp 0x42aad
jmp 0x42aad
jmp 0x42aad
jmp 0x42aad
movq %rax, %rbx
leaq 0x218(%rsp), %rdi
jmp 0x42a68
jmp 0x42aad
movq %rax, %rbx
leaq 0x238(%rsp), %rdi
jmp 0x42a68
jmp 0x42aad
movq %rax, %rbx
leaq 0x258(%rsp), %rdi
callq 0x9708
jmp 0x42b00
jmp 0x42aad
movq %rax, %rbx
jmp 0x42b0d
movq %rax, %rbx
jmp 0x42b1a
jmp 0x42a86
movq %rax, %rbx
jmp 0x42b34
jmp 0x42ab4
jmp 0x42ad2
jmp 0x42ad2
jmp 0x42aa6
jmp 0x42aad
jmp 0x42aad
jmp 0x42aad
jmp 0x42aad
movq %rax, %rbx
jmp 0x42b27
movq %rax, %rbx
jmp 0x42af6
jmp 0x42aad
movq %rax, %rbx
jmp 0x42b00
jmp 0x42ab4
movq %rax, %rbx
leaq 0x60(%rsp), %rdi
callq 0x333e4
movq 0xe8(%rsp), %rdi
callq 0x93c0
jmp 0x42ad5
jmp 0x42ad2
movq %rax, %rbx
movq 0x20(%rsp), %rdi
callq 0x93c0
movq 0x50(%rsp), %rdi
callq 0x93c0
leaq 0x108(%rsp), %rdi
callq 0x33400
movq 0x40(%rsp), %rdi
callq 0x93c0
leaq 0x150(%rsp), %rdi
callq 0x333e4
movq 0xf8(%rsp), %rdi
callq 0x93c0
movq 0xd8(%rsp), %rdi
callq 0x93c0
leaq 0x358(%rsp), %rdi
callq 0x33400
leaq 0x2b8(%rsp), %rdi
callq 0x33400
movq %rbx, %rdi
callq 0x9640
nop