Safe Haskell | None |
---|
see usage in examples/Test3.hs
(and other examples)
IPOPT does support naming variables if you use c++
(by overriding a virtual void finalize_metadata
), but
it's not clear that we can set that from c/haskell
- data NLPFun = NLPFun {}
- data NLPState = NLPState {
- _nMax :: Ix
- _currentEnv :: [String]
- _variables :: Map String Ix
- _variablesInv :: IxMap String
- _constraintLabels :: IntMap String
- _objLabels :: IntMap String
- _varLabels :: IxMap String
- _varEnv :: IxMap (Set [String])
- _constraintEnv :: IntMap [String]
- _objEnv :: IntMap [String]
- _nlpfun :: NLPFun
- _defaultBounds :: (Double, Double)
- _defaultConstraintTol :: (Double, Double)
- _constraintTol :: Seq (Double, Double)
- _initX :: Vector Double
- newtype IxMap a = IxMap (IntMap a)
- newtype Ix = Ix {}
- nlpstate0 :: NLPState
- type NLPT = StateT NLPState
- type NLP = NLPT IO
- 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
- variablesInv :: Lens' NLPState (IxMap String)
- variables :: Lens' NLPState (Map String Ix)
- varLabels :: Lens' NLPState (IxMap String)
- varEnv :: Lens' NLPState (IxMap (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)
- defaultConstraintTol :: Lens' NLPState (Double, Double)
- defaultBounds :: Lens' NLPState (Double, Double)
- currentEnv :: Lens' NLPState [String]
- constraintTol :: Lens' NLPState (Seq (Double, Double))
- constraintLabels :: Lens' NLPState (IntMap String)
- constraintEnv :: Lens' NLPState (IntMap [String])
- ixMap :: forall a a. Iso (IntMap a) (IntMap a) (IxMap a) (IxMap a)
- ix_ :: Applicative f => Ix -> (a -> f a) -> IxMap a -> f (IxMap a)
- at_ :: Functor f => Ix -> (Maybe a -> f (Maybe a)) -> IxMap a -> f (IxMap a)
- 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' :: (Vector v Double, MonadIO m) => (IpProblem -> IO ()) -> NLPT m (IpOptSolved v)
- 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) -> Maybe String -> String -> NLPT m Ix
- var :: (Monad m, Functor m) => Maybe (Double, Double) -> String -> StateT NLPState m (AnyRF Identity)
- varFresh' :: (Monad m, Functor m) => Maybe (Double, Double) -> String -> NLPT m Ix
- varFresh :: (Monad m, Functor m) => Maybe (Double, Double) -> String -> 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
- splitVar :: (Monad m, Functor m) => Double -> Ix -> NLPT m (AnyRF Identity, AnyRF Identity)
- ixToVar :: Ix -> AnyRF Identity
- 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 | |
|
the 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
low level lenses to NLPState
ix_ :: Applicative f => Ix -> (a -> f a) -> IxMap a -> f (IxMap a)Source
should be a way to write an instance of At that'll make the normal atix work with the IxMap Ix (as opposed to IntMap/Int)
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
:: (Vector v Double, MonadIO m) | |
=> (IpProblem -> IO ()) | set ipopt options (using functions from Ipopt.Raw) |
-> NLPT m (IpOptSolved v) |
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 |
-> Maybe String | optional longer description |
-> String | variable name (namespace from the |
-> NLPT m Ix | the index (into the rawvector 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) -> String -> NLPT m IxSource
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 and other constraints).
varFresh :: (Monad m, Functor m) => Maybe (Double, Double) -> String -> StateT NLPState m (AnyRF Identity)Source
see varFresh'
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).
piecewise linear
see for example chapter 20 of http://www.ampl.com/BOOK/download.html
and use of the splines package in examples/Test4
and examples/Test5
:: (Monad m, Functor m) | |
=> Double | b |
-> Ix | index for |
-> NLPT m (AnyRF Identity, AnyRF Identity) | (b-x)_+, (x-b)_+ |
splits a variable x
into two positive variables such that
x = x^+ - x^-
the new variables represent the positive and negative
parts of x - b
(xMinus, xPlus) <- splitVar b x
Using max (x-b) 0
instead of xPlus (ie. not telling the solver that b
is
a special point) seems to work just as well
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.