commonpower.control.safety_layer.safety_layers.ActionProjectionSafetyLayer
- class ActionProjectionSafetyLayer(penalty: BasePenalty, solver: OptSolver | None = None)[source]
Bases:
ActionReplacementWithOptSafetyLayerComputes safe action by minimizing the distance between the RL action and the safe action while also satisfying constraints.
- Parameters:
penalty (BasePenalty) – class defining the penalty behavior for unsafe actions
solver (OptSolver, optional) – solver for optimization problem, defaults to direct gurobi https://pyomo.readthedocs.io/en/stable/library_reference/solvers/gurobi_direct.html
- Returns:
ActionReplacementSafetyLayer
Methods
action_distanceEuclidean norm between action expressed by the model and the action in dict
compute_safe_actionChecks whether the actions proposed by the controller satisfy the constraints of the controlled entities and replaces by pyomo-generated output if necessary.
get_penaltyGet penalty depending on the penalty class used.
initializeInitializes the safety layer :param nodes: list of controlled entities to be safeguarded :type nodes: List[ModelEntity] :param top_level_nodes: list of controlled entities in highest level of model tree :type top_level_nodes: List[ModelEntity] :param solver: solver for optimization problem which will be called by Pyomo :type solver: OptSolver
As feasibility check is quite costly, we can skip for projection layer as we check action distance to the original action after optimization
Prepare model.
set_action_from_modelCorrects an action according to a model.
set_action_in_modelSets the model values to the action to initialize the optimization.
solve_modelFinds a feasible action by solving a local model.
Attributes
DISTANCE_EPS