-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconstructLabyrinth.py
More file actions
155 lines (136 loc) · 5.15 KB
/
Copy pathconstructLabyrinth.py
File metadata and controls
155 lines (136 loc) · 5.15 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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
'''
Created on 26/03/2018
@author: gtexier
SAR WARS Creation de graphes
'''
import os
# import numpy as np
import networkx as nx
import matplotlib.pyplot as plt
from intersection import Intersection as inter
import orientation as orient
from orientation import Orientation as ori
##
class Labyrinth():
entry_name = "ENTRY"
exit_name = "EXIT"
def __init__(self, name):
self.name = name
# self.tree = nx.DiGraph()
self.tree = nx.DiGraph()
def add_intersection(self, type_intersection, parent_name, dir):
'''
Adds an intersection to the graph
Parameters:
type_intersection: what kind of intersection to add
parent_name: name of the nodes where to insert the intersection
dir: the direction of the robot
'''
# Ajoutez le code pour gérer l'insertion des différents types d'intersection
# if type_intersection == ..... :
# .....
# elif type_intersection == .....:
# .....
# etc...
if type_intersection == inter.PathFour:
self.add_new_node(parent_name,dir)
self.add_new_node(parent_name,orient.get_left(dir))
self.add_new_node(parent_name,orient.get_right(dir))
if type_intersection == inter.PathThreeLeftFront:
self.add_new_node(parent_name,dir)
self.add_new_node(parent_name,orient.get_left(dir))
if type_intersection == inter.PathThreeRightFront:
self.add_new_node(parent_name,dir)
self.add_new_node(parent_name,orient.get_right(dir))
if type_intersection == inter.PathThreeLeftRight:
self.add_new_node(parent_name,orient.get_left(dir))
self.add_new_node(parent_name,orient.get_right(dir))
if type_intersection == inter.PathTwoLeft:
self.add_new_node(parent_name,orient.get_left(dir))
if type_intersection == inter.PathTwoRight:
self.add_new_node(parent_name,orient.get_right(dir))
'''if type_intersection == inter.PathTwoFront:
# Add node ?
if type_intersection == inter.PathOne:
# Add node ?'''
def add_new_node(self, parent_name, dir):
'''
Adds a new node to the graph
Parameters:
parent_name: name of the nodes where to insert the intersection
dir: the direction of the robot
'''
# Ajoutez le code pour ajouter un nouveau sommet dans le graphe
# dans lequel vous gérez le nom du nouveau sommet
self.tree.add_edge(parent_name, self.get_dir_child(parent_name, dir))
def add_entry(self, dir):
'''
Adds the first node of the graph, corresponding to the entry of
the labyrinth. This node is named ENTRY
Parameters:
dir: the direction of the robot
'''
# Ajoutez le code pour ajouter le sommet ENTRY dans le graphe
pass
def add_exit(self, tmp_name, dir):
'''
Adds the node named EXIT to the graph, corresponding to the exit of
the labyrinth.
Parameters:
dir: the direction of the robot
'''
# Ajoutez le code pour ajouter le sommet EXIT dans le graphe
pass
def get_dir_child(self, parent_name, dir):
'''
Returns the name of a new node to the graph
Parameters:
parent_name: name of the parent nodes
dir: the direction of child node whose name is asked
'''
# Ajoutez le code pour retourner le nom du sommet fils de parent_name
# dans la direction dir
last_direction = parent_name[-1]
if last_direction == orient.inverse_direction(dir).name[0]:
return parent_name[:-1]
else:
return parent_name + str(dir.name[0])
def go_to_next(self, parent_name, dir):
'''
Returns the name of the child node we will reach from parent_name
when going in the direction dir
Parameters:
parent_name: name of the parent nodes
dir: the direction of child node where we want to go
'''
# Ajoutez le code pour retourner le nom du sommet fils de parent_name
# dans la direction dir. Gerez le cas ou ce sommet n'existe pas.
if self.get_dir_child(parent_name, dir) in self.tree.neighbors(parent_name):
return self.get_dir_child(parent_name, dir)
else:
pass
def draw(self, withlabels=True):
'''
Draws the graph
Parameters:
withlabels: if True the label of the edges is shown, else it
is hidden
'''
# Ajoutez le code pour afficher le graphe.
# Choisissez votre representation.
pass
def main():
# Ajoutez votre code pour instancier un graphe et creer un graphe
# correspondant a un labyrinthe
G = nx.DiGraph()
G.add_edge(1, 2) # default edge data=1
G.add_edge(2, 3)
G.add_edge(2, 4)
G.add_edge(2, 6)
G.add_node(5)
G.add_edge(5, 6)
print([n for n in G.neighbors(2)])
nx.draw(G, pos=nx.circular_layout(G), nodecolor='r', edge_color='b')
pass
if __name__ == "__main__":
main()