Skip to content

Agent

Package defining agent related functionality.

ResourceManagementActuator

Bases: Actuator

Actuator class that will be part of a ScheduledAgent or any other agent that controls the evolution of the resource management task.

Source code in matbii\tasks\resource_management\resource_management.py
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
class ResourceManagementActuator(Actuator):
    """Actuator class that will be part of a `ScheduledAgent` or any other agent that controls the evolution of the resource management task."""

    @attempt
    def burn_fuel(
        self,
        target: int | str,
        burn: float,
    ) -> "BurnFuelAction":
        """Burns a given amount of fuel in the `target` tank, if the tank is empty this has no effect.

        Args:
            target (int | Literal["a", "b"]): target tank
            burn (float): amount of fuel to burn.

        Returns:
            BurnFuelAction: the action
        """
        return BurnFuelAction(target=target, burn=burn)

    @attempt
    def pump_fuel(
        self,
        target: int | str,
        flow: float,
    ) -> "PumpFuelAction":
        """Pumps the given amount of fuel via the given pump.

        Args:
            target (int | Literal["ab", "ba", "ca", "ec", "ea", "db", "fd", "fb"]): target pump (this will determine which tanks are pumped to/from).
            flow (float): amount of fuel to pump.

        Returns:
            PumpFuelAction: the action
        """
        return PumpFuelAction(target=target, flow=flow)

    @attempt
    def toggle_pump_failure(
        self,
        target: int | str,
    ) -> "TogglePumpFailureAction":
        """Toggle a pump failure (on/off -> failure, failure -> off).

        Args:
            target (int | Literal["ab", "ba", "ca", "ec", "ea", "db", "fd", "fb"]): target pump.

        Returns:
            TogglePumpFailureAction: the action
        """
        return TogglePumpFailureAction(target=target)

    @attempt
    def toggle_pump(
        self,
        target: int | str,
    ) -> "TogglePumpAction":
        """Toggle pump state (on -> off, off -> on).

        Args:
            target (int | Literal["ab", "ba", "ca", "ec", "ea", "db", "fd", "fb"]): target pump.

        Returns:
            TogglePumpFailureAction: the action
        """
        return TogglePumpAction(target=target)

burn_fuel(target, burn)

Burns a given amount of fuel in the target tank, if the tank is empty this has no effect.

Parameters:

Name Type Description Default
target int | Literal['a', 'b']

target tank

required
burn float

amount of fuel to burn.

required

Returns:

Name Type Description
BurnFuelAction BurnFuelAction

the action

Source code in matbii\tasks\resource_management\resource_management.py
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
@attempt
def burn_fuel(
    self,
    target: int | str,
    burn: float,
) -> "BurnFuelAction":
    """Burns a given amount of fuel in the `target` tank, if the tank is empty this has no effect.

    Args:
        target (int | Literal["a", "b"]): target tank
        burn (float): amount of fuel to burn.

    Returns:
        BurnFuelAction: the action
    """
    return BurnFuelAction(target=target, burn=burn)

pump_fuel(target, flow)

Pumps the given amount of fuel via the given pump.

Parameters:

Name Type Description Default
target int | Literal['ab', 'ba', 'ca', 'ec', 'ea', 'db', 'fd', 'fb']

target pump (this will determine which tanks are pumped to/from).

required
flow float

amount of fuel to pump.

required

Returns:

Name Type Description
PumpFuelAction PumpFuelAction

the action

Source code in matbii\tasks\resource_management\resource_management.py
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
@attempt
def pump_fuel(
    self,
    target: int | str,
    flow: float,
) -> "PumpFuelAction":
    """Pumps the given amount of fuel via the given pump.

    Args:
        target (int | Literal["ab", "ba", "ca", "ec", "ea", "db", "fd", "fb"]): target pump (this will determine which tanks are pumped to/from).
        flow (float): amount of fuel to pump.

    Returns:
        PumpFuelAction: the action
    """
    return PumpFuelAction(target=target, flow=flow)

toggle_pump(target)

Toggle pump state (on -> off, off -> on).

Parameters:

Name Type Description Default
target int | Literal['ab', 'ba', 'ca', 'ec', 'ea', 'db', 'fd', 'fb']

target pump.

required

Returns:

Name Type Description
TogglePumpFailureAction TogglePumpAction

the action

Source code in matbii\tasks\resource_management\resource_management.py
158
159
160
161
162
163
164
165
166
167
168
169
170
171
@attempt
def toggle_pump(
    self,
    target: int | str,
) -> "TogglePumpAction":
    """Toggle pump state (on -> off, off -> on).

    Args:
        target (int | Literal["ab", "ba", "ca", "ec", "ea", "db", "fd", "fb"]): target pump.

    Returns:
        TogglePumpFailureAction: the action
    """
    return TogglePumpAction(target=target)

