coinor-clp-0.0.1: Linear Programming using COIN-OR/CLP and comfort-array
Safe HaskellSafe-Inferred
LanguageHaskell98

Numeric.COINOR.CLP.Monad

Description

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

Synopsis

Documentation

data T sh a Source #

Instances

Instances details
Applicative (T sh) Source # 
Instance details

Defined in Numeric.COINOR.CLP.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 #

Functor (T sh) Source # 
Instance details

Defined in Numeric.COINOR.CLP.Monad

Methods

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

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

Monad (T sh) Source # 
Instance details

Defined in Numeric.COINOR.CLP.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 #

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

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

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

>>> case Shape.indexTupleFromShape tripletShape of
      (x,y,z) ->
         mapSnd Array.toTuple <$>
         LP.run tripletShape []
            (LP.simplex LP.dual
               [[2.*x, 1.*y] <=. 10, [1.*y, (5::Double).*z] <=. 20]
               (LP.Maximize, Array.fromTuple (4,-3,2) :: Array.Array TripletShape Double))
Right (28.0,(5.0,0.0,4.0))
forAllMethod $ \method ->
   TestLP.forAllOrigin $ \origin ->
   TestLP.forAllProblem origin $ \bounds constrs ->
   QC.forAll (TestLP.genObjective origin) $ \(dir,obj) ->
   case (CLP.simplex method bounds constrs (dir,obj),
         LP.run (Array.shape origin) bounds $
            LP.simplex method constrs (dir,obj)) of
      (Right (optA,_), Right (optB,_)) ->
         TestLP.approxReal 0.1 optA optB; _ -> False
forAllMethod $ \method ->
   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 method (Array.shape origin) bounds (constrs,dirObj) objs
forAllMethod $ \method ->
   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 (LP.simplex method)
               (Array.shape origin) bounds (constrs,dirObj) objs)
            (solveSuccessiveGen method
               (Array.shape origin) bounds (constrs,dirObj) objs)

concurrent :: (Eq sh, Indexed sh, Index sh ~ ix) => T [] Method -> Constraints Double ix -> (Direction, Objective sh) -> T sh (Result sh) Source #

forAllMethod $ \method ->
   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 (LP.simplex method)
               (Array.shape origin) bounds (constrs,dirObj) objs)
            (solveSuccessiveWarm
               (LP.concurrent (NonEmpty.singleton method))
               (Array.shape origin) bounds (constrs,dirObj) objs)
forAllMethod $ \method ->
   forAllMethod $ \methodA ->
   forAllMethod $ \methodB ->
   forAllMethod $ \methodC ->
   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 (LP.simplex method)
               (Array.shape origin) bounds (constrs,dirObj) objs)
            (solveSuccessiveWarm
               (LP.concurrent (methodA!:methodB:methodC:[]))
               (Array.shape origin) bounds (constrs,dirObj) objs)