0

Need clarification regarding the statement that Problem fact class is used by the score constraints, but does NOT change during planning (as long as the problem stays the same).

Can Optaplanner handle scenarios (and return optimzed solution) where problem properties have a dependency on the Fact Values?

For example: In Vehicle Routing problem, can optaplanner engine return optimized solution based on the fact that it takes more time (say 1.2 times more) for Vehicle_1 than Vehicle_0 to travel from Location_A to Location_B.

Similarly in Project Job Scheduling example, Resource_X takes 1.2 days to complete a task but Resource_Y takes .9 days to complete the same task.

Manish
  • 47
  • 5
  • Each of your domain classes is either a problem fact or planning entity. The difference is the latter changes during planning and the former only changes during ProblemFactChange's or before the solve() method call. – Geoffrey De Smet Feb 24 '16 at 10:36

1 Answers1

0

Yes, it can. Several examples do that actually. There are several ways to design/implement that. Here's one that I prefer:

@PlanningEntity class TaskAssignment {
     Task task;
     @PlanningVariable Employee employee;

     public int getDuration() {
         // Warning: If affinity's or task types would change during planning (except during real-time planning ProblemFactChange of course),
         // we would need to do this through DRL or break incremental score calculation.
         return employee.getAffinityTo(task.getType()).getDuration();
     }

}


rule affinityBasedDuration
when
   TaskAssignment(employee != null, $d : duration)
then
   // addSoft(-$d)
end

You can even pass in arguments:

when
    $a : TaskAssignment($id : id)
    $b : TaskAssignment($id < id, $d: calculateOverlap($a))
then
   // addSoft(-$d)
end


@PlanningEntity class TaskAssignment {
     ...

     public int calculateOverlap(TaskAssignment other) {
         // calculate overlap with this.startTimestamp vs other.startTimestamp
         // and this.endTimestamp vs other.endTimestamp
     }

}
Geoffrey De Smet
  • 26,223
  • 11
  • 73
  • 120