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

Lukáš Petrovický lpetrovi at redhat.com
Tue Jun 28 05:23:56 EDT 2011


Geoffrey De Smet píše v Út 28. 06. 2011 v 11:18 +0200:
> 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?

I'd vote for 1) - when the solution is not fully initialized, it doesn't
fulfill my requirements for a solution. So, instead of calling it the
best solution, let's make it null.

Regards!

-- 
Lukáš Petrovický
QA Engineer, JBoss Enterprise BRMS
Phone: +420 532 294 123
irc: lpetrovi, triceo

Red Hat Czech, s. r. o.
Purkyňova 99, 612 00 Brno, Czech Republic



More information about the rules-dev mailing list