The next step in our example (after creating an empty
Model object) is to add decision variables to the model. The variables are created using
addVars, and are returned in a
tupledict which we'll call
# Create optimization model m = gp.Model('netflow') # Create variables flow = m.addVars(commodities, arcs, obj=cost, name="flow")
The first, positional arguments to
addVars give the index set. In this case, we'll be indexing
arcs. In other words,
flow[c,i,j] will capture the flow of commodity
c from node
i to node
j. Note that
flow only contains variables for source, destination pairs that are present in
arcs. Note also that
flow[c,i,j] is a continuous decision variable; variables are assumed to be continuous unless you state otherwise.
Please sign in to leave a comment.