# Path: rawe/utils/codegen.py
# def makeJobs():
# def memoizeFiles(genfiles,prefix=''):
#         def doAssertions(blah):
# def writeDifferentFiles(path,gfs):
#             def writeFile():
# def _getExportPath(genfiles,prefix):
# def flattenFileDict(fd,prefix=''):
# def directoryToDict(top):
# def withTempdir(command):
# def writeCCode(f, name):
#     def callme(tmpdir):
# 
# Path: rawe/utils/subprocess_tee.py
# def call(args, cwd = '.'):
# 
# Path: rawe/utils/options.py
# class Options(object):
#     '''
#     To use this, subclass Options and call .add() with a bunch of options.
#     Then the use __setitem__ to set options.
#     '''
#     def __init__(self,name):
#         self._name = name
#         self._options = {}
# 
#     def _assertValidName(self,name):
#         assert type(name) == str, 'option key must be a string, you gave: '+str(name)
#         assert name in self._options, '"'+name+'" is not a valid option\n'+\
#             'valid options: '+str(sorted(self._options.keys()))
# 
#     def add(self,opt):
#         assert isinstance(opt, Option)
#         name = opt.name()
#         assert name not in self._options, self._name+' already has Option '+str(name)
#         opt._parentName = self._name
#         self._options[name] = opt
# 
#     def __setitem__(self,name,value):
#         self._assertValidName(name)
#         self._options[name].setVal(value)
# 
#     def __getitem__(self,key):
#         self._assertValidName(key)
#         return self._options[key].getOutputVal()
# 
#     def getAcadoOpts(self):
#         ret = {}
#         for name,opt in self._options.iteritems():
#             ret[name] = opt.toAcadoStr()
#         return ret
# 
# class OptStr(Option):
#     def __init__(self, name, opts, default=None):
#         self._legalOptions = opts
#         if default is not None:
#             self._assertLegalOption(default)
#         Option.__init__(self,name,str,default)
# 
#     def _assertLegalOption(self,value):
#         assert value in self._legalOptions, self.prettyName()+' must be in '+\
#             str(self._legalOptions)+', you gave: '+str(value)
# 
#     def setVal(self,value):
#         self._assertLegalOption(value)
#         Option.setVal(self,value)
# 
#     def toAcadoStr(self):
#         return self.getOutputVal()
# 
# class OptInt(Option):
#     def __init__(self, name, default=None):
#         Option.__init__(self,name,int,default)
# 
#     def toAcadoStr(self):
#         return repr(self.getOutputVal())
# 
# class OptBool(Option):
#     def __init__(self, name, default=None):
#         Option.__init__(self,name,bool,default)
# 
#     def toAcadoStr(self):
#         if self.getOutputVal():
#             return 'YES'
#         else:
#             return 'NO'


import ctypes
import numpy
import casadi as C
import matplotlib.pyplot as plt
from rtIntegratorExport import exportIntegrator
from ..utils import codegen, subprocess_tee
from ..utils.options import Options, OptStr, OptInt, OptBool
#
# rawesome is free software: you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# rawesome is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with rawesome.  If not, see <http://www.gnu.org/licenses/>.





class RtIntegratorOptions(Options):
    def __init__(self):
        Options.__init__(self, 'RtIntegrator')
        self.add(OptStr('LINEAR_ALGEBRA_SOLVER',['GAUSS_LU','HOUSEHOLDER_QR'],default='GAUSS_LU'))
        self.add(OptInt('NUM_INTEGRATOR_STEPS',default=1))
        integratorTypes = \
            ['INT_EX_EULER',
             'INT_RK2','INT_RK3','INT_RK4',
             'INT_IRK_GL2','INT_IRK_GL4','INT_IRK_GL6','INT_IRK_GL8',
             'INT_IRK_RIIA1','INT_IRK_RIIA3','INT_IRK_RIIA5',
             'INT_DIRK3','INT_DIRK4','INT_DIRK5',
             'INT_DT','INT_NARX']

