'Optaplanner dynamic state changes

I want to model a problem in which are multiple different machines and jobs consisting tasks/steps in some machines. the jobs also contain a amount of pieces which will be processed.

After a machine processed a specified amount of pieces it must be maintained (for this example its automated and needs always a specific time). But the maintenance will only trigger if the remaining count is 0 or less then 0 - so if the remaining pieces for machine 2 is 10 it can process a job task with 50 pieces. The remaining pieces after the task will be -40 and will trigger the maintenance. The order of the tasks within a job is predefined and can not be changed. Also between each job task there must be no (time) gap to the following task.

all times are in sec. the job tasks are defined as tuple (machine, duration)

e.g.:

Machines:

m1: 
   remaining pieces: 25 
   maintenance time: 180 
m2:
   remaining pieces: 10 
   maintenance time: 100 
m3:
   remaining pieces: 55 
   maintenance time: 160 

Jobs:

j1: 
   pieces: 10
   tasks: [(m1, 200), (m3, 100)]
j2: 
   pieces: 25
   tasks: [(m1, 100), (m2, 120), (m3, 100)]
j3: 
   pieces: 5
   tasks: [(m2, 180), (m3, 100), (m1, 100)]

so the order in which the tasks will be processed can change a lot in the overall make span - which should me minimized.

Here a visualization with two possibilities: enter image description here

so how can i archive this? i have the entity for the machine with the member remaining pieces which i can update via shadow variables but how can i "disable" the machine for the maintenance time?

Edit: i forgot that each machine also got a member which contains the value to set the remaining pieces after a maintenance. e.g. 600.

Edit 2: maybe i can change my question a bit: whats the best approach for such a problem? handle the states in separate arrays which contains the state for each second or just calculate the states in the constraints.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source