-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathChemin.py
More file actions
74 lines (63 loc) · 2.73 KB
/
Chemin.py
File metadata and controls
74 lines (63 loc) · 2.73 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
import random
import numpy as np
import matplotlib as mpl
mpl.use('Agg')
import matplotlib.pyplot as plt
class Chemin:
def setChemin(self, chemin):
self.chemin = chemin
def setEvaluation(self, evaluation):
self.evaluation = evaluation
def tracer(self, carte, fichier, couleur):
# On recupere les coordonnees du chemin
xChemin = []
yChemin = []
for ville in self.chemin:
xChemin.append(carte.villes[ville].x)
yChemin.append(carte.villes[ville].y)
# On recupere les coordonnes des villes
xVilles = []
yVilles = []
for ville in carte.villes:
xVilles.append(ville.x)
yVilles.append(ville.y)
# On genere l'image
fig = plt.figure() # On creer la figure
ax = fig.add_subplot(111)
ax.plot(xVilles, yVilles, linestyle='', marker='o', color='black') # On ajoute les points des villes
ax.plot(xChemin, yChemin, linestyle="--", color=couleur) # On ajoute le chemin
ax.axis([-2, 102, -2, 102]) # On gradue les axes
ax.axis('off') #On ne les affiche plus
fig.savefig(fichier) # On genere l'image
@staticmethod
def tracerChemins(carte, chemins, fichier, couleur):
# On recupere les coordonnes des villes
xVilles = []
yVilles = []
for ville in carte.villes:
xVilles.append(ville.x)
yVilles.append(ville.y)
# On genere l'image
fig = plt.figure() # On creer la figure
ax = fig.add_subplot(111)
ax.plot(xVilles, yVilles, linestyle='', marker='o', color='black') # On ajoute les points des villes
ax.axis([-2, 102, -2, 102]) # On gradue les axes
ax.axis('off') #On ne les affiche plus
# On ajoute les chemins
for chemin in chemins:
# On recupere les coordonnees du chemin
xChemin = []
yChemin = []
for ville in chemin.chemin:
xChemin.append(carte.villes[ville].x)
yChemin.append(carte.villes[ville].y)
ax.plot(xChemin, yChemin, linestyle="--", color=couleur) # On ajoute le chemin
fig.savefig(fichier) # On genere l'image
def calculDistanceReelle(self, carte):
distance = 0
for i in range(0, len(self.chemin)):
if i < len(self.chemin) - 1:
distance = distance + carte.getDistance(carte.villes[self.chemin[i]], carte.villes[self.chemin[i+1]])
else: # Distance entre la derniere ville et la premiere
distance = distance + carte.getDistance(carte.villes[self.chemin[0]], carte.villes[self.chemin[i]])
return distance