summaryrefslogtreecommitdiff
path: root/packages/glpk
diff options
context:
space:
mode:
Diffstat (limited to 'packages/glpk')
-rw-r--r--packages/glpk/examples/simplex1.hs14
-rw-r--r--packages/glpk/examples/simplex2.hs10
-rw-r--r--packages/glpk/examples/simplex3.hs10
-rw-r--r--packages/glpk/examples/simplex4.hs10
-rw-r--r--packages/glpk/hmatrix-glpk.cabal4
-rw-r--r--packages/glpk/lib/Numeric/LinearProgramming.hs34
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
5objFun = Maximize [10, 6, 4] 5objFun = Maximize [10, 6, 4]
6 6
7constr = Dense [ [1,1,1] :<: 100 7constr = 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
12bnds = [ 1 :>: 0 12bnds = [ 1 :=>: 0
13 , 2 :>: 0 13 , 2 :=>: 0
14 , 3 :>: 0 ] 14 , 3 :=>: 0 ]
15 15
16main = do 16main = 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
3prob = Maximize [4, -3, 2] 3prob = Maximize [4, -3, 2]
4 4
5constr1 = Sparse [ [2#1, 1#2] :<: 10 5constr1 = Sparse [ [2#1, 1#2] :<=: 10
6 , [1#2, 5#3] :<: 20 6 , [1#2, 5#3] :<=: 20
7 ] 7 ]
8 8
9constr2 = Dense [ [2,1,0] :<: 10 9constr2 = Dense [ [2,1,0] :<=: 10
10 , [0,1,5] :<: 20 10 , [0,1,5] :<=: 20
11 ] 11 ]
12 12
13main = do 13main = 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
8constr = Dense 8constr = 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
8constr = Sparse 8constr = 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 @@
1Name: hmatrix-glpk 1Name: hmatrix-glpk
2Version: 0.1.0 2Version: 0.2.0
3License: GPL 3License: GPL
4License-file: LICENSE 4License-file: LICENSE
5Author: Alberto Ruiz 5Author: Alberto Ruiz
@@ -22,7 +22,7 @@ extra-source-files: examples/simplex1.hs
22 examples/simplex4.hs 22 examples/simplex4.hs
23 23
24library 24library
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
29prob = Maximize [4, -3, 2] 29prob = Maximize [4, -3, 2]
30 30
31constr1 = Sparse [ [2\#1, 1\#2] :<: 10 31constr1 = 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
38The coefficients of the constraint matrix can also be given in dense format: 38The 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
44By default all variables are bounded as @x_i >= 0@, but this can be 44By default all variables are bounded as @x_i >= 0@, but this can be
45changed: 45changed:
46 46
47@\> simplex prob constr2 [ 2 :>: 1, 3 :&: (2,7)] 47@\> simplex prob constr2 [ 2 :=>: 1, 3 :&: (2,7)]
48Optimal (22.6,[4.5,1.0,3.8]) 48Optimal (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@
53The given bound for a variable completely replaces the default, 53The given bound for a variable completely replaces the default,
54so @0 <= x_i <= b@ must be explicitly given as @i :&: (0,b)@. 54so @0 <= x_i <= b@ must be explicitly given as @i :&: (0,b)@.
55Multiple bounds for a variable are not allowed, instead of 55Multiple 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)
84infixl 5 # 84infixl 5 #
85(#) = (,) 85(#) = (,)
86 86
87data Bound x = x :<: Double 87data 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
149obj :: Bound t -> t 149obj :: Bound t -> t
150obj (x :<: _) = x 150obj (x :<=: _) = x
151obj (x :>: _) = x 151obj (x :=>: _) = x
152obj (x :&: _) = x 152obj (x :&: _) = x
153obj (x :==: _) = x 153obj (x :==: _) = x
154obj (Free x) = x 154obj (Free x) = x
155 155
156tb :: Bound t -> Double 156tb :: Bound t -> Double
157tb (_ :<: _) = glpUP 157tb (_ :<=: _) = glpUP
158tb (_ :>: _) = glpLO 158tb (_ :=>: _) = glpLO
159tb (_ :&: _) = glpDB 159tb (_ :&: _) = glpDB
160tb (_ :==: _) = glpFX 160tb (_ :==: _) = glpFX
161tb (Free _) = glpFR 161tb (Free _) = glpFR
162 162
163lb :: Bound t -> Double 163lb :: Bound t -> Double
164lb (_ :<: _) = 0 164lb (_ :<=: _) = 0
165lb (_ :>: a) = a 165lb (_ :=>: a) = a
166lb (_ :&: (a,_)) = a 166lb (_ :&: (a,_)) = a
167lb (_ :==: a) = a 167lb (_ :==: a) = a
168lb (Free _) = 0 168lb (Free _) = 0
169 169
170ub :: Bound t -> Double 170ub :: Bound t -> Double
171ub (_ :<: a) = a 171ub (_ :<=: a) = a
172ub (_ :>: _) = 0 172ub (_ :=>: _) = 0
173ub (_ :&: (_,a)) = a 173ub (_ :&: (_,a)) = a
174ub (_ :==: a) = a 174ub (_ :==: a) = a
175ub (Free _) = 0 175ub (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
193mkConstrD :: Int -> [Double] -> [Bound [Double]] -> Matrix Double 193mkConstrD :: Int -> [Double] -> [Bound [Double]] -> Matrix Double