aboutsummaryrefslogtreecommitdiff
path: root/Math/LinProg/LP.hs
diff options
context:
space:
mode:
authorJustin Bedo <cu@cua0.org>2014-11-11 13:37:48 +1100
committerJustin Bedo <cu@cua0.org>2014-11-11 13:37:48 +1100
commit19a7c7e4225ad6650d8a60d673edb7b23294f9d5 (patch)
tree55149c8792ea14be5ed05147bd77ad4f8589cdb5 /Math/LinProg/LP.hs
parentaeafc1692afa5952f3d06195916bb38463c1674c (diff)
Correct bug with fractional handlingHEADmaster
Diffstat (limited to 'Math/LinProg/LP.hs')
-rw-r--r--Math/LinProg/LP.hs6
1 files changed, 3 insertions, 3 deletions
diff --git a/Math/LinProg/LP.hs b/Math/LinProg/LP.hs
index 513bdad..e4984f7 100644
--- a/Math/LinProg/LP.hs
+++ b/Math/LinProg/LP.hs
@@ -45,7 +45,7 @@ data CompilerS t v = CompilerS {
$(makeLenses ''CompilerS)
-- | Compiles a linear programming monad to intermediate form which is easier to process
-compile :: (Num t, Show t, Ord t, Eq v) => LinProg t v () -> CompilerS t v
+compile :: (Num t, Fractional t, Show t, Ord t, Eq v) => LinProg t v () -> CompilerS t v
compile ast = compile' ast initCompilerS where
compile' (Free (Objective a c)) state = compile' c $ state & objective +~ a
compile' (Free (EqConstraint a b c)) state = compile' c $ state & equals %~ (split (a-b):)
@@ -62,7 +62,7 @@ compile ast = compile' ast initCompilerS where
[]
-- | Shows a compiled state as LP format. Requires variable ids are strings.
-instance (Show t, Num t, Ord t) => Show (CompilerS t String) where
+instance (Show t, Num t, Fractional t, Ord t) => Show (CompilerS t String) where
show s = unlines $ catMaybes [
Just "Minimize"
,Just (showEq (s ^. objective))
@@ -89,7 +89,7 @@ instance (Show t, Num t, Ord t) => Show (CompilerS t String) where
render x = (if x >= 0 then "+" else "") ++ show x
-findBounds :: (Hashable v, Eq v, Num t, Ord t, Eq t) => [Equation t v] -> ([(t, v, t)], [Equation t v])
+findBounds :: (Hashable v, Eq v, Num t, Fractional t, Ord t, Eq t) => [Equation t v] -> ([(t, v, t)], [Equation t v])
findBounds eqs = (mapMaybe bound singleTerms, eqs \\ filter (isBounded . head . vars . fst) singleTermEqs)
where
singleTermEqs = filter (\(ts, _) -> length (vars ts) == 1) eqs