-
Notifications
You must be signed in to change notification settings - Fork 35
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add dependency matrix to constrains #450
Comments
With dependent binary variables you have to define the types of dependencies between the variables. The side constraints are formulated based on type. For example: x1 requires x2: x1, x2 mutually dependent: x1, x2 mutually exclusive: There are other cases. Dependency constraints with more than 2 variables can be chained together. The specific constraint you need will be a function of the dependencies among a, b, c, d. Edit your question to include that info for more help. |
Thanks for the reply!
In my case, projects that have a 1 in the dependency matrix are mutually dependent on each other. I need to add a constraint that the sum of dependencies for each row of a matrix containing only selected projects must be equal to 1. The problem is that I don't understand how to properly include this constraint in the model.
|
Again, you have to specify the type of each dependency because it determines the signs of the coefficients, the type of inequality/equality and the value of the right hand side (RHS). So for example row 1 in your matrix, what is the dependency relationship between b and c? And also the other rows? |
Projects depend on each other if the matrix at their intersection has a value greater than 0. For example:
For example, let’s take three projects: “a”, “b”, “d” and do this check manually. To do this, you need to take the original matrix, exclude the row and column with project “с” and calculate the sum for each row.
Project "a" depends on project "c" and if it is excluded, the row sum for project "a" will be less than 1. |
But exactly HOW do they depend on each other? If project a requires project b and project c then that maps to case 1 above: So for the a requires b AND c case could be written as: a - b <= 0 So you can see that the coefficients, inequality and RHS are dependent on the type of constraint. |
Thank you for your help and patience. This is my first experience using this package, as well as designing MILP models, so a number of my questions may be quite primitive or I may be mistaken. The inequality you proposed for project "b" correctly describes the dependencies. But this is only true for one project; for other projects it will be different. What if there are 1000 such projects? for each of them is it necessary to write down such an inequality? Or should I specify a matrix as the decision variable? |
You could use matrices with 1 matrix block for each constraint type. The values in a matrix are the coefficients of the contraints. So with: the a requires b AND c case could be written as: a - b <= 0 Better to use the 2 constraint version with the coefficients being: a b c d For the block of constraints the inequality would be <= and the RHS would be 0 |
Thanks to your hint, I improved the coefficient matrix and constrain type. The a requires b AND c and they are completely dependent on each other: Coefficients would be:
Then I try to set the constrain:
But I get an error
|
You have a bunch of errors in your model. Here's an update:
|
Thank you for your feedback. I was able to add the required constraint to the model (#259 (comment)). Here is the working code:
|
The use of the coef_matrix does not make sense since you have only a single constraint. Moreover you stated:
What you are saying there is that a OR b OR c must be selected. That means only 1 solution variable of the 3. Since d has no dependencies, you do not have to include d in a constraint. Simple visual inspection of your profit vector shows that a and d should be selected since a = 100 and d = 50. However, run the code:
Please clarify what you really want. |
The model generates the right solutions for my task. Perhaps I didn't describe the constraints quite correctly:
I will try to describe the problem in simple words without mathematical equations:
In the given example, the solution of the model is projects a, b and с. These are three interdependent projects with a total profit of 115. If change the conditions and assign a profit of 500 to the project d, then the solution of the model will be the project d. Thus, the model takes into account the dependency matrix.
|
That constraint type is usually solved using auxiliary binary variables:
In the above code the defined coefficient |
Your code works on this data, but I tried to add another group of interdependent projects (e and f) and the solution did not match my expectations.
I tried to use the model on real data. I have a data set for 1800 projects and a dependency matrix of 1800x1800. I waited about 4 hours and, without waiting for an answer, stopped the calculation. Is there a way to estimate the approximate time it will take to find a solution? Or maybe it's worth trying to use a different solver? |
It worked for me:
Your constraint says that projects 1:3, 5:6 are linked. Only one project of those 5 can be selected, so project 1 and project 4 which has no dependencies are basic. The solution is degenerate since project 5 has the same profit coefficient as project 1. A MIP problem with 1800 variables and 1800 binary constraints is considered small and should solve very quickly with any solver. |
There are two groups of interdependent projects in the data set (c(a, b, c) & c(e, f) and one independent project (d). One of the constrain is “all projects from the same group or none must be selected”. The correct solution would be to select project d and a group of projects e and f. Changing the abcsum parameter does not produce the desired result.
|
I
It should be obvious that you have to add a second auxiliary constraint. |
I modified your solution to take into account the dependency matrix. This could only be achieved using a loop.
|
It's not clear to me what you are trying to do. I ran the model and the solution is a, b, c = 1. In
You don't need a You're welcome... |
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?
This model selects projects a, b, d, but given dependencies, projects a, b, c should be selected.
The text was updated successfully, but these errors were encountered: