Skip to content

Instantly share code, notes, and snippets.

@kindlyfire
Created August 11, 2018 17:38
Show Gist options
  • Save kindlyfire/c372c24e3ee5ff0e1cc58a99ad910546 to your computer and use it in GitHub Desktop.
Save kindlyfire/c372c24e3ee5ff0e1cc58a99ad910546 to your computer and use it in GitHub Desktop.
classes:
5Ga: [5, 501]
5Gb: [5, 502]
5Gc: [5, 503]
5TTr: [5, 504]
6Ga: []
6Gb: []
6Gc: []
6TTr: []
course_bundles:
0: []
5:
- 5_math
- 5_fr
- 5_hist
- 5_geo
- 5_sc_general
- 5_lang_1
- 5_lang_2
501:
- "!5_sc_general"
- 5_a_chimie
- 5_a_bio
- 5_a_physique
502:
- 5_b_eco
503:
- 5_c_social
504:
- "!5_lang_2"
- 5_ttr_info
- 5_ttr_prog
- 5_ttr_logi
courses:
#
# 5 ème
#
# Général
5_math: ["C. Belot", 4]
5_fr: ["Vanquaethem I.", 4]
5_hist: ["Michel E.", 2]
5_geo: ["Hublet G.", 2]
5_lang_1: ["Jomouton I.", 4]
5_lang_2: ["Jomouton I.", 4]
5_sc_general: ["Derenne C.", 4]
# Ga
5_a_chimie: ["De Buyser M.", 2]
5_a_bio: ["Derenne C.", 2]
5_a_physique: ["De Buyser M.", 2]
# Gb
5_b_eco: ["Marc C.", 4]
# Gc
5_c_social: ["Lefèbre P.", 4]
# TTr
5_ttr_info: ["Cauchie A.", 2]
5_ttr_prog: ["Cauchie A.", 2]
5_ttr_logi: ["Bartels J.", 2]
from pyschedule import Scenario, solvers, plotters, alt
import matplotlib, yaml
DAYS = 7
def run(scen):
if solvers.mip.solve(scen):
plotters.matplotlib.plot(scen)
else:
print('no solution exist')
def transform_classes(config):
classes = {}
for k, v in config['classes'].items():
classes[k] = courses = []
for course_bundle_id in v:
bundle = config['course_bundles'][course_bundle_id]
for cls in bundle:
if cls.startswith('!') and cls.replace('!', '') in courses:
courses.remove(cls.replace('!', ''))
courses += [i for i in bundle if not i.startswith('!')]
return classes
config = yaml.load(open('config.yml', 'r'))
config['tclasses'] = transform_classes(config)
scen = Scenario('Cours_example', horizon=(DAYS * 5))
# Will be created when needed
teachers = {}
classes = {}
for cls, _ in config['tclasses'].items():
classes[cls] = scen.Resource(cls)
courses = {}
for course, info in config['courses'].items():
courses[course] = task = scen.Task(course, info[1])
if info[1] == 4:
task.periods = [x for x in range(0, DAYS * 5) if x % 5 == 0]
elif info[1] == 2:
task.periods = [x for x in range(0, DAYS * 5) if x % 5 == 0]
task.periods += [x + 2 for x in range(0, DAYS * 5) if x % 5 == 0]
for teacher in info[0].split('|'):
if (not teacher in teachers):
teachers[teacher] = scen.Resource(teacher.replace(' ', '_'))
# print(" - " + teacher)
task += teachers[teacher]
for cls, cls_courses in config['tclasses'].items():
if course in cls_courses:
task += classes[cls]
run(scen)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment