prioritizr / prioritizr
Showing 2 of 166 files from the diff.
Other files ignored by Codecov
docs/index.html has changed.
docs/pkgdown.yml has changed.
docs/404.html has changed.
docs/authors.html has changed.
README.md has changed.
NEWS.md has changed.
DESCRIPTION has changed.

@@ -32,7 +32,7 @@
Loading
32 32
#'      add_relative_targets(0.1) %>%
33 33
#'      add_binary_decisions()
34 34
#'
35 -
#' # save problem to file (using the Rsymphony R package)
35 +
#' # save problem to file (using the Rsymphony package)
36 36
#' write_problem(p, "model.lp")
37 37
#' }
38 38
#'

@@ -43,6 +43,8 @@
Loading
43 43
#' For further details on installing this package, please consult
44 44
#' [official installation instructions for the package](https://dirkschumacher.github.io/rcbc/).
45 45
#'
46 +
#' @inheritSection add_gurobi_solver Start solution format
47 +
#'
46 48
#' @return Object (i.e. [`ConservationProblem-class`]) with the solver
47 49
#'  added to it.
48 50
#'
@@ -63,16 +65,32 @@
Loading
63 65
#'
64 66
#' # create problem
65 67
#' p <- problem(sim_pu_raster, sim_features) %>%
66 -
#'   add_min_set_objective() %>%
67 -
#'   add_relative_targets(0.1) %>%
68 -
#'   add_binary_decisions() %>%
69 -
#'   add_cbc_solver(gap = 0.1, verbose = FALSE)
68 +
#'      add_min_set_objective() %>%
69 +
#'      add_relative_targets(0.1) %>%
70 +
#'      add_binary_decisions() %>%
71 +
#'      add_cbc_solver(gap = 0, verbose = FALSE)
70 72
#'
71 73
#' # generate solution %>%
72 74
#' s <- solve(p)
73 75
#'
74 76
#' # plot solution
75 77
#' plot(s, main = "solution", axes = FALSE, box = FALSE)
78 +
#'
79 +
#' # create a similar problem with boundary length penalties and
80 +
#' # specify the solution from the previous run as a starting solution
81 +
#' p2 <- problem(sim_pu_raster, sim_features) %>%
82 +
#'      add_min_set_objective() %>%
83 +
#'      add_relative_targets(0.1) %>%
84 +
#'      add_boundary_penalties(10) %>%
85 +
#'      add_binary_decisions() %>%
86 +
#'      add_cbc_solver(gap = 0, start_solution = s, verbose = FALSE)
87 +
#'
88 +
#' # generate solution
89 +
#' s2 <- solve(p2)
90 +
#'
91 +
#' # plot solution
92 +
#' plot(s2, main = "solution with boundary penalties", axes = FALSE,
93 +
#'      box = FALSE)
76 94
#' }
77 95
#' @name add_cbc_solver
78 96
NULL
@@ -83,8 +101,9 @@
Loading
83 101
                           time_limit = .Machine$integer.max,
84 102
                           presolve = TRUE, threads = 1,
85 103
                           first_feasible = FALSE,
104 +
                           start_solution = NULL,
86 105
                           verbose = TRUE) {
87 -
  # assert that arguments are valid
106 +
  # assert that arguments are valid (except start_solution)
88 107
  assertthat::assert_that(inherits(x, "ConservationProblem"),
89 108
                          isTRUE(all(is.finite(gap))),
90 109
                          assertthat::is.scalar(gap),
@@ -100,12 +119,26 @@
Loading
100 119
                          assertthat::noNA(first_feasible),
101 120
                          assertthat::is.flag(verbose),
102 121
                          requireNamespace("rcbc", quietly = TRUE))
122 +
 # extract start solution
123 +
  if (!is.null(start_solution)) {
124 +
    # verify that version of rcbc installed supports starting solution
125 +
    assertthat::assert_that(
126 +
      any(grepl(
127 +
        "initial_solution", deparse1(args(rcbc::cbc_solve)), fixed = TRUE)),
128 +
      msg = paste(
129 +
        "please update to a newer version of the \"rcbc\" package",
130 +
        "to specify starting solutions"
131 +
      )
132 +
    )
133 +
    # extract data
134 +
    start_solution <- planning_unit_solution_status(x, start_solution)
135 +
  }
103 136
  # add solver
104 137
  x$add_solver(pproto(
105 138
    "CbcSolver",
106 139
    Solver,
107 140
    name = "CBC",
108 -
    data = list(),
141 +
    data = list(start = start_solution),
109 142
    parameters = parameters(
110 143
      numeric_parameter("gap", gap, lower_limit = 0),
111 144
      integer_parameter("time_limit", time_limit, lower_limit = -1L,
@@ -122,7 +155,7 @@
Loading
122 155
      sense <- x$sense()
123 156
      assertthat::assert_that(
124 157
        all(sense %in% c("=", "<=", ">=")),
125 -
        msg = "failed to prepare problem formulation for rcbc package")
158 +
        msg = "failed to prepare problem formulation for \"rcbc\" package")
126 159
      ## initialize CBC arguments
127 160
      row_lb <- numeric(length(rhs))
128 161
      row_ub <- numeric(length(rhs))
@@ -148,6 +181,12 @@
Loading
148 181
        col_ub = x$ub(),
149 182
        row_lb = row_lb,
150 183
        row_ub = row_ub)
184 +
      # add starting solution if specified
185 +
      start <- self$get_data("start")
186 +
      if (!is.null(start) && !is.Waiver(start)) {
187 +
        n_extra <- length(model$obj) - length(start)
188 +
        model$initial_solution <- c(c(start), rep(NA_real_, n_extra))
189 +
      }
151 190
      # create parameters
152 191
      p <- list(
153 192
        log = as.character(as.numeric(self$parameters$get("verbose"))),
Files Coverage
R 94.93%
src 98.81%
Project Totals (124 files) 96.12%

No yaml found.

Create your codecov.yml to customize your Codecov experience

Sunburst
The inner-most circle is the entire project, moving away from the center are folders then, finally, a single file. The size and color of each slice is representing the number of statements and the coverage, respectively.
Icicle
The top section represents the entire project. Proceeding with folders and finally individual files. The size and color of each slice is representing the number of statements and the coverage, respectively.
Grid
Each block represents a single file in the project. The size and color of each block is represented by the number of statements and the coverage, respectively.
Loading