forecast_layer
agentevac.utils.forecast_layer
Fire forecast construction and route-head risk summarization.
This module transforms raw fire geometry data (circles with positions and radii from
agentevac.simulation.main.active_fires) into structured forecast objects and natural-language
briefings that are embedded in the LLM prompt.
Fire forecast (build_fire_forecast):
Compares current fire circles against projected circles (queried at
sim_t + FORECAST_HORIZON_S) to derive growth metrics: max and average radius
growth per fire, and any new fire IDs that appear in the projected snapshot.
Edge risk (estimate_edge_forecast_risk):
Queries the caller-supplied edge_risk_fn (a thin wrapper around
agentevac.simulation.main.compute_edge_risk_for_fires) to obtain (blocked, risk_score,
margin_m) for a single edge, then classifies the result into a margin band.
Route-head summary (summarize_route_forecast):
Evaluates the first max_edges non-junction edges of the agent's planned route,
finding the minimum margin (worst-case proximity to fire) and counting blocked edges.
Briefing (render_forecast_briefing):
Assembles a concise natural-language sentence from the above data, providing the
LLM with a human-readable situational summary without requiring it to parse raw
numbers.
build_fire_forecast(sim_t_s, current_fires, projected_fires, horizon_s)
Compute a fire growth forecast by comparing current and projected fire circles.
Each fire is identified by an "id" key. For fires present in both snapshots,
growth is projected_r - current_r. For fires that appear only in the projected
snapshot (new ignitions within the horizon), their full projected radius is counted
as growth.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
sim_t_s
|
float
|
Current simulation time in seconds. |
required |
current_fires
|
List[Dict[str, Any]]
|
List of active fire dicts at |
required |
projected_fires
|
List[Dict[str, Any]]
|
List of active fire dicts at |
required |
horizon_s
|
float
|
Forecast horizon in seconds. |
required |
Returns:
| Type | Description |
|---|---|
Dict[str, Any]
|
A forecast summary dict with:
- |
Source code in agentevac/utils/forecast_layer.py
81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 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 134 135 136 137 138 139 | |
estimate_edge_forecast_risk(edge_id, edge_risk_fn)
Query the risk of a single edge against the projected fire field.
Delegates the geometry computation to edge_risk_fn, which is typically a
closure around agentevac.simulation.main.compute_edge_risk_for_fires evaluated at the
projected fire positions (sim_t + FORECAST_HORIZON_S).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
edge_id
|
str
|
SUMO edge ID to evaluate. |
required |
edge_risk_fn
|
Callable[[str], Any]
|
Callable that accepts an edge ID and returns
|
required |
Returns:
| Type | Description |
|---|---|
Dict[str, Any]
|
A dict with:
- |
Source code in agentevac/utils/forecast_layer.py
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 | |
render_forecast_briefing(agent_id, forecast, belief, edge_forecast, route_forecast)
Render a one-sentence natural-language situational briefing for the LLM prompt.
Combines three information streams into a concise, human-readable sentence:
- The overall hazard tone (based on p_danger and uncertainty).
- The current edge status (edge band or "may be overtaken").
- The route-head status (band or blocked-segment count).
This briefing is embedded in the LLM prompt as a plain-English complement to the structured forecast JSON, making key risk indicators immediately legible to the model.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
agent_id
|
str
|
Vehicle ID (currently unused; retained for future per-agent logging). |
required |
forecast
|
Dict[str, Any]
|
Fire forecast summary from |
required |
belief
|
Dict[str, Any]
|
The agent's current Bayesian belief dict (for p_danger, uncertainty_bucket). |
required |
edge_forecast
|
Dict[str, Any]
|
Per-edge forecast dict from |
required |
route_forecast
|
Dict[str, Any]
|
Route-head forecast dict from |
required |
Returns:
| Type | Description |
|---|---|
str
|
A one-sentence briefing string. |
Source code in agentevac/utils/forecast_layer.py
232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 | |
summarize_route_forecast(route_edges, edge_risk_fn, max_edges)
Evaluate the first max_edges non-junction edges of a route against the forecast.
Junction edges (IDs starting with ":") are skipped because they are short
connector segments without meaningful geometry in the SUMO network.
Finds the minimum margin (most dangerous approach) and counts blocked edges to provide a worst-case picture of the upcoming route segment.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
route_edges
|
List[str]
|
Ordered list of edge IDs along the planned route. |
required |
edge_risk_fn
|
Callable[[str], Any]
|
Callable returning |
required |
max_edges
|
int
|
Maximum number of route-head edges to evaluate. |
required |
Returns:
| Type | Description |
|---|---|
Dict[str, Any]
|
A dict with:
- |
Source code in agentevac/utils/forecast_layer.py
175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 | |