# Path: rawe/utils/codegen.py
# def makeJobs():
# def memoizeFiles(genfiles,prefix=''):
#         def doAssertions(blah):
# def writeDifferentFiles(path,gfs):
#             def writeFile():
# def _getExportPath(genfiles,prefix):
# def flattenFileDict(fd,prefix=''):
# def directoryToDict(top):
# def withTempdir(command):
# def writeCCode(f, name):
#     def callme(tmpdir):
# 
# Path: rawe/utils/subprocess_tee.py
# def call(args, cwd = '.'):
# 
# Path: rawe/utils/options.py
# class Options(object):
#     '''
#     To use this, subclass Options and call .add() with a bunch of options.
#     Then the use __setitem__ to set options.
#     '''
#     def __init__(self,name):
#         self._name = name
#         self._options = {}
# 
#     def _assertValidName(self,name):
#         assert type(name) == str, 'option key must be a string, you gave: '+str(name)
#         assert name in self._options, '"'+name+'" is not a valid option\n'+\
#             'valid options: '+str(sorted(self._options.keys()))
# 
#     def add(self,opt):
#         assert isinstance(opt, Option)
#         name = opt.name()
#         assert name not in self._options, self._name+' already has Option '+str(name)
#         opt._parentName = self._name
#         self._options[name] = opt
# 
#     def __setitem__(self,name,value):
#         self._assertValidName(name)
#         self._options[name].setVal(value)
# 
#     def __getitem__(self,key):
#         self._assertValidName(key)
#         return self._options[key].getOutputVal()
# 
#     def getAcadoOpts(self):
#         ret = {}
#         for name,opt in self._options.iteritems():
#             ret[name] = opt.toAcadoStr()
#         return ret
# 
# class OptStr(Option):
#     def __init__(self, name, opts, default=None):
#         self._legalOptions = opts
#         if default is not None:
#             self._assertLegalOption(default)
#         Option.__init__(self,name,str,default)
# 
#     def _assertLegalOption(self,value):
#         assert value in self._legalOptions, self.prettyName()+' must be in '+\
#             str(self._legalOptions)+', you gave: '+str(value)
# 
#     def setVal(self,value):
#         self._assertLegalOption(value)
#         Option.setVal(self,value)
# 
#     def toAcadoStr(self):
#         return self.getOutputVal()
# 
# class OptInt(Option):
#     def __init__(self, name, default=None):
#         Option.__init__(self,name,int,default)
# 
#     def toAcadoStr(self):
#         return repr(self.getOutputVal())
# 
# class OptBool(Option):
#     def __init__(self, name, default=None):
#         Option.__init__(self,name,bool,default)
# 
#     def toAcadoStr(self):
#         if self.getOutputVal():
#             return 'YES'
#         else:
#             return 'NO'


# Path: rawe/rtIntegrator/rtIntegrator.py
import ctypes
import numpy
import casadi as C
import matplotlib.pyplot as plt
from rtIntegratorExport import exportIntegrator
from ..utils import codegen, subprocess_tee
from ..utils.options import Options, OptStr, OptInt, OptBool

#
# rawesome is free software: you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# rawesome is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with rawesome.  If not, see <http://www.gnu.org/licenses/>.





class RtIntegratorOptions(Options):
    def __init__(self):
        Options.__init__(self, 'RtIntegrator')
        self.add(OptStr('LINEAR_ALGEBRA_SOLVER',['GAUSS_LU','HOUSEHOLDER_QR'],default='GAUSS_LU'))
        self.add(OptInt('NUM_INTEGRATOR_STEPS',default=1))
        integratorTypes = \
            ['INT_EX_EULER',
             'INT_RK2','INT_RK3','INT_RK4',
             'INT_IRK_GL2','INT_IRK_GL4','INT_IRK_GL6','INT_IRK_GL8',
             'INT_IRK_RIIA1','INT_IRK_RIIA3','INT_IRK_RIIA5',
             'INT_DIRK3','INT_DIRK4','INT_DIRK5',
             'INT_DT','INT_NARX']

        self.add(OptStr('INTEGRATOR_TYPE',integratorTypes,default='INT_IRK_GL4'))