]> gitweb.michael.orlitzky.com - dead/census-tools.git/commitdiff
Add the example linear programming problem solution via lp_solve.
authorMichael Orlitzky <michael@orlitzky.com>
Mon, 5 Apr 2010 19:26:17 +0000 (15:26 -0400)
committerMichael Orlitzky <michael@orlitzky.com>
Mon, 5 Apr 2010 19:26:17 +0000 (15:26 -0400)
bin/example-lp [new file with mode: 0755]

diff --git a/bin/example-lp b/bin/example-lp
new file mode 100755 (executable)
index 0000000..210a055
--- /dev/null
@@ -0,0 +1,33 @@
+#!/usr/bin/env python
+
+"""
+Solve an example problem with lp_solve.
+"""
+
+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)
+
+from lp_solve import *
+
+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] ]
+
+e = [ -1, -1, 0, 0, 0 ]
+
+b = [ 500, 600, 400, 300, 200 ]
+
+[v,x,duals] = lp_solve(c,A,b,e)
+
+print 'Optimal objective function value: ', v
+print 'Optimal solution vector: ', x
+print 'Duals: ', duals