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

MIP Hint files empty

回答済み

コメント

3件のコメント

  • Eli Towle
    Gurobi Staff Gurobi Staff

    An HNT file is used to store variable hint values and variable hint priorities. Variable hints are different from solution vectors and MIP starts. The article What are the differences between MIP Starts and Variable Hints? explains this difference in more detail.

    The HNT file won't contain any variable hint information unless you explicitly add hint values/priorities to your variables:

    import gurobipy as gp
    from gurobipy import GRB

    model = gp.Model()

    x = model.addVar(vtype=GRB.INTEGER, name="x")
    y = model.addVar(vtype=GRB.CONTINUOUS, name="y")

    x.VarHintVal = 6
    x.VarHintPri = 1

    y.VarHintVal = 0
    y.VarHintPri = 1

    model.write("model.hnt")

    # model.hnt contents:
    """
    # MIP variable hints
    x 6 1
    y 0 1
    """

    Is your goal is to create a file that can later be used to import a MIP start? If so, you should use a SOL file or MST file.

    1
  • Elias Zauscher
    First Comment
    First Question

    Thanks for the quick response. I am iteratively using the MIP model I've built and changing some values each time. Rather than having the MIP need to work up to a similar solution as the previous iteration I want to guide it to roughly the same place. When using MST I get this line: 

    User MIP start did not produce a new incumbent solution
    

    From the article you sent it says "MIP Starts are used to generate an initial feasible solution"

    If the MST start does not provide an incumbent solution are the values still used to start?

    If they do, then I will keep using MST. If they don't is there a way to save all variables values to a hint file after running my MIP using a simple command? I can also iterate through all of them if needed.

    0
  • Eli Towle
    Gurobi Staff Gurobi Staff

    If the MST start does not provide an incumbent solution are the values still used to start?

    No. However, if the MIP start does not produce an initial feasible solution, Gurobi might later try to repair the MIP start into a feasible solution.

    If they don't is there a way to save all variables values to a hint file after running my MIP using a simple command?

    After optimizing, you can set the variables' VarHintVal attributes equal to the solution values and the VarHintPri attributes equal to a positive value. Then, save the hint file:

    for v in model.getVars():
    v.VarHintVal = v.X
    v.VarHintPri = 1
    model.write("model.hnt")

    If you're modifying and re-solving the same Model object in each iteration, you wouldn't even need to write/read the hint files - setting the VarHintVal and VarHintPri variable attributes is sufficient.

    1

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