Pouknouki

Recuit simulé 3

Sep 24th, 2016
201
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.72 KB | None | 0 0
  1. # -*- coding: cp1252 -*-
  2.  
  3. import copy
  4.  
  5. class Eleve:
  6.     def __init__(self, Nom, Oraux):
  7.         self.Nom = Nom
  8.         self.Oraux = Oraux
  9.  
  10.     def estDisponible(self, Heure, OralType_):
  11.         if self.associe(OralType_):
  12.             return False
  13.         for Oral in self.Oraux:
  14.             if Oral.Heure <= Heure and Oral.HeureFin >= Heure:
  15.                 return False
  16.             elif Oral.Heure >= Heure and Heure + OralType_.Duree >= Oral.HeureFin:
  17.                 return False
  18.         return True
  19.  
  20.     def associe(self, OralType_):
  21.         return OralType_ in [o.OralType_ for o in self.Oraux]
  22.        
  23.     def Associer(self, Oral):
  24.         self.Oraux.append(Oral)
  25.  
  26. class Jury:
  27.     def __init__(self, Nom, OT, Oraux):
  28.         self.Nom = Nom
  29.         self.OralType_ = OT
  30.         self.Oraux = Oraux
  31.    
  32.     def copieVide(self):
  33.         newJury = Jury(copy.copy(self.Nom), self.OralType_, [])
  34.         return newJury
  35.    
  36.     def __str__(self):
  37.         return self.Nom
  38.  
  39.     def Associer(self, Oral):
  40.         self.Oraux.append(Oral)
  41.  
  42.     def estDisponible(self, Heure):
  43.         for Oral in self.Oraux:
  44.             if Oral.Heure <= Heure and Oral.HeureFin >= Heure:
  45.                 return False
  46.             elif Oral.Heure >= Heure and Heure + self.OralType_.Duree >= Oral.HeureFin:
  47.                 return False
  48.         return True    
  49.  
  50. class OralType:
  51.     def __init__(self, Matiere, Duree):
  52.         self.Matiere = Matiere
  53.         self.Duree = Duree
  54.  
  55. class Oral:
  56.     def __init__(self, OT, Jury, Eleve, Heure):
  57.         self.OralType_ = OT
  58.         self.Jury = Jury
  59.         self.Eleve = Eleve
  60.         self.Heure = Heure
  61.         self.HeureFin = Heure + OT.Duree
  62.  
  63. def creerEmploiDuTemps(Jurys, Eleves):
  64.     for j in range(len(Jurys)):
  65.         heure = 0
  66.         while not Associes(Eleves, Jurys[j].OralType_):
  67.             AssociesDansCetteBoucle = 0
  68.             for e in range(len(Eleves)):
  69.                 if Eleves[e].estDisponible(heure, Jurys[j].OralType_):
  70.                     if Jurys[j].estDisponible(heure):
  71.                         #Création du nouvel objet oral
  72.                         newOral = Oral(Jurys[j].OralType_, Jurys[j], Eleves[e], heure)
  73.                         #Ajout de l'oral à l'élève en cours
  74.                         Eleves[e].Associer(newOral)
  75.                         #Ajout de l'oral au jury en cours
  76.                         Jurys[j].Associer(newOral)
  77.  
  78.                         #Modification des paramètres de recherche
  79.                         AssociesDansCetteBoucle += 1
  80.                         heure += Jurys[j].OralType_.Duree
  81.                         break #Sortie du for (élèves)
  82.             if AssociesDansCetteBoucle == 0:
  83.                 heure += 1
  84.    
  85. def trouverPermutations(Liste):
  86.     renvoye = []
  87.     ListeTravail = [elt.copieVide() for elt in Liste]
  88.     longueurListe = len(ListeTravail)
  89.     if longueurListe == 0:
  90.         return []
  91.     elif longueurListe == 1:
  92.         return [[ListeTravail[0].copieVide()]]
  93.     for elt in Liste:
  94.         temp = [copy.copy(autre) for autre in Liste if autre is not elt]
  95.         for perm in trouverPermutations(temp):
  96.             renvoye.append([elt.copieVide()] + perm)
  97.     return renvoye
  98.  
  99. def creerMeilleurEmploiDuTempsAvecPermutations(Jurys, Eleves):
  100.     meilleurMakespan = -1
  101.     permutations = copy.deepcopy(trouverPermutations(Jurys))
  102.     for permutation in permutations:
  103.         creerEmploiDuTemps(permutation, Eleves)
  104.  
  105. def Associes(Eleves, OralType_):
  106.     for E in Eleves:
  107.         if E.associe(OralType_) == False:
  108.             return False
  109.     return True
  110.  
  111. Epreuves = {"Français" : OralType("Français", 2), "Anglais" : OralType("Anglais", 3), "Maths" : OralType("Maths", 4), "Physique" : OralType("Physique", 4)}
  112. Jurys = [Jury("Gugger", Epreuves["Maths"], []), Jury("Demange", Epreuves["Anglais"], []), Jury("Dervieux", Epreuves["Physique"], []), Jury("Astier", Epreuves["Français"], [])]
  113. Eleves = [Eleve("Thomas", []), Eleve("Benjamin", []), Eleve("Matthis", []), Eleve("Esprit", []), Eleve("Eldred", []), Eleve("Louis-Matis", [])]
  114.  
  115. liste = [1, 2, 3, 4, 5, 6]
  116.  
  117. #for perm in trouverPermutations(Jurys):
  118. #   print(str([e.Nom for e in perm]))
  119.  
  120. creerMeilleurEmploiDuTempsAvecPermutations(Jurys, Eleves)
  121. for Eleve in Eleves:
  122.     print(Eleve.Nom)
  123.     print("\t" + str([o.OralType_.Matiere + " / " + str(o.Heure) for o in Eleve.Oraux]))
Advertisement
Add Comment
Please, Sign In to add comment