solution_statistics: Solution statistics

View source: R/solution_statistics.R

solution_statisticsR Documentation

Solution statistics

Description

Calculate statistics describing a solution to a project prioritization problem().

Usage

solution_statistics(x, solution)

Arguments

x

project prioritization problem().

solution

base::data.frame() or tibble::tibble() table containing the solutions. Here, rows correspond to different solutions and columns correspond to different actions. Each column in the argument to solution should be named according to a different action in x. Cell values indicate if an action is funded in a given solution or not, and should be either zero or one. Arguments to solution can contain additional columns, and they will be ignored.

Value

A tibble::tibble() table containing the following columns:

"cost"

numeric cost of each solution.

"obj"

numeric objective value for each solution. This is calculated using the objective function defined for the argument to x.

x$project_names()

numeric column for each project indicating if it was completely funded (with a value of 1) or not (with a value of 0).

x$feature_names()

numeric column for each feature indicating the probability that it will persist into the future given each solution.

See Also

objectives, replacement_costs(), project_cost_effectiveness().

Examples

# load data
data(sim_projects, sim_features, sim_actions)

# print project data
print(sim_projects)

# print action data
print(sim_features)

# print feature data
print(sim_actions)

# build problem
p <- problem(sim_projects, sim_actions, sim_features,
             "name", "success", "name", "cost", "name") %>%
     add_max_richness_objective(budget = 400) %>%
     add_feature_weights("weight") %>%
     add_binary_decisions()

# print problem
print(p)

# create a table with some solutions
solutions <- data.frame(F1_action =       c(0, 1, 1),
                        F2_action =       c(0, 1, 0),
                        F3_action =       c(0, 1, 1),
                        F4_action =       c(0, 1, 0),
                        F5_action =       c(0, 1, 1),
                        baseline_action = c(1, 1, 1))

# print the solutions
# the first solution only has the baseline action funded
# the second solution has every action funded
# the third solution has only some actions funded
print(solutions)

# calculate statistics
solution_statistics(p, solutions)

prioritizr/ppr documentation built on Sept. 10, 2022, 1:18 p.m.