summaryrefslogtreecommitdiff
path: root/packages
diff options
context:
space:
mode:
authorPiotr Mardziel <piotrm@gmail.com>2015-02-23 17:40:31 -0500
committerPiotr Mardziel <piotrm@gmail.com>2015-02-23 17:40:31 -0500
commit012144b1e6ce75515bf3eea5dd2f0f4ddd0d3cae (patch)
tree22dc2b04f1f7d8a495ff514fc864fbb4726e8a4a /packages
parente57907c22e8a16d2a9b62b70dd04ffcfd0d96b6a (diff)
added support for glp_exact
Diffstat (limited to 'packages')
-rw-r--r--packages/glpk/examples/simplex5.hs27
1 files changed, 27 insertions, 0 deletions
diff --git a/packages/glpk/examples/simplex5.hs b/packages/glpk/examples/simplex5.hs
new file mode 100644
index 0000000..ecbcdaa
--- /dev/null
+++ b/packages/glpk/examples/simplex5.hs
@@ -0,0 +1,27 @@
1import Numeric.LinearProgramming
2
3-- This is a linear program from the paper "Picking vs. Guessing Secrets: A Game-theoretic Analysis"
4
5gamma = 100000 :: Double
6sigma = 1 :: Double
7n = 64 :: Int
8cost_fun :: Int -> Double
9cost_fun i = (fromIntegral i) / (fromIntegral n)
10size_fun :: Int -> Double
11size_fun i = 2^(fromIntegral i)
12
13prob = Minimize $ map cost_fun [1..n]
14bnds = [i :&: (0,1) | i <- [1..n]]
15
16constr1 = [[1 # i | i <- [1..n]] :==: 1] ++
17 [[1/(size_fun i) # i,
18 -1/(size_fun (i+1)) # i+1] :>=: 0 | i <- [1..n-1]] ++
19 [(
20 [gamma#i | i <- [1..k]] ++
21 (concat [[sigma*(size_fun i) # j | j <- [1..i-1]] | i <- [1..k]]) ++
22 [((size_fun i) - 1)/2 # i | i <- [1..k]])
23 :<=: (sigma * (foldr (+) 0 (map size_fun [1..k]))) | k <- [1..n]]
24
25main = do
26 print $ simplex prob (General constr1) bnds -- NoFeasible
27 print $ exact prob (General constr1) bnds -- solution found