From 544eef53181f52423f513227e2bd98c20815b243 Mon Sep 17 00:00:00 2001 From: Justin Bedo Date: Mon, 27 Oct 2014 10:17:23 +1100 Subject: Improve computational complexity of varTerms by rewriting equations. --- Math/LinProg/LP.hs | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) (limited to 'Math/LinProg/LP.hs') 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) -- cgit v1.2.3