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  

3  from coopr.pyomo import * 

4  

5  def compute_breakpoints(m, i): 

6  return [0] 

7  

8  def compute_slopes(m, i): 

9  return [1, 1] 

10  

11  model = AbstractModel() 

12  

13  model.Index = Set(initialize=[1, 2]) 

14  

15  model.X = Var(model.Index) 

16  

17  model.Z = Piecewise(model.Index, 

18  breakpoint_rule=compute_breakpoints, 

19  slope_rule=compute_slopes, 

20  offset=2, 

21  value=model.X) 

22  

23  def objective_rule(model): 

24  return sum([model.Z[i] for i in model.Index]) 

25  

26  model.obj = Objective(rule = objective_rule, sense=minimize) 

Note: See
TracBrowser
for help on using the repository browser.