summaryrefslogtreecommitdiff
path: root/packages/glpk
diff options
context:
space:
mode:
Diffstat (limited to 'packages/glpk')
-rw-r--r--packages/glpk/hmatrix-glpk.cabal4
-rw-r--r--packages/glpk/src/Numeric/LinearProgramming.hs21
-rw-r--r--packages/glpk/src/Numeric/LinearProgramming/L1.hs2
3 files changed, 14 insertions, 13 deletions
diff --git a/packages/glpk/hmatrix-glpk.cabal b/packages/glpk/hmatrix-glpk.cabal
index 5a1b59c..8593e0a 100644
--- a/packages/glpk/hmatrix-glpk.cabal
+++ b/packages/glpk/hmatrix-glpk.cabal
@@ -1,5 +1,5 @@
1Name: hmatrix-glpk 1Name: hmatrix-glpk
2Version: 0.4.1.0 2Version: 0.5.0.0
3License: GPL 3License: GPL
4License-file: LICENSE 4License-file: LICENSE
5Author: Alberto Ruiz 5Author: Alberto Ruiz
@@ -23,7 +23,7 @@ extra-source-files: examples/simplex1.hs
23 examples/simplex5.hs 23 examples/simplex5.hs
24 24
25library 25library
26 Build-Depends: base <5, hmatrix >= 0.16, containers >= 0.5.4.0 26 Build-Depends: base <5, hmatrix >= 0.17, containers
27 27
28 hs-source-dirs: src 28 hs-source-dirs: src
29 29
diff --git a/packages/glpk/src/Numeric/LinearProgramming.hs b/packages/glpk/src/Numeric/LinearProgramming.hs
index 6a0c47d..7bf4279 100644
--- a/packages/glpk/src/Numeric/LinearProgramming.hs
+++ b/packages/glpk/src/Numeric/LinearProgramming.hs
@@ -85,8 +85,8 @@ module Numeric.LinearProgramming(
85 Solution(..) 85 Solution(..)
86) where 86) where
87 87
88import Data.Packed 88import Numeric.LinearAlgebra.HMatrix
89import Data.Packed.Development 89import Numeric.LinearAlgebra.Devel hiding (Dense)
90import Foreign(Ptr) 90import Foreign(Ptr)
91import System.IO.Unsafe(unsafePerformIO) 91import System.IO.Unsafe(unsafePerformIO)
92import Foreign.C.Types 92import Foreign.C.Types
@@ -180,16 +180,17 @@ exact opt constr@(General _) bnds = exact opt (sparseOfGeneral constr) bnds
180 180
181adapt :: Optimization -> (Int, Double, [Double]) 181adapt :: Optimization -> (Int, Double, [Double])
182adapt opt = case opt of 182adapt opt = case opt of
183 Maximize x -> (size x, 1 ,x) 183 Maximize x -> (sz x, 1 ,x)
184 Minimize x -> (size x, -1, (map negate x)) 184 Minimize x -> (sz x, -1, (map negate x))
185 where size x | null x = error "simplex: objective function with zero variables" 185 where
186 | otherwise = length x 186 sz x | null x = error "simplex: objective function with zero variables"
187 | otherwise = length x
187 188
188extract :: Double -> Vector Double -> Solution 189extract :: Double -> Vector Double -> Solution
189extract sg sol = r where 190extract sg sol = r where
190 z = sg * (sol@>1) 191 z = sg * (sol!1)
191 v = toList $ subVector 2 (dim sol -2) sol 192 v = toList $ subVector 2 (size sol -2) sol
192 r = case round(sol@>0)::Int of 193 r = case round(sol!0)::Int of
193 1 -> Undefined 194 1 -> Undefined
194 2 -> Feasible (z,v) 195 2 -> Feasible (z,v)
195 3 -> Infeasible (z,v) 196 3 -> Infeasible (z,v)
@@ -261,7 +262,7 @@ mkConstrD n f b1 | ok = fromLists (ob ++ co)
261 ok = all (==n) ls 262 ok = all (==n) ls
262 den = fromLists cs 263 den = fromLists cs
263 ob = map (([0,0]++).return) f 264 ob = map (([0,0]++).return) f
264 co = [[fromIntegral i, fromIntegral j,den@@>(i-1,j-1)]| i<-[1 ..rows den], j<-[1 .. cols den]] 265 co = [[fromIntegral i, fromIntegral j,den `atIndex` (i-1,j-1)]| i<-[1 ..rows den], j<-[1 .. cols den]]
265 266
266mkConstrS :: Int -> [Double] -> [Bound [(Double, Int)]] -> Matrix Double 267mkConstrS :: Int -> [Double] -> [Bound [(Double, Int)]] -> Matrix Double
267mkConstrS n objfun b1 = fromLists (ob ++ co) where 268mkConstrS 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.