0

I'm trying to implement something like NurseRostering in example, so I did everything the same except of classes in 'solver/drools&moves' (also can someone explain what they do exactly?).

So, my problem is, I implemented Comparators: EmployeeStrengthComparator and JobDifficultyComparator, they are like EmployeeStrengthComparator and ShiftAssignmentDifficultyComparator in NurseRostering example.

So I set up my rules, my solution, and started to solve, but I get this error:

Exception in thread "main" java.lang.ClassCastException: org.demo.DemoApp.domain.JobAssignment cannot be cast to org.demo.DemoApp.domain.Employee
at org.demo.DemoApp.domain.solver.EmployeeStrengthComparator.compare(EmployeeStrengthComparator.java:12)
at java.util.TimSort.countRunAndMakeAscending(TimSort.java:355)
at java.util.TimSort.sort(TimSort.java:220)
at java.util.Arrays.sort(Arrays.java:1512)
at java.util.ArrayList.sort(ArrayList.java:1454)
at java.util.Collections.sort(Collections.java:175)
at org.optaplanner.core.impl.heuristic.selector.common.decorator.ComparatorSelectionSorter.sort(ComparatorSelectionSorter.java:45)
at org.optaplanner.core.impl.heuristic.selector.value.decorator.SortingValueSelector.constructCache(SortingValueSelector.java:43)
at org.optaplanner.core.impl.heuristic.selector.common.SelectionCacheLifecycleBridge.phaseStarted(SelectionCacheLifecycleBridge.java:49)
at org.optaplanner.core.impl.phase.event.PhaseLifecycleSupport.firePhaseStarted(PhaseLifecycleSupport.java:39)

I hope somebody knows the reasons where did I go wrong, could provide more information\sources of course, but I guess the reason is pretty obvious, because I'm very new to this framework and could missed something in configurations may be.

UPD: so it was like:

@PlanningEntityCollectionProperty
@ValueRangeProvider(id = "employeeRange")
public List<JobAssignment> getJobAssignments() {
    return jobAssignments;
}
animekun
  • 1,789
  • 4
  • 28
  • 45

1 Answers1

0

oh well... I accidentally added attribute ValueRangeProvider to planning entity JobAssignment, when it should be placed on Employee, now it's ok

UPD:

And it should be like this:

@ValueRangeProvider(id = "employeeRange")
public List<Employee> getEmployees() {
    return employees;
}

@PlanningEntityCollectionProperty
public List<VisitAssignment> getVisitAssignments() {
    return visitAssignments;
}
animekun
  • 1,789
  • 4
  • 28
  • 45
  • Which method on these? Normally a ValueRangeProvider is on a Solution class's getter (or a planning entity, but that's far less common) – Geoffrey De Smet Dec 02 '15 at 08:18
  • It's very strange that OptaPlanner didn't fail fast (with a nice error message) because the planning variable's type didn't match the ValueRangeProvider's type. If that's indeed that case, feel free to open a jira for that. – Geoffrey De Smet Dec 02 '15 at 08:19
  • @GeoffreyDeSmet wow, thanks for response, Geoffrey, this is really great framework! It was totally my fault :) just mixed up attributes in solution class. Just wondering, if there exists any descriptions of class patterns used in examples? It will be very useful for fast involve in development with Optaplanner, I guess. – animekun Dec 02 '15 at 13:16
  • See my latest blog on optaplanner.org about time design patterns and the docs chapter Planner configuration section "is my class an entity or ...?" – Geoffrey De Smet Dec 02 '15 at 13:18
  • Can you recall exactly how you messed them up and copy paste a snippet of code that did that? When a user does that, OptaPlanner shouldn't fail late with a ClassCastException, but it should probably fail faster with a clear indication. – Geoffrey De Smet Dec 02 '15 at 13:19
  • @GeoffreyDeSmet I'm sorry for the delay, was busy with critical tasks, now is it ok? – animekun Dec 02 '15 at 23:41
  • 1
    Thanks for the snippets Greag! – Geoffrey De Smet Dec 03 '15 at 07:27