diff options
Diffstat (limited to 'packages/glpk')
-rw-r--r-- | packages/glpk/examples/simplex1.hs | 14 | ||||
-rw-r--r-- | packages/glpk/examples/simplex2.hs | 10 | ||||
-rw-r--r-- | packages/glpk/examples/simplex3.hs | 10 | ||||
-rw-r--r-- | packages/glpk/examples/simplex4.hs | 10 | ||||
-rw-r--r-- | packages/glpk/hmatrix-glpk.cabal | 4 | ||||
-rw-r--r-- | packages/glpk/lib/Numeric/LinearProgramming.hs | 34 |
6 files changed, 41 insertions, 41 deletions
diff --git a/packages/glpk/examples/simplex1.hs b/packages/glpk/examples/simplex1.hs index ec72bdc..e7aeaa9 100644 --- a/packages/glpk/examples/simplex1.hs +++ b/packages/glpk/examples/simplex1.hs | |||
@@ -4,17 +4,17 @@ import Numeric.LinearProgramming | |||
4 | 4 | ||
5 | objFun = Maximize [10, 6, 4] | 5 | objFun = Maximize [10, 6, 4] |
6 | 6 | ||
7 | constr = Dense [ [1,1,1] :<: 100 | 7 | constr = Dense [ [1,1,1] :<=: 100 |
8 | , [10,4,5] :<: 600 | 8 | , [10,4,5] :<=: 600 |
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 [] |
18 | print $ simplex objFun constr bnds | 18 | print $ simplex objFun constr bnds |
19 | print $ simplex objFun constr [Free 3] | 19 | print $ simplex objFun constr [Free 3] |
20 | print $ simplex objFun constr [ 2 :<: 50 ] | 20 | print $ simplex objFun constr [ 2 :<=: 50 ] |
diff --git a/packages/glpk/examples/simplex2.hs b/packages/glpk/examples/simplex2.hs index 0b865a6..f4e27fd 100644 --- a/packages/glpk/examples/simplex2.hs +++ b/packages/glpk/examples/simplex2.hs | |||
@@ -2,17 +2,17 @@ import Numeric.LinearProgramming | |||
2 | 2 | ||
3 | prob = Maximize [4, -3, 2] | 3 | prob = Maximize [4, -3, 2] |
4 | 4 | ||
5 | constr1 = Sparse [ [2#1, 1#2] :<: 10 | 5 | constr1 = Sparse [ [2#1, 1#2] :<=: 10 |
6 | , [1#2, 5#3] :<: 20 | 6 | , [1#2, 5#3] :<=: 20 |
7 | ] | 7 | ] |
8 | 8 | ||
9 | constr2 = Dense [ [2,1,0] :<: 10 | 9 | constr2 = Dense [ [2,1,0] :<=: 10 |
10 | , [0,1,5] :<: 20 | 10 | , [0,1,5] :<=: 20 |
11 | ] | 11 | ] |
12 | 12 | ||
13 | main = do | 13 | main = do |
14 | print $ simplex prob constr1 [] | 14 | print $ simplex prob constr1 [] |
15 | print $ simplex prob constr2 [] | 15 | print $ simplex prob constr2 [] |
16 | print $ simplex prob constr2 [ 2 :>: 1, 3 :&: (2,7)] | 16 | print $ simplex prob constr2 [ 2 :=>: 1, 3 :&: (2,7)] |
17 | print $ simplex prob constr2 [ Free 2 ] | 17 | print $ simplex prob constr2 [ Free 2 ] |
18 | 18 | ||
diff --git a/packages/glpk/examples/simplex3.hs b/packages/glpk/examples/simplex3.hs index 1df6b28..e093124 100644 --- a/packages/glpk/examples/simplex3.hs +++ b/packages/glpk/examples/simplex3.hs | |||
@@ -7,11 +7,11 @@ prob = Minimize [0.03, 0.08, 0.17, 0.12, 0.15, 0.21, 0.38] | |||
7 | 7 | ||
8 | constr = Dense | 8 | constr = Dense |
9 | [ [1,1,1,1,1,1,1] :==: 2000 | 9 | [ [1,1,1,1,1,1,1] :==: 2000 |
10 | , [0.15, 0.04, 0.02, 0.04, 0.2,0.01, 0.03] :<: 60 | 10 | , [0.15, 0.04, 0.02, 0.04, 0.2,0.01, 0.03] :<=: 60 |
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 dd65002..9a205ad 100644 --- a/packages/glpk/examples/simplex4.hs +++ b/packages/glpk/examples/simplex4.hs | |||
@@ -7,11 +7,11 @@ prob = Minimize [0.03, 0.08, 0.17, 0.12, 0.15, 0.21, 0.38] | |||
7 | 7 | ||
8 | constr = Sparse | 8 | constr = Sparse |
9 | [ [1#1,1#2,1#3,1#4,1#5,1#6,1#7] :==: 2000 | 9 | [ [1#1,1#2,1#3,1#4,1#5,1#6,1#7] :==: 2000 |
10 | , [0.15#1, 0.04#2, 0.02#3, 0.04#4, 0.2#5,0.01#6, 0.03#7] :<: 60 | 10 | , [0.15#1, 0.04#2, 0.02#3, 0.04#4, 0.2#5,0.01#6, 0.03#7] :<=: 60 |
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/hmatrix-glpk.cabal b/packages/glpk/hmatrix-glpk.cabal index b7f0db4..d251eca 100644 --- a/packages/glpk/hmatrix-glpk.cabal +++ b/packages/glpk/hmatrix-glpk.cabal | |||
@@ -1,5 +1,5 @@ | |||
1 | Name: hmatrix-glpk | 1 | Name: hmatrix-glpk |
2 | Version: 0.1.0 | 2 | Version: 0.2.0 |
3 | License: GPL | 3 | License: GPL |
4 | License-file: LICENSE | 4 | License-file: LICENSE |
5 | Author: Alberto Ruiz | 5 | Author: Alberto Ruiz |
@@ -22,7 +22,7 @@ extra-source-files: examples/simplex1.hs | |||
22 | examples/simplex4.hs | 22 | examples/simplex4.hs |
23 | 23 | ||
24 | library | 24 | library |
25 | Build-Depends: base >= 3 && < 5, hmatrix >= 0.8.3 && < 0.9 | 25 | Build-Depends: base >= 3 && < 5, hmatrix >= 0.8.3 && < 0.10 |
26 | 26 | ||
27 | hs-source-dirs: lib | 27 | hs-source-dirs: lib |
28 | 28 | ||
diff --git a/packages/glpk/lib/Numeric/LinearProgramming.hs b/packages/glpk/lib/Numeric/LinearProgramming.hs index 78f55a2..f0709c3 100644 --- a/packages/glpk/lib/Numeric/LinearProgramming.hs +++ b/packages/glpk/lib/Numeric/LinearProgramming.hs | |||
@@ -28,8 +28,8 @@ can be solved as follows: | |||
28 | 28 | ||
29 | prob = Maximize [4, -3, 2] | 29 | prob = Maximize [4, -3, 2] |
30 | 30 | ||
31 | constr1 = Sparse [ [2\#1, 1\#2] :<: 10 | 31 | constr1 = Sparse [ [2\#1, 1\#2] :<=: 10 |
32 | , [1\#2, 5\#3] :<: 20 | 32 | , [1\#2, 5\#3] :<=: 20 |
33 | ] | 33 | ] |
34 | 34 | ||
35 | \> simplex prob constr1 [] | 35 | \> simplex prob constr1 [] |
@@ -37,14 +37,14 @@ Optimal (28.0,[5.0,0.0,4.0])@ | |||
37 | 37 | ||
38 | The coefficients of the constraint matrix can also be given in dense format: | 38 | The coefficients of the constraint matrix can also be given in dense format: |
39 | 39 | ||
40 | @constr2 = Dense [ [2,1,0] :<: 10 | 40 | @constr2 = Dense [ [2,1,0] :<=: 10 |
41 | , [0,1,5] :<: 20 | 41 | , [0,1,5] :<=: 20 |
42 | ]@ | 42 | ]@ |
43 | 43 | ||
44 | By default all variables are bounded as @x_i >= 0@, but this can be | 44 | By default all variables are bounded as @x_i >= 0@, but this can be |
45 | changed: | 45 | changed: |
46 | 46 | ||
47 | @\> simplex prob constr2 [ 2 :>: 1, 3 :&: (2,7)] | 47 | @\> simplex prob constr2 [ 2 :=>: 1, 3 :&: (2,7)] |
48 | Optimal (22.6,[4.5,1.0,3.8]) | 48 | Optimal (22.6,[4.5,1.0,3.8]) |
49 | 49 | ||
50 | \> simplex prob constr2 [Free 2] | 50 | \> simplex prob constr2 [Free 2] |
@@ -53,7 +53,7 @@ Unbounded@ | |||
53 | The given bound for a variable completely replaces the default, | 53 | The given bound for a variable completely replaces the default, |
54 | so @0 <= x_i <= b@ must be explicitly given as @i :&: (0,b)@. | 54 | so @0 <= x_i <= b@ must be explicitly given as @i :&: (0,b)@. |
55 | Multiple bounds for a variable are not allowed, instead of | 55 | Multiple bounds for a variable are not allowed, instead of |
56 | @[i :>: a, i:<: b]@ use @i :&: (a,b)@. | 56 | @[i :=>: a, i:<=: b]@ use @i :&: (a,b)@. |
57 | 57 | ||
58 | -} | 58 | -} |
59 | 59 | ||
@@ -84,8 +84,8 @@ import Data.Function(on) | |||
84 | infixl 5 # | 84 | infixl 5 # |
85 | (#) = (,) | 85 | (#) = (,) |
86 | 86 | ||
87 | data Bound x = x :<: Double | 87 | data Bound x = x :<=: Double |
88 | | x :>: Double | 88 | | x :=>: Double |
89 | | x :&: (Double,Double) | 89 | | x :&: (Double,Double) |
90 | | x :==: Double | 90 | | x :==: Double |
91 | | Free x | 91 | | Free x |
@@ -147,29 +147,29 @@ extract sg sol = r where | |||
147 | ----------------------------------------------------- | 147 | ----------------------------------------------------- |
148 | 148 | ||
149 | obj :: Bound t -> t | 149 | obj :: Bound t -> t |
150 | obj (x :<: _) = x | 150 | obj (x :<=: _) = x |
151 | obj (x :>: _) = x | 151 | obj (x :=>: _) = x |
152 | obj (x :&: _) = x | 152 | obj (x :&: _) = x |
153 | obj (x :==: _) = x | 153 | obj (x :==: _) = x |
154 | obj (Free x) = x | 154 | obj (Free x) = x |
155 | 155 | ||
156 | tb :: Bound t -> Double | 156 | tb :: Bound t -> Double |
157 | tb (_ :<: _) = glpUP | 157 | tb (_ :<=: _) = glpUP |
158 | tb (_ :>: _) = glpLO | 158 | tb (_ :=>: _) = glpLO |
159 | tb (_ :&: _) = glpDB | 159 | tb (_ :&: _) = glpDB |
160 | tb (_ :==: _) = glpFX | 160 | tb (_ :==: _) = glpFX |
161 | tb (Free _) = glpFR | 161 | tb (Free _) = glpFR |
162 | 162 | ||
163 | lb :: Bound t -> Double | 163 | lb :: Bound t -> Double |
164 | lb (_ :<: _) = 0 | 164 | lb (_ :<=: _) = 0 |
165 | lb (_ :>: a) = a | 165 | lb (_ :=>: a) = a |
166 | lb (_ :&: (a,_)) = a | 166 | lb (_ :&: (a,_)) = a |
167 | lb (_ :==: a) = a | 167 | lb (_ :==: a) = a |
168 | lb (Free _) = 0 | 168 | lb (Free _) = 0 |
169 | 169 | ||
170 | ub :: Bound t -> Double | 170 | ub :: Bound t -> Double |
171 | ub (_ :<: a) = a | 171 | ub (_ :<=: a) = a |
172 | ub (_ :>: _) = 0 | 172 | ub (_ :=>: _) = 0 |
173 | ub (_ :&: (_,a)) = a | 173 | ub (_ :&: (_,a)) = a |
174 | ub (_ :==: a) = a | 174 | ub (_ :==: a) = a |
175 | ub (Free _) = 0 | 175 | ub (Free _) = 0 |
@@ -187,7 +187,7 @@ mkBounds n b1 b2 = fromLists (cb++vb) where | |||
187 | | otherwise = error $ "simplex: duplicate bounds for vars " ++ show (gv'\\nub gv') | 187 | | otherwise = error $ "simplex: duplicate bounds for vars " ++ show (gv'\\nub gv') |
188 | rv | null gv || minimum gv >= 0 && maximum gv <= n = [1..n] \\ gv | 188 | rv | null gv || minimum gv >= 0 && maximum gv <= n = [1..n] \\ gv |
189 | | otherwise = error $ "simplex: bounds: variables "++show gv++" not in 1.."++show n | 189 | | otherwise = error $ "simplex: bounds: variables "++show gv++" not in 1.."++show n |
190 | vb = map snd $ sortBy (compare `on` fst) $ map (mkBound2 . (:>: 0)) rv ++ map mkBound2 b2 | 190 | vb = map snd $ sortBy (compare `on` fst) $ map (mkBound2 . (:=>: 0)) rv ++ map mkBound2 b2 |
191 | cb = map mkBound1 b1 | 191 | cb = map mkBound1 b1 |
192 | 192 | ||
193 | mkConstrD :: Int -> [Double] -> [Bound [Double]] -> Matrix Double | 193 | mkConstrD :: Int -> [Double] -> [Bound [Double]] -> Matrix Double |