diff options
Diffstat (limited to 'packages/glpk/src')
-rw-r--r-- | packages/glpk/src/Numeric/LinearProgramming.hs | 21 | ||||
-rw-r--r-- | packages/glpk/src/Numeric/LinearProgramming/L1.hs | 2 |
2 files changed, 12 insertions, 11 deletions
diff --git a/packages/glpk/src/Numeric/LinearProgramming.hs b/packages/glpk/src/Numeric/LinearProgramming.hs index b0537cc..d2e9f3c 100644 --- a/packages/glpk/src/Numeric/LinearProgramming.hs +++ b/packages/glpk/src/Numeric/LinearProgramming.hs | |||
@@ -75,8 +75,8 @@ module Numeric.LinearProgramming( | |||
75 | Solution(..) | 75 | Solution(..) |
76 | ) where | 76 | ) where |
77 | 77 | ||
78 | import Data.Packed | 78 | import Numeric.LinearAlgebra.HMatrix |
79 | import Data.Packed.Development | 79 | import Numeric.LinearAlgebra.Devel hiding (Dense) |
80 | import Foreign(Ptr) | 80 | import Foreign(Ptr) |
81 | import System.IO.Unsafe(unsafePerformIO) | 81 | import System.IO.Unsafe(unsafePerformIO) |
82 | import Foreign.C.Types | 82 | import Foreign.C.Types |
@@ -135,16 +135,17 @@ simplex opt (Sparse constr) bnds = extract sg sol where | |||
135 | 135 | ||
136 | adapt :: Optimization -> (Int, Double, [Double]) | 136 | adapt :: Optimization -> (Int, Double, [Double]) |
137 | adapt opt = case opt of | 137 | adapt opt = case opt of |
138 | Maximize x -> (size x, 1 ,x) | 138 | Maximize x -> (sz x, 1 ,x) |
139 | Minimize x -> (size x, -1, (map negate x)) | 139 | Minimize x -> (sz x, -1, (map negate x)) |
140 | where size x | null x = error "simplex: objective function with zero variables" | 140 | where |
141 | | otherwise = length x | 141 | sz x | null x = error "simplex: objective function with zero variables" |
142 | | otherwise = length x | ||
142 | 143 | ||
143 | extract :: Double -> Vector Double -> Solution | 144 | extract :: Double -> Vector Double -> Solution |
144 | extract sg sol = r where | 145 | extract sg sol = r where |
145 | z = sg * (sol@>1) | 146 | z = sg * (sol!1) |
146 | v = toList $ subVector 2 (dim sol -2) sol | 147 | v = toList $ subVector 2 (size sol -2) sol |
147 | r = case round(sol@>0)::Int of | 148 | r = case round(sol!0)::Int of |
148 | 1 -> Undefined | 149 | 1 -> Undefined |
149 | 2 -> Feasible (z,v) | 150 | 2 -> Feasible (z,v) |
150 | 3 -> Infeasible (z,v) | 151 | 3 -> Infeasible (z,v) |
@@ -209,7 +210,7 @@ mkConstrD n f b1 | ok = fromLists (ob ++ co) | |||
209 | ok = all (==n) ls | 210 | ok = all (==n) ls |
210 | den = fromLists cs | 211 | den = fromLists cs |
211 | ob = map (([0,0]++).return) f | 212 | ob = map (([0,0]++).return) f |
212 | co = [[fromIntegral i, fromIntegral j,den@@>(i-1,j-1)]| i<-[1 ..rows den], j<-[1 .. cols den]] | 213 | co = [[fromIntegral i, fromIntegral j,den `atIndex` (i-1,j-1)]| i<-[1 ..rows den], j<-[1 .. cols den]] |
213 | 214 | ||
214 | mkConstrS :: Int -> [Double] -> [Bound [(Double, Int)]] -> Matrix Double | 215 | mkConstrS :: Int -> [Double] -> [Bound [(Double, Int)]] -> Matrix Double |
215 | mkConstrS n objfun b1 = fromLists (ob ++ co) where | 216 | mkConstrS n objfun b1 = fromLists (ob ++ co) where |
diff --git a/packages/glpk/src/Numeric/LinearProgramming/L1.hs b/packages/glpk/src/Numeric/LinearProgramming/L1.hs index f55c721..d7f1258 100644 --- a/packages/glpk/src/Numeric/LinearProgramming/L1.hs +++ b/packages/glpk/src/Numeric/LinearProgramming/L1.hs | |||
@@ -14,7 +14,7 @@ module Numeric.LinearProgramming.L1 ( | |||
14 | l1SolveU, | 14 | l1SolveU, |
15 | ) where | 15 | ) where |
16 | 16 | ||
17 | import Numeric.LinearAlgebra | 17 | import Numeric.LinearAlgebra.HMatrix |
18 | import Numeric.LinearProgramming | 18 | import Numeric.LinearProgramming |
19 | 19 | ||
20 | -- | L_inf solution of overconstrained system Ax=b. | 20 | -- | L_inf solution of overconstrained system Ax=b. |