Skip to content

add dependency matrix to constrains #450

@RKonstantinR

Description

@RKonstantinR

Hello, thanks for the great package!

I'm trying to use your library to develop a model for creating an optimal project portfolio. I was able to set constraint on the total number of projects and write the resulting function that maximizes profit.

But in addition to standard constraints, I’m trying to add project dependency matrix into the model. A number of projects depend on each other. The implementation of two projects out of three does not make economic sense.

There is a way to set constraints based on a dependency matrix and check that all related projects are present in the resulting list of projects?

library(dplyr)
library(ROI)
library(ROI.plugin.symphony)
library(ompr)
library(ompr.roi)
library(ROI.plugin.glpk)

project_list <- tibble(name = c("a", "b", "c", "d"), profit = c(100, 10, 5, 50)) %>% 
  mutate(item = row_number())

max_project <- 3

# dependency matrix (if 1 - the project depends on another project)
my_matrix <- matrix(
  c(0, 1, 1, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0), 
  nrow = 4,   
  ncol = 4,        
  byrow = TRUE         
)

rownames(my_matrix) <- c("a", "b", "c", "d")
colnames(my_matrix) <- c("a", "b", "c", "d")

m <- MIPModel() %>%
  add_variable(x[i], i=project_list$item, type="binary") %>%
  add_constraint(sum_over(x[i], i=project_list$item) <= max_project) %>% 
  set_objective(sum_over(project_list$profit[i]*x[i], i=project_list$item),"max") %>% 
  solve_model(with_ROI(solver = "symphony", verbosity=1))

This model selects projects a, b, d, but given dependencies, projects a, b, c should be selected.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions