Skip to contents

This function generates or appends the budget and transition cost to a .dat file for ampl. The file will be written to the location specified by the name argument. If the file already exists, it will be overwritten. The file format is plain text, with each line terminated by a newline character.

Usage

create_budget(
  budget,
  Rastercurrentlanduse,
  landuses,
  name = "Problem",
  verbose = FALSE
)

Arguments

budget

maximum cost for the problem

Rastercurrentlanduse

raster object of current landuses

landuses

character vector with all landuses

name

The name of the output file

verbose

Logical whether messages will be written while the function is generating calculations, defaults to FALSE

Value

A .dat file. This function is used for the side-effect of writing values to a file.

Author

Derek Corcoran

Examples


data(CurrentLanduse)
CurrentLU <- terra::unwrap(CurrentLanduse)


TroublemakeR::create_budget(budget = 2,
Rastercurrentlanduse = CurrentLU,
landuses = c("Agriculture", "Forest", "Urban"),
name = "Problem",
verbose = TRUE)
#> Landuse 1 of 3 ready 2024-04-02 12:17:30.060274
#> Landuse 2 of 3 ready 2024-04-02 12:17:30.255159
#> Landuse 3 of 3 ready 2024-04-02 12:17:30.399683

# delete the file so the test on cran can pass this

file.remove("Problem.dat")
#> [1] TRUE