Skip to main content

How to extract fractional solution from GUROBI ILP?

Answered

Comments

7 comments

  • Riley Clement
    Gurobi Staff Gurobi Staff

    Hi Tarun,

    Can you explain in detail what you mean by "solution and fractional values"?

    - Riley

    0
  • David Torres Sanchez
    Gurobi Staff Gurobi Staff

    Hi Tarun,

    The easiest way to get the relaxed solution is to use model.relax():

    with model.relax() as r:
    r.optimize()
    r.printAttr("X")

    Cheers, 
    David

    0
  • Tarun Suresh
    First Comment
    First Question

    Hey Riley, 

     

    By "fractional values and solution", I mean the .X that produced the Obj = 1351975.00 in the first row and the 70 "IntInf" values. I want to see which values are violating integer feasibility. Is it possible to do this? 

     0     0 1351975.00    0   70          - 1351975.00      -     -    1s

     

     

    I am trying to speed up the search by stopping it early even if some values are fractional. However, I don't want to relax all values. 

     

    0
  • Riley Clement
    Gurobi Staff Gurobi Staff

    Hi Tarun,

    This code could serve as the basis for what you want to do

    def cb(model, where):
        if where == gp.GRB.Callback.MIPNODE:
            # Found a new MIP incumbent
            if model.cbGet(gp.GRB.Callback.MIPNODE_STATUS) == gp.GRB.OPTIMAL:
                m._lp_x = model.cbGetNodeRel(model._vars)
        if where == gp.GRB.Callback.MESSAGE:
            if m._lp_x:
                print(m._lp_x)
                
    m = gp.Model()

    # build model

    m._vars = m.getVars()
    m._lp_x = 0

    m.optimize(cb)

    - Riley

    0
  • Tarun Suresh
    First Comment
    First Question

    So it is not possible to get the information at each row? Is it possible to see which constraints are producing the "IntInf"?

    Additionally, are there any other parameters and callbacks I should consider to speedup the search based on the above results?

    This is the current combination I am using: 

    Set parameter Heuristics to value 0
    Set parameter Presolve to value 0
    Set parameter Method to value 1
    Set parameter SolutionLimit to value 1

     

    0
  • Tarun Suresh
    First Comment
    First Question

    Hey David, 

     

    Is it possible to get 

    r.printAttr("X")

    in list or array format? I have two matrix variables "x" and "y". I want to get the nonzero values for "x" and "y" in two separate lists. 

     

     

     

    0
  • Riley Clement
    Gurobi Staff Gurobi Staff

    Hi Tarun,

    Sorry, I misunderstood what you were wanting to do.  Can you take a look at the updated code in my answer above?

    - Riley

    0

Please sign in to leave a comment.