diff options
author | Justin Bedo <cu@cua0.org> | 2014-10-23 11:33:18 +1100 |
---|---|---|
committer | Justin Bedo <cu@cua0.org> | 2014-10-23 11:33:18 +1100 |
commit | 365afb5dca44d1ce19b30921aa9032e41d9c8e06 (patch) | |
tree | 10bd94b3589bd7e66b3c108c62341a6564dc7a56 /Math/LinProg/LP.hs | |
parent | f4f5c99fcce607e72847cb11fd3ec90b0c089a63 (diff) |
Merged files
Diffstat (limited to 'Math/LinProg/LP.hs')
-rw-r--r-- | Math/LinProg/LP.hs | 32 |
1 files changed, 30 insertions, 2 deletions
diff --git a/Math/LinProg/LP.hs b/Math/LinProg/LP.hs index 50bcb1f..5f9e168 100644 --- a/Math/LinProg/LP.hs +++ b/Math/LinProg/LP.hs @@ -1,15 +1,43 @@ -{-# LANGUAGE FlexibleInstances, ScopedTypeVariables #-} +{-# LANGUAGE TemplateHaskell, FlexibleInstances, ScopedTypeVariables #-} module Math.LinProg.LP ( compile + ,Equation + ,CompilerS(..) + ,objective + ,equals + ,leqs ) where import Data.List import Math.LinProg.Types -import Math.LinProg.Compile import Control.Lens import Data.Maybe +import Control.Monad.Free +type Equation t v = (LinExpr t v, t) -- LHS and RHS + +data CompilerS t v = CompilerS { + _objective :: LinExpr t v + ,_equals :: [Equation t v] + ,_leqs :: [Equation t v] +} deriving (Eq) + +$(makeLenses ''CompilerS) + +compile :: (Num 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):) + compile' (Free (LeqConstraint a b c)) state = compile' c $ state & leqs %~ (split (a-b):) + compile' _ state = state + + initCompilerS = CompilerS + 0 + [] + [] + +-- Printing to LP format instance (Show t, Num t, Ord t) => Show (CompilerS t String) where show s = unlines $ catMaybes [ Just "Minimize" |