Results

Results

Once we've added the model constraints, we call optimize and then output the optimal solution:

if m.status == GRB.Status.OPTIMAL:
  for h in commodities:
    print '\nOptimal flows for', h, ':'
    for i,j in arcs:
      if flow[h,i,j].x > 0:
        print i, '->', j, ':', flow[h,i,j].x

If you run the example (gurobi.bat netflow.py on Windows, or gurobi.sh netflow.py on Linux and Mac), you should see the following output:

Optimize a model with 16 rows, 12 columns and 36 nonzeros
Presolve removed 16 rows and 12 columns
Presolve time: 0.00s
Presolve: All rows and columns removed
Iteration    Objective       Primal Inf.    Dual Inf.      Time
       0    5.5000000e+03   0.000000e+00   0.000000e+00      0s

Solved in 0 iterations and 0.00 seconds
Optimal objective  5.500000000e+03

Optimal flows for Pencils :
Detroit -> Boston : 50.0
Denver -> New York : 50.0
Denver -> Seattle : 10.0

Optimal flows for Pens :
Detroit -> Boston : 30.0
Detroit -> New York : 30.0
Denver -> Boston : 10.0
Denver -> Seattle : 30.0