and that seems to work.
However, now I get "gurobipy.GurobiError: Unable to retrieve attribute 'X' ". Which goes away when I take c4 out - but I get a useless calculation result.
from gurobipy import *
# Set calculation-loop lists
days = range(1,366)
speedlist = range(5,115,5)
# Repeat entire optimisation calculation for every increment of train operating
# speed = {5;10;15;...;110}
for i in speedlist:
v = i
print
print "--- --- --- --- ---"
print
print "For train operating speed set to", v, "km/h:"
print
print "--- --- --- --- ---"
print
# Set calculation values for each iteration of operating speed:
d = 117.70
t = d/v
# Create model
m = Model('Swazilink Optimisation')
# Define variables
n = m.addVar(vtype=GRB.INTEGER, name='Number of trains per day')
w = m.addVar(vtype=GRB.INTEGER, name='Number of wagons per train')
c = m.addVar(vtype=GRB.INTEGER, name='Number of containers per train')
l = m.addVar(vtype=GRB.CONTINUOUS, name='Load hauled per train')
# Update Gurobi variables
m.update()
# Define objective function
obj = quicksum(QuadExpr(n*l*v)
for i in days)
yearly = quicksum(n*w
for j in days)
# Maximise minimise objective function
m.setObjective(obj, GRB.MINIMIZE)
# Set constraints
c1 = m.addConstr(w, GRB.LESS_EQUAL, 50)
c2 = m.addConstr(c, GRB.EQUAL, 2*w)
c3 = m.addConstr(l, GRB.EQUAL, w)
c4 = m.addConstr(l == 16.0373*w + 31.9586)
c5 = m.addConstr(n*w, GRB.GREATER_EQUAL, 1305)
c6 = m.addConstr(yearly, GRB.GREATER_EQUAL, 476463)
c7 = m.addConstr(w, GRB.GREATER_EQUAL, 0)
c8 = m.addConstr(c, GRB.GREATER_EQUAL, 0)
# Run model optimization
m.optimize()
# Print attributes
m.printAttr('obj')
m.printAttr('X')