'cplex changes the fixed variable after solving the problem in pyomo

I am trying to solve a MIP, I use pyomo, and Cplex(Interactive Optimizer 20.1.0.0) is solver. The problem is that I want to fix some binary integer variables then solve the problem, and I used:

model.y[1,4].fix(1)
model.y[2,3].fix(0)

, but I have noticed that after solving the problem those fixed variables have changed to another values. How can I say cplex to not change that fixed variables?



Solution 1:[1]

let me use the bus example for fixed start with pyomo

import pyomo.environ as pyo
from pyomo.opt import SolverFactory

opt = pyo.SolverFactory("cplex")

model = pyo.ConcreteModel()

model.nbBus = pyo.Var([40,30], domain=pyo.PositiveIntegers)

#fixed start

model.nbBus[40].fix(3)

# end of fixed start

model.OBJ = pyo.Objective(expr = 500*model.nbBus[40] + 400*model.nbBus[30])

model.Constraint1 = pyo.Constraint(expr = 40*model.nbBus[40] + 30*model.nbBus[30] >= 300)

results = opt.solve(model)

print("nbBus40=",int(model.nbBus[40].value))
print("nbBus30=",int(model.nbBus[30].value))

gives

nbBus40= 3
nbBus30= 6

whereas if you remove the fixed start you get

nbBus40= 6
nbBus30= 2

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Alex Fleischer