This file is a slight modification of the basic "WYNDOR GLASS CO." example file which shows how to use indexed decision variables.

In [1]:
from pyomo.environ import *
from pyomo.opt import *
opt = solvers.SolverFactory("glpk")
In [2]:
model = ConcreteModel()

model.x = Var([1,2], within=NonNegativeReals)

model.c1 = Constraint(expr = model.x[1] <= 4)
model.c2 = Constraint(expr = 2*model.x[2] <= 12)
model.c3 = Constraint(expr = 3*model.x[1] + 2*model.x[2] <= 18)
model.z = Objective(expr = 3*model.x[1] + 5*model.x[2], sense=maximize)

results = opt.solve(model)
In [3]:
model.x.get_values()
Out[3]:
{1: 2.0, 2: 6.0}
In [4]:
model.z.expr()
Out[4]:
36.0