---
title: "Scenario comparison"
description: "Compare walking-speed and least-cost-path assumptions across named scenarios."
output: rmarkdown::html_vignette
vignette: >
  %\VignetteIndexEntry{Scenario comparison}
  %\VignetteEngine{knitr::rmarkdown}
  %\VignetteEncoding{UTF-8}
---

```{r, include = FALSE}
knitr::opts_chunk$set(collapse = TRUE, comment = "#>", eval = FALSE)
scenario_summary <- utils::read.csv(system.file(
  "extdata/pkgdown-example-scenario-summary.csv", package = "evacpath"
))
figure_html <- function(name, alt) {
  path <- system.file("extdata", name, package = "evacpath")
  if (!nzchar(path)) stop("Installed example figure is unavailable.", call. = FALSE)
  knitr::asis_output(sprintf(
    '<figure><img src="%s" alt="%s" style="width: 100%%; height: auto;"><figcaption>%s</figcaption></figure>',
    knitr::image_uri(path), alt, alt
  ))
}
```

`compare_evac_scenarios()` runs the same study inputs under named parameter
overrides. It returns each raw result, a scenario summary, and combined spatial
layers when available.

```{r compare}
comparison <- compare_evac_scenarios(
  hazard_zone = hazard_zone,
  roads = roads,
  dem = dem,
  target_crs = "EPSG:32748",
  max_origins = 100,
  max_destinations = 25,
  scenarios = list(
    baseline = list(walking_speed_mps = 1.22),
    slow_walkers = list(walking_speed_mps = 0.75),
    conservative_lcp = list(
      lcp_neighbours = 8,
      lcp_max_slope = 30
    )
  )
)

comparison$summary
```

```{r scenario-comparison-figure, echo = FALSE, eval = TRUE, results = "asis"}
figure_html("pkgdown-example-scenarios.png", "Scenario sensitivity in modeled evacuation time.")
```

The compact packaged example below retains the scenario-level time metrics and
the assumptions used to generate them.

```{r scenario-summary, echo = FALSE, eval = TRUE}
knitr::kable(
  scenario_summary[, c(
    "scenario", "n_origins", "n_destinations", "walking_speed_mps",
    "median_evac_time", "mean_evac_time", "max_evac_time", "note"
  )],
  digits = 2,
  col.names = c("Scenario", "Origins", "Exits", "Walking speed",
                "Median min.", "Mean min.", "Maximum min.", "Assumption")
)
```

Treat scenario outputs as sensitivity analysis. A slower walking speed changes
time conversion; conductance and neighbourhood settings can change modeled route
geometry as well as distance. A scenario with incomplete outputs is retained
with missing summary values rather than discarding the whole comparison.
