Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # -*- 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 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 creerMeilleurEmploiDuTempsAvecPermutations(Jurys, Eleves):
- meilleurMakespan = -1
- permutations = copy.deepcopy(trouverPermutations(Jurys))
- for permutation in permutations:
- creerEmploiDuTemps(permutation, Eleves)
- 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", [])]
- liste = [1, 2, 3, 4, 5, 6]
- #for perm in trouverPermutations(Jurys):
- # print(str([e.Nom for e in perm]))
- creerMeilleurEmploiDuTempsAvecPermutations(Jurys, Eleves)
- for Eleve in Eleves:
- print(Eleve.Nom)
- print("\t" + str([o.OralType_.Matiere + " / " + str(o.Heure) for o in Eleve.Oraux]))
Advertisement
Add Comment
Please, Sign In to add comment