source: coopr.pyomo/trunk/examples/pyomo/piecewise/example6.py @ 4155

Revision 4155, 672 bytes checked in by wehart, 3 years ago (diff)

Updating examples to reorder rule arguments to put the model first.

Line 
1# an example of an indexed piecewise function, i.e., a set of piecewise functions, each identified by a unique index.
2
3from coopr.pyomo import *
4
5def compute_breakpoints(m, i):
6    return [0]
7
8def compute_slopes(m, i):
9    return [-1, 1]
10
11model = AbstractModel()
12
13model.Index = Set(initialize=[1, 2])
14
15model.X = Var(model.Index)
16
17model.Z = Piecewise(model.Index,
18                    breakpoint_rule=compute_breakpoints,
19                    slope_rule=compute_slopes,
20                    offset=2,
21                    value=model.X)
22
23def objective_rule(model):
24    return sum([model.Z[i] for i in model.Index])
25
26model.obj = Objective(rule = objective_rule, sense=minimize)
Note: See TracBrowser for help on using the repository browser.