Skip to main content

Fixing all variables results in a better objective than fixing only some variables

Awaiting user input

Comments

3 comments

  • Riley Clement
    Gurobi Staff Gurobi Staff

    Hi Matthew,

    It doesn't look like all your variables are fixed as you suggest:

    >> import gurobipy as gp
    >> m = gp.read("maryfal_allfixed.mps")
    >> fixed = [v.lb == v.ub for v in m.getVars()]
    >> print(f"fixed {sum(fixed)}/{len(fixed)}")
    fixed 597383/634494

    It also appears that there are variables fixed in maryfal_somefixed.mps that are not fixed in maryfal_allfixed.mps

    >> m2 = gp.read("maryfal_somefixed.mps")
    >> also_fixed = [
    m.getVarByName(v.VarName).lb == m.getVarByName(v.VarName).ub
    for v in m2.getVars()
    if v.lb == v.ub
    ]
    >>> print(f"also fixed {sum(also_fixed)}/{len(also_fixed)}")
    also fixed 495655/512447

    If the feasible region of one model is a superset of the other then it should accept a solution that is produced by the more constrained model.

    If I run the following

    >> m.optimize()
    >> m2.setAttr("Start", m2.getVars(), m.X)
    >> m2.optimize()

    Then the log complains that "User MIP start violates constraint c117566 by 1.000000000"

    The evidence is pointing to the situation being different to what you're expecting.

    - Riley

     

    0
  • Matthew Davison
    Gurobi-versary
    First Question
    First Comment

    Hi Riley Clement,

    Thank you for the response. 

    For your first comment, I am aware that not every variable is fixed (apologies for not being fully clear on this) but the remaining variables should be determined by what is fixed.

    For your second comment, this surprised me as there should be overlap. For example, every variable that is fixed in m2 should be fixed in m1. Is there some naming issue when I output to .mps format using the "write" function of a model?

    In any case, I think there is an issue with my constraints and model building that I have spotted. I'm happy for this issue to be closed but thank you for the help. (The code snippets helped me spot my error)

    0
  • Riley Clement
    Gurobi Staff Gurobi Staff

    Hi Matthew,

    If you're using a Gurobi API and the variables are being created in the same order then I'd expect the names to be the same.

    When I look at the result of m.getObjective() and m2.getObjective() the resulting linear expressions look the same which is good evidence to suggest the names of the variables are the same.

    - Riley

    0

Please sign in to leave a comment.