Before, when using optaplanner + drools, we can use insertLogical to create new instances with entity collection parameters & problem fact collection parameters to calculate multiple score points values basing on calculated instances results to determine how to deduct points,such as
rule “create pointscalculateinstance”
when
$requestList : ArrayList() from collect (
Request ()
)
$stockList : ArrayList() from collect (
Stock()
)
$taskList : ArrayList() from collect (
Task (machine != null)
)
then
insertLogical(new pointscalculateinstance($requestList,$stockList,$taskList));
end
rule “point1 rule”
when
$pointscalculateinstance : pointscalculateinstance ($point1 : point1)
eval($point1 > 0)
then
scoreHolder.addSoftConstraintMatch(kcontext, $point1);
end
rule “point2 rule”
when
$pointscalculateinstance: pointscalculateinstance($point2 : point2)
eval($point2 > 0)
then
scoreHolder.addSoftConstraintMatch(kcontext, $point2);
end
rule “point3 rule”
when
$pointscalculateinstance : pointscalculateinstance($point3 : point3)
eval($point3 > 0)
then
scoreHolder.addHardConstraintMatch(kcontext, $point3);
end
…….
pointscalculateinstance class such as:
public class pointscalculateinstance{
private ArrayList<Request> requestList;
private ArrayList<Stock> stockList;
private ArrayList<Task> taskList;
private int point1;
private int point2;
private int point3;
private int point4;
private int point5;
private int point6;
private int point7;
private int point8;
private int point9;
private int point10;
……
Solution such as:
@PlanningSolution
public class Planning{
@PlanningScore
private HardMediumSoftScore score;
@PlanningEntityCollectionProperty
@ValueRangeProvider(id = “taskRange”)
private ArrayList taskList;
@ProblemFactCollectionProperty
@ValueRangeProvider(id = "machineRange")
private ArrayList<Machine> machineList;
@ProblemFactCollectionProperty
private ArrayList<Request> requestList;
@ProblemFactCollectionProperty
private ArrayList<Stock> stockList;
………..
In fact, this is a chained model, due to special operational requirements, I need to calculate Stock consumption utilization corresponding to each solution based on the chained order of the task list;
Now when I refactor the project , how to achieve this when using timefold by constraint stream?
The only way I can think of is to use group by + tolist(), but there are many constraints, repeatedly writing so many constraints for the same computational procedure is not a good idea
How to create new instances with entity collection parameters & problem fact collection parameters to calculate multiple score points values basing on calculated instances results to determine how to deduct points when using timefold