2017-03-07 72 views
0

我正在從事像nurseroster這樣的項目,我需要一個建議。問題是:每個員工每天可以工作在不止一個航班上,而且這些航班有不同的開始時間和結束時間。每個員工都被分配到飛行中的飛行協助。 考慮到第一班航班的開始時間和最後一班航班的結束時間,是否有規則能夠計算總工作時間?例如:flightAssignment1 employee1在8:00結束於10:00,flightAssigment2 employee1從12:00結束於15:00。員工1的總工作時間是8:00 - 15:00(7小時)。NurseRoster的總工作時間,如項目

我想這一個,但它返回一個無法解析對象類型 'CheckinRoster.getEmployeeTotalHours'錯誤:

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我改變了這樣的規則:

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 

獲得如下兩個好結果:

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

個而且像這樣的,我與在整數變換一些錯誤或其他東西壞的結果

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

的minWorkedHour和maxWorkedHour是在類FlightAssignemnt整數,蓄能器似乎是雙人或浮動。有什麼問題?

+0

使用累積函數,請參閱其他optaplanner示例 –

+0

使用max和min獲取最大時間和最短時間? – Giancarlo

回答

0

簽在論壇上我找到一個recent post與我修改我的問題的解決方案:

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 

但比分我得到的是不符合的解決方案是一致的。我得到-21分,但解決方案應該有-40分。它有什麼問題?

這是關於總工作時間的結果:

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 
0

這是除了一個問題,我的解決方案...

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

// Minimum number of assignments 
rule "minimumTotalAssignments" 
    when 
     EmployeeAssignmentTotal(total < 5, 
      $total : total) 
    then 
     scoreHolder.addSoftConstraintMatch(kcontext, ($total - 5)); 
end 

// Maximum number of assignments 
rule "maximumTotalAssignments" 
    when 
     EmployeeAssignmentTotal(total > 7, 
      $total : total) 
    then 
     scoreHolder.addSoftConstraintMatch(kcontext, (7 - $total)); 
end 

給出的結果是好的,除了一些奇怪值:

好成績

Employee 1 ---DIFFERENCE MIN MAX: 11 --- MIN: 7.0 --- MAX: 18.0 
Employee 2 ---DIFFERENCE MIN MAX: 7 --- MIN: 12.0 --- MAX: 19.0 

壞的結果

Employee 3 ---DIFFERENCE MIN MAX: 1 --- MIN: 1.7976931348623157E308 --- MAX: -1.7976931348623157E308 

任何線索這一奇怪的值?從它們中獲取intValue,然後返回2147483647和-2147483648給出差異1

相關問題