toggle_pump_failure(target)

Toggle a pump failure (on/off -> failure, failure -> off).

Parameters:

Name Type Description Default
target int | Literal['ab', 'ba', 'ca', 'ec', 'ea', 'db', 'fd', 'fb']

target pump.

required

Returns:

Name Type Description
TogglePumpFailureAction TogglePumpFailureAction

the action

Source code in matbii\tasks\resource_management\resource_management.py
143
144
145
146
147
148
149
150
151
152
153
154
155
156
@attempt
def toggle_pump_failure(
    self,
    target: int | str,
) -> "TogglePumpFailureAction":
    """Toggle a pump failure (on/off -> failure, failure -> off).

    Args:
        target (int | Literal["ab", "ba", "ca", "ec", "ea", "db", "fd", "fb"]): target pump.

    Returns:
        TogglePumpFailureAction: the action
    """
    return TogglePumpFailureAction(target=target)

SystemMonitoringActuator

Bases: Actuator

Actuator class that will be part of a ScheduledAgent or any other agent that controls the evolution of the system monitoring task.

Source code in matbii\tasks\system_monitoring\system_monitoring.py
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
@agent_actuator
class SystemMonitoringActuator(Actuator):
    """Actuator class that will be part of a `ScheduledAgent` or any other agent that controls the evolution of the system monitoring task."""

    @attempt
    def on_light(self, target: int) -> "SetLightAction":
        """Switch the `target` light to the "on" state.

        Args:
            target (int): the integer `id` of the target light (1 or 2).

        Returns:
            SetLightAction: the action
        """
        return SetLightAction(target=target, state=SetLightAction.ON)

    @attempt
    def off_light(self, target: int) -> "SetLightAction":
        """Switch the `target` light to the "off" state.

        Args:
            target (int): the integer `id` of the target light (1 or 2).

        Returns:
            SetLightAction: the action
        """
        return SetLightAction(target=target, state=SetLightAction.OFF)

    @attempt
    def toggle_light(self, target: int) -> "SetLightAction":
        """Toggle the `target` light (on->off, off->on).

        Args:
            target (int): the integer `id` of the target light (1 or 2).

        Returns:
            SetLightAction: the action
        """
        return ToggleLightAction(target=target)

    @attempt
    def perturb_slider(self, target: int) -> "SetSliderAction":
        """Perturb the `target` slider by +/- 1 slot.

        Args:
            target (int): the integer `id` of the target slider (1, 2, 3 or 4).

        Returns:
            SetSliderAction: the action
        """
        state = 2 * random.randint(0, 1) - 1  # randomly perturb +/- 1
        return SetSliderAction(target=target, state=state, relative=True)

off_light(target)

Switch the target light to the "off" state.

Parameters:

Name Type Description Default
target int

the integer id of the target light (1 or 2).

required

Returns:

Name Type Description
SetLightAction SetLightAction

the action

Source code in matbii\tasks\system_monitoring\system_monitoring.py
146
147
148
149
150
151
152
153
154
155
156
@attempt
def off_light(self, target: int) -> "SetLightAction":
    """Switch the `target` light to the "off" state.

    Args:
        target (int): the integer `id` of the target light (1 or 2).

    Returns:
        SetLightAction: the action
    """
    return SetLightAction(target=target, state=SetLightAction.OFF)

on_light(target)

Switch the target light to the "on" state.

Parameters:

Name Type Description Default
target int

the integer id of the target light (1 or 2).

required

Returns:

Name Type Description
SetLightAction SetLightAction

the action

Source code in matbii\tasks\system_monitoring\system_monitoring.py
134
135
136
137
138
139
140
141
142
143
144
@attempt
def on_light(self, target: int) -> "SetLightAction":
    """Switch the `target` light to the "on" state.

    Args:
        target (int): the integer `id` of the target light (1 or 2).

    Returns:
        SetLightAction: the action
    """
    return SetLightAction(target=target, state=SetLightAction.ON)

perturb_slider(target)

Perturb the target slider by +/- 1 slot.

Parameters:

Name Type Description Default
target int

the integer id of the target slider (1, 2, 3 or 4).

required

Returns:

Name Type Description
SetSliderAction SetSliderAction

the action

