]>
gitweb.michael.orlitzky.com - dead/census-tools.git/blob - trials-uniform-medium
dfe9864195c0ee9db01f5e451ec272ece7ae446d
4 Perform a series of trials given uniform distributions for the cost
5 coefficients. Output the number of times each solution winds up being
14 # Basically, add '../src' to our path.
15 # Needed for the imports that follow.
16 site
.addsitedir(os
.path
.dirname(os
.path
.abspath(sys
.argv
[0])) + '/../../src')
18 import LinearProgramming
19 import probability
.Distribution
21 # How many linear programs will we solve?
25 lp
= LinearProgramming
.LinearProgram()
27 # We will say that the cost coefficients have the following means:
36 dist1
= probability
.Distribution
.Uniform(0, 10)
37 dist2
= probability
.Distribution
.Uniform(25, 175)
38 dist3
= probability
.Distribution
.Uniform(10, 50)
39 dist4
= probability
.Distribution
.Uniform(0, 20)
40 dist5
= probability
.Distribution
.Uniform(5, 35)
41 dist6
= probability
.Distribution
.Uniform(50, 550)
43 # We'll store all of the solution vectors and the number of times
44 # that they have occurred in this hash.
47 for idx
in range(0, NUM_TRIALS
):
55 lp
.objective_coefficients
= [c1
, c2
, c3
, c4
, c5
, c6
]
57 lp
.constraint_matrix
= [ [1,1,1,0,0,0],
63 lp
.inequalities
= ([LinearProgramming
.LE
] * 2) + ([LinearProgramming
.EQ
] * 3)
65 lp
.rhs
= [ 500, 600, 400, 300, 200 ]
67 [v
,x
,duals
] = lp
.solve()
69 # Implementation detail: lists can't serve as the key in a hash,
70 # so we just use the string representation of x.
71 solution_string
= str(x
)
73 if solution_string
in solutions
:
74 solutions
[solution_string
] += 1
76 solutions
[solution_string
] = 1
79 print "Solution Vector : Count"
80 print "-----------------------"
82 for (key
, value
) in solutions
.iteritems():