summaryrefslogtreecommitdiff
path: root/ero1/src/drone/postier_chinois_montreal.py
blob: 04ade411a955d1482dbecb129ca12f3c08fd96c0 (plain)
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
import osmnx as ox
import networkx as nx
import parameters as params

from src.helper.debug_printer import debug_print
from src.helper.display_graph import display_graph
from src.helper.duplicate_removal import remove_duplicates
from src.helper.export_import_yaml import save_paths_to_yaml

arrondissements = [
    'Ahuntsic-Cartierville',    
    'Anjou',
    'Côte-des-Neiges–Notre-Dame-de-Grâce',
    'Lachine',
    'LaSalle',
    'Le Plateau-Mont-Royal',
    'Le Sud-Ouest',
    'L\'Île-Bizard–Sainte-Geneviève',
    'Mercier–Hochelaga-Maisonneuve',
    'Montréal-Nord',
    'Outremont',
    'Pierrefonds-Roxboro',
    'Rivière-des-Prairies–Pointe-aux-Trembles',
    'Rosemont–La Petite-Patrie',
    'Saint-Laurent',
    'Saint-Léonard',
    'Verdun',
    'Ville-Marie',
    'Villeray–Saint-Michel–Parc-Extension'
]  # first list, we changed its order manually to make a "smart path" for the drone

connection_order = [
    'Rivière-des-Prairies–Pointe-aux-Trembles',
    'Montréal-Nord',
    'Saint-Léonard',
    'Anjou',
    'Mercier–Hochelaga-Maisonneuve',
    'Rosemont–La Petite-Patrie',
    'Villeray–Saint-Michel–Parc-Extension',
    'Outremont',
    'Le Sud-Ouest',
    'Ville-Marie',
    'L\'Île-Bizard–Sainte-Geneviève',
    'Verdun',
    'LaSalle',
    'Côte-des-Neiges–Notre-Dame-de-Grâce',
    'Le Plateau-Mont-Royal',
    'Saint-Laurent',
    'Ahuntsic-Cartierville',
    'Pierrefonds-Roxboro',
    'Lachine'
]

def find_circuit(G_undirected, debug_mode):
    if nx.is_eulerian(G_undirected):
        G_eulerian = G_undirected
    else:
        G_eulerian = nx.eulerize(G_undirected)
    return nx.eulerian_circuit(G_eulerian), G_eulerian

def generate_graph(name, debug_mode=False):
    """
    permet de charger un graphe
    d'une localisation a partir du nom de cette derniere.
    """
    G = ox.graph_from_place(name, network_type='drive')
    G = remove_duplicates(G, False)
    G = ox.project_graph(G)
    return G

def process_graphs(Graphe_montreal, debug_mode):
    """
    Création des paths
    """
    paths = {}
    debug_print(f"Génération : Montréal", debug_mode)
    G_undirected = Graphe_montreal.to_undirected()
    circuit, _ = find_circuit(G_undirected, debug_mode)
    c = [edge for edge in circuit]
    paths["Montréal"] = c
    return paths

def postier_chinois_process_montreal(Graphe_montreal, debug_mode):
    paths = process_graphs(Graphe_montreal, debug_mode)

    # Save Path with YML
    save_paths_to_yaml(paths, "paths-PostierChinoisMontreal.yml")

    return paths, finalPath