Commit 23d418e1 authored by Aliaume Lopez's avatar Aliaume Lopez
Browse files

Graphes

parent 17835041
import city
class Graph:
def __init__ (self, cities, weights=None):
self.cities = cities
self.weights = weights
def distance(self, city1, city2):
def distance (self, city1, city2):
""" Calcule la distance entre deux villes
dans le graphe
Utilise la matrice de poids
ou la distance géographique
en fonction des paramètres
de création de l'objet
"""
if self.weights = None:
return city1.distance (city2)
else:
return weights
return weights[city1.number][city2.number]
def cout_chemin (self, chemin):
""" Calcule le coût d'un chemin
comme la somme des distances
parcourues
(coût additif)
"""
paires = zip (chemin, chemin[1:])
return sum (self.distance (x,y) for (x,y) in paires)
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment