diff options
author | Alberto Ruiz <aruiz@um.es> | 2010-03-31 19:52:46 +0000 |
---|---|---|
committer | Alberto Ruiz <aruiz@um.es> | 2010-03-31 19:52:46 +0000 |
commit | 261db58d71fbc378a5bb39f35a64d1c9fd4691e3 (patch) | |
tree | 1cd8257016408c27b5e9ad24338de4601a7fbfef /packages/glpk/lib | |
parent | 80f6ea4a8b1c5fb0bcd68f8d934364fd9c9b4780 (diff) |
corrected Bound constructors (thx Ozgur Akgun)
Diffstat (limited to 'packages/glpk/lib')
-rw-r--r-- | packages/glpk/lib/Numeric/LinearProgramming.hs | 34 |
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 | ||
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 |