Calculate the total cost of a solution to a conservation planning problem(). For example, if the planning unit cost data describe land acquisition costs (USD), then the total cost would be net cost (USD) needed to acquire all planning units selected within the solution.

eval_cost_summary(x, solution)

# S3 method for default
eval_cost_summary(x, solution)

# S3 method for ConservationProblem
eval_cost_summary(x, solution)

Arguments

x

problem() (i.e. ConservationProblem) object.

solution

numeric, matrix, data.frame, Raster, Spatial, or sf::sf() object. The argument should be in the same format as the planning unit cost data in the argument to x. See the Solution format section for more information.

Value

tibble::tibble() object containing the solution cost. It contains the following columns:

summary

character description of the summary statistic. The statistic associated with the "overall" value in this column is calculated using the entire solution (including all management zones if there are multiple zones). If multiple management zones are present, then summary statistics are also provided for each zone separately (indicated using zone names).

cost

numeric cost value. Greater values correspond to solutions that are more costly to implement. Thus conservation planning exercises typically prefer solutions with smaller values, because they are cheaper to implement (assuming all other relevant factors, such as feature representation, are equal).

Details

This metric is equivalent to the Cost metric reported by the Marxan software (Ball et al. 2009). Specifically, the cost of a solution is defined as the sum of the cost values, supplied when creating a problem() object (e.g. using the cost_column argument), weighted by the status of each planning unit in the solution.

Solution format

The argument to solution must be in the same format as the planning unit data in the argument to x (e.g. in terms of data representation, dimensionality, and spatial attributes). For example, if the planning unit data in x is a numeric vector, then the argument to solution must be a numeric vector with the same number of elements. Similarly, if the planning units in x are a data.frame, then the argument to solution must also be a data.frame with each column corresponding to a different zone, each row corresponding to a different planning unit, and cell values corresponding to the solution value. Additionally, if the planning unit data in x is a Raster object, then the argument to solution must also be a Raster object with the same dimensionality (rows and columns), resolution, extent, and coordinate reference system. Furthermore, if the planning unit data in x is a Spatial or sf::sf() object then the argument to solution must also be a Spatial or sf::sf() object (respectively) with the same spatial information (e.g. polygons and coordinate reference system), and contain columns corresponding to different zones, and cell values corresponding to the solution values.

The argument to solution must also have missing (NA) values for planning units that have missing (NA) cost values. In other words, the solution must have missing (NA) values in the same elements, cells, or pixels (depending on the cost data format) as the planning unit cost data. For example, if the planning unit data are a Raster object, then the argument to solution must have missing (NA) values in the same pixels as the planning unit cost data. Similarly, if the planning unit data are a Spatial, sf::sf(), or data.frame object, then the solution must have missing (NA) values in the same cells as the planning unit cost data columns. If an argument is supplied to solution where the missing (NA) values in the argument to solution do not match those in the planning unit cost data, then an error will be thrown.

References

Ball IR, Possingham HP, and Watts M (2009) Marxan and relatives: Software for spatial conservation prioritisation in Spatial conservation prioritisation: Quantitative methods and computational tools. Eds Moilanen A, Wilson KA, and Possingham HP. Oxford University Press, Oxford, UK.

See also

Examples

