API Reference¶
This page is auto-generated from the source code and is intended to be used as an API reference. See Quickstart Guide to get started the easy way.
MetaOptimizationProblem¶
-
class
rtc_tools_meta.meta_optimization_problem.MetaOptimizationProblem(**kwargs)[source]¶ Bases:
rtctools.optimization.optimization_problem.OptimizationProblemAn optimization problem of aggregated submodels and a global objective
Use this class to define a meta optimization problem. A meta problem consists of
submodels, which interact viavariable_mappings.To optimize the meta model, call the
optimize()method. This will:- Optimize aggregated model
- Impose interface constraints on submodels
- Optimize submodels
Results will be located in their respective submodel
outputdirectories.-
interface_variables¶ Tuple of interface variables
Note: This property is extracted from
self.variable_mappingsReturn type: Tuple[str]
-
meta_objective()[source]¶ Symbolic expression to be minimized
For example, here is a quadratic minimization objective:
def meta_objective(self): return ca.sum1(self.states_in("ModelA::var_name")) ** 2.0
Return type: MX
-
optimize(preprocessing=True, postprocessing=True, log_solver_failure_as_error=True)[source]¶ Perform one initialize-transcribe-solve-finalize cycle.
Parameters: - preprocessing – True to enable a call to
prepreceding the optimization. - postprocessing – True to enable a call to
postfollowing the optimization.
Returns: True on success.
- preprocessing – True to enable a call to
-
pop_submodel(variable)[source]¶ Function to split submodel name from variable
The submodel a variable is stored in is indicated by preceding that variable’s name with the model name, seperated by
::. For example,>>> self.pop_submodel("submodel_name::variable_name") ("submodel_name", "variable_name") >>> self.pop_submodel("submodelA_name::submodelB_name::variable_name") ("submodelA_name", "submodelB_name::variable_name") # Nested models
Parameters: variable ( str) – Submodel name and variable name in a single stringReturn type: Tuple[str,str]Returns: Submodel name and variable name as separate strings Raises: AssertionError, ValueError
-
submodels¶ Dictionary of submodels
This variable is where we store the submodel instances. The models are indexed by a unique short name. For example:
# Meta Problem Optimizing ModelA and ModelB submodels = { "ModelA": collect_model_instance('ModelA', path_to_a), "ModelB": collect_model_instance('ModelB', path_to_b), }
Return type: Dict[str,OptimizationProblem]
-
variable_mappings¶ Mappings that constrain variables in separate submodels to be equal
To define how submodels interact with each other, we set
variable_mappingsequal to a list of 3-tuples. The 3-tuples have the structure (var1, var2, sign). For example:# Meta Problem Optimizing ModelA and ModelB variable_mappings = [ ( "ModelA::some_variable", "ModelB::another_variable", "-", # Either "-" (if vars are equal) or "+" (if they sum to 0) ) ]
Return type: List[Tuple[str,str,str]]
MetaMixin¶
-
class
rtc_tools_meta.meta_mixin.MetaMixin(**kwargs)[source]¶ Bases:
rtctools.optimization.optimization_problem.OptimizationProblemAdds Compatibility with MetaOptimizationProblem models
This mixin allows MetaOptimizationProblem models to assimilate your RTC-Tools model into its meta problem and impose constraints back onto your model. Resistance is futile.