diff options
Diffstat (limited to 'packages/glpk/src/Numeric/LinearProgramming.hs')
-rw-r--r-- | packages/glpk/src/Numeric/LinearProgramming.hs | 21 |
1 files changed, 11 insertions, 10 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 |