Source code in matbii\tasks\system_monitoring\system_monitoring.py
170
171
172
173
174
175
176
177
178
179
180
181
@attempt
def perturb_slider(self, target: int) -> "SetSliderAction":
    """Perturb the `target` slider by +/- 1 slot.

    Args:
        target (int): the integer `id` of the target slider (1, 2, 3 or 4).

    Returns:
        SetSliderAction: the action
    """
    state = 2 * random.randint(0, 1) - 1  # randomly perturb +/- 1
    return SetSliderAction(target=target, state=state, relative=True)

toggle_light(target)

Toggle the target light (on->off, off->on).

Parameters:

Name Type Description Default
target int

the integer id of the target light (1 or 2).

required

Returns:

Name Type Description
SetLightAction SetLightAction

the action

Source code in matbii\tasks\system_monitoring\system_monitoring.py
158
159
160
161
162
163
164
165
166
167
168
@attempt
def toggle_light(self, target: int) -> "SetLightAction":
    """Toggle the `target` light (on->off, off->on).

    Args:
        target (int): the integer `id` of the target light (1 or 2).

    Returns:
        SetLightAction: the action
    """
    return ToggleLightAction(target=target)

TrackingActuator

Bases: Actuator

Actuator class that will be part of a ScheduledAgent or any other agent that controls the evolution of the tracking task.

Source code in matbii\tasks\tracking\tracking.py
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
class TrackingActuator(Actuator):
    """Actuator class that will be part of a `ScheduledAgent` or any other agent that controls the evolution of the tracking task."""

    @attempt
    def move_target(
        self, direction: tuple[float, float] | int | float, speed: float
    ) -> "TargetMoveAction":
        """Move the tracking target in a given direction at a given speed.

        Args:
            direction (tuple[float, float] | int | float): direction to move.
            speed (float): speed to move (svg units per call to this function) # TODO perhaps this should be per second!

        Returns:
            TargetMoveAction: the action to move the tracking target.
        """
        # an angle was provided (in degrees), convert it to a direction vector
        if isinstance(direction, int | float):
            angle = math.radians(direction)
            direction = (math.sin(angle), math.cos(angle))
        return TargetMoveAction(direction=direction, speed=speed)

    @attempt
    def perturb_target(self, speed: float) -> "TargetMoveAction":
        """Move the tracking target in a random direction at a given speed.

        Args:
            speed (float): speed to move (svg units per call to this function) # TODO perhaps this should be per second!

        Returns:
            TargetMoveAction: the action to move the tracking target.
        """
        angle = (random.random() * 2 - 1) * math.pi
        direction = (math.sin(angle), math.cos(angle))
        return TargetMoveAction(direction=direction, speed=speed)

move_target(direction, speed)

Move the tracking target in a given direction at a given speed.

Parameters:

Name Type Description Default
direction tuple[float, float] | int | float

direction to move.

required
speed float

speed to move (svg units per call to this function) # TODO perhaps this should be per second!

required

Returns:

Name Type Description
TargetMoveAction TargetMoveAction

the action to move the tracking target.

Source code in matbii\tasks\tracking\tracking.py
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
@attempt
def move_target(
    self, direction: tuple[float, float] | int | float, speed: float
) -> "TargetMoveAction":
    """Move the tracking target in a given direction at a given speed.

    Args:
        direction (tuple[float, float] | int | float): direction to move.
        speed (float): speed to move (svg units per call to this function) # TODO perhaps this should be per second!

    Returns:
        TargetMoveAction: the action to move the tracking target.
    """
    # an angle was provided (in degrees), convert it to a direction vector
    if isinstance(direction, int | float):
        angle = math.radians(direction)
        direction = (math.sin(angle), math.cos(angle))
    return TargetMoveAction(direction=direction, speed=speed)

perturb_target(speed)

Move the tracking target in a random direction at a given speed.

Parameters:

Name Type Description Default
speed float

speed to move (svg units per call to this function) # TODO perhaps this should be per second!

required

Returns:

Name Type Description
TargetMoveAction TargetMoveAction

the action to move the tracking target.

Source code in matbii\tasks\tracking\tracking.py
121
122
123
124
125
126
127
128
129
130
131
132
133
@attempt
def perturb_target(self, speed: float) -> "TargetMoveAction":
    """Move the tracking target in a random direction at a given speed.

    Args:
        speed (float): speed to move (svg units per call to this function) # TODO perhaps this should be per second!

    Returns:
        TargetMoveAction: the action to move the tracking target.
    """
    angle = (random.random() * 2 - 1) * math.pi
    direction = (math.sin(angle), math.cos(angle))
    return TargetMoveAction(direction=direction, speed=speed)