@@ -3,7 +3,10 @@ module Linear.Simplex.Solver.Types where
33import qualified Data.Map as Map
44import GHC.Generics (Generic )
55import Linear.Expr.Types (ExprVarsOnly )
6+ import Linear.System.Linear.Types (LinearSystem )
67import Linear.Var.Types (SimplexNum , Var )
8+ import Linear.SlackForm.Types (SlackForm )
9+ import System.Posix.Types (CMode )
710
811data OptimisationDirection = Minimize | Maximize
912 deriving (Show , Eq , GHC.Generics.Generic )
@@ -16,10 +19,62 @@ data Objective = Objective
1619
1720-- TODO: Is it useful to include the system in the result?
1821data Result = Result
22+
23+ -- TODO: Include the canonical form?
24+ data OptimisationResult = OptimisationResult
1925 { varMap :: Map. Map Var SimplexNum
2026 , objVal :: SimplexNum
2127 }
2228 deriving (Show , Read , Eq , GHC.Generics.Generic )
2329
2430-- class (CanBeLinearSystem s) => Solver s where
2531-- solve :: s -> Objective -> Result
32+ class TwoPhaseSolver inputSystem where
33+ firstPhase :: inputSystem -> Maybe SlackForm
34+
35+ twoPhaseSolve :: inputSystem -> Objective -> Maybe OptimisationResult
36+ twoPhaseSolve inputSystem obj =
37+ let mSf = firstPhase inputSystem
38+ in case mSf of
39+ Nothing -> Nothing
40+ Just sf -> Just $ systemResult $ secondPhase obj sf
41+ where
42+ secondPhase :: Objective -> SlackForm -> SlackForm
43+ secondPhase = undefined
44+
45+ -- This will probably be a proper function
46+ systemResult :: SlackForm -> OptimisationResult
47+ systemResult = undefined
48+
49+ class CanBeStandardForm problem where
50+ findSolution :: problem -> Maybe SlackForm
51+
52+ -- solveStandardForm :: StandardForm -> Objective -> Maybe Result
53+
54+ class LinearSystemProcessor s where
55+ type System s :: *
56+
57+ data FeasibleSystem = FeasibleSystem
58+ { varVals :: Map. Map Var SimplexNum
59+ , system :: LinearSystem
60+ }
61+
62+ data Model = Model { model :: Map. Map Var SimplexNum }
63+
64+ data SatResult model = Unsat | Sat model
65+
66+ -- s is a system
67+ class (Monad (SatSolverMonad s )) => SatSolver s where
68+ type SatSolverOptions s :: *
69+ type SatSolverMonad s :: * -> *
70+
71+ solve :: SatSolverOptions s -> s -> (SatSolverMonad s ) (SatResult Model )
72+
73+ class (Monad (OptSolverMonad s )) => OptSolver s where
74+ type OptSolverOptions s :: *
75+ type OptSolverMonad s :: * -> *
76+
77+ optimise :: OptSolverOptions s -> s -> Objective -> (OptSolverMonad s ) (SatResult Model )
78+
79+ -- class (CanBeLinearSystem s) => Solver2 s where
80+ -- solve2 :: s -> Objective -> Result
0 commit comments