google / or-tools

Google's Operations Research tools:
https://developers.google.com/optimization/
Apache License 2.0
10.82k stars 2.09k forks source link

Constraints reuse #919

Closed rotcx closed 5 years ago

rotcx commented 5 years ago

Comparing to the "define solver -> solver.makeConstraint" way, the "define a constraint -> add the constraint to a model/solver" way made constraints reusable?

When the overall model is complex and difficult to solver directly, constraint reuse is usual by iteratively solve two decomposed models with (largely) overlapped constraints.

Is it possible?

lperron commented 5 years ago

I guess you are using the constraint solver engine.

I would recommend you use the CP-SAT solver as the original CP solver is in maintenance mode. With the CP-SAT solver, you cannot create a model without adding it to the solver. So this question is moot IMO :-) Laurent Perron | Operations Research | lperron@google.com | (33) 1 42 68 53 00

Le sam. 3 nov. 2018 à 17:07, xuanc notifications@github.com a écrit :

Comparing to the "define solver -> solver.makeConstraint" way, the "define a constraint -> add the constraint to a model/solver" way made constraints reusable?

When the overall model is complex and difficult to solver directly, constraint reuse is usual by iteratively solve two decomposed models with (largely) overlapped constraints.

Is it possible?

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/google/or-tools/issues/919, or mute the thread https://github.com/notifications/unsubscribe-auth/AKj17bx99o6hTx0jhe6IY6Z3IHkLxmjcks5urb85gaJpZM4YM3rW .

lperron commented 5 years ago

I will close the issue. Please reopen if you need help.

rotcx commented 5 years ago

I was using the MILP wrapper/solver.

For instance, in GAMS we can define that the model consists several constraints, where constraints are reusable in other models.

https://www.gams.com/latest/gamslib_ml/libhtml/gamslib_gapmin.html Model assign 'original assignment model' / capacity, choice, defz /; Model pknap / knapsack, defzlrx /;

lperron commented 5 years ago

The linear solver has no concept of constraints created but not added. If you want to disable a constraint, just change its LB/UB to -inf, +inf Laurent Perron | Operations Research | lperron@google.com | (33) 1 42 68 53 00

Le mer. 19 déc. 2018 à 04:44, xuanc notifications@github.com a écrit :

I was using the MILP wrapper/solver.

— You are receiving this because you modified the open/close state. Reply to this email directly, view it on GitHub https://github.com/google/or-tools/issues/919#issuecomment-448459620, or mute the thread https://github.com/notifications/unsubscribe-auth/AKj17TCttO8vZpEvOZlp7i4vIaWpaoUMks5u6bYSgaJpZM4YM3rW .

rotcx commented 5 years ago

Are you planning to develop the following feature? It strongly adds applicability.

Comparing to the "define solver -> solver.makeConstraint" way, the "define a constraint -> add the constraint to a model/solver" way made constraints reusable?

When the overall model is complex and difficult to solver directly, constraint reuse is usual by iteratively solve two decomposed models with (largely) overlapped constraints.

lperron commented 5 years ago

Short answer: no.

Long answer: I challenge the usefulness. Most times, the code is divided into blocks, one reads the data, and one build the model from that data. Adding a layer of decomposition is just adding parameters or filters to the code building block.

So instead of changing your model, you just call the model building block with different parameters.

Thanks

Laurent Perron | Operations Research | lperron@google.com | (33) 1 42 68 53 00

Le jeu. 20 déc. 2018 à 07:03, xuanc notifications@github.com a écrit :

Are you planning to develop the following feature? It strongly adds applicability.

Comparing to the "define solver -> solver.makeConstraint" way, the "define a constraint -> add the constraint to a model/solver" way made constraints reusable?

When the overall model is complex and difficult to solver directly, constraint reuse is usual by iteratively solve two decomposed models with (largely) overlapped constraints.

— You are receiving this because you modified the open/close state. Reply to this email directly, view it on GitHub https://github.com/google/or-tools/issues/919#issuecomment-448883882, or mute the thread https://github.com/notifications/unsubscribe-auth/AKj17dDxYIrTwDMWxOwMBAqLXjUzcKx9ks5u6ygUgaJpZM4YM3rW .

rotcx commented 4 years ago

https://amsterdamoptimization.com/pdf/benders.pdf

Here is an example.

GAMS uses: model /constraints 1, constraints, ... / to flexibly define models/sub models/relaxed models ... in a word, models with different constraints to implement decomposition / iteration algorithms of "hard" problems.

lperron commented 4 years ago

I understand decomposition, and benders. I am just saying you can tweak your model on the fly.

You can already change the model and resolve. Laurent Perron | Operations Research | lperron@google.com | (33) 1 42 68 53 00

Le lun. 30 sept. 2019 à 10:35, xuanc notifications@github.com a écrit :

https://amsterdamoptimization.com/pdf/benders.pdf

Here is an example.

GAMS uses: model /constraints 1, constraints, ... / to flexibly define models/sub models/relaxed models ... in a word, models with different constraints to implement decomposition / iteration algorithms of "hard" problems.

— You are receiving this because you modified the open/close state. Reply to this email directly, view it on GitHub https://github.com/google/or-tools/issues/919?email_source=notifications&email_token=ACUPL3PM72CM6WKK7TEQPR3QMG25PA5CNFSM4GBTPLLKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOD744ABY#issuecomment-536461319, or mute the thread https://github.com/notifications/unsubscribe-auth/ACUPL3KHTPKBTMOOXQXLTGDQMG25PANCNFSM4GBTPLLA .