I want to add a function of the list of planning entities as a constraint. More specifically, each planning entity has a contribution x, and I want to implement a constraint that adds a HARD score if the sum of all the x contributions is greater than X. Something like...
Constraint ConstraintX(ConstraintFactory constraintFactory) {
return constraintFactory
.forEach(planningEntity.class)
.filter(planningEntity-> planningEntity.get_x())
.sum().penalize("Sum of xs bigger than X",
HardMediumSoftScore.ONE_HARD,
sum > X # what goes here???
);
}
See OptaPlanner documentation on Constraint Collectors . Specifically ConstraintCollectors.sum(...)
does exactly what you need.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.