Search code examples
optaplanner

Dynamic planningVariable with rangeProvider


I try to keep the domain for my problem as simple as possible:

I have jobs with jobSteps. The job needs a start time and the jobSteps have different machines, process times and an allowed overprocesstime. But the maximal overprocesstime is different for each job or even 0 (not allowed).

now the jobs should be scheduled with some conditions: once a job started it have to be finished without any pause (each step must be worked through) The jobs should be startet as soon as possible.

So i have two planning Variables: start time of the job and the usedOverprocessTime for the jobstep (it can make sense to overprocess some jobs - cause the next machine is still working a short time on an other job)

simple example: job 1: {[machine: A, processTime: 80, allowedOverprocessTime: 20], [machine: B, processTime: 80, allowedOverprocessTime: 0], [machine: C, processTime: 100, allowedOverprocessTime: 30]}

job 2: {[machine: A, processTime: 50, allowedOverprocessTime: 10], [machine: B, processTime: 80, allowedOverprocessTime: 30], [machine: C, processTime: 100, allowedOverprocessTime: 30]}

enter image description here

The code for the start time of the jobs is kinda simple:

@PlanningEntity
@Entity
public class Job {
   ...
   @PlanningVariable(valueRangeProviderRefs = "jobStartTimeRange")
   private Integer jobStartTime;

and then i have a planningsolution class:

@PlanningSolution
public class JobSchedule {
    ...
    @ValueRangeProvider(id = "jobStartTimeRange")
    public List<Integer> createStartTimeList() {
        // here i calculate a worst case range if the jobs have to 
        // be worked on one after the other without overlapping
    }

sofar this should work. now the problem with the overprocess time:

@PlanningEntity
public class JobStep {
    ...
    @PlanningVariable(valueRangeProviderRefs = "plannedOverprocessTimeRange")
    public Integer plannedOverprocessTime = 0;

for the provider i would need the current step to return an individual range from 0 to the specific max value. I even had the idea of returning a Map<JobStep, List> so each step could lookup the specific range. But the annotation is only for collections.

so is it somehow possible to create the ranges for the planningvariable dynamic like i need to? I would be surprised if i were the first to have this request to be honest.


Solution

  • OptaPlanner supports a wide range of ValueRangeProvider implementations, and it also allows you to implement your own. The question does not make it clear whether you've already tried this mechanism and it didn't work for your use case, or if you're not aware of this functionality at all.

    My interpretation is that, if you put a ValueRangeProvider on your planning entity, you will be able to do what you need.