aboutsummaryrefslogtreecommitdiff
path: root/Math/LinProg/LP.hs
diff options
context:
space:
mode:
authorJustin Bedo <cu@cua0.org>2014-10-27 10:17:23 +1100
committerJustin Bedo <cu@cua0.org>2014-10-27 10:18:31 +1100
commit544eef53181f52423f513227e2bd98c20815b243 (patch)
tree5af4b35386c603b0fbbe5c7705a325d5f9b0d69b /Math/LinProg/LP.hs
parente60c072870ee428720dce1f22890f1ce075325e4 (diff)
Improve computational complexity of varTerms by rewriting equations.
Diffstat (limited to 'Math/LinProg/LP.hs')
-rw-r--r--Math/LinProg/LP.hs9
1 files changed, 2 insertions, 7 deletions
diff --git a/Math/LinProg/LP.hs b/Math/LinProg/LP.hs
index 1fc59e0..18d2068 100644
--- a/Math/LinProg/LP.hs
+++ b/Math/LinProg/LP.hs
@@ -56,7 +56,7 @@ compile ast = compile' ast initCompilerS where
instance (Show t, Num t, Ord t) => Show (CompilerS t String) where
show s = unlines $ catMaybes [
Just "Minimize"
- ,Just (showEq $ varTerms (s ^. objective))
+ ,Just (showEq (s ^. objective))
,if hasST then Just "Subject to" else Nothing
,if hasEqs then Just (intercalate "\n" $ map (\(a, b) -> showEq a ++ " = " ++ show (negate b)) $ s ^. equals) else Nothing
,if hasUnbounded then Just (intercalate "\n" $ map (\(a, b) -> showEq a ++ " <= " ++ show (negate b)) unbounded) else Nothing
@@ -64,12 +64,7 @@ instance (Show t, Num t, Ord t) => Show (CompilerS t String) where
,if hasBounded then Just (intercalate "\n" $ map (\(l, v, u) -> show l ++ " <= " ++ v ++ " <= " ++ show u) bounded) else Nothing
]
where
- getVars eq = zip vs ws
- where
- vs = vars eq
- ws = map (`getVar` eq) vs
-
- showEq = unwords . map (\(a, b) -> render b ++ " " ++ a) . getVars
+ showEq = unwords . map (\(a, b) -> render b ++ " " ++ a) . varTerms
(bounded, unbounded) = findBounds $ s ^. leqs
hasBounded = not (null bounded)