Exemplo n.º 1
0
# test artefact for the case that pyschedule is
# read from folder
import sys
sys.path.append('../src')
horizon = 5

import getopt
opts, _ = getopt.getopt(sys.argv[1:], 't:', ['test'])
from pyschedule import Scenario, solvers, plotters, alt
S = Scenario('test', horizon=horizon)

# define two employees
R = S.Resources('R', num=2)

T0 = S.Task('T0', completion_time_cost=10)
T0 += alt(R)

T1 = S.Task('T1', length=2, completion_time_cost=2)
T1 += alt(R)

T2 = S.Task('T2', length=2, completion_time_cost=1)
T2 += alt(R)

S += T1 * R[0] <= T0
S += T2 * R[0] <= T0

if solvers.mip.solve(S, msg=0):
    if ('--test', '') in opts:
        assert (T0.start_value == 0)
        assert (T1.start_value == 0)
        assert (T2.start_value == 2)
Exemplo n.º 2
0
import sys
sys.path.append('../src')
from pyschedule import Scenario, solvers, plotters, alt

n_teams = 10
n_stadiums = n_teams
n_slots = n_teams - 1

n_plays_at_home = 4
max_n_not_at_home_periods = 3

S = Scenario('sports_scheduline', horizon=n_slots)
Stadiums = S.Resources('Stadium', num=n_stadiums)
Teams = S.Resources('T', num=n_teams)
Team2Stadium = dict(zip(Teams, Stadiums))

Games = list()
for Team0 in Teams:
    count = 1
    for Team1 in Teams:
        if Team0.name >= Team1.name:
            continue
        Game = S.Task('%s%s' % (Team0, Team1), delay_cost=2**count)
        Game[Team0.name] = 1
        Game[Team1.name] = 1
        Games.append(Game)
        Game += Team0, Team1
        Game += Team2Stadium[Team0] | Team2Stadium[Team1]
        count += 1

for Team in Team2Stadium: