Esempio n. 1
0
 def _set(self, name, value):
     """ 
     Set the value of an independent parameter and recompute dependents.
     
     Parameters::
         
         name -- 
             The name of the parameter to set.
             Type: string
             
         value -- 
             The new parameter value.
             Type: float
     
     Raises::
         
         XMLException if name not present in model or if variable is not an
         independent parameter.
     """
     try:
         variable = self.ocp.variable(name)
     except RuntimeError:
         raise XMLException("Could not find variable: " + name)
     if variable.getVariability() != casadi.PARAMETER:
         raise XMLException(name + " is not a parameter.")
     if variable.getFree():
         raise XMLException(name + " is a free parameter.")
     if variable.getCategory() == casadi.CAT_DEPENDENT_PARAMETER:
         raise XMLException(name + " is a dependent parameter.")
     variable.setStart(value)
Esempio n. 2
0
 def _get(self, name):
     """
     Get the value of a non-free parameter or a constant.
     
     Parameters::
         
         name -- 
             The name of the parameter or constant to get.
             Type: string
     
     Returns::
         
         value --
             Parameter or constant value.
             Type: float
     
     Raises::
         
         XMLException if name not present in model or if variable is not a
         non-free parameter or a constant.
     
     Example::
         
         CasadiModel.get('damper.d')
         CasadiModel.get(['damper.d', 'gear.a'])
     """
     try:
         variable = self.ocp.variable(name)
     except RuntimeError:
         raise XMLException("Could not find variable: " + name)
     if (variable.getVariability() != casadi.PARAMETER and
         variable.getVariability() != casadi.CONSTANT):
         raise XMLException(name + " is neither a parameter nor a " +
                            "constant.")
     if variable.getFree():
         raise XMLException(name + " is a free parameter.")
     return variable.getStart()
Esempio n. 3
0
 def _set_nominal(self, name, value):
     """ 
     Set the nominal value of a variable.
     
     Parameters::
         
         name -- 
             The names of the variable to set a new nominal value for.
             Type: string
             
         value -- 
             The new nominal value.
             Type: float
     
     Raises::
         
         XMLException if name not present in model.
     """
     try:
         variable = self.ocp.variable(name)
     except RuntimeError:
         raise XMLException("Could not find variable: " + name)
     variable.setNominal(value)