メインコンテンツへスキップ

Issue retrieving Unbounded Ray from Unbounded LP

回答済み

コメント

8件のコメント

  • Sam Garvin
    Conversationalist
    First Question

    Hi, 

    Yes, I was mistaken and that was the issue. Thanks for your patience and the help. 

    -Sam

    1
  • Simranjit Kaur
    Gurobi Staff Gurobi Staff

    Hi Sam,

    Please set the parameter InfUnbdInfo to 1 before solving the model. When a Gurobi model is unbounded, you need to ensure that the InfUnbdInfo parameter is set before the optimization process. This parameter enables the computation of the unbounded ray, which is required to access the UnbdRay attribute of a variable.

    price.setParam(GRB.Param.InfUnbdInfo, 1)
    price.optimize()

    if price.Status == 5:
    ...

    Best regards,
    Simran

    0
  • Sam Garvin
    Conversationalist
    First Question

    Hi Simran, 

    thanks for the quick reply. I made these changes and I'm still having the same issue. This is the code I'm running now:

    price.setParam(GRB.Param.InfUnbdInfo, 1)
    price.optimize()
    vars = price.getVars()
    new_point = np.array([])

    if price.Status == 5:
    for var in vars:
    new_point = np.append(new_point, var.UnbdRay)

    I'm still getting the same error output.

    Best, 

    Sam

    0
  • Simranjit Kaur
    Gurobi Staff Gurobi Staff

    Hi Sam,

    Could you please check that the parameter InfUnbdInfo is set correctly in your code?

    The following code works fine on my end. 

    import gurobipy as gp
    import numpy as np

    m=gp.Model()
    x = m.addVar()
    m.addConstr( x >= 10)
    m.setObjective(x, sense=gp.GRB.MAXIMIZE)

    m.setParam(gp.GRB.Param.InfUnbdInfo, 1)
    m.optimize()

    print("status", m.Status)
    new_point = np.array([])
    if m.Status == 5:
      for var in m.getVars():
          new_point = np.append(new_point, var.UnbdRay)
    print(new_point)
    Best regards,
    Simran
    0
  • Sam Garvin
    Conversationalist
    First Question

    Hi, calling 

    print(price.getParamInfo(GRB.Param.InfUnbdInfo))

    returns

    ('InfUnbdInfo', <class 'int'>, 1, 0, 1, 0), indicating that the parameter is indeed set to 1. When I run the code you replied with in a new project, it also runs with no errors. Still the same issue with the unbounded ray, however. 

    -Sam

    0
  • Simranjit Kaur
    Gurobi Staff Gurobi Staff

    Hi Sam,

    Could you please solve your model using a simplex algorithm (set the Method parameter 0 or 1)? 

    If a model is determined to be unbounded when solving with Barrier, prior to crossover, then the UnbdRay information will not be available.

    Best regards,
    Simran

    0
  • Sam Garvin
    Conversationalist
    First Question

    Hi, 

    I still get the same issue running

    price.setParam(GRB.Param.Method, 1)
    price.setParam(GRB.Param.InfUnbdInfo, 1)

    price.optimize()

    variables = price.getVars()

    new_point = np.array([])
    if price.Status == 5:
    print(price.getParamInfo(GRB.Param.InfUnbdInfo))
    print(price.getParamInfo(GRB.Param.Method))
    ...

    and the same if the parameter is set to 0. Is there anything else relating to the model or solve process which could cause the attribute to be inaccessible?

    0
  • Simranjit Kaur
    Gurobi Staff Gurobi Staff

    Hi Sam,

    Does your model have binary/integer variables or general constraints?

    Unbounded rays are only supported for continuous linear models with no integer variables.General constraints are reformulated using auxiliary binary variables and SOS constraints. Adding them to an otherwise continuous model will transform it into a MIP.

    For unbounded IP/MIP models, you can still the unbounded ray by first converting the model to an LP using model.relax(), solving this model, and then querying the unbounded ray. You may find this article helpful: How do I relax the integrality conditions in my model?

    import gurobipy as gp
    import numpy as np

    m = gp.Model()
    x = m.addVar(vtype=gp.GRB.INTEGER)
    m.addConstr( x >= 10)
    m.setObjective(x, sense=gp.GRB.MAXIMIZE)

    m.params.InfUnbdInfo = 1
    m.params.Method=1
    m.optimize()

    if m.Status == 5:
      relaxed_model = m.relax()
        relaxed_model.optimize()

      new_point = np.array([])
      for var in relaxed_model.getVars():
          new_point = np.append(new_point, var.UnbdRay)
        print(new_point)
    I hope this helps!
     
    Best regards,
    Simran
    0

サインインしてコメントを残してください。