source: coopr.pyomo/stable/2.3/coopr/pyomo/tests/examples/pmedian.py @ 2388

Last change on this file since 2388 was 2388, checked in by wehart, 11 years ago

Merged revisions 2360-2387 via svnmerge from
https://software.sandia.gov/svn/public/coopr/coopr.pyomo/trunk

........

r2369 | wehart | 2010-02-17 18:11:43 -0700 (Wed, 17 Feb 2010) | 2 lines


Adding functionality for ordered sets.

........

r2378 | wehart | 2010-02-19 15:17:49 -0700 (Fri, 19 Feb 2010) | 2 lines


Specifying the symbols that are exported from convert.py

........

r2379 | wehart | 2010-02-19 15:31:35 -0700 (Fri, 19 Feb 2010) | 5 lines


Resolving a weakness in the pmedian.py data declaration. The facility
'd' data was monotonically increasing for every facility, so only one sensor placement
was important. The current model eliminates this, which should make the results portable
to other solvers.

........

r2381 | wehart | 2010-02-19 15:50:11 -0700 (Fri, 19 Feb 2010) | 2 lines


Misc baseline updates.

........

r2385 | wehart | 2010-02-21 23:14:18 -0700 (Sun, 21 Feb 2010) | 3 lines


Adding a work-around when importing 'bidict' fails. This occurs with
Python 2.5 and earlier.

........

r2387 | wehart | 2010-02-21 23:27:44 -0700 (Sun, 21 Feb 2010) | 3 lines


Bug fix: needed to protect the use of ordered_dict_inv with
the using_bidict flag.

........

File size: 1.1 KB
Line 
1
2from coopr.pyomo import *
3import math
4
5model = Model()
6
7model.N = Param(within=PositiveIntegers)
8
9model.Locations = RangeSet(1,model.N)
10
11model.P = Param(within=RangeSet(1,model.N))
12
13model.M = Param(within=PositiveIntegers)
14
15model.Customers = RangeSet(1,model.M)
16
17def d_rule(n, m, model):
18    return math.sin(n*2.33333+m*7.99999)
19model.d = Param(model.Locations, model.Customers, rule=d_rule, within=Reals)
20
21model.x = Var(model.Locations, model.Customers, bounds=(0.0,1.0))
22
23model.y = Var(model.Locations, within=Binary)
24
25def rule(model):
26    return sum( [model.d[n,m]*model.x[n,m] for n in model.Locations for m in model.Customers] )
27model.obj = Objective(rule=rule)
28
29def rule(m, model):
30    return (sum( [model.x[n,m] for n in model.Locations]), 1.0)
31model.single_x = Constraint(model.Customers, rule=rule)
32
33def rule(n,m,model):
34    return (None, model.x[n,m] - model.y[n], 0.0)
35model.bound_y = Constraint(model.Locations, model.Customers, rule=rule)
36
37def rule(model):
38    return (sum( [model.y[n] for n in model.Locations] ) - model.P, 0.0)
39model.num_facilities = Constraint(rule=rule)
40
Note: See TracBrowser for help on using the repository browser.