{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE TypeOperators #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
module Numeric.COINOR.CLP.Monad (
T,
run,
simplex,
concurrent,
Direction(..),
Priv.dual, Priv.primal,
) where
import qualified Numeric.COINOR.CLP.FFI as FFI
import qualified Numeric.COINOR.CLP.Debug as Debug
import qualified Numeric.COINOR.CLP.Private as Priv
import Numeric.COINOR.CLP.Private
(Method(runMethod), Result,
runContT, withBuffer,
storeBounds, prepareRowBoundsArrays, prepareColumnBoundsArrays,
storeConstraints, prepareConstraints,
setOptimizationDirection, examineStatus)
import Numeric.LinearProgramming.Common
(Bounds, Constraints, Direction(..), Objective)
import qualified Data.Array.Comfort.Storable as Array
import qualified Data.Array.Comfort.Shape as Shape
import qualified Data.NonEmpty as NonEmpty
import Data.NonEmpty ((!:))
import Data.Traversable (for)
import Data.Foldable (traverse_)
import qualified Control.Concurrent.Split.MVar as MVar
import qualified Control.Concurrent as Conc
import qualified Control.Monad.Trans.RWS as MRWS
import Control.Monad.IO.Class (liftIO)
import Control.Monad (when)
import System.IO.Unsafe (unsafePerformIO)
import Foreign.Ptr (Ptr, nullPtr)
newtype T sh a = Cons (MRWS.RWST sh () (Ptr FFI.Simplex) IO a)
deriving ((forall a b. (a -> b) -> T sh a -> T sh b)
-> (forall a b. a -> T sh b -> T sh a) -> Functor (T sh)
forall a b. a -> T sh b -> T sh a
forall a b. (a -> b) -> T sh a -> T sh b
forall sh a b. a -> T sh b -> T sh a
forall sh a b. (a -> b) -> T sh a -> T sh b
forall (f :: * -> *).
(forall a b. (a -> b) -> f a -> f b)
-> (forall a b. a -> f b -> f a) -> Functor f
$cfmap :: forall sh a b. (a -> b) -> T sh a -> T sh b
fmap :: forall a b. (a -> b) -> T sh a -> T sh b
$c<$ :: forall sh a b. a -> T sh b -> T sh a
<$ :: forall a b. a -> T sh b -> T sh a
Functor, Functor (T sh)
Functor (T sh)
-> (forall a. a -> T sh a)
-> (forall a b. T sh (a -> b) -> T sh a -> T sh b)
-> (forall a b c. (a -> b -> c) -> T sh a -> T sh b -> T sh c)
-> (forall a b. T sh a -> T sh b -> T sh b)
-> (forall a b. T sh a -> T sh b -> T sh a)
-> Applicative (T sh)
forall sh. Functor (T sh)
forall a. a -> T sh a
forall sh a. a -> T sh a
forall a b. T sh a -> T sh b -> T sh a
forall a b. T sh a -> T sh b -> T sh b
forall a b. T sh (a -> b) -> T sh a -> T sh b
forall sh a b. T sh a -> T sh b -> T sh a
forall sh a b. T sh a -> T sh b -> T sh b
forall sh a b. T sh (a -> b) -> T sh a -> T sh b
forall a b c. (a -> b -> c) -> T sh a -> T sh b -> T sh c
forall sh a b c. (a -> b -> c) -> T sh a -> T sh b -> T sh c
forall (f :: * -> *).
Functor f
-> (forall a. a -> f a)
-> (forall a b. f (a -> b) -> f a -> f b)
-> (forall a b c. (a -> b -> c) -> f a -> f b -> f c)
-> (forall a b. f a -> f b -> f b)
-> (forall a b. f a -> f b -> f a)
-> Applicative f
$cpure :: forall sh a. a -> T sh a
pure :: forall a. a -> T sh a
$c<*> :: forall sh a b. T sh (a -> b) -> T sh a -> T sh b
<*> :: forall a b. T sh (a -> b) -> T sh a -> T sh b
$cliftA2 :: forall sh a b c. (a -> b -> c) -> T sh a -> T sh b -> T sh c
liftA2 :: forall a b c. (a -> b -> c) -> T sh a -> T sh b -> T sh c
$c*> :: forall sh a b. T sh a -> T sh b -> T sh b
*> :: forall a b. T sh a -> T sh b -> T sh b
$c<* :: forall sh a b. T sh a -> T sh b -> T sh a
<* :: forall a b. T sh a -> T sh b -> T sh a
Applicative, Applicative (T sh)
Applicative (T sh)
-> (forall a b. T sh a -> (a -> T sh b) -> T sh b)
-> (forall a b. T sh a -> T sh b -> T sh b)
-> (forall a. a -> T sh a)
-> Monad (T sh)
forall sh. Applicative (T sh)
forall a. a -> T sh a
forall sh a. a -> T sh a
forall a b. T sh a -> T sh b -> T sh b
forall a b. T sh a -> (a -> T sh b) -> T sh b
forall sh a b. T sh a -> T sh b -> T sh b
forall sh a b. T sh a -> (a -> T sh b) -> T sh b
forall (m :: * -> *).
Applicative m
-> (forall a b. m a -> (a -> m b) -> m b)
-> (forall a b. m a -> m b -> m b)
-> (forall a. a -> m a)
-> Monad m
$c>>= :: forall sh a b. T sh a -> (a -> T sh b) -> T sh b
>>= :: forall a b. T sh a -> (a -> T sh b) -> T sh b
$c>> :: forall sh a b. T sh a -> T sh b -> T sh b
>> :: forall a b. T sh a -> T sh b -> T sh b
$creturn :: forall sh a. a -> T sh a
return :: forall a. a -> T sh a
Monad)
run ::
(Shape.Indexed sh, Shape.Index sh ~ ix) =>
sh -> Bounds ix -> T sh a -> a
run :: forall sh ix a.
(Indexed sh, Index sh ~ ix) =>
sh -> Bounds ix -> T sh a -> a
run sh
shape Bounds ix
bounds (Cons RWST sh () (Ptr Simplex) IO a
act) =
IO a -> a
forall a. IO a -> a
unsafePerformIO (IO a -> a) -> IO a -> a
forall a b. (a -> b) -> a -> b
$ ContT a IO a -> IO a
forall a. ContT a IO a -> IO a
runContT (ContT a IO a -> IO a) -> ContT a IO a -> IO a
forall a b. (a -> b) -> a -> b
$ do
Ptr Simplex
lp <- IO (Ptr Simplex) -> ContT a IO (Ptr Simplex)
forall a. IO a -> ContT a IO a
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO IO (Ptr Simplex)
FFI.newModel
IO () -> ContT a IO ()
forall a. IO a -> ContT a IO a
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO () -> ContT a IO ()) -> IO () -> ContT a IO ()
forall a b. (a -> b) -> a -> b
$ Ptr Simplex -> IO ()
Debug.initLog Ptr Simplex
lp
Ptr BigIndex
startPtr <- Array (ZeroBased Int) BigIndex -> ContT a IO (Ptr BigIndex)
forall sh a r. Array sh a -> ContT r IO (Ptr a)
withBuffer (Array (ZeroBased Int) BigIndex -> ContT a IO (Ptr BigIndex))
-> Array (ZeroBased Int) BigIndex -> ContT a IO (Ptr BigIndex)
forall a b. (a -> b) -> a -> b
$ [BigIndex] -> Array (ZeroBased Int) BigIndex
forall a. Storable a => [a] -> Array (ZeroBased Int) a
Array.vectorFromList [BigIndex
0]
(Ptr CDouble
collbPtr,Ptr CDouble
colubPtr) <-
(Array sh CDouble, Array sh CDouble)
-> ContT a IO (Ptr CDouble, Ptr CDouble)
forall sh r.
(Array sh CDouble, Array sh CDouble)
-> ContT r IO (Ptr CDouble, Ptr CDouble)
storeBounds ((Array sh CDouble, Array sh CDouble)
-> ContT a IO (Ptr CDouble, Ptr CDouble))
-> (Array sh CDouble, Array sh CDouble)
-> ContT a IO (Ptr CDouble, Ptr CDouble)
forall a b. (a -> b) -> a -> b
$ sh -> Bounds ix -> (Array sh CDouble, Array sh CDouble)
forall sh ix.
(Indexed sh, Index sh ~ ix) =>
sh -> Bounds ix -> (Array sh CDouble, Array sh CDouble)
prepareColumnBoundsArrays sh
shape Bounds ix
bounds
IO a -> ContT a IO a
forall a. IO a -> ContT a IO a
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO a -> ContT a IO a) -> IO a -> ContT a IO a
forall a b. (a -> b) -> a -> b
$ do
Ptr Simplex
-> CInt
-> Ptr CDouble
-> Ptr CDouble
-> Ptr CDouble
-> Ptr BigIndex
-> Ptr CInt
-> Ptr CDouble
-> IO ()
FFI.addColumns Ptr Simplex
lp (Int -> CInt
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Int -> CInt) -> Int -> CInt
forall a b. (a -> b) -> a -> b
$ sh -> Int
forall sh. C sh => sh -> Int
Shape.size sh
shape)
Ptr CDouble
collbPtr Ptr CDouble
colubPtr Ptr CDouble
forall a. Ptr a
nullPtr
Ptr BigIndex
startPtr Ptr CInt
forall a. Ptr a
nullPtr Ptr CDouble
forall a. Ptr a
nullPtr
(a
a, Ptr Simplex
lpFinal, ()) <- RWST sh () (Ptr Simplex) IO a
-> sh -> Ptr Simplex -> IO (a, Ptr Simplex, ())
forall r w s (m :: * -> *) a.
RWST r w s m a -> r -> s -> m (a, s, w)
MRWS.runRWST RWST sh () (Ptr Simplex) IO a
act sh
shape Ptr Simplex
lp
Ptr Simplex -> IO ()
FFI.deleteModel Ptr Simplex
lpFinal
a -> IO a
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return a
a
simplex ::
(Eq sh, Shape.Indexed sh, Shape.Index sh ~ ix) =>
Method -> Constraints Double ix ->
(Direction, Objective sh) -> T sh (Result sh)
simplex :: forall sh ix.
(Eq sh, Indexed sh, Index sh ~ ix) =>
Method
-> Constraints Double ix
-> (Direction, Objective sh)
-> T sh (Result sh)
simplex Method
method Constraints Double ix
constrs (Direction
dir,Objective sh
obj) = RWST sh () (Ptr Simplex) IO (Result sh) -> T sh (Result sh)
forall sh a. RWST sh () (Ptr Simplex) IO a -> T sh a
Cons (RWST sh () (Ptr Simplex) IO (Result sh) -> T sh (Result sh))
-> RWST sh () (Ptr Simplex) IO (Result sh) -> T sh (Result sh)
forall a b. (a -> b) -> a -> b
$ do
sh
shape <- RWST sh () (Ptr Simplex) IO sh
forall w (m :: * -> *) r s. (Monoid w, Monad m) => RWST r w s m r
MRWS.ask
Ptr Simplex
lp <- RWST sh () (Ptr Simplex) IO (Ptr Simplex)
forall w (m :: * -> *) r s. (Monoid w, Monad m) => RWST r w s m s
MRWS.get
IO (Result sh) -> RWST sh () (Ptr Simplex) IO (Result sh)
forall a. IO a -> RWST sh () (Ptr Simplex) IO a
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO (Result sh) -> RWST sh () (Ptr Simplex) IO (Result sh))
-> IO (Result sh) -> RWST sh () (Ptr Simplex) IO (Result sh)
forall a b. (a -> b) -> a -> b
$ do
Ptr Simplex
-> sh
-> Constraints Double ix
-> (Direction, Objective sh)
-> IO ()
forall sh ix.
(Eq sh, Indexed sh, Index sh ~ ix) =>
Ptr Simplex
-> sh
-> Constraints Double ix
-> (Direction, Objective sh)
-> IO ()
storeStage Ptr Simplex
lp sh
shape Constraints Double ix
constrs (Direction
dir,Objective sh
obj)
Method -> Ptr Simplex -> IO ()
runMethod Method
method Ptr Simplex
lp
sh -> Ptr Simplex -> IO (Result sh)
forall sh. C sh => sh -> Ptr Simplex -> IO (Result sh)
examineStatus sh
shape Ptr Simplex
lp
concurrent ::
(Eq sh, Shape.Indexed sh, Shape.Index sh ~ ix) =>
NonEmpty.T [] Method -> Constraints Double ix ->
(Direction, Objective sh) -> T sh (Result sh)
concurrent :: forall sh ix.
(Eq sh, Indexed sh, Index sh ~ ix) =>
T [] Method
-> Constraints Double ix
-> (Direction, Objective sh)
-> T sh (Result sh)
concurrent (NonEmpty.Cons Method
method [Method]
methods) Constraints Double ix
constrs (Direction
dir,Objective sh
obj) =
RWST sh () (Ptr Simplex) IO (Result sh) -> T sh (Result sh)
forall sh a. RWST sh () (Ptr Simplex) IO a -> T sh a
Cons (RWST sh () (Ptr Simplex) IO (Result sh) -> T sh (Result sh))
-> RWST sh () (Ptr Simplex) IO (Result sh) -> T sh (Result sh)
forall a b. (a -> b) -> a -> b
$ (sh -> Ptr Simplex -> IO (Result sh, Ptr Simplex, ()))
-> RWST sh () (Ptr Simplex) IO (Result sh)
forall r w s (m :: * -> *) a.
(r -> s -> m (a, s, w)) -> RWST r w s m a
MRWS.RWST ((sh -> Ptr Simplex -> IO (Result sh, Ptr Simplex, ()))
-> RWST sh () (Ptr Simplex) IO (Result sh))
-> (sh -> Ptr Simplex -> IO (Result sh, Ptr Simplex, ()))
-> RWST sh () (Ptr Simplex) IO (Result sh)
forall a b. (a -> b) -> a -> b
$ \sh
shape Ptr Simplex
lp -> do
Ptr Simplex
-> sh
-> Constraints Double ix
-> (Direction, Objective sh)
-> IO ()
forall sh ix.
(Eq sh, Indexed sh, Index sh ~ ix) =>
Ptr Simplex
-> sh
-> Constraints Double ix
-> (Direction, Objective sh)
-> IO ()
storeStage Ptr Simplex
lp sh
shape Constraints Double ix
constrs (Direction
dir,Objective sh
obj)
[Ptr Simplex]
lps <-
[Method] -> (Method -> IO (Ptr Simplex)) -> IO [Ptr Simplex]
forall (t :: * -> *) (f :: * -> *) a b.
(Traversable t, Applicative f) =>
t a -> (a -> f b) -> f (t b)
for [Method]
methods ((Method -> IO (Ptr Simplex)) -> IO [Ptr Simplex])
-> (Method -> IO (Ptr Simplex)) -> IO [Ptr Simplex]
forall a b. (a -> b) -> a -> b
$ IO (Ptr Simplex) -> Method -> IO (Ptr Simplex)
forall a b. a -> b -> a
const (IO (Ptr Simplex) -> Method -> IO (Ptr Simplex))
-> IO (Ptr Simplex) -> Method -> IO (Ptr Simplex)
forall a b. (a -> b) -> a -> b
$ do
Ptr Simplex
newLp <- Ptr Simplex -> IO (Ptr Simplex)
FFI.copyModel Ptr Simplex
lp
Ptr Simplex -> IO ()
Debug.initLog Ptr Simplex
newLp
Ptr Simplex -> IO (Ptr Simplex)
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return Ptr Simplex
newLp
(In (Ptr Simplex)
resultIn, Out (Ptr Simplex)
resultOut) <- IO (In (Ptr Simplex), Out (Ptr Simplex))
forall a. IO (In a, Out a)
MVar.newEmpty
T [] ThreadId
threads <-
T [] (Method, Ptr Simplex)
-> ((Method, Ptr Simplex) -> IO ThreadId) -> IO (T [] ThreadId)
forall (t :: * -> *) (f :: * -> *) a b.
(Traversable t, Applicative f) =>
t a -> (a -> f b) -> f (t b)
for ((Method
method,Ptr Simplex
lp) (Method, Ptr Simplex)
-> [(Method, Ptr Simplex)] -> T [] (Method, Ptr Simplex)
forall a (f :: * -> *). a -> f a -> T f a
!: [Method] -> [Ptr Simplex] -> [(Method, Ptr Simplex)]
forall a b. [a] -> [b] -> [(a, b)]
zip [Method]
methods [Ptr Simplex]
lps) (((Method, Ptr Simplex) -> IO ThreadId) -> IO (T [] ThreadId))
-> ((Method, Ptr Simplex) -> IO ThreadId) -> IO (T [] ThreadId)
forall a b. (a -> b) -> a -> b
$ \(Method
methodi,Ptr Simplex
lpi) ->
IO () -> IO ThreadId
Conc.forkIO (IO () -> IO ThreadId) -> IO () -> IO ThreadId
forall a b. (a -> b) -> a -> b
$ do
Method -> Ptr Simplex -> IO ()
runMethod Method
methodi Ptr Simplex
lpi
In (Ptr Simplex) -> Ptr Simplex -> IO ()
forall a. In a -> a -> IO ()
MVar.put In (Ptr Simplex)
resultIn Ptr Simplex
lpi
Ptr Simplex
lpWinner <- Out (Ptr Simplex) -> IO (Ptr Simplex)
forall a. Out a -> IO a
MVar.take Out (Ptr Simplex)
resultOut
(ThreadId -> IO ()) -> T [] ThreadId -> IO ()
forall (t :: * -> *) (f :: * -> *) a b.
(Foldable t, Applicative f) =>
(a -> f b) -> t a -> f ()
traverse_ ThreadId -> IO ()
Conc.killThread T [] ThreadId
threads
(Ptr Simplex -> IO ()) -> [Ptr Simplex] -> IO ()
forall (t :: * -> *) (f :: * -> *) a b.
(Foldable t, Applicative f) =>
(a -> f b) -> t a -> f ()
traverse_ Ptr Simplex -> IO ()
FFI.deleteModel ([Ptr Simplex] -> IO ()) -> [Ptr Simplex] -> IO ()
forall a b. (a -> b) -> a -> b
$ (Ptr Simplex -> Bool) -> [Ptr Simplex] -> [Ptr Simplex]
forall a. (a -> Bool) -> [a] -> [a]
filter (Ptr Simplex
lpWinnerPtr Simplex -> Ptr Simplex -> Bool
forall a. Eq a => a -> a -> Bool
/=) ([Ptr Simplex] -> [Ptr Simplex]) -> [Ptr Simplex] -> [Ptr Simplex]
forall a b. (a -> b) -> a -> b
$ Ptr Simplex
lpPtr Simplex -> [Ptr Simplex] -> [Ptr Simplex]
forall a. a -> [a] -> [a]
:[Ptr Simplex]
lps
(Result sh -> (Result sh, Ptr Simplex, ()))
-> IO (Result sh) -> IO (Result sh, Ptr Simplex, ())
forall a b. (a -> b) -> IO a -> IO b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (\Result sh
result -> (Result sh
result, Ptr Simplex
lpWinner, ())) (IO (Result sh) -> IO (Result sh, Ptr Simplex, ()))
-> IO (Result sh) -> IO (Result sh, Ptr Simplex, ())
forall a b. (a -> b) -> a -> b
$
sh -> Ptr Simplex -> IO (Result sh)
forall sh. C sh => sh -> Ptr Simplex -> IO (Result sh)
examineStatus sh
shape Ptr Simplex
lpWinner
storeStage ::
(Eq sh, Shape.Indexed sh, Shape.Index sh ~ ix) =>
Ptr FFI.Simplex -> sh ->
Constraints Double ix -> (Direction, Objective sh) -> IO ()
storeStage :: forall sh ix.
(Eq sh, Indexed sh, Index sh ~ ix) =>
Ptr Simplex
-> sh
-> Constraints Double ix
-> (Direction, Objective sh)
-> IO ()
storeStage Ptr Simplex
lp sh
shape Constraints Double ix
constrs (Direction
dir,Objective sh
obj) = do
Bool -> IO () -> IO ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
when (sh
shape sh -> sh -> Bool
forall a. Eq a => a -> a -> Bool
/= Objective sh -> sh
forall sh a. Array sh a -> sh
Array.shape Objective sh
obj) (IO () -> IO ()) -> IO () -> IO ()
forall a b. (a -> b) -> a -> b
$
[Char] -> IO ()
forall a. HasCallStack => [Char] -> a
error [Char]
"COINOR.CLP.Monad.solve: objective shape mismatch"
ContT () IO () -> IO ()
forall a. ContT a IO a -> IO a
runContT (ContT () IO () -> IO ()) -> ContT () IO () -> IO ()
forall a b. (a -> b) -> a -> b
$ do
(Ptr CDouble
coefficientsPtr, Ptr CInt
indexPtr, Ptr BigIndex
startPtr) <-
(Array (ZeroBased Int) CDouble, Array (ZeroBased Int) CInt,
Array (ZeroBased Int) BigIndex)
-> ContT () IO (Ptr CDouble, Ptr CInt, Ptr BigIndex)
forall r.
(Array (ZeroBased Int) CDouble, Array (ZeroBased Int) CInt,
Array (ZeroBased Int) BigIndex)
-> ContT r IO (Ptr CDouble, Ptr CInt, Ptr BigIndex)
storeConstraints ((Array (ZeroBased Int) CDouble, Array (ZeroBased Int) CInt,
Array (ZeroBased Int) BigIndex)
-> ContT () IO (Ptr CDouble, Ptr CInt, Ptr BigIndex))
-> (Array (ZeroBased Int) CDouble, Array (ZeroBased Int) CInt,
Array (ZeroBased Int) BigIndex)
-> ContT () IO (Ptr CDouble, Ptr CInt, Ptr BigIndex)
forall a b. (a -> b) -> a -> b
$ sh
-> Constraints Double ix
-> (Array (ZeroBased Int) CDouble, Array (ZeroBased Int) CInt,
Array (ZeroBased Int) BigIndex)
forall sh ix.
(Indexed sh, Index sh ~ ix) =>
sh
-> Constraints Double ix
-> (Array (ZeroBased Int) CDouble, Array (ZeroBased Int) CInt,
Array (ZeroBased Int) BigIndex)
prepareConstraints sh
shape Constraints Double ix
constrs
(Ptr CDouble
rowlbPtr,Ptr CDouble
rowubPtr) <- (Array (ZeroBased Int) CDouble, Array (ZeroBased Int) CDouble)
-> ContT () IO (Ptr CDouble, Ptr CDouble)
forall sh r.
(Array sh CDouble, Array sh CDouble)
-> ContT r IO (Ptr CDouble, Ptr CDouble)
storeBounds ((Array (ZeroBased Int) CDouble, Array (ZeroBased Int) CDouble)
-> ContT () IO (Ptr CDouble, Ptr CDouble))
-> (Array (ZeroBased Int) CDouble, Array (ZeroBased Int) CDouble)
-> ContT () IO (Ptr CDouble, Ptr CDouble)
forall a b. (a -> b) -> a -> b
$ Constraints Double ix
-> (Array (ZeroBased Int) CDouble, Array (ZeroBased Int) CDouble)
forall ix.
Bounds ix
-> (Array (ZeroBased Int) CDouble, Array (ZeroBased Int) CDouble)
prepareRowBoundsArrays Constraints Double ix
constrs
Ptr CDouble
objPtr <- Array sh CDouble -> ContT () IO (Ptr CDouble)
forall sh a r. Array sh a -> ContT r IO (Ptr a)
withBuffer (Array sh CDouble -> ContT () IO (Ptr CDouble))
-> Array sh CDouble -> ContT () IO (Ptr CDouble)
forall a b. (a -> b) -> a -> b
$ (Double -> CDouble) -> Objective sh -> Array sh CDouble
forall sh a b.
(C sh, Storable a, Storable b) =>
(a -> b) -> Array sh a -> Array sh b
Array.map Double -> CDouble
forall a b. (Real a, Fractional b) => a -> b
realToFrac Objective sh
obj
IO () -> ContT () IO ()
forall a. IO a -> ContT () IO a
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO () -> ContT () IO ()) -> IO () -> ContT () IO ()
forall a b. (a -> b) -> a -> b
$ do
Ptr Simplex
-> CInt
-> Ptr CDouble
-> Ptr CDouble
-> Ptr BigIndex
-> Ptr CInt
-> Ptr CDouble
-> IO ()
FFI.addRows Ptr Simplex
lp (Int -> CInt
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Int -> CInt) -> Int -> CInt
forall a b. (a -> b) -> a -> b
$ Constraints Double ix -> Int
forall a. [a] -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
length Constraints Double ix
constrs)
Ptr CDouble
rowlbPtr Ptr CDouble
rowubPtr Ptr BigIndex
startPtr Ptr CInt
indexPtr Ptr CDouble
coefficientsPtr
Ptr Simplex -> Ptr CDouble -> IO ()
FFI.chgObjCoefficients Ptr Simplex
lp Ptr CDouble
objPtr
Ptr Simplex -> Direction -> IO ()
setOptimizationDirection Ptr Simplex
lp Direction
dir