Rukawaa11
Rukawaa11

Reputation: 41

Using the Optaplanner algorithm to solve, how can I set the solution to automatically stop when the optimal solution is found?

Using Optaplanner to solve the problem, I configured the first fit algorithm. At present, I can only set a fixed time for the solution. Even if the optimal solution has been found in advance, I need to continue to wait for the end of the solution. How can I set the solution to stop automatically when the optimal solution is found?

Upvotes: 1

Views: 574

Answers (2)

yurloc
yurloc

Reputation: 2358

TLDR: if you know what the optimal solution to your problem is, then you don't need OptaPlanner :)

Presuming you really have an optimization problem, then you don't know how an optimal solution looks like, what its score is, neither how to find it. You only have a scoring function that is used to quickly compare quality of different solutions.

With a good local search algorithm configuration, OptaPlanner will keep providing you with better and better solutions with varying frequency. And you will never know if the last solution OptaPlanner has found is the optimal one.

You have a couple of basic options to tell OptaPlanner when to stop solving:

  1. You have a limited time to spend optimizing the problem. Then use time based termination.

  2. You have a rough idea what the score of a "good enough" solution should be. Then use best score termination.

  3. You have a vague idea of the time available for solving. Then you can think: if OptaPlanner is unable to improve the solution for say 1 hour, then stop. Use unimproved time spent termination for that.

  4. Finally, you can terminate solving asynchronously based on some external event (user's decision, etc.).

Upvotes: 6

OptaPlanner does not know what the best solution is. If you know what the best solution is, you can have it terminate when that solution is reached.

Upvotes: 3

Related Questions