]> gitweb.michael.orlitzky.com - dead/census-tools.git/commitdiff
Update example-lp to use the LinearProgram class.
authorMichael Orlitzky <michael@orlitzky.com>
Mon, 19 Apr 2010 04:56:35 +0000 (00:56 -0400)
committerMichael Orlitzky <michael@orlitzky.com>
Mon, 19 Apr 2010 04:56:35 +0000 (00:56 -0400)
bin/example-lp

index 210a055842db05bd646d49dd7eed86ffb9846e66..25b04539dfa3370b25e4846694bff87b3d35c2bf 100755 (executable)
@@ -8,25 +8,28 @@ import os
 import site
 import sys
 
-# Add LP_SOLVE_PATH to our path.
-LP_SOLVE_PATH = '../lib/lp_solve'
-site.addsitedir(os.path.dirname(os.path.abspath(sys.argv[0])) + '/' + LP_SOLVE_PATH)
+# Basically, add '../src' to our path.
+# Needed for the imports that follow.
+site.addsitedir(os.path.dirname(os.path.abspath(sys.argv[0])) + '/../src')
 
-from lp_solve import *
+import LinearProgramming
 
-c = [5, 100, 30, 10, 20, 300]
 
-A = [ [1,1,1,0,0,0],
-      [0,0,0,1,1,1],
-      [1,0,0,1,0,0],
-      [0,1,0,0,1,0],
-      [0,0,1,0,0,1] ]
+lp = LinearProgramming.LinearProgram()
 
-e = [ -1, -1, 0, 0, 0 ]
+lp.objective_function_coefficients = [5, 100, 30, 10, 20, 300]
 
-b = [ 500, 600, 400, 300, 200 ]
+lp.constraint_matrix = [ [1,1,1,0,0,0],
+                         [0,0,0,1,1,1],
+                         [1,0,0,1,0,0],
+                         [0,1,0,0,1,0],
+                         [0,0,1,0,0,1] ]
 
-[v,x,duals] = lp_solve(c,A,b,e)
+lp.inequalities = ([LinearProgramming.LEQ] * 2) + ([LinearProgramming.EQ] * 3)
+
+lp.rhs = [ 500, 600, 400, 300, 200 ]
+
+[v,x,duals] = lp.solve()
 
 print 'Optimal objective function value: ', v
 print 'Optimal solution vector: ', x