diff options
Diffstat (limited to 'packages/glpk/examples')
-rw-r--r-- | packages/glpk/examples/simplex2.hs | 5 | ||||
-rw-r--r-- | packages/glpk/examples/simplex5.hs | 27 |
2 files changed, 32 insertions, 0 deletions
diff --git a/packages/glpk/examples/simplex2.hs b/packages/glpk/examples/simplex2.hs index e9e8859..0d83ca9 100644 --- a/packages/glpk/examples/simplex2.hs +++ b/packages/glpk/examples/simplex2.hs | |||
@@ -10,9 +10,14 @@ constr2 = Dense [ [2,1,0] :<=: 10 | |||
10 | , [0,1,5] :<=: 20 | 10 | , [0,1,5] :<=: 20 |
11 | ] | 11 | ] |
12 | 12 | ||
13 | constr3 = General [ [1#1, 1#1, 1#2] :<=: 10 | ||
14 | , [1#2, 5#3] :<=: 20 | ||
15 | ] | ||
16 | |||
13 | main = do | 17 | main = do |
14 | print $ simplex prob constr1 [] | 18 | print $ simplex prob constr1 [] |
15 | print $ simplex prob constr2 [] | 19 | print $ simplex prob constr2 [] |
20 | print $ simplex prob constr3 [] | ||
16 | print $ simplex prob constr2 [ 2 :>=: 1, 3 :&: (2,7)] | 21 | print $ simplex prob constr2 [ 2 :>=: 1, 3 :&: (2,7)] |
17 | print $ simplex prob constr2 [ Free 2 ] | 22 | print $ simplex prob constr2 [ Free 2 ] |
18 | 23 | ||
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 @@ | |||
1 | import Numeric.LinearProgramming | ||
2 | |||
3 | -- This is a linear program from the paper "Picking vs. Guessing Secrets: A Game-theoretic Analysis" | ||
4 | |||
5 | gamma = 100000 :: Double | ||
6 | sigma = 1 :: Double | ||
7 | n = 64 :: Int | ||
8 | cost_fun :: Int -> Double | ||
9 | cost_fun i = (fromIntegral i) / (fromIntegral n) | ||
10 | size_fun :: Int -> Double | ||
11 | size_fun i = 2^(fromIntegral i) | ||
12 | |||
13 | prob = Minimize $ map cost_fun [1..n] | ||
14 | bnds = [i :&: (0,1) | i <- [1..n]] | ||
15 | |||
16 | constr1 = [[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 | |||
25 | main = do | ||
26 | print $ simplex prob (General constr1) bnds -- NoFeasible | ||
27 | print $ exact prob (General constr1) bnds -- solution found | ||