-
Notifications
You must be signed in to change notification settings - Fork 53
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
Constraint with binary variable not being respected? #53
Comments
Hey @prakaa it is hard to tell just from code. One thing I spotted: The line discharge_mw - power_cap * (1 - charge_state) <= 0, does not work (and acutally linopy should raise an error here). Constants should always be on the right hand side, e.g. discharge_mw + power_cap * charge_state <= power_cap, And a tip: when initializing the model could you can set the argument |
Thanks @FabianHofmann, that fixed the binary variable issue. Unfortunately I'm still not getting an objective comparable to those I get from pyomo/mip/JuMP. Not sure why, the LP file looks OK... That error is not raised unless a non-constant is on the RHS - if the RHS is 0, then the error is not raised. So in this case the error was not raised. Happy to suggest a change via PR, but I think that requirement re constraints could be clearer in the docs on this page https://linopy.readthedocs.io/en/latest/creating-constraints.html. In my mind that change to the docs would include:
|
A PR with your points would be fantastic. The only thing I can offer to solve that is to that you send me you nb with the underlying data. Otherwise its hard to debug... |
Oh, i didn't know there was an issue about this already. Well, the problem is #57 . |
Thanks @coroa. @FabianHofmann sorry I am a bit snowed under, will hopefully get to that PR in the next couple of weeks. |
This seems to be solved in the current master. I you still encounter problems please reopen :) |
Hi there,
I'm comparing a few packages for solving a MILP with binary variables: https://github.com/prakaa/Battery-Optimisation-Benchmarking
I have formulated the problem to respect linopy's requirements (e.g. all variables on LHS, minimisation only) and have been able to find an appropriate solution in JuMP, pyomo and python-mip. However the solution does not appear to be right for linopy: https://github.com/prakaa/Battery-Optimisation-Benchmarking/blob/master/battery_optimisation_benchmarking/python/linopy.ipynb
Specifically, there is a pair of constraints that contain a binary variable ("charge state") that should ensure that the modelled battery cannot discharge and charge at the same time. This appears to be respected in other packages (making me think the model formulation is OK), but does not appear to be in linopy.
Have I made a mistake in formulating the model using linopy, or is this a bug?
The text was updated successfully, but these errors were encountered: