Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # -*- coding: utf-8 -*-
- """
- Created on Fri Nov 4 16:00:47 2016
- @author: Thomas
- """
- # -*- coding: cp1252 -*-
- import copy
- class Eleve:
- def __init__(self, Nom, Oraux):
- self.Nom = Nom
- self.Oraux = Oraux
- def estDisponible(self, Heure, OralType_):
- if self.associe(OralType_):
- return False
- for Oral in self.Oraux:
- if Oral.Heure <= Heure and Oral.HeureFin >= Heure:
- return False
- elif Oral.Heure >= Heure and Heure + OralType_.Duree >= Oral.HeureFin:
- return False
- return True
- def copieVide(self):
- newEleve = Eleve(self.Nom, [])
- return newEleve
- def associe(self, OralType_):
- return OralType_ in [o.OralType_ for o in self.Oraux]
- def Associer(self, Oral):
- self.Oraux.append(Oral)
- class Jury:
- def __init__(self, Nom, OT, Oraux):
- self.Nom = Nom
- self.OralType_ = OT
- self.Oraux = Oraux
- def copieVide(self):
- newJury = Jury(copy.copy(self.Nom), self.OralType_, [])
- return newJury
- def __str__(self):
- return self.Nom
- def Associer(self, Oral):
- self.Oraux.append(Oral)
- def estDisponible(self, Heure):
- for Oral in self.Oraux:
- if Oral.Heure <= Heure and Oral.HeureFin >= Heure:
- return False
- elif Oral.Heure >= Heure and Heure + self.OralType_.Duree >= Oral.HeureFin:
- return False
- return True
- class OralType:
- def __init__(self, Matiere, Duree):
- self.Matiere = Matiere
- self.Duree = Duree
- class Oral:
- def __init__(self, OT, Jury, Eleve, Heure):
- self.OralType_ = OT
- self.Jury = Jury
- self.Eleve = Eleve
- self.Heure = Heure
- self.HeureFin = Heure + OT.Duree
- def creerEmploiDuTemps(Jurys, Eleves):
- for j in range(len(Jurys)):
- heure = 0
- while not Associes(Eleves, Jurys[j].OralType_):
- AssociesDansCetteBoucle = 0
- for e in range(len(Eleves)):
- if Eleves[e].estDisponible(heure, Jurys[j].OralType_):
- if Jurys[j].estDisponible(heure):
- #Création du nouvel objet oral
- newOral = Oral(Jurys[j].OralType_, Jurys[j], Eleves[e], heure)
- #Ajout de l'oral à l'élève en cours
- Eleves[e].Associer(newOral)
- #Ajout de l'oral au jury en cours
- Jurys[j].Associer(newOral)
- #Modification des paramètres de recherche
- AssociesDansCetteBoucle += 1
- heure += Jurys[j].OralType_.Duree
- break #Sortie du for (élèves)
- if AssociesDansCetteBoucle == 0:
- heure += 1
- def trouverPermutations(Liste):
- renvoye = []
- ListeTravail = [elt.copieVide() for elt in Liste]
- longueurListe = len(ListeTravail)
- if longueurListe == 0:
- return []
- elif longueurListe == 1:
- return [[ListeTravail[0].copieVide()]]
- for elt in Liste:
- temp = [copy.copy(autre) for autre in Liste if autre is not elt]
- for perm in trouverPermutations(temp):
- renvoye.append([elt.copieVide()] + perm)
- return renvoye
- def dureeEmploiDuTemps(Jurys):
- maximum = 0
- for Jury in Jurys:
- for Oral in Jury.Oraux:
- if Oral.HeureFin > maximum:
- maximum = Oral.HeureFin
- return maximum
- def creerMeilleurEmploiDuTempsAvecPermutations(Jurys, Eleves):
- meilleurMakespan = -1
- meilleureSerie = ([], [])
- permutations = copy.deepcopy(trouverPermutations(Jurys))
- for permutation in permutations:
- tempEleves = [Eleve.copieVide() for Eleve in Eleves]
- creerEmploiDuTemps(permutation, tempEleves)
- duree = dureeEmploiDuTemps(permutation)
- if duree < meilleurMakespan or meilleurMakespan == -1:
- meilleurMakespan = duree
- meilleureSerie = (permutation, tempEleves, meilleurMakespan)
- return meilleureSerie
- def Associes(Eleves, OralType_):
- for E in Eleves:
- if E.associe(OralType_) == False:
- return False
- return True
- Epreuves = {"Français" : OralType("Français", 2), "Anglais" : OralType("Anglais", 3), "Maths" : OralType("Maths", 4), "Physique" : OralType("Physique", 4)}
- Jurys = [Jury("Gugger", Epreuves["Maths"], []), Jury("Demange", Epreuves["Anglais"], []), Jury("Dervieux", Epreuves["Physique"], []), Jury("Astier", Epreuves["Français"], [])]
- Eleves = [Eleve("Thomas", []), Eleve("Benjamin", []), Eleve("Matthis", []), Eleve("Esprit", []), Eleve("Eldred", []), Eleve("Louis-Matis", [])]
- #Eleves = [Eleve("Esprit", []), Eleve("Eldred", []), Eleve("Louis-Matis", [])]
- Couleurs = ['red', 'green', 'blue', 'yellow', 'brown', 'black', 'fuchsia']
- liste = [1, 2, 3, 4, 5, 6]
- #for perm in trouverPermutations(Jurys):
- # print(str([e.Nom for e in perm]))
- test = creerMeilleurEmploiDuTempsAvecPermutations(Jurys, Eleves)
- import disp
- patches = []
- for Prof in test[0]:
- temp = copy.deepcopy([e.Eleve.Nom for e in Prof.Oraux])
- temp.sort()
- for oral in Prof.Oraux:
- disp.ajouterOral(oral, [Epreuves[k] for k in Epreuves.keys()], Couleurs[temp.index(oral.Eleve.Nom)], patches)
- disp.afficher(patches)
- #
- #for Eleve in test[1]:
- # print(Eleve.Nom)
- # print("\t" + str([o.OralType_.Matiere + " / " + str(o.Heure) for o in Eleve.Oraux]))
- #for Prof in test[0]:
- # print(Prof.Nom)
- # print("\t" + str([str(o.Heure) + " / " + str(o.HeureFin) for o in Prof.Oraux]))
Advertisement
Add Comment
Please, Sign In to add comment