diff options
author | Alberto Ruiz <aruiz@um.es> | 2015-04-09 12:48:57 +0200 |
---|---|---|
committer | Alberto Ruiz <aruiz@um.es> | 2015-04-09 12:48:57 +0200 |
commit | c10f27ac40ff74612a6c773baa572573f3186506 (patch) | |
tree | efe9bf1b62e20c1163eed98753c4bef2afca6d06 /packages/glpk/examples | |
parent | 5eba1bc309d7845366e8d00849d85426bf8f666d (diff) | |
parent | 8d7c921bdff0d57a4579d3de71cd5ba3bf5276a1 (diff) |
merge recent changes
Diffstat (limited to 'packages/glpk/examples')
-rw-r--r-- | packages/glpk/examples/simplex1.hs | 6 | ||||
-rw-r--r-- | packages/glpk/examples/simplex2.hs | 7 | ||||
-rw-r--r-- | packages/glpk/examples/simplex3.hs | 2 | ||||
-rw-r--r-- | packages/glpk/examples/simplex4.hs | 2 | ||||
-rw-r--r-- | packages/glpk/examples/simplex5.hs | 27 |
5 files changed, 38 insertions, 6 deletions
diff --git a/packages/glpk/examples/simplex1.hs b/packages/glpk/examples/simplex1.hs index e7aeaa9..a326555 100644 --- a/packages/glpk/examples/simplex1.hs +++ b/packages/glpk/examples/simplex1.hs | |||
@@ -9,9 +9,9 @@ constr = Dense [ [1,1,1] :<=: 100 | |||
9 | , [2,2,6] :<=: 300 ] | 9 | , [2,2,6] :<=: 300 ] |
10 | 10 | ||
11 | -- default bounds | 11 | -- default bounds |
12 | bnds = [ 1 :=>: 0 | 12 | bnds = [ 1 :>=: 0 |
13 | , 2 :=>: 0 | 13 | , 2 :>=: 0 |
14 | , 3 :=>: 0 ] | 14 | , 3 :>=: 0 ] |
15 | 15 | ||
16 | main = do | 16 | main = do |
17 | print $ simplex objFun constr [] | 17 | print $ simplex objFun constr [] |
diff --git a/packages/glpk/examples/simplex2.hs b/packages/glpk/examples/simplex2.hs index f4e27fd..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 [] |
16 | print $ simplex prob constr2 [ 2 :=>: 1, 3 :&: (2,7)] | 20 | print $ simplex prob constr3 [] |
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/simplex3.hs b/packages/glpk/examples/simplex3.hs index e093124..0997320 100644 --- a/packages/glpk/examples/simplex3.hs +++ b/packages/glpk/examples/simplex3.hs | |||
@@ -11,7 +11,7 @@ constr = Dense | |||
11 | , [0.03, 0.05, 0.08, 0.02, 0.06, 0.01, 0] :<=: 100 | 11 | , [0.03, 0.05, 0.08, 0.02, 0.06, 0.01, 0] :<=: 100 |
12 | , [0.02, 0.04, 0.01, 0.02, 0.02, 0, 0] :<=: 40 | 12 | , [0.02, 0.04, 0.01, 0.02, 0.02, 0, 0] :<=: 40 |
13 | , [0.02, 0.03, 0, 0, 0.01, 0, 0] :<=: 30 | 13 | , [0.02, 0.03, 0, 0, 0.01, 0, 0] :<=: 30 |
14 | , [0.7, 0.75, 0.8, 0.75, 0.8, 0.97, 0] :=>: 1500 | 14 | , [0.7, 0.75, 0.8, 0.75, 0.8, 0.97, 0] :>=: 1500 |
15 | , [0.02, 0.06, 0.08, 0.12, 0.02, 0.01, 0.97] :&: (250,300) | 15 | , [0.02, 0.06, 0.08, 0.12, 0.02, 0.01, 0.97] :&: (250,300) |
16 | ] | 16 | ] |
17 | 17 | ||
diff --git a/packages/glpk/examples/simplex4.hs b/packages/glpk/examples/simplex4.hs index 9a205ad..22b131c 100644 --- a/packages/glpk/examples/simplex4.hs +++ b/packages/glpk/examples/simplex4.hs | |||
@@ -11,7 +11,7 @@ constr = Sparse | |||
11 | , [0.03#1, 0.05#2, 0.08#3, 0.02#4, 0.06#5, 0.01#6] :<=: 100 | 11 | , [0.03#1, 0.05#2, 0.08#3, 0.02#4, 0.06#5, 0.01#6] :<=: 100 |
12 | , [0.02#1, 0.04#2, 0.01#3, 0.02#4, 0.02#5] :<=: 40 | 12 | , [0.02#1, 0.04#2, 0.01#3, 0.02#4, 0.02#5] :<=: 40 |
13 | , [0.02#1, 0.03#2, 0.01#5] :<=: 30 | 13 | , [0.02#1, 0.03#2, 0.01#5] :<=: 30 |
14 | , [0.7#1, 0.75#2, 0.8#3, 0.75#4, 0.8#5, 0.97#6] :=>: 1500 | 14 | , [0.7#1, 0.75#2, 0.8#3, 0.75#4, 0.8#5, 0.97#6] :>=: 1500 |
15 | , [0.02#1, 0.06#2, 0.08#3, 0.12#4, 0.02#5, 0.01#6, 0.97#7] :&: (250,300) | 15 | , [0.02#1, 0.06#2, 0.08#3, 0.12#4, 0.02#5, 0.01#6, 0.97#7] :&: (250,300) |
16 | ] | 16 | ] |
17 | 17 | ||
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 | ||