#Help with Timefold Constraint Stream Type Mismatches in Employee Scheduling

3 messages · Page 1 of 1 (latest)

prime osprey
#

I'm working on an employee scheduling system using Timefold (formerly OptaPlanner) and I'm running into type mismatch issues with my constraint streams. Specifically, I'm trying to implement a work percentage constraint that ensures employees are scheduled according to their preferred work percentage.

Here's the relevant part of my constraint:

public Constraint workPercentage(ConstraintFactory constraintFactory) {
    return constraintFactory.forEach(Employee.class)
            .join(Shift.class, equal(Employee::getName, Shift::getEmployee))
            .groupBy(Employee::getName, 
                    ConstraintCollectors.sum(shift -> 
                        Duration.between(shift.getStart(), shift.getEnd()).toHours()))
            // ... rest of constraint
}

I'm getting several type mismatch errors:

  1. The groupBy method is expecting BiConstraintCollector<Employee,Shift,ResultContainerA_,ResultA_> but getting UniConstraintCollector<Object,?,Integer>
  2. The lambda in the sum collector can't resolve getStart() and getEnd() methods because it's seeing the parameter as Object instead of Shift
  3. The functional interface type mismatch for Employee::getName

My domain classes are:

  • Employee with @PlanningId String name and int workPercentage
  • Shift with LocalDateTime start/end and @PlanningVariable Employee employee

I'm trying to:

  1. Join employees with their shifts
  2. Group by employee name
  3. Sum up the total hours worked
  4. Compare against their desired work percentage

Other constraints in my system (like shiftPreference) work fine, but I can't get the types right for this grouping operation. Any help would be appreciated!

Has anyone encountered similar issues with constraint streams and grouping operations? What's the correct way to handle these type parameters?

blissful oceanBOT
#

This post has been reserved for your question.

Hey @prime osprey! Please use /close or the Close Post button above when your problem is solved. Please remember to follow the help guidelines. This post will be automatically marked as dormant after 300 minutes of inactivity.

TIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here.