# \dontrun{ # set seed for reproducibility set.seed(500) # load data data(sim_pu_raster, sim_pu_sf, sim_features, sim_pu_zones_sf, sim_features_zones) # build minimal conservation problem with raster data p1 <- problem(sim_pu_raster, sim_features) %>% add_min_set_objective() %>% add_relative_targets(0.1) %>% add_binary_decisions() %>% add_default_solver(verbose = FALSE) # solve the problem s1 <- solve(p1) # print solution print(s1)
#> class : RasterLayer #> dimensions : 10, 10, 100 (nrow, ncol, ncell) #> resolution : 0.1, 0.1 (x, y) #> extent : 0, 1, 0, 1 (xmin, xmax, ymin, ymax) #> crs : NA #> source : memory #> names : layer #> values : 0, 1 (min, max) #>
# plot solution plot(s1, main = "solution", axes = FALSE, box = FALSE)
# calculate cost of the solution r1 <- eval_cost_summary(p1, s1) print(r1)
#> # A tibble: 1 x 2 #> summary cost #> <chr> <dbl> #> 1 overall 1987.
# build minimal conservation problem with polygon (sf) data p2 <- problem(sim_pu_sf, sim_features, cost_column = "cost") %>% add_min_set_objective() %>% add_relative_targets(0.1) %>% add_binary_decisions() %>% add_default_solver(verbose = FALSE) # solve the problem s2 <- solve(p2) # plot solution plot(s2[, "solution_1"])
# print first six rows of the attribute table print(head(s2))
#> Simple feature collection with 6 features and 4 fields #> geometry type: POLYGON #> dimension: XY #> bbox: xmin: 0 ymin: 0.9 xmax: 0.6 ymax: 1 #> CRS: NA #> cost locked_in locked_out solution_1 geometry #> 1 215.8638 FALSE FALSE 0 POLYGON ((0 1, 0.1 1, 0.1 0... #> 2 212.7823 FALSE FALSE 0 POLYGON ((0.1 1, 0.2 1, 0.2... #> 3 207.4962 FALSE FALSE 0 POLYGON ((0.2 1, 0.3 1, 0.3... #> 4 208.9322 FALSE TRUE 0 POLYGON ((0.3 1, 0.4 1, 0.4... #> 5 214.0419 FALSE FALSE 0 POLYGON ((0.4 1, 0.5 1, 0.5... #> 6 213.7636 FALSE FALSE 0 POLYGON ((0.5 1, 0.6 1, 0.6...
# calculate cost of the solution r2 <- eval_cost_summary(p2, s2[, "solution_1"]) print(r2)
#> # A tibble: 1 x 2 #> summary cost #> <chr> <dbl> #> 1 overall 1793.
# manually calculate cost of the solution r2_manual <- sum(s2$solution * sim_pu_sf$cost, na.rm = TRUE) print(r2_manual)
#> [1] 1792.535
# build multi-zone conservation problem with polygon (sf) data p3 <- problem(sim_pu_zones_sf, sim_features_zones, cost_column = c("cost_1", "cost_2", "cost_3")) %>% add_min_set_objective() %>% add_relative_targets(matrix(runif(15, 0.1, 0.2), nrow = 5, ncol = 3)) %>% add_binary_decisions() %>% add_default_solver(verbose = FALSE) # solve the problem s3 <- solve(p3) # print first six rows of the attribute table print(head(s3))
#> Simple feature collection with 6 features and 9 fields #> geometry type: POLYGON #> dimension: XY #> bbox: xmin: 0 ymin: 0.9 xmax: 0.6 ymax: 1 #> CRS: NA #> cost_1 cost_2 cost_3 locked_1 locked_2 locked_3 solution_1_zone_1 #> 1 215.8638 183.3344 205.4113 FALSE FALSE FALSE 0 #> 2 212.7823 189.4978 209.6404 FALSE FALSE FALSE 0 #> 3 207.4962 193.6007 215.4212 TRUE FALSE FALSE 0 #> 4 208.9322 197.5897 218.5241 FALSE FALSE FALSE 0 #> 5 214.0419 199.8033 220.7100 FALSE FALSE FALSE 0 #> 6 213.7636 203.1867 224.6809 FALSE FALSE FALSE 0 #> solution_1_zone_2 solution_1_zone_3 geometry #> 1 0 1 POLYGON ((0 1, 0.1 1, 0.1 0... #> 2 0 0 POLYGON ((0.1 1, 0.2 1, 0.2... #> 3 0 0 POLYGON ((0.2 1, 0.3 1, 0.3... #> 4 0 0 POLYGON ((0.3 1, 0.4 1, 0.4... #> 5 0 0 POLYGON ((0.4 1, 0.5 1, 0.5... #> 6 1 0 POLYGON ((0.5 1, 0.6 1, 0.6...
# create new column representing the zone id that each planning unit # was allocated to in the solution s3$solution <- category_vector( s3[, c("solution_1_zone_1", "solution_1_zone_2", "solution_1_zone_3")]) s3$solution <- factor(s3$solution) # plot solution plot(s3[, "solution"])
# calculate cost of the solution r3 <- eval_cost_summary( p3, s3[, c("solution_1_zone_1", "solution_1_zone_2", "solution_1_zone_3")]) print(r3)
#> # A tibble: 4 x 2 #> summary cost #> <chr> <dbl> #> 1 overall 10160. #> 2 zone_1 3395. #> 3 zone_2 3322. #> 4 zone_3 3443.
# }