Skip to content
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

Binary variable <= Binary matrix: Error in constraint$lhs - constraint$rhs : non-numeric argument to binary operator #422

Open
datadrivensupplychain opened this issue Apr 28, 2022 · 4 comments

Comments

@datadrivensupplychain
Copy link

I am building a MILPModel where the primary decision variables are binary, x[i,j]. Depending upon the i,j pair, I may want to force x[i,j] to 0 instead of giving the model the choice of 0 or 1. I have a static matrix, allowed_binary, that is i rows and j columns, with value of 0 if x[i,j] must be 0, and a value of 1 if x[i,j] can be 0 or 1. I made a very simple constraint:

add_constraint(x[i,j] <= allowed_binary[i,j], i=1:10, j = 1:20)

This constraint is accepted by ompr with a MIPModel but when I add it in a MILPModel, I get the error Error in constraint$lhs - constraint$rhs : non-numeric argument to binary operator. Is this because of how MILPModel handles multidimensional decision variables? I could probably form my decision variables x to be along a single vector if necessary.

@sbmack
Copy link

sbmack commented Apr 28, 2022

Is this because of how MILPModel handles multidimensional decision variables? I could probably form my decision variables x to be along a single vector if necessary.

Right. MILPModel was formulated with significant performance improvement over the original MIPModel. But using arrays in MILPModel constraints requires the use of the colwise auxiliary function which users found not intuitive. Dirk has since updated MIPModel incorporating the performance improvements of MILPModel while maintaining the formulation elements of the original MIPModel.

So it is my impression now that the updated MIPModel supercedes MILPModel. So your MIPModel version is what you should use.

@datadrivensupplychain
Copy link
Author

OK, I'm actually (sorta) used to using colwise now, so if that's they key then I'll use that. Good to hear that MIPModel now has the performance benefits of MILPModel. I've been using MILPModel exclusively for a couple years now because of the speed of the model build, and just had to accept that the syntax was an acquired taste.

@sbmack
Copy link

sbmack commented Apr 28, 2022

BTW, you may want to install the development versions of ompr, ompr.roi to ensure that the latest functionality is being accessed by your MIPModel formulation:

remotes::install_github("dirkschumacher/ompr")
remotes::install_github("dirkschumacher/ompr.roi")

@datadrivensupplychain
Copy link
Author

Thanks, I'll try that. Right now I'm using the latest CRAN versions of both ompr and ompr.roi. I'm also using some random version of ROI.plugin.gurobi I was able to successfully install

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants