prioritizr / prioritizr

Compare 4585a84 ... +0 ... b9f7b7e

Coverage Reach
R/problem.R R/planning_unit_solution_status.R R/eval_replacement_importance.R R/marxan_problem.R R/eval_ferrier_importance.R R/add_linear_constraints.R R/parameters.R R/add_cbc_solver.R R/eval_rare_richness_importance.R R/add_neighbor_constraints.R R/solve.R R/add_linear_penalties.R R/add_feature_contiguity_constraints.R R/add_lpsymphony_solver.R R/presolve_check.R R/add_rsymphony_solver.R R/marxan_boundary_data_to_matrix.R R/add_manual_targets.R R/add_boundary_penalties.R R/add_locked_in_constraints.R R/add_locked_out_constraints.R R/add_manual_locked_constraints.R R/add_manual_bounded_constraints.R R/add_connectivity_penalties.R R/compile.R R/eval_connectivity_summary.R R/boundary_matrix.R R/add_contiguity_constraints.R R/zones.R R/eval_target_coverage_summary.R R/internal.R R/add_shuffle_portfolio.R R/intersecting_units.R R/add_max_phylo_end_objective.R R/add_feature_weights.R R/eval_feature_representation_summary.R R/fast_extract.R R/add_max_phylo_div_objective.R R/add_loglinear_targets.R R/connectivity_matrix.R R/add_absolute_targets.R R/proximity_matrix.R R/add_relative_targets.R R/adjacency_matrix.R R/eval_boundary_summary.R R/rij_matrix.R R/write_problem.R R/predefined_optimization_problem.R R/add_min_largest_shortfall_objective.R R/add_cuts_portfolio.R R/add_max_utility_objective.R R/add_min_shortfall_objective.R R/add_max_features_objective.R R/OptimizationProblem-methods.R R/add_max_cover_objective.R R/pproto.R R/simulate.R R/category_vector.R R/loglinear_interpolation.R R/add_mandatory_allocation_constraints.R R/add_semicontinuous_decisions.R R/feature_abundances.R R/distribute_load.R R/eval_cost_summary.R R/eval_n_summary.R R/binary_stack.R R/add_min_set_objective.R R/run_calculations.R R/add_binary_decisions.R R/add_proportion_decisions.R R/category_layer.R R/Id.R R/branch_matrix.R R/misc.R R/number_of_zones.R R/number_of_features.R R/feature_names.R R/zone_names.R R/number_of_planning_units.R R/tbl_df.R R/number_of_total_units.R R/add_default_objective.R R/targets.R R/add_default_decisions.R R/waiver.R R/new_optimization_problem.R R/add_default_portfolio.R src/rcpp_apply_feature_contiguity_constraints.cpp src/rcpp_boundary_data.cpp src/rcpp_ferrier_score.cpp src/rcpp_apply_contiguity_constraints.cpp src/optimization_problem.cpp src/rcpp_apply_boundary_penalties.cpp src/rcpp_apply_max_phylo_objective.cpp src/rcpp_apply_min_largest_shortfall_objective.cpp src/rcpp_apply_connectivity_penalties.cpp src/rcpp_apply_max_cover_objective.cpp src/rcpp_apply_max_utility_objective.cpp src/rcpp_add_rij_data.cpp src/rcpp_apply_max_features_objective.cpp src/rcpp_apply_min_shortfall_objective.cpp src/rcpp_boundary_data.h src/rcpp_apply_neighbor_constraints.cpp src/rcpp_sp_to_polyset.cpp src/rcpp_boundary.cpp src/rcpp_summarize_exactextractr.cpp src/rcpp_branch_matrix.cpp src/rcpp_absolute_amount_held_by_solution.cpp src/optimization_problem.h src/rcpp_apply_min_set_objective.cpp src/rcpp_str_tree_to_sparse_matrix.cpp src/rcpp_list_to_matrix_indices.cpp src/rcpp_apply_linear_penalties.cpp src/functions.cpp src/rcpp_forbid_solution.cpp src/rcpp_connectivity.cpp src/rcpp_add_zones_constraints.cpp src/rcpp_apply_decisions.cpp src/rcpp_add_linear_constraints.cpp src/rcpp_apply_feature_weights.cpp src/rcpp_apply_bounded_constraints.cpp src/rcpp_apply_locked_constraints.cpp src/functions.h src/init.c

No flags found

Use flags to group coverage reports by test type, project and/or folders.
Then setup custom commit statuses and notifications for each flag.

e.g., #unittest #integration

#production #enterprise

#frontend #backend

Learn more about Codecov Flags here.

Showing 2 of 166 files from the diff.
Other files ignored by Codecov
docs/authors.html has changed.
docs/404.html has changed.
README.md has changed.
docs/index.html has changed.
docs/pkgdown.yml 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"))),

Everything is accounted for!

No changes detected that need to be reviewed.
What changes does Codecov check for?
Lines, not adjusted in diff, that have changed coverage data.
Files that introduced coverage data that had none before.
Files that have missing coverage data that once were tracked.
Files Coverage
R 0.01% 94.93%
src 98.81%
Project Totals (124 files) 96.12%
Loading