agentlib_mpc.modules.deactivate_mpc package

Submodules

agentlib_mpc.modules.deactivate_mpc.deactivate_mpc module

class agentlib_mpc.modules.deactivate_mpc.deactivate_mpc.MPCOnOff(*, config: dict, agent: Agent)[source]

Bases: BaseModule

activate_mpc()[source]

Performs mpc activation. Sends activation signal, as well as the public active message.

check_mpc_deactivation() bool[source]

This function can be overridden, to define conditions based on which an MPC module within this agent should be deactivated. Returns True if MPC should be deactivated, and False if it should be active.

deactivate_mpc()[source]

Performs mpc deactivation. Sends the deactivation signal, as well as default control signals.

process()[source]

This abstract method must be implemented in order to sync the module with the other processes of the agent and the whole MAS.

register_callbacks()[source]

This function can be overridden to check the deactivation in an event-based manner.

pydantic model agentlib_mpc.modules.deactivate_mpc.deactivate_mpc.MPCOnOffConfig[source]

Bases: BaseModuleConfig

Config:
  • arbitrary_types_allowed: bool = True

  • validate_assignment: bool = True

  • extra: str = forbid

  • frozen: bool = True

Fields:
Validators:
field active: AgentVariable = AgentVariable(name='MPC_FLAG_ACTIVE', type='bool', timestamp=None, unit='Not defined', description='MPC is active', ub=inf, lb=-inf, clip=False, allowed_values=[], value=True, alias='MPC_FLAG_ACTIVE', source=Source(agent_id=None, module_id=None), shared=False, rdf_class=None)

Variable used to activate or deactivate the MPC operation

field controls_when_deactivated: List[AgentVariable] = []

List of AgentVariables to send as Fallback Controls.

field inputs: List[AgentVariable] = []

Inputs based on which switch decisions can be made.

field public_active_message: AgentVariable | None = None

If needed, specify an AgentVariable that is sent when the MPC is active, for example to suppress a local controller.

field public_inactive_message: AgentVariable | None = None

If needed, specify an AgentVariable that is sent when the MPC is inactive, for example to awaken a local controller.

field shared_variable_fields: list[str] = ['public_active_message', 'controls_when_deactivated']
Validated by:
  • check_valid_fields

field t_sample: float = 60

Sends the active variable every other t_sample

model_post_init(context: Any, /) None

This function is meant to behave like a BaseModel method to initialise private attributes.

It takes context as an argument since that’s what pydantic-core passes when calling it.

Parameters:
  • self – The BaseModel instance.

  • context – The context.

class agentlib_mpc.modules.deactivate_mpc.deactivate_mpc.SkipMPCInIntervals(*, config: dict, agent: Agent)[source]

Bases: MPCOnOff

Module which deactivates any MPC by sending the variable active in the specified intervals.

check_mpc_deactivation() bool[source]

This function can be overridden, to define conditions based on which an MPC module within this agent should be deactivated. Returns True if MPC should be deactivated, and False if it should be active.

pydantic model agentlib_mpc.modules.deactivate_mpc.deactivate_mpc.SkipMPCInIntervalsConfig[source]

Bases: MPCOnOffConfig

Config for a module which deactivates any MPC by sending the variable active in the specified intervals.

Config:
  • arbitrary_types_allowed: bool = True

  • validate_assignment: bool = True

  • extra: str = forbid

  • frozen: bool = True

Fields:
Validators:

field intervals: list[tuple[float, float]] = []

If environment time is within these intervals

field time_unit: Literal['seconds', 'minutes', 'hours', 'days'] = 'seconds'

Specifies the unit of the given skip_mpc_in_intervals, e.g. seconds or days.

model_post_init(context: Any, /) None

This function is meant to behave like a BaseModel method to initialise private attributes.

It takes context as an argument since that’s what pydantic-core passes when calling it.

Parameters:
  • self – The BaseModel instance.

  • context – The context.

agentlib_mpc.modules.deactivate_mpc.fallback_pid module

class agentlib_mpc.modules.deactivate_mpc.fallback_pid.FallbackPID(*, config: FallbackPIDConfig, agent: Agent)[source]

Bases: PID

PID controller active only when the MPC (indicated by mpc_active_flag) is inactive. Simplified error handling. Assumes configuration and data are valid. Resets integral state and timing upon activation/deactivation.

pydantic model agentlib_mpc.modules.deactivate_mpc.fallback_pid.FallbackPIDConfig[source]

Bases: PIDConfig

Config for FallbackPID: Adds the MPC active flag.

Config:
  • arbitrary_types_allowed: bool = True

  • validate_assignment: bool = True

  • extra: str = forbid

  • frozen: bool = True

Fields:
Validators:

field mpc_active_flag: AgentVariable = AgentVariable(name='MPC_FLAG_ACTIVE', type='bool', timestamp=None, unit='Not defined', description='Not defined', ub=inf, lb=-inf, clip=False, allowed_values=[], value=True, alias='MPC_FLAG_ACTIVE', source=Source(agent_id=None, module_id=None), shared=None, rdf_class=None)

Boolean variable indicating if MPC is active (True=MPC active, PID inactive).

model_post_init(context: Any, /) None

This function is meant to behave like a BaseModel method to initialise private attributes.

It takes context as an argument since that’s what pydantic-core passes when calling it.

Parameters:
  • self – The BaseModel instance.

  • context – The context.