From 365afb5dca44d1ce19b30921aa9032e41d9c8e06 Mon Sep 17 00:00:00 2001 From: Justin Bedo Date: Thu, 23 Oct 2014 11:33:18 +1100 Subject: Merged files --- LinProg.cabal | 2 +- Math/LinProg/Compile.hs | 37 ------------------------------------- Math/LinProg/LP.hs | 32 ++++++++++++++++++++++++++++++-- Math/LinProg/LPSolve.hs | 2 +- 4 files changed, 32 insertions(+), 41 deletions(-) delete mode 100644 Math/LinProg/Compile.hs diff --git a/LinProg.cabal b/LinProg.cabal index b0ddf5b..d3056b4 100644 --- a/LinProg.cabal +++ b/LinProg.cabal @@ -17,7 +17,7 @@ cabal-version: >=1.10 library exposed-modules: Math.LinProg.Types, Math.LinProg.LP, Math.LinProg.LPSolve - other-modules: Math.LinProg.Compile, Math.LinProg.LPSolve.FFI, Math.LinProg.Compile + other-modules: Math.LinProg.LPSolve.FFI extra-libraries: lpsolve55 extensions: DeriveFunctor, FlexibleInstances, FlexibleContexts, UndecidableInstances, TemplateHaskell, ScopedTypeVariables, ForeignFunctionInterface, ViewPatterns build-depends: base >=4.7 && <4.8, recursion-schemes >=4.1 && <4.2, free >=4.9 && <4.10, containers >=0.5 && <0.6, lens >=4.4 && <4.5, mtl >=2.1 && <2.2 diff --git a/Math/LinProg/Compile.hs b/Math/LinProg/Compile.hs deleted file mode 100644 index c14d45b..0000000 --- a/Math/LinProg/Compile.hs +++ /dev/null @@ -1,37 +0,0 @@ -{-# LANGUAGE TemplateHaskell, FlexibleInstances, ScopedTypeVariables #-} - -module Math.LinProg.Compile ( - compile - ,Equation - ,CompilerS(..) - ,objective - ,equals - ,leqs -) where - -import Math.LinProg.Types -import Control.Lens -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 - [] - [] - 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" diff --git a/Math/LinProg/LPSolve.hs b/Math/LinProg/LPSolve.hs index 85f536d..7b1f8ca 100644 --- a/Math/LinProg/LPSolve.hs +++ b/Math/LinProg/LPSolve.hs @@ -11,7 +11,7 @@ import Data.List import Control.Lens import Math.LinProg.LPSolve.FFI hiding (solve) import qualified Math.LinProg.LPSolve.FFI as F -import Math.LinProg.Compile +import Math.LinProg.LP import Math.LinProg.Types import qualified Data.Map as M import Prelude hiding (EQ) -- cgit v1.2.3