From 4f9836c83f16418adeca6fe05ccbda10aff20856 Mon Sep 17 00:00:00 2001 From: Dassire Date: Mon, 29 Jan 2024 23:18:18 +0100 Subject: [PATCH] =?UTF-8?q?Scripts=20de=20cr=C3=A9ation=20de=20graphes?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- scripts/CreeGraphe.py | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 scripts/CreeGraphe.py diff --git a/scripts/CreeGraphe.py b/scripts/CreeGraphe.py new file mode 100644 index 00000000..2e8720b3 --- /dev/null +++ b/scripts/CreeGraphe.py @@ -0,0 +1,42 @@ +import osmnx +import numpy as np +import scipy as sp +import sys + +if(__name__=="__main__"): + if(len(sys.argv)<=2): # 2 pour le fichier out + sys.stderr.write("Erreur : pas d'arguments") + exit(1) + else: + ville=sys.argv[1] +else: + ville=input("Entrez un nom de ville : ") + +graph=osmnx.graph_from_place(ville); +nbEdges=graph.size(); +nbNodes=len(graph.nodes) +colIndex=np.ndarray(nbEdges); +rowIndex=np.ndarray(nbNodes) + +nodeToIndice={} # label -> indice dans matrice +i=0; +for u in graph.nodes: + nodeToIndice[u]=i; + print(len(nodeToIndice)) + i+=1 + +# Remplissage des tableaux +# V ? (maybe le nb de rues parallèles car non ponderes dans notre cas) +i=0; +j=0; +for u in graph.nodes: + rowIndex[nodeToIndice[u]]=i; + for v in graph.succ[u]: # Ne prends ps en compte les rues paralleles + colIndex[nodeToIndice[v]]=j; + # if not v in nodeToIndice.keys(): + # print(v); + print(v,rowIndex[nodeToIndice[v]]) + j+=1; + i+=1; + +# TODO write \ No newline at end of file