source: coopr.pyomo/trunk/examples/pyomo/concrete/knapsack-concrete.py @ 3215

Last change on this file since 3215 was 3215, checked in by wehart, 10 years ago

Adding a simple knapsack example to illustrate the difference between
a concrete and abstract model.

File size: 367 bytes
Line 
1#
2# Knapsack Problem
3#
4
5from coopr.pyomo import *
6
7v = [8, 11, 6, 4]
8w = [5, 7, 4, 3]
9limit = 14
10
11model = ConcreteModel()
12
13model.items = RangeSet(0,3)
14
15model.x = Var(model.items, within=Binary)
16
17model.value = Objective(expr=sum(v[i]*model.x[i] for i in model.items), sense=maximize)
18
19model.weight = Constraint(expr=sum(w[i]*model.x[i] for i in model.items) <= limit)
Note: See TracBrowser for help on using the repository browser.