Created
November 3, 2014 14:31
-
-
Save ghorn/d82b88e14fbb1d08036e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| {-# OPTIONS_GHC -Wall #-} | |
| {-# Language DeriveGeneric #-} | |
| {-# Language DeriveFunctor #-} | |
| module Main where | |
| import GHC.Generics ( Generic ) | |
| import Data.Vector ( Vector ) | |
| import qualified Data.Vector as V | |
| import Dyno.TypeVecs | |
| import Dyno.View | |
| import Dyno.Vectorize | |
| import Dyno.Nlp | |
| import Dyno.Nats | |
| import Dyno.NlpSolver | |
| import Dyno.Solvers | |
| data X a = X a a deriving (Functor, Generic, Generic1, Show) | |
| data U a = U a deriving (Functor, Generic, Generic1, Show) | |
| instance Vectorize X | |
| instance Vectorize U | |
| data G n a = G (J (JVec n (JV X)) a) deriving (Generic, Generic1, Show) | |
| data Dvs n a = Dvs | |
| (J (JVec n (JTuple (JV X) (JV U))) a) | |
| (J (JV X) a) | |
| deriving (Generic, Generic1, Show) | |
| instance Dim n => View (Dvs n) | |
| instance Dim n => View (G n) | |
| data IntegratorIn a = IntegratorIn (J (JV X) a) (J (JV U) a) | |
| deriving (Generic, Generic1) | |
| data IntegratorOut a = IntegratorOut (J (JV X) a) | |
| deriving (Generic, Generic1) | |
| instance Scheme IntegratorIn | |
| instance Scheme IntegratorOut | |
| dt :: Floating a => a | |
| dt = 0.1 | |
| makeNlp :: IO (Nlp' (Dvs D20) JNone (G D20) MX) | |
| makeNlp = do | |
| integrator <- toMXFun "my integrator" $ \(IntegratorIn x0 u) -> IntegratorOut (x0 + dt*x0) | |
| let _ = integrator :: MXFun IntegratorIn IntegratorOut -- just for type signature | |
| let nlp = | |
| Nlp' | |
| { nlpFG' = fg | |
| , nlpBX' = bx | |
| , nlpBG' = bg | |
| , nlpX0' = x0 | |
| , nlpP' = cat JNone | |
| , nlpLamX0' = Nothing | |
| , nlpLamG0' = Nothing | |
| , nlpScaleF' = Nothing | |
| , nlpScaleX' = Nothing | |
| , nlpScaleG' = Nothing | |
| } | |
| x0 :: J (Dvs D20) (V.Vector Double) | |
| x0 = undefined | |
| bx :: J (Dvs D20) (Vector Bounds) | |
| bx = undefined | |
| bg :: J (G D20) (Vector Bounds) | |
| bg = undefined | |
| fg :: J (Dvs D20) MX -> J JNone MX -> (J S MX, J (G D20) MX) | |
| fg dvs _ = (f, cat g) | |
| where | |
| Dvs xus xf = split dvs | |
| x1s :: Vec D20 (J (JV X) MX) | |
| x1s = fmap (integrate . split) $ unJVec $ (split xus) | |
| integrate (JTuple x0 u) = x1 | |
| where | |
| IntegratorOut x1 = callMXFun integrator (IntegratorIn x0 u) | |
| f = undefined | |
| g :: G D20 MX | |
| g = undefined | |
| return nlp | |
| main :: IO () | |
| main = do | |
| myNlp <- makeNlp | |
| opt <- solveNlp' ipoptSolver myNlp Nothing | |
| print opt |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment