Firefighting
One recorded episode planned by PFT-DPW, replayed in 3D. Drag to orbit, scroll to zoom, and use the bar to play, scrub and switch camera.
FirefightingPOMDP puts N firefighters on an R x C
grid and asks them to put out a fire that spreads under a hidden, constant
wind. The firefighters see the fire only near themselves, carry a finite tank of
suppressant, and take heat damage for standing in flames. The task is complete
when no cell is burning.
The wind is never observed. It has to be inferred from how the fire spreads, while the firefighters decide where to look, where to spray, and when to go back to the depot to refill. Use it to test planning over a large joint action space with a belief over a whole map.
What the agent sees and does
State — one
float64vector of length3 + 4N + R*C: the step counter,(row, col, tank, health)per firefighter, the wind direction and strength, then one category per cell (0unburnt to4wet). Length 111 at the defaults.Actions (discrete) — one
intin[0, 5 ** N). Its base-5 digits, least significant first, are the per-firefighter actionsNORTH(0),EAST(1),SOUTH(2),WEST(3),SUPPRESS(4). 25 actions at the default two firefighters.Observations (discrete) — one
float64vector of length4N + R*C: exact(row, col, tank, health)per firefighter, then a noisy category per cell withinsensing_radiusof a live firefighter and-1(unknown) everywhere else. The wind never appears.
Formal definition
The environment is the POMDP \(\langle S, A, Z, T, O, R, b_0, \gamma
\rangle\). Names in typewriter font are constructor arguments of
FirefightingPOMDP; \(\{0..n\}\) is the integers \(0\) to
\(n\).
State space. The notation:
Grid. \(H\) =
num_rowsrows and \(W\) =num_colscolumns. A cell is \(k = (y, z)\), row \(y\) (0 at the top) and column \(z\) (0 at the left). The cells are \(K = \{0..H{-}1\} \times \{0..W{-}1\}\), in row-major order.Obstacles. \(\mathcal{B} \subseteq K\) =
obstacle_cells; the free cells are \(\overline{\mathcal{B}} = K \setminus \mathcal{B}\).Firefighters. \(M\) =
num_firefighters, indexed \(j = 1..M\).Categories. \(\mathcal{C} = \{\textsf{UNBURNT}, \textsf{SMOLDERING}, \textsf{BURNING}, \textsf{BURNT}, \textsf{WET}\}\), coded \(0..4\) in that order.
Directions. \(D = \{\textsf{N}, \textsf{E}, \textsf{S}, \textsf{W}\}\), coded \(0..3\) in that order: \(\textsf{N}\) is toward row 0, \(\textsf{E}\) toward higher columns, \(\textsf{S}\) toward higher rows, \(\textsf{W}\) toward column 0.
A state holds:
\(t\), the step count.
For each firefighter \(j\): its cell \(p_j \in \overline{\mathcal{B}}\), its sprays left \(\text{tank}_j\), and its health \(\text{hp}_j\).
The hidden wind: its direction \(w_{\text{dir}} \in D\), the way it blows toward, and its strength \(w_{\text{str}} \in \{\textsf{LOW}, \textsf{HIGH}\}\). The wind lies in \(\Theta = D \times \{\textsf{LOW}, \textsf{HIGH}\}\).
\(f_k \in \mathcal{C}\), the category of each cell \(k\).
Action space. There are \(M\) = num_firefighters firefighters.
A joint action \(a\) packs one digit \(a_j \in \{0..4\}\) per
firefighter \(j\), least significant first:
Firefighter \(j\) is live while its health \(\text{hp}_j > 0\), and disabled once \(\text{hp}_j = 0\). For a live firefighter at cell \((y, z)\) (row \(y\) from the top, column \(z\) from the left):
\(a_j = 0\) (north) moves to \((y{-}1, z)\);
\(1\) (east) to \((y, z{+}1)\);
\(2\) (south) to \((y{+}1, z)\);
\(3\) (west) to \((y, z{-}1)\);
\(4\) (\(\textsf{SUPPRESS}\)) stays and, if it has sprays left (\(\text{tank}_j > 0\)), sprays its own cell and the up to four neighbouring cells one step north, east, south and west of it that lie on the grid of
num_rowsbynum_colscells.
A disabled firefighter’s digit is ignored.
Observation space. An observation lists, for each of the \(M\) =
num_firefighters firefighters \(j\), its cell \(p_j\), its sprays
left \(\text{tank}_j\) and its health \(\text{hp}_j\), where a cell is
a pair \((y, z)\), row \(y\) from the top and column \(z\) from the
left; then, for every
cell \(k\) of the grid \(K = \{0..H{-}1\} \times \{0..W{-}1\}\)
(\(H\) = num_rows, \(W\) = num_cols), a reported category
\(\hat f_k\):
Here \(\overline{\mathcal{B}}\) is the cells of \(K\) not in
obstacle_cells and \(\mathcal{C} = \{\textsf{UNBURNT}, \textsf{SMOLDERING},
\textsf{BURNING}, \textsf{BURNT}, \textsf{WET}\}\), coded \(0..4\). The
firefighter fields are exact for every firefighter, including one whose health
is zero.
\(\hat f_k\) is a reported category, possibly
different from the cell’s true category, for a cell within Chebyshev distance sensing_radius of the
cell \(p_j\) of a firefighter with health above zero, and \(\textsf{UNKNOWN}\) (coded
\(-1\)) for every other cell; \(\textsf{UNKNOWN}\) is not in
\(\mathcal{C}\). The step count and the wind are not observed.
Transition model. \(T\) maps the state \(s\) and the joint action \(a\) to the successor \(s'\); a prime marks a component of \(s'\). The components of \(s\) are:
the step count \(t\);
for each of the \(M\) =
num_firefightersfirefighters \(j = 1..M\): its cell \(p_j\), sprays left \(\text{tank}_j\) and health \(\text{hp}_j\);the hidden wind’s direction \(w_{\text{dir}} \in D\) and strength \(w_{\text{str}} \in \{\textsf{LOW}, \textsf{HIGH}\}\);
each cell \(k\)’s category \(f_k \in \mathcal{C} = \{\textsf{UNBURNT}, \textsf{SMOLDERING}, \textsf{BURNING}, \textsf{BURNT}, \textsf{WET}\}\).
The model also uses:
Actions. Firefighter \(j\)’s action is the digit \(a_j = \lfloor a / 5^{j-1} \rfloor \bmod 5\) of the joint action \(a \in A = \{0..5^M{-}1\}\). The firefighter is live while \(\text{hp}_j > 0\).
Cells. A cell is \(k = (y, z)\), row \(y\) from the top and column \(z\) from the left, in the grid \(K = \{0..H{-}1\} \times \{0..W{-}1\}\) (\(H\) =
num_rows, \(W\) =num_cols).Obstacles. \(\mathcal{B}\) =
obstacle_cellsand \(\overline{\mathcal{B}} = K \setminus \mathcal{B}\).Directions. \(D = \{\textsf{N}, \textsf{E}, \textsf{S}, \textsf{W}\}\), coded \(0..3\) in that order, with offsets \(\Delta_{\textsf{N}} = (-1, 0)\), \(\Delta_{\textsf{E}} = (0, 1)\), \(\Delta_{\textsf{S}} = (1, 0)\), \(\Delta_{\textsf{W}} = (0, -1)\), added to or subtracted from a cell \((y, z)\) componentwise.
Neighbours. \(\mathcal{N}(k) = \{k + \Delta_d : d \in D\} \cap K\) are the neighbours of \(k\).
One step, in this order; all draws are independent.
Motion. For \(a_j \in \{0..3\}\) let \(u_j = p_j + \Delta_{a_j}\). If firefighter \(j\) is live, \(u_j \in \overline{\mathcal{B}}\) and \(f_{u_j} \neq \textsf{BURNT}\), then \(p'_j = u_j\) w.p. \(1 - \sigma\) and \(p'_j = p_j\) w.p. \(\sigma\), with \(\sigma\) =
slip_probability. Otherwise \(p'_j = p_j\).Suppression. Action digit \(4\) is \(\textsf{SUPPRESS}\). The sprayers are \(J = \{j : \text{hp}_j > 0,\; a_j = 4,\; \text{tank}_j > 0\}\), and \(c_k\) is the number of sprayers with \(k \in \{p'_j\} \cup \mathcal{N}(p'_j)\). Cell \(k\) turns \(\textsf{WET}\), giving the map \(\mathbf{f}^{\text{sup}}\), w.p.
\[1 - \big(1 - q(f_k)\big)^{c_k}\]with \(q(\textsf{UNBURNT})\), \(q(\textsf{SMOLDERING})\), \(q(\textsf{BURNING})\) =
suppression_probability_unburnt,_smoldering,_burning, and \(q(\textsf{BURNT}) = q(\textsf{WET}) = 0\). Then, with \(k_{\text{dep}}\) =depot_cell, \(\text{tank}'_j = \texttt{max\_tank}\) if \(p'_j = k_{\text{dep}}\), else \(\text{tank}_j - \mathbb{1}[j \in J]\).Spread. A cell is alight if its category is in \(\mathcal{A}\ell = \{\textsf{SMOLDERING}, \textsf{BURNING}\}\). A cell \(k \notin \mathcal{B}\) with \(f^{\text{sup}}_k = \textsf{UNBURNT}\) becomes \(\textsf{SMOLDERING}\) w.p.
\[\begin{split}&1 - \prod_{\nu \in \mathcal{N}(k),\; f^{\text{sup}}_\nu \in \mathcal{A}\ell} \big(1 - p_{\text{ign}}(\nu, k)\big), \\ &p_{\text{ign}}(\nu, k) = \begin{cases} \min\!\big(1,\; \lambda\, g(w_{\text{str}})\big) & k - \nu = \Delta_{w_{\text{dir}}} \\ \lambda\, (1 - \texttt{crosswind\_attenuation}) & \text{otherwise} \end{cases}\end{split}\]with \(\lambda\) =
spread_probability, \(g(\textsf{LOW})\) =wind_gain_low, \(g(\textsf{HIGH})\) =wind_gain_high. The case \(k - \nu = \Delta_{w_{\text{dir}}}\) is the neighbour \(\nu\) directly upwind of \(k\).Growth and burnout. A cell with \(f^{\text{sup}}_k = \textsf{SMOLDERING}\) becomes \(\textsf{BURNING}\) w.p.
growth_probability; one with \(f^{\text{sup}}_k = \textsf{BURNING}\) becomes \(\textsf{BURNT}\) w.p.burnout_probability. Every other cell keeps its category from the spread, giving \(\mathbf{f}'\).Heat damage. \(\text{hp}'_j = \max\big(0,\; \text{hp}_j - \mathrm{dmg}(f'_{p'_j})\big)\), with \(\mathrm{dmg}(\textsf{SMOLDERING}) = 1\), \(\mathrm{dmg}(\textsf{BURNING}) = 2\), and \(0\) otherwise.
Clock and wind. \(t' = t + 1\); the wind is unchanged.
Observation model. \(O\) gives the observation from the successor state \(s'\). The model uses:
Firefighters. In \(s'\), firefighter \(j \in \{1..M\}\), of the \(M\) =
num_firefighters, is at cell \(p'_j = (y'_j, z'_j)\) with sprays left \(\text{tank}'_j\) and health \(\text{hp}'_j\).Cells. Cell \(k = (y, z)\) of the grid \(K\) (row \(y\), column \(z\)) has category \(f'_k \in \mathcal{C} = \{\textsf{UNBURNT}, \textsf{SMOLDERING}, \textsf{BURNING}, \textsf{BURNT}, \textsf{WET}\}\).
Settings. \(\rho\) =
sensing_radiusand \(p_{\text{err}}\) =observation_error_probability.
The visible cells are those within Chebyshev distance \(\rho\) of a firefighter whose health is above zero:
The observation is \(o = \big((p'_j, \text{tank}'_j, \text{hp}'_j)_{j=1}^{M},\, (\hat f_k)_{k \in K}\big)\): the firefighter fields are copied from \(s'\), and each cell is reported independently, a wrong report being one of the four categories of \(\mathcal{C}\) other than the true one. \(\textsf{UNKNOWN}\) (coded \(-1\)) is not in \(\mathcal{C}\):
Reward function. The reward reads the successor \(s'\)
(reward_requires_next_state is True). It uses:
Cells. \(k\) ranges over the grid cells \(K = \{0..H{-}1\} \times \{0..W{-}1\}\) (\(H\) =
num_rows, \(W\) =num_cols), and \(f_k\), \(f'_k\) are cell \(k\)’s category in \(s\) and \(s'\), from \(\mathcal{C} = \{\textsf{UNBURNT}, \textsf{SMOLDERING}, \textsf{BURNING}, \textsf{BURNT}, \textsf{WET}\}\).Firefighters. \(j\) ranges over the \(M\) =
num_firefightersfirefighters, \(j = 1..M\), and \(\text{hp}_j\), \(\text{hp}'_j\) are firefighter \(j\)’s health in \(s\) and \(s'\).Actions. Firefighter \(j\)’s action is the digit \(a_j = \lfloor a / 5^{j-1} \rfloor \bmod 5\) of the joint action, with \(4\) meaning \(\textsf{SUPPRESS}\), and \(\text{tank}_j\) is its sprays left in \(s\).
Sprayers. \(J = \{j : \text{hp}_j > 0,\; a_j = 4,\; \text{tank}_j > 0\}\).
Alight categories. \(\mathcal{A}\ell = \{\textsf{SMOLDERING}, \textsf{BURNING}\}\).
Initial belief. A state \(s\) holds:
the step count \(t\);
for each of the \(M\) =
num_firefightersfirefighters \(j = 1..M\), its cell \(p_j\), sprays left \(\text{tank}_j\) and health \(\text{hp}_j\);the hidden wind \((w_{\text{dir}}, w_{\text{str}})\);
the category \(f_k \in \{\textsf{UNBURNT}, \textsf{SMOLDERING}, \textsf{BURNING}, \textsf{BURNT}, \textsf{WET}\}\) of every cell \(k\) of the grid \(K = \{0..H{-}1\} \times \{0..W{-}1\}\) (\(H\) =
num_rows, \(W\) =num_cols).
At the start:
The step count is \(t = 0\).
Each firefighter \(j\) starts at cell \(p^0_j\) =
firefighter_start_cells[j-1]with a full tank, \(\text{tank}_j = \texttt{max\_tank}\), and full health, \(\text{hp}_j = \texttt{max\_health}\).The wind \((w_{\text{dir}}, w_{\text{str}})\) is uniform over its eight values \(\Theta = \{\textsf{N}, \textsf{E}, \textsf{S}, \textsf{W}\} \times \{\textsf{LOW}, \textsf{HIGH}\}\) (the direction it blows toward, and its strength).
\(n_0\) =
num_initial_firesdistinct cells, chosen uniformly from the free cells \(\overline{\mathcal{B}}\) (the grid cells not inobstacle_cells), have category \(f_k = \textsf{BURNING}\), and every other cell \(k\) is \(\textsf{UNBURNT}\):
Discount. \(\gamma\) = discount_factor.
Terminal set. Among other fields, a state \(s\) holds:
the step count \(t\);
the health \(\text{hp}_j\) of each of the \(M\) =
num_firefightersfirefighters \(j = 1..M\);the category \(f_k \in \{\textsf{UNBURNT}, \textsf{SMOLDERING}, \textsf{BURNING}, \textsf{BURNT}, \textsf{WET}\}\) of every cell \(k\) of the grid \(K = \{0..H{-}1\} \times \{0..W{-}1\}\) (\(H\) =
num_rows, \(W\) =num_cols).
An episode ends when:
no cell \(k\) has a category \(f_k\) in the alight set \(\mathcal{A}\ell = \{\textsf{SMOLDERING}, \textsf{BURNING}\}\);
is_all_firefighters_disabled_terminalis set and every firefighter \(j\) has health \(\text{hp}_j = 0\);or the step count \(t\) reaches
max_steps:
World and state
Every cell holds one of five categories:
UNBURNT(has fuel);SMOLDERING(intensity 1);BURNING(intensity 2);BURNT(fuel consumed);WET(soaked, cannot reignite).
BURNT and WET are absorbing, and no rule maps
either back into an alight category. So once no cell is alight, no later step
can relight one, and a completed episode stays completed.
The hidden wind is a direction in {N, E, S, W} crossed with a strength in
{low, high} – eight values, drawn uniformly at reset and constant for the
episode. It is never observed.
The state is one float64 vector of length 3 + 4N + R*C:
[step, (row, col, tank, health) x N, wind_direction, wind_strength, cells]
A firefighter’s tank holds max_tank sprays (6 by default) and its health starts at
max_health (3 by default). At zero health a firefighter is disabled: its digit of
the joint action is ignored and it sees nothing for the rest of the episode.
Observation
An observation is one float64 vector of length 4N + R*C:
[(row, col, tank, health) x N, reported category per cell]
Poses, tanks and healths are exact. Every cell within Chebyshev radius
sensing_radius (2 by default) of any live firefighter reports its true category
with probability 1 - observation_error_probability and one of the other four
uniformly otherwise. Every other cell reports -1, the unknown marker, so the
observation has a fixed shape whatever the firefighters do. Two firefighters standing
together see barely more than one, so spreading out is what buys information.
The opening observation is a sentinel, not a scan: the known start cells, full
tanks and full health, with every cell -1. The first sensor reading arrives
with the first transition.
The wind never enters the observation. It is observable only through its effect
on the fire, which is what makes this an inference problem rather than a lookup.
Both the transition and the observation density are available in closed form:
transition_log_probability is exact, because the intermediate map is
recoverable from the pair of maps – wet is reachable only by suppression, burnt
only by burnout, and a cell ignited this step cannot also grow.
Rewards
Every term reads the realised successor, so
reward_requires_next_state is True.
Term |
Value |
|---|---|
step cost |
|
active fire |
|
property loss |
|
firefighter damage |
|
suppressant |
|
success |
|
The declared reward range is computed from the constructor’s own coefficients,
grid size and firefighter count – never a constant. The maximum is
success_reward - step_cost, not success_reward, because the step cost is
charged on the terminating transition too. The minimum is:
-(step_cost
+ max(smoldering_cell_cost, burning_cell_cost, burnt_cell_cost) * R * C
+ damage_cost * N * min(max_health, 2)
+ water_cost * N)
A cell in the successor is smoldering, or burning, or newly burnt, or none of
those – never two at once – so those three terms share one budget of R * C
cells rather than stacking, which is what allows the max instead of a sum.
With the defaults that is (-540.3, 99.9).
is_all_firefighters_disabled_terminal changes only termination, so it moves
neither end of the bound.
Termination is evaluated in this order: goal (no cell alight), failure
(every firefighter disabled while fire is still active, when
is_all_firefighters_disabled_terminal), then timeout (max_steps, 100 by
default). Goal wins over failure, so a fire put out by firefighters that then burned
out is still a success.
Key settings
The default world is 10 by 10 with two firefighters, a 2 by 2 obstacle block at rows 5–6 and columns 5–6, and a depot in the north-west corner.
spread_probability defaults to 0.10 and burnout_probability to
0.03, and the pair was measured rather than proposed. At the originally
drafted 0.06 and 0.12 an unattended fire on the default world went out by
itself in 93% of episodes: a planner that did nothing would have “completed the
task” nine times in ten, and no margin over a random baseline would have been
measurable. At 0.10 and 0.03 the same unattended fire goes out 6% of the time, a
uniformly random policy 27%, and a hand-written greedy firefighter 89%, so the
completion rate reports what the planner did.
Metrics
task_completion_ratereports a fire-free map, reduced withANY: wet and burnt are absorbing, so a fire-free map cannot be undone andANYandLASTagree.ended_by_goal_rate,ended_by_failure_rateandended_by_timeout_ratereport how each episode ended and sum to one.average_episode_lengthis a constant channel summed.
The danger is reported both as a count – average_firefighter_steps_in_fire,
average_firefighter_health_lost – and as a severity –
max_simultaneous_alight_cells, max_burnt_cell_fraction. A planner that
lets the fire reach forty cells and then beats it out is not the same as one
that never let it past five, and the totals alone would not distinguish them.
average_suppressant_units_used and final_firefighters_disabled are also reported.
Visualization
Runs write a trace of each episode through the environment’s episode visualizer. The results site replays it in 3D, as the replay on this page does.
Filtering and limits
VOPP plans on FirefightingVectorizedModel, a torch copy of the
transition, observation, reward and terminal rules that runs a whole batch of
states in one call. It supports every configuration, including more than two
firefighters, but the joint action space grows as 5 ** num_firefighters,
and VOPP keeps one preference per action at every belief node. PFT_DPW
takes the scalar API directly.
Sampling, both densities, the reward, the terminal check and the random rollout run in a C++ extension; the Python versions stay in the class as the reference the extension is tested against.
VOPP’s tree branches on an integer key per reading. A reading has
4 * num_firefighters + num_rows * num_cols entries, too many for an exact
key in 64 bits, so the model hashes it and two different readings can share a
key.
The belief is FirefightingVectorizedBelief, which
create_environment_belief returns. It runs every part of the transition
over the particle axis and the grid at once, and it does two things a
bootstrap filter does not, both because a bootstrap filter over whole 100-cell
maps is degenerate here:
The poses, tanks and healths come back from the sensor exactly but depend on hidden state, so weighting by them puts every weight on the floor and both belief panels render as noise; this belief writes the reported values onto the particles instead.
The wind never changes, so resampling across wind values deletes hypotheses no later evidence can restore; resampling therefore happens inside a wind value.
That does not make the filter free of the usual cautions. Use enough particles and inspect effective sample size rather than trusting the wind histogram on sight. The wind is identifiable from the spread – an exact posterior over the eight values, given the map, puts most of its mass on the true wind within about twenty-five steps – but with random actions this filter is slower than that: in a twenty-episode check it held about 0.2 of its weight on the true wind after thirty steps, against a prior of 0.125, and in most single episodes it held almost none. A flat histogram late in an episode is a statement about the filter, not about the environment.
Can I use?
|
Discrete |
Continuous |
|---|---|---|
State |
✔️ |
❌ |
Action |
✔️ |
❌ |
Observation |
✔️ |
❌ |
Also supports |
|
|---|---|
Native C++ backend |
✔️ |
Vectorized (torch) model |
✔️ |
In the |
✔️ |
Optional dependencies |
None |
Example
from POMDPPlanners.environments.firefighting_pomdp import (
FirefightingPOMDP,
)
from POMDPPlanners.utils.belief_factory import create_environment_belief
env = FirefightingPOMDP()
belief = create_environment_belief(env, n_particles=100)
Parameters
- class POMDPPlanners.environments.firefighting_pomdp.FirefightingPOMDP(num_rows=10, num_cols=10, num_firefighters=2, obstacle_cells=None, depot_cell=None, firefighter_start_cells=None, num_initial_fires=1, max_tank=6, max_health=3, sensing_radius=2, observation_error_probability=0.1, slip_probability=0.05, spread_probability=0.1, wind_gain_low=2.0, wind_gain_high=3.5, crosswind_attenuation=0.5, growth_probability=0.35, burnout_probability=0.03, suppression_probability_unburnt=1.0, suppression_probability_smoldering=0.9, suppression_probability_burning=0.6, max_steps=100, success_reward=100.0, step_cost=0.1, smoldering_cell_cost=0.5, burning_cell_cost=1.0, burnt_cell_cost=5.0, damage_cost=10.0, water_cost=0.1, is_all_firefighters_disabled_terminal=True, discount_factor=0.95, name='Firefighting', output_dir=None, debug=False, use_queue_logger=False)[source]
Bases:
DiscreteActionsEnvironmentPut out a wind-driven grid fire with
Npartially sighted firefighters.The episode ends when no cell is alight (goal), when every firefighter is disabled while fire is still active (failure, when
is_all_firefighters_disabled_terminal), or when the step budget runs out (timeout). Goal wins over failure: a fire put out by firefighters that then burned out is still a success.- Parameters:
num_rows (int)
num_cols (int)
num_firefighters (int)
num_initial_fires (int)
max_tank (int)
max_health (int)
sensing_radius (int)
observation_error_probability (float)
slip_probability (float)
spread_probability (float)
wind_gain_low (float)
wind_gain_high (float)
crosswind_attenuation (float)
growth_probability (float)
burnout_probability (float)
suppression_probability_unburnt (float)
suppression_probability_smoldering (float)
suppression_probability_burning (float)
max_steps (int)
success_reward (float)
step_cost (float)
smoldering_cell_cost (float)
burning_cell_cost (float)
burnt_cell_cost (float)
damage_cost (float)
water_cost (float)
is_all_firefighters_disabled_terminal (bool)
discount_factor (float)
name (str)
output_dir (Path | None)
debug (bool)
use_queue_logger (bool)
- decode_action(action)[source]
Return the per-firefighter actions of a joint action.
- Parameters:
action (
Any) – The joint action, an integer in[0, 5 ** num_firefighters).- Return type:
- Returns:
(num_firefighters,)int64array ofFirefightingActioncodes, firefighter 0 first.- Raises:
ValueError – If the joint action is outside the action space.
- episode_visualizer()[source]
Return the visualizer that writes this environment’s traces.
- Return type:
FirefightingVisualizer
- get_actions()[source]
Return every joint action, as plain integers.
Integer actions also sidestep the
id(action)caching trap the environment API contract documents: there is no action array whose memory address a cache could be keyed on, so the recycled-address bug that cost ContinuousPush 95% of its steps cannot arise here.
- get_metric_specs()[source]
Declare the firefighting metrics.
Completion reduces with
ANY.BURNTandWETare absorbing, so a fire-free map cannot be undone andANYandLASTagree here;ANYis the honest name for “the task was completed at some point” and is what the reduction’s own docstring recommends for a reach-a-goal task.The danger is reported both as a count and as a severity, because the worst moment and the total say different things about a planner: a planner that lets the fire reach forty cells and then beats it out is not the same as one that never let it past five, and the totals alone would not distinguish them.
- Return type:
- Returns:
One spec per metric named in
FirefightingMetrics.
- hash_observation(observation)[source]
Return a hashable key agreeing with
is_equal_observation().
- initial_observation_dist()[source]
The pre-episode reading: firefighters at their posts, nothing sensed yet.
- Return type:
- Returns:
A point mass on the known firefighter fields with every cell marked unknown. This is a sentinel, not a scan: the first real reading arrives with the first transition, and scoring this one against a state would be scoring a reading that no observation model produced.
- initial_state_dist()[source]
A uniform hidden wind and a uniformly placed fire, firefighters at their posts.
- Return type:
- Returns:
The reset distribution.
- is_equal_observation(observation1, observation2)[source]
Check whether two readings are the same array of numbers.
- is_terminal(state)[source]
Whether the fire is out, every firefighter is down, or time has run out.
- observation_log_probability(next_state, action, observations)[source]
Log-likelihood of each reading under
next_state.The poses, tanks and healths are reported exactly, so any mismatch in them gives
-inf. Every visible cell contributes its confusion probability. Unobserved cells contribute nothing, because the unknown marker is deterministic given the poses – but reporting a category for a cell nobody is looking at is impossible and gives-inf.
- reward(state, action, next_state=None)[source]
Score one transition.
The success bonus is paid on the transition into a fire-free state, and the step cost is charged on that transition too – which is why the largest reachable reward is
success_reward - step_cost.- Parameters:
state (
ndarray) – The state the step was taken from.action (
Any) – The joint action.next_state (
Any) – The realised successor. Defaults toNone, in which case one is drawn: every term here reads the successor, so there is no correct number to return without one and returning a wrong one silently would be worse than the extra draw.
- Return type:
- Returns:
The immediate reward.
- reward_batch(states, action, next_states=None)[source]
Score one transition per row, all under the same action.
- property reward_requires_next_state: bool
Every reward term reads the realised successor, so this is
True.
- sample_next_state(state, action, n_samples=1)[source]
Draw one or more successors of
stateunderaction.
- sample_next_state_batch(states, action)[source]
Draw one successor per input state, all under the same action.
- sample_next_step(state, action)[source]
Draw a successor, its reading and the reward in one native call.
- sample_observation(next_state, action, n_samples=1)[source]
Draw one or more readings of
next_state.The observation depends on the successor alone, not on the action.
- simulate_random_rollout(state, action_sampler, max_depth, discount_factor, depth=0)[source]
Random rollout, run in C++ when the action law is a uniform list.
A
DiscreteActionSamplerdraws uniformly from itsactionslist, so the joint actions are drawn here withrandom.choicesfrom that list and the whole rollout runs in one native call. Any other sampler may follow another law, so it gets the Python rollout, which callsaction_sampler.sample()at every step.- Parameters:
- Return type:
- Returns:
The discounted sum of rewards until
max_depthor a terminal state.
- step_info(state, action, next_state)[source]
Report the per-step channels this environment’s metrics are built on.
Draws no randomness: every channel is a deterministic read of
state,actionandnext_state.The state-shaped channels are read from
next_statewhen there is one, for the reason Battleship documents: the episode runner checks its step budget before it checks terminality, so an episode whose final allowed step puts the fire out records no terminal bookkeeping step, and reading fromstatealone would score that episode as a still-burning timeout.- Parameters:
- Return type:
- Returns:
The channels named by
FirefightingStepChannel. The two transition channels report0.0on the terminal step, where no action was taken.
- transition_log_probability(state, action, next_states)[source]
Log-probability of each candidate successor.
See also
POMDPPlanners.environments.firefighting_pomdp.FirefightingPOMDPBase Environment Class — the full catalog and the environment interface.