Hey pretty new to optaplanner. What I have is a process planning entity that has an "availability zone" and set of computers that also have an assigned availability zone. Since a process can only be put on a computer with the same availability zone I wanted to use the ValueRangeProvider to narrow down the possible selections to include only those computers (similar to how the example in the documentation narrows down rooms based on the teachers department). But there is no direct connection from availability zones to the lower level entities (i.e. computers) the object I am working with currently only points up.
I was thinking that I could just pass in the list of computers to every process and just create a valuerange list based on that similar to what I did below, but I was hoping for a more elegant solution. I was looking at filters but I could not figure out how to create a filter to restricted a possible move based on the planning entity and that entity's planning variable.
@PlanningVariable(strengthComparatorClass = ComputerStrengthComparator.class)
public Computer getComputer() {
return computer;
}
@ValueRangeProvider(id="computerRange")
public List<Computer> getPossibleComputers(){
return computers.stream().filter(computer -> computer.getAvalibilityZone().equals(this.getAvalibilityZone())).collect(Collectors.toList());
}
If anyone knows of something I missed or has any ideas I would much appreciate the help.
That code actually works as far as I can tell. See docs "Value Range Provider from entity" (as opposed to "from solution").
That being said, it does have limitations: some features do not support it and will fail fast if combined with value ranges "from entity" - most do these days so I wouldn't worry about it. Furthermore, it prevents the Local Search from breaking that hard constraints to escape a local optima, but that's usually not a problem.