summaryrefslogtreecommitdiff
path: root/packages/glpk/lib/Numeric/LinearProgramming.hs
diff options
context:
space:
mode:
authorAlberto Ruiz <aruiz@um.es>2010-03-31 19:52:46 +0000
committerAlberto Ruiz <aruiz@um.es>2010-03-31 19:52:46 +0000
commit261db58d71fbc378a5bb39f35a64d1c9fd4691e3 (patch)
tree1cd8257016408c27b5e9ad24338de4601a7fbfef /packages/glpk/lib/Numeric/LinearProgramming.hs
parent80f6ea4a8b1c5fb0bcd68f8d934364fd9c9b4780 (diff)
corrected Bound constructors (thx Ozgur Akgun)
Diffstat (limited to 'packages/glpk/lib/Numeric/LinearProgramming.hs')
-rw-r--r--packages/glpk/lib/Numeric/LinearProgramming.hs34
1 files changed, 17 insertions, 17 deletions
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