[rules-dev] Planner: should getBestSolution() return null when there is no initialized solution?

Geoffrey De Smet ge0ffrey.spam at gmail.com
Tue Jun 28 05:18:00 EDT 2011


Normally you use Planner like this:

solver.solve()
Solution bestSolution = solver.getBestSolution();
// ... do things with bestSolution
Score bestScore = bestSolution.getScore();

But let's suppose we give it 1 millisecond to plan and use a big, 
uninitialized starting solution
and our initialization algorithm actually terminates immediately as 
requested.
It won't be able to completely initialize the solution in that case.
What should solver.getBestSolution() return in that case? null or the 
partially initialized solution?

1) It returns null. So you 'll need to do null checks:
Solution bestSolution = solver.getBestSolution();
if (bestSolution == null) {
      // ... do things with bestSolution
      Score bestScore = bestSolution.getScore();
}

2) It returns the partially initialized solution. So you'll need to do 
isBestSolutionInitialized checks:
Solution bestSolution = solver.getBestSolution();
if (solver.isBestSolutionInitialized()) {
      // ... do things with bestSolution
      Score bestScore = bestSolution.getScore();
}

What makes more sense?

-- 
With kind regards,
Geoffrey De Smet




More information about the rules-dev mailing list