Safe Haskell | Safe-Inferred |
---|---|
Language | Haskell98 |
Synopsis
- simplex :: (Coefficient a, Indexed sh, Index sh ~ ix) => Method -> Bounds ix -> Constraints a ix -> (Direction, Objective sh) -> Result sh
- concurrent :: (Coefficient a, Indexed sh, Index sh ~ ix) => T [] Method -> Bounds ix -> Constraints a ix -> (Direction, Objective sh) -> Result sh
- data Direction
- data PlusMinusOne
- data Term a ix = Term a ix
- (.*) :: a -> ix -> Term a ix
- type Constraints a ix = [Inequality [Term a ix]]
- free :: x -> Inequality x
- (<=.) :: x -> Double -> Inequality x
- (>=.) :: x -> Double -> Inequality x
- (==.) :: x -> Double -> Inequality x
- (>=<.) :: x -> (Double, Double) -> Inequality x
- data Method
- dual :: Method
- primal :: Method
- initialSolve :: Method
- initialDualSolve :: Method
- initialPrimalSolve :: Method
- initialBarrierSolve :: Method
- initialBarrierNoCrossSolve :: Method
- data FailureType
- type Result sh = Either FailureType (Double, Array sh Double)
- solveEndless :: Method
Documentation
simplex :: (Coefficient a, Indexed sh, Index sh ~ ix) => Method -> Bounds ix -> Constraints a ix -> (Direction, Objective sh) -> Result sh Source #
>>>
case Shape.indexTupleFromShape tripletShape of (x,y,z) -> mapSnd Array.toTuple <$> 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))
>>>
case Shape.indexTupleFromShape tripletShape of (x,y,z) -> mapSnd Array.toTuple <$> LP.simplex LP.primal [y >=<. (-12,12)] [[1.*x, (-1).*y] <=. 10, [(-1).*y, (1::Double).*z] <=. 20] (LP.Maximize, Array.fromTuple (4,-3,2) :: Array.Array TripletShape Double)
Right (116.0,(22.0,12.0,32.0))
>>>
case Shape.indexTupleFromShape tripletShape of (x,y,z) -> mapSnd Array.toTuple <$> LP.simplex LP.primal [y >=<. (-12,12)] [[PlusOne .* x, MinusOne .* y] <=. 10, [MinusOne .* y, PlusOne .* z] <=. 20] (LP.Maximize, Array.fromTuple (4,-3,2) :: Array.Array TripletShape Double)
Right (116.0,(22.0,12.0,32.0))
>>>
case Shape.indexTupleFromShape tripletShape of (x,y,z) -> mapSnd Array.toTuple <$> LP.simplex LP.primal [y >=<. (-12,12)] [[1.*x, 1.*y] <=. 10, [1.*y, (-1::Double).*z] >=. 20] (LP.Maximize, Array.fromTuple (4,3,2) :: Array.Array TripletShape Double)
Left PrimalInfeasible
>>>
case Shape.indexTupleFromShape tripletShape of (x,y,z) -> mapSnd Array.toTuple <$> LP.simplex LP.primal [y >=<. (-12,12)] [[1.*x, 1.*y] <=. 10, [1.*y, (1::Double).*z] >=. 20] (LP.Maximize, Array.fromTuple (4,3,2) :: Array.Array TripletShape Double)
Left DualInfeasible
forAllMethod $ \method (QC.Positive posWeight) (QC.Positive negWeight) target -> case Shape.indexTupleFromShape pairShape of (pos,neg) -> case mapSnd Array.toTuple <$> LP.simplex method [] [[1.*pos, (-1::Double).*neg] ==. target] (LP.Minimize, Array.fromTuple (posWeight,negWeight) :: Array.Array PairShape Double) of Left _ -> QC.property False Right (absol,(posResult,negResult)) -> QC.property (absol>=0) .&&. (posResult === 0 .||. negResult === 0)
forAllMethod $ \method target -> case Shape.indexTupleFromShape pairShape of (pos,neg) -> case mapSnd Array.toTuple <$> LP.simplex method [] [[1.*pos, (-1::Double).*neg] ==. target] (LP.Minimize, Array.fromTuple (1,1) :: Array.Array PairShape Double) of Left _ -> QC.property False Right (absol,(posResult,negResult)) -> QC.counterexample (show(absol,(posResult,negResult))) $ QC.property (approxReal 0.001 absol (abs target)) .&&. (posResult === 0 .||. negResult === 0)
forAllMethod $ \method -> TestLP.forAllOrigin $ \origin -> TestLP.forAllProblem origin $ \bounds constrs -> QC.forAll (TestLP.genObjective origin) $ \(dir,obj) -> case LP.simplex method bounds constrs (dir,obj) of Left _ -> False Right _ -> True
forAllMethod $ \method -> TestLP.forAllOrigin $ \origin -> TestLP.forAllProblem origin $ \bounds constrs -> QC.forAll (TestLP.genObjective origin) $ \(dir,obj) -> case LP.simplex method bounds constrs (dir,obj) of Left _ -> QC.property False Right (_,sol) -> TestLP.checkFeasibility 0.1 bounds constrs sol
forAllMethod $ \method -> TestLP.forAllOrigin $ \origin -> TestLP.forAllProblem origin $ \bounds constrs -> QC.forAll (TestLP.genObjective origin) $ \(dir,obj) -> case LP.simplex method bounds constrs (dir,obj) of Left _ -> QC.property False Right (_,sol) -> QC.forAll (QC.choose (0,1)) $ \lambda -> TestLP.checkFeasibility 0.1 bounds constrs $ TestLP.affineCombination lambda sol (Array.map fromIntegral origin)
forAllMethod $ \method -> TestLP.forAllOrigin $ \origin -> TestLP.forAllProblem origin $ \bounds constrs -> QC.forAll (TestLP.genObjective origin) $ \(dir,obj) -> case LP.simplex method bounds constrs (dir,obj) of Left _ -> QC.property False Right (opt,sol) -> QC.forAll (QC.choose (0,1)) $ \lambda -> let val = TestLP.scalarProduct obj $ TestLP.affineCombination lambda sol (Array.map fromIntegral origin) in case dir of LP.Minimize -> opt-0.01 <= val LP.Maximize -> opt+0.01 >= val
forAllMethod $ \method -> TestLP.forAllOrigin $ \origin -> TestLP.forAllBoundedProblem origin $ \bounds constrs -> QC.forAll (TestLP.genObjective origin) $ \dirObjA -> QC.forAll (TestLP.genObjective origin) $ \dirObjB -> let solA = LP.simplex method bounds constrs dirObjA in let solB = LP.simplex method bounds constrs dirObjB in QC.counterexample (show (mapRight fst solA, mapRight fst solB)) $ case (solA, solB) of (Right _, Right _) -> True (Left _, Left _) -> True _ -> False
forAllMethod $ \method -> TestLP.forAllOrigin $ \origin -> TestLP.forAllProblem origin $ \bounds constrs -> QC.forAll (TestLP.genObjective origin) $ \(_dir,obj) -> case (LP.simplex method bounds constrs (LP.Minimize,obj), LP.simplex method bounds constrs (LP.Maximize,obj)) of (Right (optMin,_), Right (optMax,_)) -> QC.counterexample (show (optMin, optMax)) $ optMin <= optMax + 0.01 _ -> QC.property False
forAllMethod $ \method -> TestLP.forAllOrigin $ \origin -> TestLP.forAllProblem origin $ \bounds allConstrs -> QC.forAll (QC.sublistOf allConstrs) $ \someConstrs -> QC.forAll (TestLP.genObjective origin) $ \(dir,obj) -> case (LP.simplex method bounds allConstrs (dir,obj), LP.simplex method bounds someConstrs (dir,obj)) of (Right (optAll,_), Right (optSome,_)) -> QC.counterexample (show (optAll, optSome)) $ case dir of LP.Minimize -> optAll >= optSome-0.01 LP.Maximize -> optAll <= optSome+0.01 _ -> QC.property False
forAllMethod $ \methodA -> forAllMethod $ \methodB -> TestLP.forAllOrigin $ \origin -> TestLP.forAllProblem origin $ \bounds constrs -> QC.forAll (TestLP.genObjective origin) $ \dirObj -> case (LP.simplex methodA bounds constrs dirObj, LP.simplex methodB bounds constrs dirObj) of (Right (optA,_), Right (optB,_)) -> QC.counterexample (show (optA, optB)) $ approxReal 0.01 optA optB _ -> QC.property False
concurrent :: (Coefficient a, Indexed sh, Index sh ~ ix) => T [] Method -> Bounds ix -> Constraints a ix -> (Direction, Objective sh) -> Result sh Source #
Run many solvers concurrently and take the result of the solver that finishes first.
Remember to run programs using concurrent
with threaded runtime and +RTS -N
runtime option.
>>>
case Shape.indexTupleFromShape tripletShape of (x,y,z) -> mapSnd Array.toTuple <$> LP.concurrent (LP.solveEndless!: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.forAllBoundedProblem origin $ \bounds constrs -> QC.forAll (TestLP.genObjective origin) $ \dirObj -> let solA = LP.simplex method bounds constrs dirObj in let solB = LP.concurrent (NonEmpty.singleton method) bounds constrs dirObj in QC.counterexample (show (mapRight fst solA, mapRight fst solB)) $ case (solA, solB) of (Right (optA,_), Right (optB,_)) -> approxReal 0.01 optA optB (Left _, Left _) -> True _ -> False
forAllMethod $ \method -> forAllMethod $ \methodA -> forAllMethod $ \methodB -> forAllMethod $ \methodC -> TestLP.forAllOrigin $ \origin -> TestLP.forAllBoundedProblem origin $ \bounds constrs -> QC.forAll (TestLP.genObjective origin) $ \dirObj -> let solA = LP.simplex method bounds constrs dirObj in let solB = LP.concurrent (methodA!:methodB:methodC:[]) bounds constrs dirObj in QC.counterexample (show (mapRight fst solA, mapRight fst solB)) $ case (solA, solB) of (Right (optA,_), Right (optB,_)) -> approxReal 0.01 optA optB (Left _, Left _) -> True _ -> False
Instances
Bounded Direction | |
Enum Direction | |
Defined in Numeric.LinearProgramming.Common succ :: Direction -> Direction # pred :: Direction -> Direction # fromEnum :: Direction -> Int # enumFrom :: Direction -> [Direction] # enumFromThen :: Direction -> Direction -> [Direction] # enumFromTo :: Direction -> Direction -> [Direction] # enumFromThenTo :: Direction -> Direction -> Direction -> [Direction] # | |
Show Direction | |
Eq Direction | |
data PlusMinusOne Source #
Instances
Show PlusMinusOne Source # | |
Defined in Numeric.COINOR.CLP showsPrec :: Int -> PlusMinusOne -> ShowS # show :: PlusMinusOne -> String # showList :: [PlusMinusOne] -> ShowS # | |
Eq PlusMinusOne Source # | |
Defined in Numeric.COINOR.CLP (==) :: PlusMinusOne -> PlusMinusOne -> Bool # (/=) :: PlusMinusOne -> PlusMinusOne -> Bool # |
Term a ix |
type Constraints a ix = [Inequality [Term a ix]] #
free :: x -> Inequality x #
(<=.) :: x -> Double -> Inequality x infix 4 #
(>=.) :: x -> Double -> Inequality x infix 4 #
(==.) :: x -> Double -> Inequality x infix 4 #
(>=<.) :: x -> (Double, Double) -> Inequality x infix 4 #
data FailureType Source #
Instances
Show FailureType Source # | |
Defined in Numeric.COINOR.CLP.Private showsPrec :: Int -> FailureType -> ShowS # show :: FailureType -> String # showList :: [FailureType] -> ShowS # | |
Eq FailureType Source # | |
Defined in Numeric.COINOR.CLP.Private (==) :: FailureType -> FailureType -> Bool # (/=) :: FailureType -> FailureType -> Bool # |