Pouknouki

Recuit

Nov 4th, 2016
227
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 4.94 KB | None | 0 0
  1. # -*- coding: utf-8 -*-
  2. """
  3. Created on Fri Nov  4 16:00:47 2016
  4.  
  5. @author: Thomas
  6. """
  7.  
  8. # -*- coding: cp1252 -*-
  9.  
  10. import copy
  11.  
  12. class Eleve:
  13.     def __init__(self, Nom, Oraux):
  14.         self.Nom = Nom
  15.         self.Oraux = Oraux
  16.  
  17.     def estDisponible(self, Heure, OralType_):
  18.         if self.associe(OralType_):
  19.             return False
  20.         for Oral in self.Oraux:
  21.             if Oral.Heure <= Heure and Oral.HeureFin >= Heure:
  22.                 return False
  23.             elif Oral.Heure >= Heure and Heure + OralType_.Duree >= Oral.HeureFin:
  24.                 return False
  25.         return True
  26.  
  27.     def copieVide(self):
  28.         newEleve = Eleve(self.Nom, [])
  29.         return newEleve
  30.    
  31.     def associe(self, OralType_):
  32.         return OralType_ in [o.OralType_ for o in self.Oraux]
  33.        
  34.     def Associer(self, Oral):
  35.         self.Oraux.append(Oral)
  36.  
  37. class Jury:
  38.     def __init__(self, Nom, OT, Oraux):
  39.         self.Nom = Nom
  40.         self.OralType_ = OT
  41.         self.Oraux = Oraux
  42.    
  43.     def copieVide(self):
  44.         newJury = Jury(copy.copy(self.Nom), self.OralType_, [])
  45.         return newJury
  46.    
  47.     def __str__(self):
  48.         return self.Nom
  49.  
  50.     def Associer(self, Oral):
  51.         self.Oraux.append(Oral)
  52.  
  53.     def estDisponible(self, Heure):
  54.         for Oral in self.Oraux:
  55.             if Oral.Heure <= Heure and Oral.HeureFin >= Heure:
  56.                 return False
  57.             elif Oral.Heure >= Heure and Heure + self.OralType_.Duree >= Oral.HeureFin:
  58.                 return False
  59.         return True    
  60.  
  61. class OralType:
  62.     def __init__(self, Matiere, Duree):
  63.         self.Matiere = Matiere
  64.         self.Duree = Duree
  65.  
  66. class Oral:
  67.     def __init__(self, OT, Jury, Eleve, Heure):
  68.         self.OralType_ = OT
  69.         self.Jury = Jury
  70.         self.Eleve = Eleve
  71.         self.Heure = Heure
  72.         self.HeureFin = Heure + OT.Duree
  73.  
  74. def creerEmploiDuTemps(Jurys, Eleves):
  75.     for j in range(len(Jurys)):
  76.         heure = 0
  77.         while not Associes(Eleves, Jurys[j].OralType_):
  78.             AssociesDansCetteBoucle = 0
  79.             for e in range(len(Eleves)):
  80.                 if Eleves[e].estDisponible(heure, Jurys[j].OralType_):
  81.                     if Jurys[j].estDisponible(heure):
  82.                         #Création du nouvel objet oral
  83.                         newOral = Oral(Jurys[j].OralType_, Jurys[j], Eleves[e], heure)
  84.                         #Ajout de l'oral à l'élève en cours
  85.                         Eleves[e].Associer(newOral)
  86.                         #Ajout de l'oral au jury en cours
  87.                         Jurys[j].Associer(newOral)
  88.  
  89.                         #Modification des paramètres de recherche
  90.                         AssociesDansCetteBoucle += 1
  91.                         heure += Jurys[j].OralType_.Duree
  92.                         break #Sortie du for (élèves)
  93.             if AssociesDansCetteBoucle == 0:
  94.                 heure += 1
  95.    
  96. def trouverPermutations(Liste):
  97.     renvoye = []
  98.     ListeTravail = [elt.copieVide() for elt in Liste]
  99.     longueurListe = len(ListeTravail)
  100.     if longueurListe == 0:
  101.         return []
  102.     elif longueurListe == 1:
  103.         return [[ListeTravail[0].copieVide()]]
  104.     for elt in Liste:
  105.         temp = [copy.copy(autre) for autre in Liste if autre is not elt]
  106.         for perm in trouverPermutations(temp):
  107.             renvoye.append([elt.copieVide()] + perm)
  108.     return renvoye
  109.  
  110. def dureeEmploiDuTemps(Jurys):
  111.     maximum = 0
  112.     for Jury in Jurys:
  113.         for Oral in Jury.Oraux:
  114.             if Oral.HeureFin > maximum:
  115.                 maximum = Oral.HeureFin
  116.     return maximum
  117.  
  118. def creerMeilleurEmploiDuTempsAvecPermutations(Jurys, Eleves):
  119.     meilleurMakespan = -1
  120.     meilleureSerie = ([], [])  
  121.     permutations = copy.deepcopy(trouverPermutations(Jurys))
  122.     for permutation in permutations:
  123.         tempEleves = [Eleve.copieVide() for Eleve in Eleves]       
  124.         creerEmploiDuTemps(permutation, tempEleves)
  125.         duree = dureeEmploiDuTemps(permutation)
  126.         if duree < meilleurMakespan or meilleurMakespan == -1:
  127.             meilleurMakespan = duree
  128.             meilleureSerie = (permutation, tempEleves, meilleurMakespan)
  129.     return meilleureSerie          
  130.    
  131.    
  132.  
  133. def Associes(Eleves, OralType_):
  134.     for E in Eleves:
  135.         if E.associe(OralType_) == False:
  136.             return False
  137.     return True
  138.  
  139. Epreuves = {"Français" : OralType("Français", 2), "Anglais" : OralType("Anglais", 3), "Maths" : OralType("Maths", 4), "Physique" : OralType("Physique", 4)}
  140. Jurys = [Jury("Gugger", Epreuves["Maths"], []), Jury("Demange", Epreuves["Anglais"], []), Jury("Dervieux", Epreuves["Physique"], []), Jury("Astier", Epreuves["Français"], [])]
  141. Eleves = [Eleve("Thomas", []), Eleve("Benjamin", []), Eleve("Matthis", []), Eleve("Esprit", []), Eleve("Eldred", []), Eleve("Louis-Matis", [])]
  142. #Eleves = [Eleve("Esprit", []), Eleve("Eldred", []), Eleve("Louis-Matis", [])]
  143. Couleurs = ['red', 'green', 'blue', 'yellow', 'brown', 'black', 'fuchsia']
  144. liste = [1, 2, 3, 4, 5, 6]
  145.  
  146. #for perm in trouverPermutations(Jurys):
  147. #   print(str([e.Nom for e in perm]))
  148.  
  149. test = creerMeilleurEmploiDuTempsAvecPermutations(Jurys, Eleves)
  150.  
  151. import disp
  152.  
  153. patches = []
  154. for Prof in test[0]:
  155.     temp = copy.deepcopy([e.Eleve.Nom for e in Prof.Oraux])
  156.     temp.sort()
  157.     for oral in Prof.Oraux:
  158.         disp.ajouterOral(oral, [Epreuves[k] for k in Epreuves.keys()], Couleurs[temp.index(oral.Eleve.Nom)], patches)
  159. disp.afficher(patches)
  160.  
  161. #
  162. #for Eleve in test[1]:
  163. #   print(Eleve.Nom)
  164. #   print("\t" + str([o.OralType_.Matiere + " / " + str(o.Heure) for o in Eleve.Oraux]))
  165. #for Prof in test[0]:
  166. #   print(Prof.Nom)
  167. #   print("\t" + str([str(o.Heure) + " / " + str(o.HeureFin) for o in Prof.Oraux]))
Advertisement
Add Comment
Please, Sign In to add comment