Safe Haskell | None |
---|
see usage in examples/Test3.hs
- data NLPFun = NLPFun {}
- data NLPState = NLPState {
- _nMax :: Ix
- _currentEnv :: [String]
- _variables :: Map String Ix
- _constraintLabels :: IntMap String
- _objLabels :: IntMap String
- _varLabels :: IntMap String
- _varEnv :: IntMap (Set [String])
- _constraintEnv :: IntMap [String]
- _objEnv :: IntMap [String]
- _nlpfun :: NLPFun
- _defaultBounds :: (Double, Double)
- _initX :: Vector Double
- newtype Ix = Ix {}
- nlpstate0 :: NLPState
- type NLPT = StateT NLPState
- type NLP = NLPT IO
- data AnyRF cb = AnyRF (forall a. RealFloat a => Vector a -> cb a)
- liftOp0 :: (forall a. RealFloat a => a) -> AnyRF Identity
- liftOp1 :: (forall a. RealFloat a => a -> a) -> AnyRF Identity -> AnyRF Identity
- liftOp2 :: (forall a. RealFloat a => a -> a -> a) -> AnyRF Identity -> AnyRF Identity -> AnyRF Identity
- funG :: Lens' NLPFun (AnyRF Seq)
- funF :: Lens' NLPFun (AnyRF Seq)
- boundX :: Lens' NLPFun (Seq (Double, Double))
- boundG :: Lens' NLPFun (Seq (Double, Double))
- varIx :: Iso' Ix Int
- variables :: Lens' NLPState (Map String Ix)
- varLabels :: Lens' NLPState (IntMap String)
- varEnv :: Lens' NLPState (IntMap (Set [String]))
- objLabels :: Lens' NLPState (IntMap String)
- objEnv :: Lens' NLPState (IntMap [String])
- nlpfun :: Lens' NLPState NLPFun
- nMax :: Lens' NLPState Ix
- initX :: Lens' NLPState (Vector Double)
- defaultBounds :: Lens' NLPState (Double, Double)
- currentEnv :: Lens' NLPState [String]
- constraintLabels :: Lens' NLPState (IntMap String)
- constraintEnv :: Lens' NLPState (IntMap [String])
- copyEnv :: MonadState NLPState m => ALens NLPState NLPState (IntMap [String]) (IntMap [String]) -> Key -> m ()
- addDesc :: MonadState s m => Setting (->) s s (IntMap a) (IntMap a) -> Maybe a -> Key -> m ()
- solveNLP' :: MonadIO m => (IpProblem -> IO ()) -> NLPT m IpOptSolved
- addG :: Monad m => Maybe String -> (Double, Double) -> AnyRF Identity -> NLPT m ()
- addF :: Monad m => Maybe String -> AnyRF Identity -> NLPT m ()
- var' :: (Monad m, Functor m) => Maybe (Double, Double) -> String -> NLPT m (AnyRF Identity, Ix)
- var :: (Monad m, Functor m) => Maybe (Double, Double) -> String -> StateT NLPState m (AnyRF Identity)
- varFresh :: (Monad m, Functor m) => Maybe (Double, Double) -> [Char] -> StateT NLPState m (AnyRF Identity)
- inEnv :: Monad m => String -> NLPT m a -> NLPT m a
- pushEnv :: Monad m => String -> NLPT m ()
- popEnv :: Monad m => NLPT m String
- setBounds :: Monad m => Ix -> (Double, Double) -> NLPT m ()
- narrowBounds :: Monad m => Ix -> (Double, Double) -> NLPT m ()
- seqToVecs :: MonadIO m => Seq (Double, Double) -> m (Vec, Vec)
state
NLPState | |
|
solver deals with arrays. This type is for indexes into the array for the current variables that the solver is trying to find.
the initial state to use when you actually have to get to IO with the solution
representing functions
this wrapper holds functions that can be used
for the objective (f
) or for constraints (g
). Many functions
in the instances provided are partial: this seems to be unavoidable
because the input variables haven't been decided yet, so you should
not be allowed to use compare
on these. But for now just use the
standard Prelude classes, and unimplementable functions (which
would not produce an AnyRF
) are calls to error
generate these using var
, or perhaps by directly using the constructor:
AnyRF $ Identity . V.sum
, would for example give the sum of all variables.
helpers for defining instances
liftOp2 :: (forall a. RealFloat a => a -> a -> a) -> AnyRF Identity -> AnyRF Identity -> AnyRF IdentitySource
low level lenses to NLPState
copyEnv :: MonadState NLPState m => ALens NLPState NLPState (IntMap [String]) (IntMap [String]) -> Key -> m ()Source
to
is one of varEnv
, constraintEnv
, objEnv
addDesc :: MonadState s m => Setting (->) s s (IntMap a) (IntMap a) -> Maybe a -> Key -> m ()Source
to
should be constraintLabels
, objLabels
, varLabels
high-level functions
:: MonadIO m | |
=> (IpProblem -> IO ()) | set ipopt options (using functions from Ipopt.Raw) |
-> NLPT m IpOptSolved |
calls createIpoptProblemAD
and ipoptSolve
. To be used at the
end of a do-block.
:: Monad m | |
=> Maybe String | optional description |
-> (Double, Double) | bounds |
-> AnyRF Identity | g_i(x) |
-> NLPT m () |
add a constraint
add a piece of the objective function, which is added in the form `f_1 + f_2 + ...`, to make it easier to understand (at some point) which components are responsible for the majority of the cost, and which are irrelevant.
:: (Monad m, Functor m) | |
=> Maybe (Double, Double) | bounds |
-> String | variable name (namespace from the |
-> NLPT m (AnyRF Identity, Ix) | the value, and index (into the raw vector of variables that the solver sees) |
add a variable, or get a reference to the the same variable if it has already been used
var :: (Monad m, Functor m) => Maybe (Double, Double) -> String -> StateT NLPState m (AnyRF Identity)Source
varFresh :: (Monad m, Functor m) => Maybe (Double, Double) -> [Char] -> StateT NLPState m (AnyRF Identity)Source
var
, except this causes the solver to get a new variable,
so that you can use:
[a,b,c,d,e] <- replicateM 5 (varFresh (Just (0, 10)) "x")
and the different letters can take different values (between 0 and 10)
in the optimal solution (depending on what you do with a
and similar
in the objective function).
namespace
When you build up an optimization problem, it may be composed of pieces. Functions in this section help to ease the pain of making unique variables. To illustrate:
m <- inEnv "A" (var b "x") n <- var b "A.x"
m
and n
above should refer to the same variable. In some sense this
is "better" that using varFresh
all the time, since perhaps you would
like to add dependencies between components (say the size of a header pipe,
refridgeration unit, foundation etc. has to satisfy sizes of individual
components).
bounds
setBounds :: Monad m => Ix -> (Double, Double) -> NLPT m ()Source
override bounds. Should be unnecessary given var
takes bounds.
narrowBounds :: Monad m => Ix -> (Double, Double) -> NLPT m ()Source
shrink the interval in which that variable is allowed.