I make the constraint provider implementation class as component Spring and i inject it in the controller also i make a configuration bean implementation of ConstraintFactory and i inject it also in my controlleur.In the web service i fetch all constraints using constraintProvider and constraintFactory , i filter this constraints with the data body from the web service an i set constraint in the constraintProvider implementation class but it still use all constraints due to the defineConstraints method which i think execuded once in the execution of project. how i do dynamic constraints with Spring boot and Timefold also i want an exemple of code how i do that i read some stack-overflow's questions:
Optaplanner : Add / remove constraints dynamically
I want an example of code. How i make dynamic constraints?
example of my code :
@Component public class PlanningConstraintsProvider implementsConstraintProvider {
@Override
public Constraint[] defineConstraints(ConstraintFactory constraintFactory) {
return new Constraint[]{
noMissingSkills(constraintFactory),
employeeTaskOverlapConstraint(constraintFactory),
locationConstraint(constraintFactory)
};
}
private Constraint noMissingSkills(ConstraintFactory constraintFactory) {
return constraintFactory.forEach(Task.class)
.filter(task -> task.getMissingSkillCount() > 0)
.penalize(HardMediumSoftScore.ONE_HARD, Task::getMissingSkillCount)
.asConstraint("NO_MISSING_SKILL");
}
private Constraint locationConstraint(ConstraintFactory constraintFactory) {
return constraintFactory.forEach(Task.class)
.penalize(HardMediumSoftScore.ONE_HARD,
task -> calculateWeightLocation(task.getAssignedEmployee().getLocation(), task.getLocation()))
.asConstraint("LOCATION");
}
} i want to calculate dynamicaly the weight for each 3 method with penalizeConfigurable and the constraint configuration class how to do that and justifyWith what is her role and for my solution i set attribute in construtor with the ConstraintConfiguration object then i do the solve with solve manager but it doesn't work respond with the correct solution how i do? i based this to this stack overflow response : How to choose dynamically which constraints should be applied on the optimization problem based on the frontend input in Timefold Spring Boot?
my goal is to give the constraints that i want to take in consideration in solving from my API
Take a look at @ConstraintConfiguration and @ConstraintWeight.