Simple model modification

Simple model modification

We will now demonstrate a simple model modification. Imagine that you only want to consider solutions where you make at least 10 pennies (i.e., where the Pennies variable has a lower bound of 10.0). This is done by setting the lb attribute on the appropriate variable (the first variable in the list v in our example)...

gurobi> v = m.getVars()
gurobi> v[0].lb = 10

The Gurobi optimizer keeps track of the state of the model, so it knows that the currently loaded solution is not necessarily optimal for the modified model. When you invoke the optimize() method again, it performs a new optimization on the modified model...

gurobi> m.optimize()
Optimize a model with 4 rows, 9 columns and 16 nonzeros
Presolve removed 2 rows and 5 columns
Presolve time: 0.00s
Presolved: 2 rows, 4 columns, 5 nonzeros

MIP start did not produce a feasible solution

Variable types: 0 continuous, 4 integer (0 binary)
Found heuristic solution: objective 25.9500000

Root relaxation: objective 7.190000e+01, 2 iterations, 0.00 seconds

    Nodes    |    Current Node    |     Objective Bounds      |     Work
 Expl Unexpl |  Obj  Depth IntInf | Incumbent    BestBd   Gap | It/Node Time

*    0     0               0      71.9000000   71.90000   0.0%     -    0s

Explored 0 nodes (2 simplex iterations) in 0.00 seconds
Thread count was 4 (of 4 available processors)

Optimal solution found (tolerance 1.00e-04)
Best objective 7.190000000000e+01, best bound 7.190000000000e+01, gap 0.0%

The result shows that, if you force the solution to include at least 10 pennies, the maximum possible objective value for the model decreases from 113.45 to 71.9. A simple check confirms that the new lower bound is respected:

gurobi> print v[0].x