-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathalgorithme.py
More file actions
149 lines (128 loc) · 6.34 KB
/
algorithme.py
File metadata and controls
149 lines (128 loc) · 6.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
import pandas as pd
import random
# creation d'une liste des avions pouvant accomplir la mision
def besoinEnMission(m,l_m, l_a, nbmiss, affect,nb,t,i):
liste = []
for a in l_a:
#nb mois * potdemandé/mois + 100 à la place des 600 (demande DGA)
#print(m.type_avion)
if (m.opex == i and m.type_avion == a.type_avion and capaciteMission(a,m)
and a.pot_horaire >=(nb*m.pu+100) and isFree(a,t,nb,affect) and isFree(a,t,-2,affect)):
if t<=2:
liste.append(a)
break
h=0
for k in l_m:
if (affect(t-1)[a]==k.nom or affect(t-2)[a]==k.nom):
h=1
if h==0:
liste.append(a)
return liste
# fonction pour verifier si les capacites necessaires pour la mission sont satisfaites par l'avion
# set(a)<set(b) permet verifier si tt element de la liste a est dans la liste b
def capaciteMission(a,m):
l2=m.capa_avion
l1=a.capacite
return set(l2)<=set(l1)
# creation d'une liste des avions pouvant accomplir la mission
def choixAvion(liste,choix):
if choix == 0: # liste ordonnee par le critère : CRAVATE
listeOrdonnee = sorted(liste, key=cravate)
else: # liste triée de façon aléatoire pour obtenir des solutions différentes
listeOrdonnee = sorted(liste, key=lambda *args: random.random())
return listeOrdonnee
# Troncature de la liste choixAvions au nombre necessaire d'avions pour la mission m
# puis affectation des missions dans le dataframe sous le format (nom_mission)
# la modification du potentiel de l'avion est realisée avec la fonction modifPot.
def affectationMission(m, listeAvion, avions_aff, data, nb, t, listeMission, i, choix):
listeAlpha = besoinEnMission(m,listeMission, listeAvion, avions_aff, data,nb,t,i)
#print(type(listeAlpha),listeAlpha)
listeBeta = choixAvion(listeAlpha,choix)
#print(type(listeBeta),listeBeta)
listeGamma = listeBeta[0:m.nb_avion - avions_aff]
#print("nb d'avions necessaires pour la mission", m.nb_avion)
#print("nb d'avions deja affectes pour la mission", nbmiss)
for i in range(0, nb):
data(t + i)[listeGamma] = m.nom #+"$"+str(int(m.pu)))
return len(listeGamma)
# la modification des potentiels s'effectue separement de l'affectation (pour prendre en compte le rebouclage)
# la fonction modifPot permet de modifier le pot. Elle enlève du potentiel la valeur indiquée dans la cellule
# correspandate dans le dataframe.
def modifPot(m,data,a,t, indic, dict_pots):
#for a in listeAvion:
#! if str(df.xs(t)[a]).split("$")[0] == m.nom:
if data.xs(t)[a] == m.nom: #!
#! a.pot_horaire -= int((data.xs(t)[a]).split("$")[1])
a.pot_horaire -= dict_pots[m.nom][0]
a.pot_mois -= 1
indic["nbrAvionMission"][t-1] += 1
#if (a.nom)=='D602':
# print(a.nom,"", a.pot_horaire," ",t, " ")
def listeMaint(listeMaintenance,a): # renvoie la liste des maintenances correspondantes à l'avion
if a.type_avion == "2000_C":
l_maint = listeMaintenance[0:6]
if a.type_avion == "2000_D":
l_maint = listeMaintenance[6:12]
if a.type_avion == "2000_5":
l_maint = listeMaintenance[12:18]
if a.type_avion == "2000_B":
l_maint = listeMaintenance[18:24]
return l_maint
def affectMaint(a, t, df, listeMaintenance):
if t > 1: #! str()
if isinstance(df.xs(t)[a],str):
if df.xs(t)[a][0] == "V" :
if isinstance(df.xs(t-1)[a],str):
if df.xs(t - 1)[a][0] != "V": # maintenance à la main
l_maint=listeMaint(listeMaintenance, a)
for i in range(0, len(l_maint)):
if a.proch_maint == l_maint[i].nom:
a.pot_mois = l_maint[i].gain_mois
a.pot_horaire = l_maint[i].gain_heures
a.proch_maint = l_maint[(i + 1) % len(l_maint)].nom
break
else: # maintenance programmé par l'algorithme
l_maint=listeMaint(listeMaintenance, a)
for i in range(0,len(l_maint)):
if a.proch_maint == l_maint[i].nom:
for j in range(0, int(l_maint[i].duree)):
df.xs(t + j)[a] = l_maint[i].nom
a.pot_mois = l_maint[i].gain_mois
a.pot_horaire = l_maint[i].gain_heures
a.proch_maint = l_maint[(i+1)%len(l_maint)].nom
break
if t==1 : #! str()
if isinstance(df.xs(t)[a],str):
if df.xs(t)[a][0] == "V": # maintenance à la main
l_maint=listeMaint(listeMaintenance, a)
for i in range(0, len(l_maint)):
if a.proch_maint == l_maint[i].nom:
a.pot_mois = l_maint[i].gain_mois
a.pot_horaire = l_maint[i].gain_heures
a.proch_maint = l_maint[(i + 1) % len(l_maint)].nom
break
else: # maintenance programmé par l'algorithme
l_maint=listeMaint(listeMaintenance, a)
for i in range(0, len(l_maint)):
if a.proch_maint == l_maint[i].nom:
for j in range(0, int(l_maint[i].duree)):
df.xs(t + j)[a] = l_maint[i].nom
a.pot_mois = l_maint[i].gain_mois
a.pot_horaire = l_maint[i].gain_heures
a.proch_maint = l_maint[(i + 1) % len(l_maint)].nom
break
# pour un avion donnée a, la fonction calcule le rapport entre les potentiels calendaire et horaire.
def cravate(a):
return float(a.pot_mois) / a.pot_horaire
def lissage(d): # fonction qui envoie en sortie la liste des avions classés par potentiel calendaire croissant
# fonction utilisée lors de l'affectation en maintenance et non en mission. Elle ne remplace pas la cravate
liste = sorted(d["listeAvion"], key=lambda avion: avion.pot_mois)
return liste
# Cette fonction vérifié si les cellules de la matrice entre [t][a] et [t+n][a] sont vides, n peut etre négatif
def isFree(a,t,n,df):
b=True
j = max(t,t+n)
k = min(t,t+n) if t>abs(n) else 1
for i in range(k,j+1):
b=b*pd.isnull(df(i)[a])
return b