[rules-users] Best Solution found but latest solution does not work

Geoffrey De Smet ge0ffrey.spam at gmail.com
Tue Mar 4 11:17:55 EST 2014


It's likely you have separate issues:
- score corruption
- bug in your custom cloner (which fails sooner than the score 
corruption, that's why it doesn't show up)

I suggest fixing the score corruption first, while using the build-in 
cloner.
Looks like you're using IncrementalJavaScoreCalculator (so no drools)
because it's not reporting the constraint matches - .
Writing an IncrementalJavaScoreCalculator is hard.
Debugging it, is harder.
There's little advice I can give you to fix it. Look into 
<assertionScoreDirectorFactory> in the docs.

On 04-03-14 16:22, moltenice wrote:
> Oh, I actually decided to implement my own cloning methods because without
> them FULL_ASSERT gave me the following error:
>
> 14:46:41.601 [main] INFO  o.o.core.impl.solver.DefaultSolver - Solving
> started: time spend (7), score (-1hard/0soft), new best score
> (-1hard/0soft), random seed (0).
> 14:46:41.620 [main] INFO  o.o.c.i.c.DefaultConstructionHeuristicSolverPhase
> - Phase (0) constructionHeuristic ended: step total (0), time spend (28),
> best score (-1hard/0soft).
> 14:46:41.798 [main] DEBUG o.o.c.i.l.DefaultLocalSearchSolverPhase -     Step
> index (0), time spend (207), score (-1hard/0soft),     best score
> (-1hard/0soft), accepted/selected move count (1000/1000) for picked step
> (TimetableSlot at 44c099ef => Thomas).
> 14:46:41.947 [main] DEBUG o.o.c.i.l.DefaultLocalSearchSolverPhase -     Step
> index (1), time spend (356), score (-1hard/0soft),     best score
> (-1hard/0soft), accepted/selected move count (1000/1889) for picked step
> (TimetableSlot at 5289178b => Thomas).
> 14:46:42.092 [main] DEBUG o.o.c.i.l.DefaultLocalSearchSolverPhase -     Step
> index (2), time spend (501), score (0hard/0soft), new best score
> (0hard/0soft), accepted/selected move count (1000/2869) for picked step
> (TimetableSlot at c7b2b3e => Thomas).
> Exception in thread "main" java.lang.IllegalStateException: Score
> corruption: the solution's score (0hard/0soft) is not the uncorruptedScore
> (-1hard/0soft).
> 	at
> org.optaplanner.core.impl.score.director.AbstractScoreDirectorFactory.assertScoreFromScratch(AbstractScoreDirectorFactory.java:75)
> 	at
> org.optaplanner.core.impl.solver.scope.DefaultSolverScope.assertScoreFromScratch(DefaultSolverScope.java:113)
> 	at
> org.optaplanner.core.impl.bestsolution.BestSolutionRecaller.stepEnded(BestSolutionRecaller.java:90)
> 	at
> org.optaplanner.core.impl.phase.AbstractSolverPhase.stepEnded(AbstractSolverPhase.java:93)
> 	at
> org.optaplanner.core.impl.localsearch.DefaultLocalSearchSolverPhase.stepEnded(DefaultLocalSearchSolverPhase.java:126)
> 	at
> org.optaplanner.core.impl.localsearch.DefaultLocalSearchSolverPhase.solve(DefaultLocalSearchSolverPhase.java:83)
> 	at
> org.optaplanner.core.impl.solver.DefaultSolver.runSolverPhases(DefaultSolver.java:190)
> 	at
> org.optaplanner.core.impl.solver.DefaultSolver.solve(DefaultSolver.java:155)
> 	at Main.main(Main.java:29)
> 	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
> 	at
> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
> 	at
> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
> 	at java.lang.reflect.Method.invoke(Method.java:601)
> 	at com.intellij.rt.execution.application.AppMain.main(AppMain.java:120)
>
>
> Also, thanks for pointing me to the doc on cloning, I have tried to
> implement it as follows but now it doesn't seem to be able to update the
> values and just runs without changing original inputted solution until
> timelimit:
> My Solution's clone:
>      @Override
>      public Timetable planningClone() {
>          TimetableSlot[][] clonedTimetableSlotArray = new
> TimetableSlot[Constants.TIME_SLOTS][Constants.NUMBER_OF_STUDENTS];
>          for (int i = 0; i < Constants.TIME_SLOTS; i++) {
>              for (int j = 0; j < Constants.NUMBER_OF_STUDENTS; j++) {
>                  try {
>                      clonedTimetableSlotArray[i][j] = (TimetableSlot)
> this.timetable[i][j].clone();
>                  } catch (CloneNotSupportedException e) {
>                      e.printStackTrace();
>                  }
>              }
>          }
>
>          Timetable clonedTimetable = new Timetable(clonedTimetableSlotArray);
>          clonedTimetable.setScore(this.getScore());
>          return clonedTimetable;
>      }
>
>
> My Solution's Entity Collection:
>      @PlanningEntityCollectionProperty
>      public Collection<TimetableSlot> getListOfTimetableSlots() {
>          Collection<TimetableSlot> timetableSlotCollection = new
> ArrayList<TimetableSlot>();
>
>          for (int i = 0; i < Constants.TIME_SLOTS; i++) {
>              for (int j = 0; j < Constants.NUMBER_OF_STUDENTS; j++) {
>                  try {
>                      timetableSlotCollection.add((TimetableSlot)
> timetable[i][j].clone());
>                  } catch (CloneNotSupportedException e) {
>                      e.printStackTrace();
>                  }
>              }
>          }
>
>          return timetableSlotCollection;
>      }
>
>
> My Planning entity's clone:
>      @Override
>      protected Object clone() throws CloneNotSupportedException {
>          return new TimetableSlot(this.timeSlot, this.student,
> this.getLecturer());
>      }
>
> this.getLecturer() ensures that the Lecturer planning variable IS NOT
> cloned. Both timeSlot and student are int.
>
> I think I have met the requirements set out when doing custom cloning as
> specified in the documentation.
>
> I am still stumped as to what the problem is, I hope I've provided more
> insight.
>
> Thanks,
> Karan
>
>
>
> --
> View this message in context: http://drools.46999.n3.nabble.com/Best-Solution-found-but-latest-solution-does-not-work-tp4028442p4028484.html
> Sent from the Drools: User forum mailing list archive at Nabble.com.
> _______________________________________________
> rules-users mailing list
> rules-users at lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/rules-users
>




More information about the rules-users mailing list