0

I'm working in a nurseroster like project and I need a suggestion on a rule. The problem is: every employee can work in more than a flight per day, and the flights have different start time and end time. every employee is assigned to a flight in flightAssigment. Is there a rule able to calculate the total working hours considering the start time of the first flight and the end time of the last flight? for ex: flightAssignment1 employee1 start at 8:00 end at 10:00, flightAssigment2 employee1 start at 12:00 end at 15:00. The total working period for employee1 is 8:00 - 15:00 (7 hours).

I'm trying this one but it return an Unable to resolve ObjectType 'CheckinRoster.getEmployeeTotalHours' error:

rule "insertEmployeeAssignmentTotal"
    salience 1 // Do these rules first (optional, for performance)
when
    $employee : Employee()
    $assignmentTotal : CheckinRoster.getEmployeeTotalHours($employee)
then
    insertLogical(new EmployeeAssignmentTotal($employee, $assignmentTotal.intValue()));
end

OK I changed the rule in this way:

rule "test"
when
    $employee : Employee()
    accumulate(
        FlightAssignment(employee == $employee, $start : minWorkedHour, $end : maxWorkedHour),
        $max : max($end),
        $min : min($start)
        )
then
    System.out.println($employee.getLabel() + " MIN: " + $min.intValue() + " --- MAX: " + $max.intValue());
    scoreHolder.addSoftConstraintMatch(kcontext, -($max.intValue() - $min.intValue()));
end

Obtaining good results like this two:

Employee 1 MIN: 7 --- MAX: 21
Employee 2 MIN: 6 --- MAX: 21

But also bad results like this one that I related to something wrong in the integer conversion or other thing

Employee 3 MIN: 2147483647 --- MAX: -2147483648

The minWorkedHour and the maxWorkedHour are integer in the class FlightAssignemnt, the accumulator seems to be Double or float. What's the problem?

Giancarlo
  • 3
  • 3

1 Answers1

0

Checkin on the forum I have find a recent post with a solution that I modified for my problem:

    rule "dailyWorkedUp"
when
    $employee : Employee()
    $dailyTotalHours : Number( intValue > 7) from accumulate(
                 $assignmentEmployee:  FlightAssignment(employee == $employee),
                sum($assignmentEmployee.getTotalWorkedHours())
        )
then
    //System.out.println($employee.getLabel() + " " +  (7-$dailyTotalHours.intValue()));
    scoreHolder.addHardConstraintMatch(kcontext, (7-$dailyTotalHours.intValue()));
end


rule "dailyWorkedDown"
when
    $employee : Employee()
    $dailyTotalHours : Number(intValue < 5) from accumulate(
                 $assignmentEmployee:  FlightAssignment(employee == $employee),
                sum($assignmentEmployee.getTotalWorkedHours())
        )
then
    //System.out.println("dailyWorkedDown " + $employee.getLabel() + " " +  ($dailyTotalHours.intValue() - 5));
    scoreHolder.addHardConstraintMatch(kcontext, ($dailyTotalHours.intValue() - 5));
end

But the score I get is not consistent with the solution. I get a score of -21 but the solution should have a score of -40. What is wrong with it?

This is the result regarding the total worked hours:

  Employee 1 total hours: 7
  Employee 2 total hours: 9
  Employee 3 total hours: 9
  Employee 4 total hours: 12
  Employee 5 total hours: 9
  Employee 6 total hours: 11
  Employee 7 total hours: 11
  Employee 8 total hours: 13
  Employee 9 total hours: 5
  Employee 10 total hours: 5
  Employee 11 total hours: 2
  Employee 12 total hours: 2
  Employee 13 total hours: 1
  Employee 14 total hours: 1
  Employee 15 total hours: 0
Community
  • 1
  • 1
Giancarlo
  • 3
  • 3