timnon / pyschedule

pyschedule - resource scheduling in python
Apache License 2.0
291 stars 61 forks source link

TIGHTPLUS constraints: how to set a difference between 2 tasks without knowing their order #64

Open fredericgirod opened 5 years ago

fredericgirod commented 5 years ago

Hi, I have to set up some TIGHTPLUS constraints in order to separate my tasks by a few time units: but how to set a difference between 2 tasks without knowing their order ? For example, I'm using such TIGHTPLUS ... S += Games[11] + 1 <= Games[10], but I don't want to set an order. I want tasks Games[11] and Games[10] to be separated by 1 time unit whatever the order they will be appearing ...

timnon commented 5 years ago

In the following script, breaks are schedule between tasks, maybe sth similar can be applied to your case. Note the is_group, since will speed up the computation, since the breaks are probably all similar, so we can treat them as an interchangeable group.

#! /usr/bin/env python
import sys
sys.path.append('../src')
from pyschedule import Scenario, solvers, plotters

horizon = 20
S = Scenario('Scenario',horizon=horizon)
tasks = S.Tasks('T',num=int(horizon/2),is_group=True,completion_time_cost=1,state=1)
breaks = S.Tasks('B',num=int(horizon/2),is_group=True,completion_time_cost=1,state=-1)

R = S.Resource('R')
tasks += R
breaks += R

# ensure that state is always between 0 and 1
for t in range(horizon):
    S += R['state'][:t] <= 1
    S += R['state'][:t] >= 0

solvers.mip.solve(S, msg=1)
plotters.matplotlib.plot(S, fig_size=(10, 5))
#plotters.matplotlib.plot(S, fig_size=(10, 5), hide_tasks=breaks)
Eduardoofc commented 4 years ago

hey @fredericgirod , I have the same problem you had 2 years ago!!

I wondering if you can share with me your solution?