pulp
pulp copied to clipboard
Vanishing variables while solving with CBC
Details for the issue
I have implemented an approach to find a minimum infeasible set of constraints that works roughly as follows:
- Assume
[C1, C2, C3, ..., Ctotal]are the constraints of the problem - Using bisection, I find the last constraint, such that
[C1, ..., CLast]is feasible, but[C1, ..., CLast+1]is infeasible. - Using bisection, I find the first constraint, such that
[CFirst, ..., CLast+1]is feasible, but[CFirst-1, ..., CLast+1]is infeasible. - For each of the remaining constraints
Ci, I remove the constraint if[CFirst-1, Ci-1,Ci+1,...CLast+1]is infeasible.
As removing these constraints does not bother with the variables, some variables may get redundant, but I do not care about that.
What did you expect to see?
I expected the above to work just fine, but...
What did you see instead?
... what I observed is an exception in the line variables[name].varValue = values[name] of the following function in pulp.py that stores the solution:
variables = self.variablesDict()
for name in values:
if name != "__dummy":
variables[name].varValue = values[name]
Namely, there were variables that were sent to the solver and stored in the dictionary as values[name] so that they could be interpeted, but they did not appear in the variables dictionary. Seemingly they disappeared from the variables dictionary while the problem was being solved.
What I did is simply validate that the variable vas not pruned:
variables = self.variablesDict()
for name in values:
if name != "__dummy":
if name not in variables:
if warnOnPruning:
print(f"Warning: Variable has been pruned: {name}.")
else:
variables[name].varValue = values[name]
Does this make a reasonable and general solution? Should I submit this to pulp? The process of forking etc. is tedious, so I would only go for it if you guys find the solution reasonable and are willing to include it into future versions. If there is desire, I can also include the above searching for minimum infeasible set.
Useful extra information
What operating system are you using?
- [x] Windows: ( version: 10)
- [ ] Linux: ( distro: ___ )
- [ ] Mac OS: ( version: ___ )
- [ ] Other: ___
I'm using python version:
- [ ] 2.7
- [ ] 3.4
- [ ] 3.5
- [ ] 3.6
- [x] Other: 3.10
I installed PuLP via:
- [x] pypi (python -m pip install pulp)
- [ ] github (python -m pip install -U git+https://github.com/coin-or/pulp)
- [ ] Other: ___ (conda?)
Did you also
- [ ] Tried out the latest github version: https://github.com/coin-or/pulp
- [x] Searched for an existing similar issue: https://github.com/coin-or/pulp/issues?utf8=%E2%9C%93&q=is%3Aissue%20
Can you please paste the code with some formatting? I cannot read it well. Also, I do not understand if this is an issue or a feature request.
Thank you very much for your response!
Can you please paste the code with some formatting?
Indeed it was ugly, I did not observe the <> code icon in the edit.
Also, I do not understand if this is an issue or a feature request.
It is an issue that I had and I (believe) I fixed. It would be great if the fix is consistent with the general behavior of pulp and can be integrated into the main distribution, so that I do not need to refix it next time I update pulp.
If there is a process I need to follow, I am willing to do so, but perhaps it is easiest for an active developer to replace the function I changed in his code and submit it to the main package. Please advise.
Thanks for the response and the clarification. I still do not understand the use case or set of circumstances where this happens. Do you have a reproducible example that I can test? Are you editing the model internals? If a variable is not used in a constraint, it should not belong in the model.
Maybe we could do a more consistant pruning before solving so that this exception doesn't happen. But for that we need the reproducible example. Also, so we can add it as a unit test inside the library.
Agreed. I myself have a unit test to that effect so that I will get warned with the updates of pulp. I will look into a smaller publishable unit test and send it to you.
Note that this may take a while, as I am currently working on a next project. Is there an optimal time or a final time by which I should send you the unit test and sample data?
Also, may I just email the files to you avoiding the web interface hassle?
V sre., 17. jan. 2024 10:30 je oseba Franco Peschiera < @.***> napisala:
Thanks for the response and the clarification. I still do not understand the use case or set of circumstances where this happens. Do you have a reproducible example that I can test? Are you editing the model internals? If a variable is not used in a constraint, it should not belong in the model.
Maybe we could do a more consistant pruning before solving so that this exception doesn't happen. But for that we need the reproducible example. Also, so we can add it as a unit test inside the library.
— Reply to this email directly, view it on GitHub https://github.com/coin-or/pulp/issues/665#issuecomment-1895422354, or unsubscribe https://github.com/notifications/unsubscribe-auth/AHNJTOQ47LXSD2CMFVIIT33YO6K4DAVCNFSM6AAAAAAZYA6G7GVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTQOJVGQZDEMZVGQ . You are receiving this because you authored the thread.Message ID: @.***>