Add constraints to a project prioritization problem() to ensure that solutions fund (or do not fund) specific actions. This function offers more fine-grained control than the add_locked_in_constraints() and add_locked_out_constraints() functions.

add_manual_locked_constraints(x, locked)

# S4 method for ProjectProblem,data.frame
add_manual_locked_constraints(x, locked)

# S4 method for ProjectProblem,tbl_df
add_manual_locked_constraints(x, locked)

Arguments

x

ProjectProblem object.

locked

data.frame or tibble::tibble() object. See the Details section for more information.

Value

ProjectProblem object with the constraints added to it.

Details

The argument to locked must contain the following fields (columns):

"action"

character action name.

"status"

numeric values indicating if actions should be funded (with a value of 1) or not (with a value of zero).

See also

Examples

# load data
data(sim_projects, sim_features, sim_actions)


# create data frame with locked statuses
status <- data.frame(action = sim_actions$name[1:2],
                     status = c(0, 1))

# print locked statuses
print(status)
#>      action status
#> 1 F1_action      0
#> 2 F2_action      1

# build problem with minimum set objective and targets that require each
# feature to have a 30% chance of persisting into the future
p <- problem(sim_projects, sim_actions, sim_features,
             "name", "success", "name", "cost", "name") %>%
      add_max_richness_objective(budget = 500) %>%
      add_manual_locked_constraints(status) %>%
      add_binary_decisions()

# print problem
print(p)
#> Project Prioritization Problem
#>   actions          F1_action, F2_action, F3_action, ... (6 actions)
#>   projects         F1_project, F2_project, F3_project, ... (6 projects)
#>   features         F1, F2, F3, ... (5 features)
#>   action costs:    min: 0, max: 103.22583
#>   project success: min: 0.81379, max: 1
#>   objective:       Maximum richness objective [budget (500)]
#>   targets:         none
#>   weights:         default
#>   decisions        Binary decision 
#>   constraints:     <Manually locked actions [2 locked units]>
#>   solver:          default

# \dontrun{
# solve problem
s <- solve(p)
#> Gurobi Optimizer version 9.5.2 build v9.5.2rc0 (linux64)
#> Thread count: 4 physical cores, 8 logical processors, using up to 1 threads
#> Optimize a model with 47 rows, 47 columns and 102 nonzeros
#> Model fingerprint: 0x54473ab0
#> Variable types: 0 continuous, 42 integer (42 binary)
#> Semi-Variable types: 5 continuous, 0 integer
#> Coefficient statistics:
#>   Matrix range     [9e-02, 1e+02]
#>   Objective range  [1e+00, 1e+00]
#>   Bounds range     [1e+00, 1e+00]
#>   RHS range        [1e+00, 5e+02]
#> Found heuristic solution: objective 1.4456093
#> Presolve removed 24 rows and 20 columns
#> Presolve time: 0.00s
#> Presolved: 23 rows, 27 columns, 46 nonzeros
#> Variable types: 0 continuous, 27 integer (27 binary)
#> Found heuristic solution: objective 2.0605492
#> Root relaxation presolved: 23 rows, 27 columns, 46 nonzeros
#> 
#> 
#> Root relaxation: objective 2.910246e+00, 7 iterations, 0.00 seconds (0.00 work units)
#> 
#>     Nodes    |    Current Node    |     Objective Bounds      |     Work
#>  Expl Unexpl |  Obj  Depth IntInf | Incumbent    BestBd   Gap | It/Node Time
#> 
#> *    0     0               0       2.9102457    2.91025  0.00%     -    0s
#> 
#> Explored 1 nodes (7 simplex iterations) in 0.00 seconds (0.00 work units)
#> Thread count was 1 (of 8 available processors)
#> 
#> Solution count 1: 2.91025 
#> 
#> Optimal solution found (tolerance 0.00e+00)
#> Best objective 2.910245655750e+00, best bound 2.910245655750e+00, gap 0.0000%

# print solution
print(s)
#> # A tibble: 1 × 21
#>   solution status    obj  cost F1_action F2_ac…¹ F3_ac…² F4_ac…³ F5_ac…⁴ basel…⁵
#>      <int> <chr>   <dbl> <dbl>     <dbl>   <dbl>   <dbl>   <dbl>   <dbl>   <dbl>
#> 1        1 OPTIMAL  2.91  403.         0       1       1       1       1       1
#> # … with 11 more variables: F1_project <dbl>, F2_project <dbl>,
#> #   F3_project <dbl>, F4_project <dbl>, F5_project <dbl>,
#> #   baseline_project <dbl>, F1 <dbl>, F2 <dbl>, F3 <dbl>, F4 <dbl>, F5 <dbl>,
#> #   and abbreviated variable names ¹​F2_action, ²​F3_action, ³​F4_action,
#> #   ⁴​F5_action, ⁵​baseline_action
# }