Reputation: 51
Can we add/remove constraints in optaplanner dynamically using Java ? Is there any example. I want the user to be allowed to add or remove this constraints at runtime using some UI.
Below link says something about it using drools. can it be done using java ? how to dynamically add / remove constraints in optaplanner
Upvotes: 5
Views: 1314
Reputation: 27337
1) Usually non hard coded constraint suffice. For example, instead of having a constraint that says:
there is:
This approach suffices in most of the use cases to avoid dynamic constraints. Notice that you can add/remove DayOfWeekDislike data in real-time with Solver.addProblemFactChange()
.
2) Next, @ConstraintConfiguration
can use @ConstraintWeight
to disable/enable constraints in real time with Solver.addProblemFactChange()
. Set a constraint weight to a zero score to disable it.
3) If both 1) and 2) fail, you really need dynamic constraints. I haven't seen any use case that needs to go this far yet, but we could support it. If you do need this approach, what's your use case?
Upvotes: 4