Skip to main content

0 on lp file objective function

Answered

Comments

4 comments

  • Silke Horn
    Gurobi Staff Gurobi Staff

    First of all, if a coefficient in the LP file is 0 when it should be 1, then there is something wrong. How did you set the objective?

    Secondly, there are a lot of variables with coefficient 0 in the objective, which might be confusing. This is because Gurobi writes all variables into the objective to preserve the order of the variables (since the order affects the solver path).

    0
  • Iason Liagkas
    Gurobi-versary
    Detective
    Thought Leader

    Hello Silke the code that sets the objective is:


    obj=gp.quicksum(uirs[i,r,s] for r,s in drs.keys() for i in ["I","E"])  - Sc*C*F*(Riinit-Rirs.sum("I",'*','*')/len(Rirs.select("I",'*','*')))\
        -250*gp.quicksum(lRirs[i,r,s] for r,s in drs.keys() for i in ["E","I"])-gp.quicksum(lkfa[i,j] for i,j in arcs)-gp.quicksum(lxa[i,j] for i,j in arcs)


    SPmodel.setObjective(obj,GRB.MINIMIZE)

    # Find optimal solution
    SPmodel.optimize()


    I observe that some of the variables are repeated with the correct coefficient. For example below the third variable is: + 0 lx_a[2,1] but then we have again a little down below: - lx_a[2,1] <- which is correct according to the last term of my objective function. I have the impression that Gurobi makes this trick with the zeros from a previous post but I cannot find it, and I am not sure if I remember correctly. I just wanted to confirm. Kind regards

     


    \ Model SP
    \ LP format - for model browsing. Use MPS format to capture full model detail.
    Minimize
      0 lx_a[1,2] + 0 lx_a[1,3] + 0 lx_a[2,1] + 0 lx_a[2,6] + 0 lx_a[3,1]
       + 0 lx_a[3,4] + 0 lx_a[3,12] + 0 lx_a[4,3] + 0 lx_a[4,5] + 0 lx_a[4,11]
       + 0 lx_a[5,4] + 0 lx_a[5,6] + 0 lx_a[5,9] + 0 lx_a[6,2] + 0 lx_a[6,5]
       + 0 lx_a[6,8] + 0 lx_a[7,8] + 0 lx_a[7,18] + 0 lx_a[8,6] + 0 lx_a[8,7]
       + 0 lx_a[8,9] + 0 lx_a[8,16] + 0 lx_a[9,5] + 0 lx_a[9,8] + 0 lx_a[9,10]
       + 0 lx_a[10,9] + 0 lx_a[10,11] + 0 lx_a[10,15] + 0 lx_a[10,16]
       + 0 lx_a[10,17] + 0 lx_a[11,4] + 0 lx_a[11,10] + 0 lx_a[11,12]
       + 0 lx_a[11,14] + 0 lx_a[12,3] + 0 lx_a[12,11] + 0 lx_a[12,13]
       + 0 lx_a[13,12] + 0 lx_a[13,24] + 0 lx_a[14,11] + 0 lx_a[14,15]
       + 0 lx_a[14,23] + 0 lx_a[15,10] + 0 lx_a[15,14] + 0 lx_a[15,19]
       + 0 lx_a[15,22] + 0 lx_a[16,8] + 0 lx_a[16,10] + 0 lx_a[16,17]
       + 0 lx_a[16,18] + 0 lx_a[17,10] + 0 lx_a[17,16] + 0 lx_a[17,19]
       + 0 lx_a[18,7] + 0 lx_a[18,16] + 0 lx_a[18,20] + 0 lx_a[19,15]
       + 0 lx_a[19,17] + 0 lx_a[19,20] + 0 lx_a[20,18] + 0 lx_a[20,19]
       + 0 lx_a[20,21] + 0 lx_a[20,22] + 0 lx_a[21,20] + 0 lx_a[21,22]
       + 0 lx_a[21,24] + 0 lx_a[22,15] + 0 lx_a[22,20] + 0 lx_a[22,21]
       + 0 lx_a[22,23] + 0 lx_a[23,14] + 0 lx_a[23,22] + 0 lx_a[23,24]
       + 0 lx_a[24,13] + 0 lx_a[24,21] + 0 lx_a[24,23] + u_i^rs[E,1,2]
       + u_i^rs[E,1,4] + u_i^rs[E,1,5] + u_i^rs[E,2,1] + u_i^rs[E,2,4]
       + u_i^rs[E,2,5] + u_i^rs[E,4,1] + u_i^rs[E,4,2] + u_i^rs[E,4,5]
       + u_i^rs[E,5,1] + u_i^rs[E,5,2] + u_i^rs[E,5,4] + u_i^rs[I,1,2]
       + u_i^rs[I,1,4] + u_i^rs[I,1,5] + u_i^rs[I,2,1] + u_i^rs[I,2,4]
       + u_i^rs[I,2,5] + u_i^rs[I,4,1] + u_i^rs[I,4,2] + u_i^rs[I,4,5]
       + u_i^rs[I,5,1] + u_i^rs[I,5,2] + u_i^rs[I,5,4]
       + 0 T_{k,i}^{rs}[T,1,2,0] + 0 T_{k,i}^{rs}[T,1,2,1]
       + 0 T_{k,i}^{rs}[T,1,2,2] + 0 T_{k,i}^{rs}[T,1,2,3]
       + 0 T_{k,i}^{rs}[T,1,2,4] + 0 T_{k,i}^{rs}[T,1,4,0]
       + 0 T_{k,i}^{rs}[T,1,4,1] + 0 T_{k,i}^{rs}[T,1,4,2]
       + 0 T_{k,i}^{rs}[T,1,4,3] + 0 T_{k,i}^{rs}[T,1,4,4]
       + 0 T_{k,i}^{rs}[T,1,5,0] + 0 T_{k,i}^{rs}[T,1,5,1]
       + 0 T_{k,i}^{rs}[T,1,5,2] + 0 T_{k,i}^{rs}[T,1,5,3]
       + 0 T_{k,i}^{rs}[T,1,5,4] + 0 T_{k,i}^{rs}[T,2,1,0]
       + 0 T_{k,i}^{rs}[T,2,1,1] + 0 T_{k,i}^{rs}[T,2,1,2]
       + 0 T_{k,i}^{rs}[T,2,1,3] + 0 T_{k,i}^{rs}[T,2,1,4]
       + 0 T_{k,i}^{rs}[T,2,4,0] + 0 T_{k,i}^{rs}[T,2,4,1]
       + 0 T_{k,i}^{rs}[T,2,4,2] + 0 T_{k,i}^{rs}[T,2,4,3]
       + 0 T_{k,i}^{rs}[T,2,4,4] + 0 T_{k,i}^{rs}[T,2,5,0]
       + 0 T_{k,i}^{rs}[T,2,5,1] + 0 T_{k,i}^{rs}[T,2,5,2]
       + 0 T_{k,i}^{rs}[T,2,5,3] + 0 T_{k,i}^{rs}[T,2,5,4]
       + 0 T_{k,i}^{rs}[T,4,1,0] + 0 T_{k,i}^{rs}[T,4,1,1]
       + 0 T_{k,i}^{rs}[T,4,1,2] + 0 T_{k,i}^{rs}[T,4,1,3]
       + 0 T_{k,i}^{rs}[T,4,1,4] + 0 T_{k,i}^{rs}[T,4,2,0]
       + 0 T_{k,i}^{rs}[T,4,2,1] + 0 T_{k,i}^{rs}[T,4,2,2]
       + 0 T_{k,i}^{rs}[T,4,2,3] + 0 T_{k,i}^{rs}[T,4,2,4]
       + 0 T_{k,i}^{rs}[T,4,5,0] + 0 T_{k,i}^{rs}[T,4,5,1]
       + 0 T_{k,i}^{rs}[T,4,5,2] + 0 T_{k,i}^{rs}[T,4,5,3]
       + 0 T_{k,i}^{rs}[T,4,5,4] + 0 T_{k,i}^{rs}[T,5,1,0]
       + 0 T_{k,i}^{rs}[T,5,1,1] + 0 T_{k,i}^{rs}[T,5,1,2]
       + 0 T_{k,i}^{rs}[T,5,1,3] + 0 T_{k,i}^{rs}[T,5,1,4]
       + 0 T_{k,i}^{rs}[T,5,2,0] + 0 T_{k,i}^{rs}[T,5,2,1]
       + 0 T_{k,i}^{rs}[T,5,2,2] + 0 T_{k,i}^{rs}[T,5,2,3]
       + 0 T_{k,i}^{rs}[T,5,2,4] + 0 T_{k,i}^{rs}[T,5,4,0]
       + 0 T_{k,i}^{rs}[T,5,4,1] + 0 T_{k,i}^{rs}[T,5,4,2]
       + 0 T_{k,i}^{rs}[T,5,4,3] + 0 T_{k,i}^{rs}[T,5,4,4]
       + 0 f_{k,i}^{rs}[T,1,2,0] + 0 f_{k,i}^{rs}[T,1,2,1]
       + 0 f_{k,i}^{rs}[T,1,2,2] + 0 f_{k,i}^{rs}[T,1,2,3]
       + 0 f_{k,i}^{rs}[T,1,2,4] + 0 f_{k,i}^{rs}[T,1,4,0]
       + 0 f_{k,i}^{rs}[T,1,4,1] + 0 f_{k,i}^{rs}[T,1,4,2]
       + 0 f_{k,i}^{rs}[T,1,4,3] + 0 f_{k,i}^{rs}[T,1,4,4]
       + 0 f_{k,i}^{rs}[T,1,5,0] + 0 f_{k,i}^{rs}[T,1,5,1]
       + 0 f_{k,i}^{rs}[T,1,5,2] + 0 f_{k,i}^{rs}[T,1,5,3]
       + 0 f_{k,i}^{rs}[T,1,5,4] + 0 f_{k,i}^{rs}[T,2,1,0]
       + 0 f_{k,i}^{rs}[T,2,1,1] + 0 f_{k,i}^{rs}[T,2,1,2]
       + 0 f_{k,i}^{rs}[T,2,1,3] + 0 f_{k,i}^{rs}[T,2,1,4]
       + 0 f_{k,i}^{rs}[T,2,4,0] + 0 f_{k,i}^{rs}[T,2,4,1]
       + 0 f_{k,i}^{rs}[T,2,4,2] + 0 f_{k,i}^{rs}[T,2,4,3]
       + 0 f_{k,i}^{rs}[T,2,4,4] + 0 f_{k,i}^{rs}[T,2,5,0]
       + 0 f_{k,i}^{rs}[T,2,5,1] + 0 f_{k,i}^{rs}[T,2,5,2]
       + 0 f_{k,i}^{rs}[T,2,5,3] + 0 f_{k,i}^{rs}[T,2,5,4]
       + 0 f_{k,i}^{rs}[T,4,1,0] + 0 f_{k,i}^{rs}[T,4,1,1]
       + 0 f_{k,i}^{rs}[T,4,1,2] + 0 f_{k,i}^{rs}[T,4,1,3]
       + 0 f_{k,i}^{rs}[T,4,1,4] + 0 f_{k,i}^{rs}[T,4,2,0]
       + 0 f_{k,i}^{rs}[T,4,2,1] + 0 f_{k,i}^{rs}[T,4,2,2]
       + 0 f_{k,i}^{rs}[T,4,2,3] + 0 f_{k,i}^{rs}[T,4,2,4]
       + 0 f_{k,i}^{rs}[T,4,5,0] + 0 f_{k,i}^{rs}[T,4,5,1]
       + 0 f_{k,i}^{rs}[T,4,5,2] + 0 f_{k,i}^{rs}[T,4,5,3]
       + 0 f_{k,i}^{rs}[T,4,5,4] + 0 f_{k,i}^{rs}[T,5,1,0]
       + 0 f_{k,i}^{rs}[T,5,1,1] + 0 f_{k,i}^{rs}[T,5,1,2]
       + 0 f_{k,i}^{rs}[T,5,1,3] + 0 f_{k,i}^{rs}[T,5,1,4]
       + 0 f_{k,i}^{rs}[T,5,2,0] + 0 f_{k,i}^{rs}[T,5,2,1]
       + 0 f_{k,i}^{rs}[T,5,2,2] + 0 f_{k,i}^{rs}[T,5,2,3]
       + 0 f_{k,i}^{rs}[T,5,2,4] + 0 f_{k,i}^{rs}[T,5,4,0]
       + 0 f_{k,i}^{rs}[T,5,4,1] + 0 f_{k,i}^{rs}[T,5,4,2]
       + 0 f_{k,i}^{rs}[T,5,4,3] + 0 f_{k,i}^{rs}[T,5,4,4]
       + 1234.5 R_i^rs[I,1,2] + 1234.5 R_i^rs[I,1,4] + 1234.5 R_i^rs[I,1,5]
       + 1234.5 R_i^rs[I,2,1] + 1234.5 R_i^rs[I,2,4] + 1234.5 R_i^rs[I,2,5]
       + 1234.5 R_i^rs[I,4,1] + 1234.5 R_i^rs[I,4,2] + 1234.5 R_i^rs[I,4,5]
       + 1234.5 R_i^rs[I,5,1] + 1234.5 R_i^rs[I,5,2] + 1234.5 R_i^rs[I,5,4]
       - 250 lR_i^rs[E,1,2] - 250 lR_i^rs[E,1,4] - 250 lR_i^rs[E,1,5]
       - 250 lR_i^rs[E,2,1] - 250 lR_i^rs[E,2,4] - 250 lR_i^rs[E,2,5]
       - 250 lR_i^rs[E,4,1] - 250 lR_i^rs[E,4,2] - 250 lR_i^rs[E,4,5]
       - 250 lR_i^rs[E,5,1] - 250 lR_i^rs[E,5,2] - 250 lR_i^rs[E,5,4]
       - 250 lR_i^rs[I,1,2] - 250 lR_i^rs[I,1,4] - 250 lR_i^rs[I,1,5]
       - 250 lR_i^rs[I,2,1] - 250 lR_i^rs[I,2,4] - 250 lR_i^rs[I,2,5]
       - 250 lR_i^rs[I,4,1] - 250 lR_i^rs[I,4,2] - 250 lR_i^rs[I,4,5]
       - 250 lR_i^rs[I,5,1] - 250 lR_i^rs[I,5,2] - 250 lR_i^rs[I,5,4]
       + 0 lR_i^rs[T,1,2] + 0 lR_i^rs[T,1,4] + 0 lR_i^rs[T,1,5]
       + 0 lR_i^rs[T,2,1] + 0 lR_i^rs[T,2,4] + 0 lR_i^rs[T,2,5]
       + 0 lR_i^rs[T,4,1] + 0 lR_i^rs[T,4,2] + 0 lR_i^rs[T,4,5]
       + 0 lR_i^rs[T,5,1] + 0 lR_i^rs[T,5,2] + 0 lR_i^rs[T,5,4]
       + 0 U_i^rs[T,1,2] + 0 U_i^rs[T,1,4] + 0 U_i^rs[T,1,5] + 0 U_i^rs[T,2,1]
       + 0 U_i^rs[T,2,4] + 0 U_i^rs[T,2,5] + 0 U_i^rs[T,4,1] + 0 U_i^rs[T,4,2]
       + 0 U_i^rs[T,4,5] + 0 U_i^rs[T,5,1] + 0 U_i^rs[T,5,2] + 0 U_i^rs[T,5,4]
       + 0 d_i^rs[T,1,2] + 0 d_i^rs[T,1,4] + 0 d_i^rs[T,1,5] + 0 d_i^rs[T,2,1]
       + 0 d_i^rs[T,2,4] + 0 d_i^rs[T,2,5] + 0 d_i^rs[T,4,1] + 0 d_i^rs[T,4,2]
       + 0 d_i^rs[T,4,5] + 0 d_i^rs[T,5,1] + 0 d_i^rs[T,5,2] + 0 d_i^rs[T,5,4]
       - lkf_a[1,2] - lkf_a[1,3] - lkf_a[2,1] - lkf_a[2,6] - lkf_a[3,1]
       - lkf_a[3,4] - lkf_a[3,12] - lkf_a[4,3] - lkf_a[4,5] - lkf_a[4,11]
       - lkf_a[5,4] - lkf_a[5,6] - lkf_a[5,9] - lkf_a[6,2] - lkf_a[6,5]
       - lkf_a[6,8] - lkf_a[7,8] - lkf_a[7,18] - lkf_a[8,6] - lkf_a[8,7]
       - lkf_a[8,9] - lkf_a[8,16] - lkf_a[9,5] - lkf_a[9,8] - lkf_a[9,10]
       - lkf_a[10,9] - lkf_a[10,11] - lkf_a[10,15] - lkf_a[10,16]
       - lkf_a[10,17] - lkf_a[11,4] - lkf_a[11,10] - lkf_a[11,12]
       - lkf_a[11,14] - lkf_a[12,3] - lkf_a[12,11] - lkf_a[12,13]
       - lkf_a[13,12] - lkf_a[13,24] - lkf_a[14,11] - lkf_a[14,15]
       - lkf_a[14,23] - lkf_a[15,10] - lkf_a[15,14] - lkf_a[15,19]
       - lkf_a[15,22] - lkf_a[16,8] - lkf_a[16,10] - lkf_a[16,17]
       - lkf_a[16,18] - lkf_a[17,10] - lkf_a[17,16] - lkf_a[17,19]
       - lkf_a[18,7] - lkf_a[18,16] - lkf_a[18,20] - lkf_a[19,15]
       - lkf_a[19,17] - lkf_a[19,20] - lkf_a[20,18] - lkf_a[20,19]
       - lkf_a[20,21] - lkf_a[20,22] - lkf_a[21,20] - lkf_a[21,22]
       - lkf_a[21,24] - lkf_a[22,15] - lkf_a[22,20] - lkf_a[22,21]
       - lkf_a[22,23] - lkf_a[23,14] - lkf_a[23,22] - lkf_a[23,24]
       - lkf_a[24,13] - lkf_a[24,21] - lkf_a[24,23] - lx_a[1,2] - lx_a[1,3]
       - lx_a[2,1] - lx_a[2,6] - lx_a[3,1] - lx_a[3,4] - lx_a[3,12] - lx_a[4,3]
       - lx_a[4,5] - lx_a[4,11] - lx_a[5,4] - lx_a[5,6] - lx_a[5,9] - lx_a[6,2]
       - lx_a[6,5] - lx_a[6,8] - lx_a[7,8] - lx_a[7,18] - lx_a[8,6] - lx_a[8,7]
       - lx_a[8,9] - lx_a[8,16] - lx_a[9,5] - lx_a[9,8] - lx_a[9,10]
       - lx_a[10,9] - lx_a[10,11] - lx_a[10,15] - lx_a[10,16] - lx_a[10,17]
       - lx_a[11,4] - lx_a[11,10] - lx_a[11,12] - lx_a[11,14] - lx_a[12,3]
       - lx_a[12,11] - lx_a[12,13] - lx_a[13,12] - lx_a[13,24] - lx_a[14,11]
       - lx_a[14,15] - lx_a[14,23] - lx_a[15,10] - lx_a[15,14] - lx_a[15,19]
       - lx_a[15,22] - lx_a[16,8] - lx_a[16,10] - lx_a[16,17] - lx_a[16,18]
       - lx_a[17,10] - lx_a[17,16] - lx_a[17,19] - lx_a[18,7] - lx_a[18,16]
       - lx_a[18,20] - lx_a[19,15] - lx_a[19,17] - lx_a[19,20] - lx_a[20,18]
       - lx_a[20,19] - lx_a[20,21] - lx_a[20,22] - lx_a[21,20] - lx_a[21,22]
       - lx_a[21,24] - lx_a[22,15] - lx_a[22,20] - lx_a[22,21] - lx_a[22,23]
       - lx_a[23,14] - lx_a[23,22] - lx_a[23,24] - lx_a[24,13] - lx_a[24,21]
       - lx_a[24,23] - 5925.6 Constant
    Subject To

     

     

     

     

    0
  • Silke Horn
    Gurobi Staff Gurobi Staff

    Yes, I assume the terms with the 0 coefficient at the beginning are there to preserve the variable order.

    But then Gurobi should repeat all with the non-zero coefficient, not just some. Is this the case? If so, then everything is working as expected.

    0
  • Iason Liagkas
    Gurobi-versary
    Detective
    Thought Leader

    Thanks Silke. 

    0

Please sign in to leave a comment.