comfort-glpk-0.1: Linear Programming using GLPK and comfort-array

Safe HaskellNone
LanguageHaskell98

Numeric.GLPK.Monad

Description

The monadic interface to GLPK allows to optimize with respect to multiple objectives, successively.

It is not intended to provide a general imperative interface to GLPK that manipulates GLPK's state by setters and getters.

Synopsis

Documentation

data T sh a Source #

Instances
Monad (T sh) Source # 
Instance details

Defined in Numeric.GLPK.Monad

Methods

(>>=) :: T sh a -> (a -> T sh b) -> T sh b #

(>>) :: T sh a -> T sh b -> T sh b #

return :: a -> T sh a #

fail :: String -> T sh a #

Functor (T sh) Source # 
Instance details

Defined in Numeric.GLPK.Monad

Methods

fmap :: (a -> b) -> T sh a -> T sh b #

(<$) :: a -> T sh b -> T sh a #

Applicative (T sh) Source # 
Instance details

Defined in Numeric.GLPK.Monad

Methods

pure :: a -> T sh a #

(<*>) :: T sh (a -> b) -> T sh a -> T sh b #

liftA2 :: (a -> b -> c) -> T sh a -> T sh b -> T sh c #

(*>) :: T sh a -> T sh b -> T sh b #

(<*) :: T sh a -> T sh b -> T sh a #

run :: (Indexed sh, Index sh ~ ix) => sh -> Bounds ix -> T sh a -> a Source #

simplex :: (Eq sh, Indexed sh, Index sh ~ ix) => Constraints ix -> (Direction, Objective sh) -> T sh (Result sh) Source #

Add new constraints to an existing problem and solve with a new direction and objective.

>>> case Shape.indexTupleFromShape tripletShape of (x,y,z) -> mapSnd (mapSnd Array.toTuple) <$> LP.run tripletShape [] (LP.simplex [[2.*x, 1.*y] <=. 10, [1.*y, (5::Double).*z] <=. 20] (LP.Maximize, Array.fromTuple (4,-3,2) :: Array.Array TripletShape Double))
Right (Optimal,(28.0,(5.0,0.0,4.0)))
TestLP.forAllOrigin $ \origin -> TestLP.forAllProblem origin $ \bounds constrs -> QC.forAll (TestLP.genObjective origin) $ \(dir,obj) -> case (GLPK.simplex bounds constrs (dir,obj), LP.run (Array.shape origin) bounds $ LP.simplex constrs (dir,obj)) of (Right (GLPK.Optimal, (optA,_)), Right (GLPK.Optimal, (optB,_))) -> TestLP.approxReal 0.1 optA optB; _ -> False
TestLP.forAllOrigin $ \origin -> TestLP.forAllProblem origin $ \bounds constrs -> TestLP.forAllObjectives origin $ \objs_ -> case TestLP.successiveObjectives origin 0.01 objs_ of (dirObj, objs) -> either (\msg -> QC.counterexample (show msg) False) (const $ QC.property True) $ runSuccessive (Array.shape origin) bounds (constrs,dirObj) objs
TestLP.forAllOrigin $ \origin -> TestLP.forAllProblem origin $ \bounds constrs -> TestLP.forAllObjectives origin $ \objs_ -> case TestLP.successiveObjectives origin 0.01 objs_ of (dirObj, objs) -> approxSuccession 0.01 (solveSuccessiveWarm (Array.shape origin) bounds (constrs,dirObj) objs) (solveSuccessiveGen (Array.shape origin) bounds (constrs,dirObj) objs)

exact :: (Eq sh, Indexed sh, Index sh ~ ix) => Constraints ix -> (Direction, Objective sh) -> T sh (Result sh) Source #