-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
61 lines (49 loc) · 2.66 KB
/
main.py
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
from contraintes import *
from donnees import *
from gloutonne1 import *
from gloutonne2 import *
from objectif import *
def solution_to_csv(solution,name):
with open(name +".csv", "w") as f:
f.write("id_lot,qté_production,nbre_article_lot,moyenne_dispo,mini_dispo,max_dispo,moyen_prix,min_prix,max_prix,moyen_indice,min_indice,max_indice \n")
for i,lot in enumerate(solution) :
f.write(str(i))#id lot
f.write(",")
f.write(str(lot[2])) #qte production
f.write(",")
f.write(str(len(lot[0]))) #nbre article lot
f.write(",")
f.write(str(sum([article.nombre for article in lot[0]])/len(lot[0]))) #moyenne dispo
f.write(",")
f.write(str(min([article.nombre for article in lot[0]]))) #mini dispo
f.write(",")
f.write(str(max([article.nombre for article in lot[0]]))) #max dispo
f.write(",")
f.write(str(sum([article.prix for article in lot[0]])/len(lot[0]))) #moyen prix
f.write(",")
f.write(str(min([article.prix for article in lot[0]])) )#min prix
f.write(",")
f.write(str(max([article.prix for article in lot[0]])) )#max prix
f.write(",")
f.write(str(sum([article.indice for article in lot[0]])/len(lot[0]))) #moyen indice
f.write(",")
f.write(str(min([article.indice for article in lot[0]])) )#min indice
f.write(",")
f.write(str(max([article.indice for article in lot[0]]))) #max indice
f.write("\n")
if __name__ == "__main__":
instance = "instances_test/test1.json"
D = import_donnees_from_json(instance)
D_after_gloutone, solution_gloutonne = gloutonne1(D)
# filtrage des lots non utilisés
#solution_gloutonne = list(filter(lambda x: x[2] > 0, solution_gloutonne))
print("Contraintes validées : " +
str(contraintes(solution_gloutonne, instance)))
print("Score Heuristique : " + str(objectif(D, solution_gloutonne)))
print("\n\n\n\n")
D_after_local_search, soluce_local_search = local_search(D_after_gloutone, solution_gloutonne, 100000)
print("Contraintes validées : " +
str(contraintes(soluce_local_search, instance)))
print("Score Heuristique : " + str(objectif(D_after_local_search, soluce_local_search)))
solution_to_csv(solution_gloutonne, "glou1")
solution_to_csv(soluce_local_search, "glou1_search")