mathematical-optimizationlinear-programming

LinProg Python, making a appliance on without interruption


I am trying to create a constraint for my appliance that it has to be non interuptable once it start.

I have an appliance with a min start and max start time, lets say 10:00 and 20:00. it also has a duration, let say 6 hours.

My problem now is that when I run the code, the result is not as expected, it gives me these hours when its on 10,11,13,14,15,16. it should not jump over 12 and stop at 15 since I want it to continue. I am trying to give it some sort of constraint that StartTime+Duration = Endtime

This is the code I'm trying to fix

for idx, appliance in enumerate(appliances):
   if appliance['continuous']:
        for i in range(appliance['time_min'], appliance['time_max'] - appliance['duration_time'] + 2):
        A_eq[idx, i + idx * 24: i + idx * 24 + appliance['duration_time']] = 1
        # Ensure continuity by adding the constraint that start + duration = end
        A_eq[idx, i + idx * 24 + appliance['duration_time'] - 1] = -1
   else:
    for i in range(appliance['time_min'], appliance['time_max'] - appliance['duration_time'] + 1):
        A_eq[idx, i + idx * 24: i + idx * 24 + appliance['duration_time']] = 1

Any help is great :) Is this even possible for linprog or is it a milp problem?


Solution

  • It is better to take a step back from code. This problem is often modeled using the concept of start-ups. A start-up is when a machine goes from off (0) to on (1). We only want to see 0 or 1 start-ups. We can implement this as:

     start[t] >= x[t] - x[t-1]
     sum(t, start[t]) <= 1
     x, start: binary variables
    

    Some care has to be taken near the first period. This is a well-known approach in the scheduling literature.