# How to calculate the duration of a task in each shift?

I am solving a job scheduling problem with three shifts,
the duration of all shifts are assumed to be known (and might be equal):

• The tasks can start from any shift
• We know the duration of each task in minutes

Some examples:

• if it starts from minute $$1\leq start \leq 480$$ then it is in shift1
• if it starts from minute $$481\leq start \leq 960$$ then it is in shift2
• if it starts from minute $$961\leq start \leq 1440$$ then it is in shift3

Now the question is how to calculate the duration that falls into each shift depending on the starting minute (variable) and duration (parameter) ?

Input:

• Duration of each shift

Output:

I am looking for the values of $$h_1,h_2,h_3$$ in each case

$$h_1, h_2, h_3$$ mean the duration time in each period, respectively? Output also including the start time variables?

Ans:

$$h_1 = (480 - start) * b_1$$

$$h_2 = duration - h_1 - h_3$$

$$h_3 = (finish - 960) * b_3$$

,where $$b_1 = 1$$ if $$start < 480$$, otherwise $$0$$. $$b_3 = 1$$ if $$finish > 960$$, otherwise $$0$$.

PS in your case $$b_1$$ and $$b_3$$ can be parameter if start time is given, otherwise should be variables. Furthermore, if you would like to apply to more general setting such as: more than 3 periods that would be very complicated to define.

• Since I don't have reputation enough yet, I put the questions in the answer block. Hop you don't mind it. Sep 14 at 13:52
• Thank you . I corrected the h2 in blue clock. The start time is determined by other constraints so let's assume for a given start time how to calculate the h1,h2,h3 but we have to treat it as a variable Sep 14 at 13:54
• Another question is the red block, h1 is equal to 400 or 380? if h1 = 380 then h2 would be 120, right? Sep 14 at 14:04
• Difficult to make too many mistakes but I did it :) Sep 14 at 14:08
• I put the answer in above. You can check the logic is valid or not. Thanks! Sep 14 at 14:16