-
Notifications
You must be signed in to change notification settings - Fork 0
/
libiintersection.pyx
647 lines (482 loc) · 24 KB
/
libiintersection.pyx
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
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
# distutils: language = c++
# distutils: sources = lib/pugixml/src/pugixml.cpp
from libcpp.map cimport map as map_
from libcpp.memory cimport shared_ptr, make_shared
from libcpp.string cimport string
from libcpp.utility cimport pair
from libcpp.vector cimport vector
from cython.operator cimport dereference as deref
from cython.operator cimport postincrement
# Defining pointers since Cython's [] syntax doesn't work sometimes
ctypedef IntersectionRoute* intersectionroutepointer
ctypedef IntersectionEdge* intersectionedgepointer
ctypedef ScenarioEdge* scenarioedgepointer
cdef extern from "<vector>" namespace "std":
cdef cppclass size_t
cdef extern from "libiintersection.h" namespace "ii::METRICS":
cdef enum METRICS_:
SAFETY, EMISSIONS, EFFICIENCY
cdef extern from "libiintersection.h" namespace "ii::BACKENDS":
cdef enum BACKENDS_:
SUMO, VISSIM, CITYFLOW
cdef extern from "libiintersection.h" namespace "ii::VEHICLETYPES":
cdef enum VEHICLETYPES_:
CAR, TRUCK, IDK
cdef extern from "libiintersection.h" namespace "ii::JUNCTIONTYPES":
cdef enum JUNCTIONTYPES_:
PRIORITY, TRAFFIC_LIGHT, RIGHT_BEFORE_LEFT, UNREGULATED, PRIORITY_STOP, TRAFFIC_LIGHT_UNREGULATED, ALLWAY_STOP, TRAFFIC_LIGHT_RIGHT_ON_RED
cdef extern from "libiintersection.h" namespace "ii":
cdef map_[JUNCTIONTYPES_, string] JUNCTIONTYPES_NAMES
cdef map_[string, VEHICLETYPES_] VEHICLETYPES_INDICES
cdef cppclass Point3d:
Point3d()
Point3d(short int x, short int y, short int z) except +
short int x()
short int y()
short int z()
cdef cppclass ScenarioNode:
ScenarioNode(Point3d) except +
Point3d* getLoc()
unsigned short int getID()
void setID(unsigned short int ID)
cdef cppclass IntersectionNode:
IntersectionNode(Point3d loc, JUNCTIONTYPES_ junctionType) except +
JUNCTIONTYPES_ getJunctionType()
Point3d* getLoc()
unsigned short int getID()
void setID(unsigned short int ID)
cdef cppclass BezierCurve:
BezierCurve()
BezierCurve(shared_ptr[IntersectionNode] s, shared_ptr[IntersectionNode] e, vector[Point3d] handles) except +
vector[Point3d] rasterize()
vector[Point3d] getHandles()
shared_ptr[IntersectionNode] getStartNode()
shared_ptr[IntersectionNode] getEndNode()
void setHandles(vector[Point3d] handles_)
cdef cppclass IntersectionEdge:
IntersectionEdge()
IntersectionEdge(shared_ptr[IntersectionNode] s, shared_ptr[IntersectionNode] e, BezierCurve shape, short int numLanes, short int speedLimit, short int priority) except +
BezierCurve getShape()
short int getNumLanes()
short int getSpeedLimit()
short int getPriority()
shared_ptr[IntersectionNode] getStartNode()
shared_ptr[IntersectionNode] getEndNode()
void setHandles(vector[Point3d] handles)
void setSpeedLimit(short int speedLimit)
void setNumLanes(short int numLanes)
void setPriority(short int priority)
cdef cppclass ScenarioEdge:
ScenarioEdge()
ScenarioEdge(shared_ptr[ScenarioNode] s, shared_ptr[ScenarioNode] e, map_[VEHICLETYPES_, short int] demand) except +
map_[VEHICLETYPES_, short int] getDemand()
shared_ptr[ScenarioNode] getStartNode()
shared_ptr[ScenarioNode] getEndNode()
cdef cppclass IntersectionRoute:
IntersectionRoute()
IntersectionRoute(vector[shared_ptr[IntersectionNode]] nodeList, vector[IntersectionEdge] edgeList) except +
vector[shared_ptr[IntersectionNode]] getNodeList()
vector[intersectionedgepointer] getEdgeList()
void setNodeList(vector[shared_ptr[IntersectionNode]] nodelist)
void setEdgeList(vector[IntersectionEdge] edgelist)
cdef cppclass Intersection:
Intersection()
Intersection(vector[IntersectionRoute]) except +
@staticmethod
void Simulate(Intersection*, BACKENDS_)
@staticmethod
Intersection fromSolFile(string solFilePath)
vector[intersectionroutepointer] getRoutes()
vector[shared_ptr[IntersectionNode]] getUniqueNodes()
vector[intersectionedgepointer] getUniqueEdges()
void updateMetrics(BACKENDS_, int safety, double efficiency, double emissions)
void markInvalid()
double getMetric(METRICS_)
string getNodeXML()
string getEdgeXML()
string getRouteXML(IntersectionScenario intersectionScenario)
string getSolXML()
cdef cppclass IntersectionScenario:
IntersectionScenario()
IntersectionScenario(string xmlFilePath) except +
vector[shared_ptr[ScenarioNode]] getNodes()
vector[scenarioedgepointer] getEdges()
PY_METRICS = {"safety": 0, "emissions": 1, "efficiency": 2}
PY_BACKENDS = {"sumo": 0, "vissim": 1, "cityflow": 2, "traci": 3}
PY_VEHICLETYPES = {"car": 0, "truck": 1}
PY_JUNCTIONTYPES = {"priority": 0, "traffic_light": 1, "right_before_left": 2, "unregulated": 3, "priority_stop": 4, "traffic_light_unregulated": 5, "allway_stop": 6, "traffic_light_on_red": 7}
cdef class PyIntersectionScenario:
cdef IntersectionScenario c_intersectionscenario
def __cinit__(self, str file_path):
self.c_intersectionscenario = IntersectionScenario(file_path.encode("utf-8"))
def getNodes(self):
cdef vector[shared_ptr[ScenarioNode]] c_nodes = self.c_intersectionscenario.getNodes()
cdef list nodes = []
cdef shared_ptr[ScenarioNode] node
for node in c_nodes:
nodes.append(PyScenarioNodePointer.fromCppPointer(node))
return nodes
def getEdges(self):
cdef vector[scenarioedgepointer] c_edges = self.c_intersectionscenario.getEdges()
cdef list edges = []
cdef scenarioedgepointer edge
for edge in c_edges:
edges.append(PyScenarioEdgePointer.fromCppPointer(edge))
return edges
cdef class PyIntersection:
cdef Intersection c_intersection
def __cinit__(self, routes=None, xmlFilePath=None):
cdef vector[IntersectionRoute] c_routes
cdef PyIntersectionRoute route
if routes:
for route in routes:
c_routes.push_back(route.c_intersectionroute)
self.c_intersection = Intersection(c_routes)
@staticmethod
def Simulate(self, PyIntersection intersection, int backend):
Intersection.Simulate(&intersection.c_intersection, <BACKENDS_>backend)
@staticmethod
def fromSolFile(str solFilePath):
cdef PyIntersection intersection = PyIntersection()
intersection.c_intersection = Intersection.fromSolFile(solFilePath.encode())
return intersection
def getUniqueNodes(self):
cdef vector[shared_ptr[IntersectionNode]] c_unique_nodes = self.c_intersection.getUniqueNodes()
cdef list unique_nodes = []
cdef shared_ptr[IntersectionNode] node
for node in c_unique_nodes:
unique_nodes.append(PyIntersectionNodePointer.fromCppPointer(node))
return unique_nodes
def getUniqueEdges(self):
cdef vector[intersectionedgepointer] c_unique_edges = self.c_intersection.getUniqueEdges()
cdef list unique_edges = []
cdef intersectionedgepointer edge
for edge in c_unique_edges:
unique_edges.append(PyIntersectionEdgePointer.fromCppPointer(edge))
return unique_edges
def updateMetrics(self, int backend, int safety = -1, float efficiency = -1, float emissions = -1):
self.c_intersection.updateMetrics(<BACKENDS_>backend, safety, efficiency, emissions)
def markInvalid(self):
self.c_intersection.markInvalid()
def getMetric(self, int metric):
return self.c_intersection.getMetric(<METRICS_>metric)
def getNodeXML(self):
return self.c_intersection.getNodeXML().decode('utf-8')
def getEdgeXML(self):
return self.c_intersection.getEdgeXML().decode('utf-8')
def getRouteXML(self, PyIntersectionScenario pyintersectionscenario):
return self.c_intersection.getRouteXML(pyintersectionscenario.c_intersectionscenario).decode('utf-8')
def getSolXML(self):
return self.c_intersection.getSolXML().decode('utf-8')
def getRoutes(self):
cdef vector[intersectionroutepointer] c_routes = self.c_intersection.getRoutes()
cdef list routes = []
cdef intersectionroutepointer route
for route in c_routes:
routes.append(PyIntersectionRoutePointer.fromCppPointer(route))
return routes
cdef class PyIntersectionRoute:
cdef IntersectionRoute c_intersectionroute
def __cinit__(self, list nodes, list edges):
cdef vector[shared_ptr[IntersectionNode]] c_nodes
cdef PyIntersectionNodePointer node
for node in nodes:
c_nodes.push_back(node.c_intersectionnodepointer)
cdef PyIntersectionEdge edge
cdef PyIntersectionEdgePointer edgepointer
cdef vector[IntersectionEdge] cyedges
for i in range(len(edges)):
if isinstance(edges[i], PyIntersectionEdgePointer):
for edgepointer in [edges[i]]:
cyedges.push_back(deref(edgepointer.c_intersectionedgepointer))
else:
for edge in [edges[i]]:
cyedges.push_back(edge.c_intersectionedge)
self.c_intersectionroute = IntersectionRoute(c_nodes, cyedges)
def getNodeList(self):
cdef vector[shared_ptr[IntersectionNode]] c_nodes = self.c_intersectionroute.getNodeList()
cdef list nodes = []
cdef shared_ptr[IntersectionNode] node
for node in c_nodes:
nodes.append(PyIntersectionNodePointer.fromCppPointer(node))
return nodes
def getEdgeList(self):
cdef vector[intersectionedgepointer] c_edges = self.c_intersectionroute.getEdgeList()
cdef list edges = []
cdef intersectionedgepointer edge
for edge in c_edges:
edges.append(PyIntersectionEdgePointer.fromCppPointer(edge))
return edges
def setNodeList(self, list nodeList):
cdef vector[shared_ptr[IntersectionNode]] c_nodes
cdef PyIntersectionNodePointer node
for node in nodeList:
c_nodes.push_back(node.c_intersectionnodepointer)
self.c_intersectionroute.setNodeList(c_nodes)
def setEdgeList(self, list edgeList):
cdef vector[IntersectionEdge] c_edges
cdef PyIntersectionEdge edge
for edge in edgeList:
c_edges.push_back(edge.c_intersectionedge)
self.c_intersectionroute.setEdgeList(c_edges)
cdef class PyBezierCurve:
cdef BezierCurve c_beziercurve
def __cinit__(self, PyIntersectionNodePointer s, PyIntersectionNodePointer e, list handles):
cdef vector[Point3d] c_handles
for handle in handles:
c_handles.push_back(Point3d(handle[0], handle[1], handle[2]))
self.c_beziercurve = BezierCurve(s.c_intersectionnodepointer, e.c_intersectionnodepointer, c_handles)
@staticmethod
cdef PyBezierCurve fromCppObject(BezierCurve bezier_curve):
cdef shared_ptr[IntersectionNode] node_ptr = bezier_curve.getStartNode()
cdef PyIntersectionNodePointer s = PyIntersectionNodePointer.fromCppPointer(node_ptr)
node_ptr = bezier_curve.getEndNode()
cdef PyIntersectionNodePointer e = PyIntersectionNodePointer.fromCppPointer(node_ptr)
cdef list handles = []
cdef Point3d handle
cdef vector[Point3d] c_handles = bezier_curve.getHandles()
for handle in c_handles:
handles.append((handle.x(), handle.y(), handle.z()))
return PyBezierCurve(s, e, handles)
def getStartNode(self):
return PyIntersectionNodePointer.fromCppPointer(self.c_beziercurve.getStartNode())
def getEndNode(self):
return PyIntersectionNodePointer.fromCppPointer(self.c_beziercurve.getEndNode())
def getHandles(self):
cdef vector[Point3d] c_handles = self.c_beziercurve.getHandles()
cdef list handles = []
cdef Point3d handle
for handle in c_handles:
handles.append((handle.x(), handle.y(), handle.z()))
return handles
cdef class PyIntersectionEdge:
cdef IntersectionEdge c_intersectionedge
def __cinit__(self, PyIntersectionNodePointer s=None, PyIntersectionNodePointer e=None,
PyBezierCurve shape=None, short int numLanes=-1, short int speedLimit=-1,
short int priority=-1):
if (s is None and e is None and shape is None and numLanes == -1 and speedLimit == -1
and priority == -1):
# Being called from `fromCppObject`
return
self.c_intersectionedge = IntersectionEdge(s.c_intersectionnodepointer,
e.c_intersectionnodepointer, shape.c_beziercurve, numLanes, speedLimit, priority)
@staticmethod
cdef PyIntersectionEdge fromCppObject(IntersectionEdge c_edge):
cdef PyIntersectionEdge edge = PyIntersectionEdge()
edge.c_intersectionedge = c_edge
return edge
def getShape(self):
cdef BezierCurve c_bezier_curve = self.c_intersectionedge.getShape()
return PyBezierCurve.fromCppObject(c_bezier_curve)
def getNumLanes(self):
return self.c_intersectionedge.getNumLanes()
def getSpeedLimit(self):
return self.c_intersectionedge.getSpeedLimit()
def getPriority(self):
return self.c_intersectionedge.getPriority()
def getStartNode(self):
cdef shared_ptr[IntersectionNode] c_node = self.c_intersectionedge.getStartNode()
return PyIntersectionNodePointer.fromCppPointer(c_node)
def getEndNode(self):
cdef shared_ptr[IntersectionNode] c_node = self.c_intersectionedge.getEndNode()
return PyIntersectionNodePointer.fromCppPointer(c_node)
def setHandles(self, handles):
cdef vector[Point3d] cyhandles
for handle in handles:
cyhandles.push_back(Point3d(handle[0], handle[1], handle[2]))
self.c_intersectionedge.setHandles(cyhandles)
def setNumLanes(self, numlanes):
self.c_intersectionedge.setNumLanes(numlanes)
def setSpeedLimit(self, speedlimit):
self.c_intersectionedge.setSpeedLimit(speedlimit)
def setPriority(self, priority):
self.c_intersectionedge.setPriority(priority)
def __eq__(self, other):
cdef PyIntersectionEdge other_
cdef PyIntersectionEdgePointer other_ptr
cdef vector[Point3d] self_handles = self.c_intersectionedge.getShape().getHandles()
cdef vector[Point3d] other_handles
cdef Point3d self_handle, other_handle
cdef size_t i
if isinstance(other, PyIntersectionEdge):
other_ = other
other_handles = other_.c_intersectionedge.getShape().getHandles()
elif isinstance(other, PyIntersectionEdgePointer):
other_ptr = other
other_handles = deref(other_ptr.c_intersectionedgepointer).getShape().getHandles()
if self_handles.size() != other_handles.size():
return False
for i in range(self_handles.size()):
self_handle = self_handles[i]
other_handle = other_handles[i]
if (self_handle.x() != other_handle.x() or self_handle.y() != other_handle.y()
or self_handle.z() != other_handle.z()):
return False
return True
cdef class PyIntersectionEdgePointer:
cdef intersectionedgepointer c_intersectionedgepointer
def __cinit__(self):
self.c_intersectionedgepointer = NULL
@staticmethod
cdef PyIntersectionEdgePointer fromCppPointer(intersectionedgepointer edge_ptr):
cdef PyIntersectionEdgePointer intersection_edge = PyIntersectionEdgePointer()
intersection_edge.c_intersectionedgepointer = edge_ptr
return intersection_edge
def getShape(self):
cdef BezierCurve c_bezier_curve = deref(self.c_intersectionedgepointer).getShape()
return PyBezierCurve.fromCppObject(c_bezier_curve)
def getStartNode(self):
cdef shared_ptr[IntersectionNode] c_node = deref(self.c_intersectionedgepointer).getStartNode()
return PyIntersectionNodePointer.fromCppPointer(c_node)
def getEndNode(self):
cdef shared_ptr[IntersectionNode] c_node = deref(self.c_intersectionedgepointer).getEndNode()
return PyIntersectionNodePointer.fromCppPointer(c_node)
def getNumLanes(self):
return deref(self.c_intersectionedgepointer).getNumLanes()
def getSpeedLimit(self):
return deref(self.c_intersectionedgepointer).getSpeedLimit()
def getPriority(self):
return deref(self.c_intersectionedgepointer).getPriority()
def setHandles(self, handles):
cdef vector[Point3d] cyhandles
for handle in handles:
cyhandles.push_back(Point3d(handle[0], handle[1], handle[2]))
deref(self.c_intersectionedgepointer).setHandles(cyhandles)
def setNumLanes(self, numlanes):
deref(self.c_intersectionedgepointer).setNumLanes(numlanes)
def setSpeedLimit(self, speedlimit):
deref(self.c_intersectionedgepointer).setSpeedLimit(speedlimit)
def setPriority(self, priority):
deref(self.c_intersectionedgepointer).setPriority(priority)
def __eq__(self, other):
cdef PyIntersectionEdge other_
cdef PyIntersectionEdgePointer other_ptr
cdef vector[Point3d] self_handles = deref(self.c_intersectionedgepointer).getShape().getHandles()
cdef vector[Point3d] other_handles
cdef Point3d self_handle, other_handle
cdef size_t i
if isinstance(other, PyIntersectionEdge):
other_ = other
other_handles = other_.c_intersectionedge.getShape().getHandles()
elif isinstance(other, PyIntersectionEdgePointer):
other_ptr = other
other_handles = deref(other_ptr.c_intersectionedgepointer).getShape().getHandles()
if self_handles.size() != other_handles.size():
return False
for i in range(self_handles.size()):
self_handle = self_handles[i]
other_handle = other_handles[i]
if (self_handle.x() != other_handle.x() or self_handle.y() != other_handle.y()
or self_handle.z() != other_handle.z()):
return False
return True
cdef class PyScenarioEdgePointer:
cdef scenarioedgepointer c_scenarioedgepointer
def __cinit__(self):
self.c_scenarioedgepointer = NULL
@staticmethod
cdef PyScenarioEdgePointer fromCppPointer(scenarioedgepointer edge_ptr):
cdef PyScenarioEdgePointer scenario_edge = PyScenarioEdgePointer()
scenario_edge.c_scenarioedgepointer = edge_ptr
return scenario_edge
def getStartNode(self):
cdef shared_ptr[ScenarioNode] c_node = deref(self.c_scenarioedgepointer).getStartNode()
return PyScenarioNodePointer.fromCppPointer(c_node)
def getEndNode(self):
cdef shared_ptr[ScenarioNode] c_node = deref(self.c_scenarioedgepointer).getEndNode()
return PyScenarioNodePointer.fromCppPointer(c_node)
def getDemand(self):
cdef map_[VEHICLETYPES_, short int] c_demand = deref(self.c_scenarioedgepointer).getDemand()
cdef dict demand = {}
cdef map_[VEHICLETYPES_, short int].iterator it = c_demand.begin()
while it != c_demand.end():
demand[<int>(deref(it).first)] = deref(it).first
postincrement(it)
return demand
cdef class PyScenarioNodePointer:
cdef shared_ptr[ScenarioNode] c_scenarionodepointer
def __cinit__(self):
pass
@staticmethod
cdef PyScenarioNodePointer fromCppPointer(shared_ptr[ScenarioNode] c_node):
cdef PyScenarioNodePointer node = PyScenarioNodePointer()
node.c_scenarionodepointer = c_node
return node
def getLoc(self):
loc = deref(self.c_scenarionodepointer).getLoc()
pytuple = (loc.x(), loc.y(), loc.z())
return pytuple
def setID(self, int id_):
deref(self.c_scenarionodepointer).setID(id_)
def getID(self):
return deref(self.c_scenarionodepointer).getID()
cdef class PyIntersectionNodePointer:
cdef shared_ptr[IntersectionNode] c_intersectionnodepointer
def __cinit__(self, tuple loc=None, int junctionType=-1):
if loc is not None and junctionType != -1:
self.c_intersectionnodepointer = make_shared[IntersectionNode](Point3d(loc[0], loc[1], loc[2]), <JUNCTIONTYPES_>junctionType)
@staticmethod
cdef PyIntersectionNodePointer fromCppPointer(shared_ptr[IntersectionNode] c_node):
cdef PyIntersectionNodePointer node = PyIntersectionNodePointer()
node.c_intersectionnodepointer = c_node
return node
@staticmethod
def fromScenarioNode(PyScenarioNodePointer sce_node):
cdef PyIntersectionNodePointer int_node = PyIntersectionNodePointer(sce_node.getLoc(), UNREGULATED)
deref(int_node.c_intersectionnodepointer).setID(sce_node.getID())
return int_node
def getJunctionType(self):
return deref(self.c_intersectionnodepointer).getJunctionType()
def getLoc(self):
loc = deref(self.c_intersectionnodepointer).getLoc()
pytuple = (loc.x(), loc.y(), loc.z())
return pytuple
def getID(self):
return deref(self.c_intersectionnodepointer).getID()
def setID(self, int id_):
deref(self.c_intersectionnodepointer).setID(id_)
def __eq__(self, other):
return self.getID() == other.getID()
def __hash__(self):
return hash((self.getLoc(), self.getID()))
cdef class PyIntersectionRoutePointer:
cdef intersectionroutepointer c_intersectionroutepointer
def __cinit__(self):
self.c_intersectionroutepointer = NULL
@staticmethod
cdef PyIntersectionRoutePointer fromCppPointer(IntersectionRoute* c_route):
cdef PyIntersectionRoutePointer route = PyIntersectionRoutePointer()
route.c_intersectionroutepointer = c_route
return route
def getNodeList(self):
cdef vector[shared_ptr[IntersectionNode]] c_nodes = deref(self.c_intersectionroutepointer).getNodeList()
nodes = []
cdef shared_ptr[IntersectionNode] node
for node in c_nodes:
nodes.append(PyIntersectionNodePointer.fromCppPointer(node))
return nodes
def getEdgeList(self):
cdef vector[intersectionedgepointer] c_edges = deref(self.c_intersectionroutepointer).getEdgeList()
edges = []
cdef intersectionedgepointer edge
for edge in c_edges:
edges.append(PyIntersectionEdgePointer.fromCppPointer(edge))
return edges
def setNodeList(self, list nodeList):
cdef vector[shared_ptr[IntersectionNode]] c_nodes
cdef PyIntersectionNodePointer node
for node in nodeList:
c_nodes.push_back(node.c_intersectionnodepointer)
deref(self.c_intersectionroutepointer).setNodeList(c_nodes)
def setEdgeList(self, list edgeList):
cdef vector[IntersectionEdge] c_edges
cdef PyIntersectionEdge edge
cdef PyIntersectionEdgePointer edgepointer
for i in range(len(edgeList)):
if isinstance(edgeList[i], PyIntersectionEdgePointer):
for edgepointer in [edgeList[i]]:
c_edges.push_back(deref(edgepointer.c_intersectionedgepointer))
else:
for edge in [edgeList[i]]:
c_edges.push_back(edge.c_intersectionedge)
deref(self.c_intersectionroutepointer).setEdgeList(c_edges)