Reputation: 1
I am trying to solve timetabling problem with OptaPlanner but I am facing with problem which may be connected to cloning issue. Why when my planning entity collection method looks like that
@PlanningEntityCollectionProperty
public List<Lesson> getLessons() {
return getProject().getLessons();
}
I am getting error
java.lang.IllegalStateException: The solutionProperty (lessons) was not cloned as expected. The FieldAccessingSolutionCloner failed to recognize that property's field, probably because its field name is different.
but, when the method looks like
@PlanningEntityCollectionProperty
public List<Lesson> getLessons() {
if (lessons == null) {
lessons = getProject().getLessons();
}
return lessons;
}
everything is ok. What could be a reason? Why I am getting this error? Thanks for any help.
Upvotes: 0
Views: 513
Reputation: 27312
The generic cloner (to planning clone the best solution so the working solution can degrade) can't currently handle that first piece of code unfortunately.
There are 2 workarounds:
I wouldn't do it with that lazy initialization trick, as you might not always be able to guarantee that the getter has been called at least once before a planning clone happened.
Upvotes: 1