4

I have been trying to implement a custom Construction Heuristic in Optaplanner on a problem similar to the Nurse Rostering one.

Everything seems to be annotated correctly, and is added to the SolverConfiguration, but i keep getting this error:

Exception in thread "main" java.lang.IllegalArgumentException: A planning entity is an instance of an entitySubclass (class java.lang.Integer) that is not configured as a planning entity.
If that class (Integer) (or superclass thereof) is not a entityClass ([class org.optaplanner.examples.nurserostering.domain.SkillRequirement, class org.optaplanner.examples.nurserostering.domain.ShiftAssignment]), check your Solution implementation's annotated methods.
If it is, check your solver configuration.
at org.optaplanner.core.impl.domain.solution.descriptor.SolutionDescriptor.findEntityDescriptorOrFail(SolutionDescriptor.java:398)
at org.optaplanner.core.impl.domain.solution.descriptor.SolutionDescriptor.findVariableDescriptorOrFail(SolutionDescriptor.java:443)
at org.optaplanner.core.impl.score.director.AbstractScoreDirector.beforeVariableChanged(AbstractScoreDirector.java:226)
at org.optaplanner.examples.nurserostering.domain.solver.CustomConstructionHeuristic.changeWorkingSolution   (CustomConstructionHeuristic.java:86)
at org.optaplanner.core.impl.phase.custom.DefaultCustomPhase.doStep(DefaultCustomPhase.java:89)
at org.optaplanner.core.impl.phase.custom.DefaultCustomPhase.solve(DefaultCustomPhase.java:71)
at org.optaplanner.core.impl.solver.DefaultSolver.runPhases(DefaultSolver.java:214)
at org.optaplanner.core.impl.solver.DefaultSolver.solve(DefaultSolver.java:176)
at org.optaplanner.examples.nurserostering.app.NurseRosterConsoleApp.main(NurseRosterConsoleApp.java:142)

I tried to fix it by using these references:

OptaPlanner Xml configuration and entitySubclass is not configured as a planning entity error

OptaPlanner: java.lang.IllegalArgumentException

https://groups.google.com/forum/#!topic/optaplanner-dev/wCdeSQhGdaQ

So far nothing worked. Any clues on how i can solve this?

Community
  • 1
  • 1
Nikola Atanasov
  • 605
  • 1
  • 4
  • 11
  • About your class `org.optaplanner.examples.nurserostering.domain.solver.CustomConstructionHeuristic` - please don't use the package org.optaplanner for your own project (especially if you ever intend to deploy it to a Maven repo), because it's confusing (I thought it was one of ours). Just refactor the namespace of the entire nurserotering example (which you copied) to for example `com.xy.nurserostering`. – Geoffrey De Smet Apr 07 '16 at 07:59

1 Answers1

3

Yea, that error message isn't 100% user friendly yet, I 'll fix that for 7.0.

Anyway, what's it's saying is you got something like this in your solution class:

 @PlanningEntityCollectionProperty
 public List<Object> getMyEntities() {
     List<Object> entities = new ArrayList<>();
     entities.add(Integer.valueOf(1));
     ...
     return entities;
 }

So you're adding an Integer to a collection that should only exist out of entities (so only out of instances of SkillRequirement or ShiftAssignment).

PS: It's weird that SkillRequirement is a planning entity, you might want to give that class a better name in your variation of nurse rostering.

Geoffrey De Smet
  • 26,223
  • 11
  • 73
  • 120
  • Turns out i declared the list as `int` instead of `Integer`, the getter and setter likewise. I corrected all of them as `Integer's`, and now the problem is gone. – Nikola Atanasov Apr 07 '16 at 18:57
  • Wierd, because Integer's cannot be a planning entity either (the Integer class is not mutable and does not have a @PlanningEntity annotation, although xml annotations will later allow that last problem). – Geoffrey De Smet Apr 08 '16 at 07:05