aboutsummaryrefslogtreecommitdiff
path: root/Math/LinProg/LPSolve.hs
diff options
context:
space:
mode:
authorJustin Bedo <cu@cua0.org>2014-10-28 10:19:49 +1100
committerJustin Bedo <cu@cua0.org>2014-10-28 10:33:14 +1100
commitd68fb49cad1a5bba7e52c7ff464d15c867052d0f (patch)
tree5cf467953736b3c41c1cfc1a57a41f9f057b0edc /Math/LinProg/LPSolve.hs
parent544eef53181f52423f513227e2bd98c20815b243 (diff)
Add support for binary/integer contraints;
Change to hash maps to speed up variable LUT for large number of variables.
Diffstat (limited to 'Math/LinProg/LPSolve.hs')
-rw-r--r--Math/LinProg/LPSolve.hs15
1 files changed, 12 insertions, 3 deletions
diff --git a/Math/LinProg/LPSolve.hs b/Math/LinProg/LPSolve.hs
index baa5d7e..5299d94 100644
--- a/Math/LinProg/LPSolve.hs
+++ b/Math/LinProg/LPSolve.hs
@@ -26,14 +26,15 @@ import Math.LinProg.LPSolve.FFI hiding (solve)
import qualified Math.LinProg.LPSolve.FFI as F
import Math.LinProg.LP
import Math.LinProg.Types
-import qualified Data.Map.Strict as M
+import qualified Data.HashMap.Strict as M
+import Data.Hashable
import Prelude hiding (EQ)
-solve :: (Eq v, Ord v) => LinProg Double v () -> IO (Maybe ResultCode, [(v, Double)])
+solve :: (Hashable v, Eq v, Ord v) => LinProg Double v () -> IO (Maybe ResultCode, [(v, Double)])
solve = solveWithTimeout 0
-- | Solves an LP using lp_solve.
-solveWithTimeout :: (Eq v, Ord v) => Integer -> LinProg Double v () -> IO (Maybe ResultCode, [(v, Double)])
+solveWithTimeout :: (Hashable v, Eq v, Ord v) => Integer -> LinProg Double v () -> IO (Maybe ResultCode, [(v, Double)])
solveWithTimeout t (compile -> lp) = do
model <- makeLP nconstr nvars
case model of
@@ -59,6 +60,14 @@ solveWithTimeout t (compile -> lp) = do
setRHS m i c
return ()
+ -- Ints
+ forM_ (lp ^. ints) $ \v -> do
+ setInt m (varLUT M.! v)
+
+ -- Bins
+ forM_ (lp ^. bins) $ \v -> do
+ setBin m (varLUT M.! v)
+
-- Objective
forM_ (varTerms (lp ^. objective)) $ \(v, w) -> do
void $ setMat m 0 (varLUT M.! v) w