summaryrefslogtreecommitdiff
path: root/packages/glpk/src/Numeric
diff options
context:
space:
mode:
Diffstat (limited to 'packages/glpk/src/Numeric')
-rw-r--r--packages/glpk/src/Numeric/LinearProgramming.hs21
-rw-r--r--packages/glpk/src/Numeric/LinearProgramming/L1.hs2
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
78import Data.Packed 78import Numeric.LinearAlgebra.HMatrix
79import Data.Packed.Development 79import Numeric.LinearAlgebra.Devel hiding (Dense)
80import Foreign(Ptr) 80import Foreign(Ptr)
81import System.IO.Unsafe(unsafePerformIO) 81import System.IO.Unsafe(unsafePerformIO)
82import Foreign.C.Types 82import Foreign.C.Types
@@ -135,16 +135,17 @@ simplex opt (Sparse constr) bnds = extract sg sol where
135 135
136adapt :: Optimization -> (Int, Double, [Double]) 136adapt :: Optimization -> (Int, Double, [Double])
137adapt opt = case opt of 137adapt 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
143extract :: Double -> Vector Double -> Solution 144extract :: Double -> Vector Double -> Solution
144extract sg sol = r where 145extract 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
214mkConstrS :: Int -> [Double] -> [Bound [(Double, Int)]] -> Matrix Double 215mkConstrS :: Int -> [Double] -> [Bound [(Double, Int)]] -> Matrix Double
215mkConstrS n objfun b1 = fromLists (ob ++ co) where 216mkConstrS 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
17import Numeric.LinearAlgebra 17import Numeric.LinearAlgebra.HMatrix
18import Numeric.LinearProgramming 18import Numeric.LinearProgramming
19 19
20-- | L_inf solution of overconstrained system Ax=b. 20-- | L_inf solution of overconstrained system Ax=b.