2021-08-17 12:52:48 -04:00
|
|
|
"""
|
|
|
|
Traffic light module
|
|
|
|
SPDX - License - Identifier: LGPL - 3.0 - or -later
|
|
|
|
Copyright © 2020 Project Author Pilar Monsalvete Alvarez de Uribarri pilar.monsalvete@concordia.ca
|
|
|
|
Contributor Milad milad.aghamohamadnia@concordia.ca
|
|
|
|
Contributor Guille guille.gutierrezmorote@concordia.ca
|
|
|
|
"""
|
|
|
|
|
2021-09-14 13:46:48 -04:00
|
|
|
import ast
|
|
|
|
from typing import List, Union
|
2021-08-17 12:52:48 -04:00
|
|
|
from city_model_structure.transport.phase import Phase
|
|
|
|
from city_model_structure.transport.traffic_node import TrafficNode
|
|
|
|
|
|
|
|
|
|
|
|
class TrafficLight(TrafficNode):
|
|
|
|
"""
|
|
|
|
Traffic light class
|
|
|
|
"""
|
|
|
|
def __init__(self, name, coordinates, offset, phases=None, edges=None, right_on_red=False):
|
2021-08-17 13:30:51 -04:00
|
|
|
super().__init__(name, coordinates, edges=edges, node_type='TrafficLight')
|
2021-08-17 12:52:48 -04:00
|
|
|
if phases is None:
|
|
|
|
phases = []
|
|
|
|
self._right_on_red = right_on_red
|
|
|
|
self._offset = offset
|
|
|
|
self._phases = phases
|
|
|
|
|
|
|
|
@property
|
2021-09-14 13:46:48 -04:00
|
|
|
def right_on_red(self) -> Union[None, bool]:
|
2021-08-26 09:19:38 -04:00
|
|
|
"""
|
2021-08-30 14:39:24 -04:00
|
|
|
Get if is possible to turn right when the traffic light is red
|
2021-09-14 13:46:48 -04:00
|
|
|
:return: None or Boolean
|
2021-08-26 09:19:38 -04:00
|
|
|
"""
|
2021-08-17 12:52:48 -04:00
|
|
|
return self._right_on_red
|
|
|
|
|
|
|
|
@right_on_red.setter
|
|
|
|
def right_on_red(self, value):
|
2021-08-26 09:19:38 -04:00
|
|
|
"""
|
2021-08-30 14:39:24 -04:00
|
|
|
Get if is possible to turn right when the traffic light is red
|
|
|
|
:param value: Boolean
|
2021-08-26 09:19:38 -04:00
|
|
|
"""
|
2021-09-14 13:46:48 -04:00
|
|
|
if value is not None:
|
|
|
|
self._right_on_red = ast.literal_eval(value)
|
2021-08-17 12:52:48 -04:00
|
|
|
|
|
|
|
@property
|
2021-09-14 13:46:48 -04:00
|
|
|
def offset(self) -> Union[None, int]:
|
2021-08-17 12:52:48 -04:00
|
|
|
"""
|
2021-08-30 14:39:24 -04:00
|
|
|
Get program initial time offset
|
2021-09-14 13:46:48 -04:00
|
|
|
:return: None or int
|
2021-08-17 12:52:48 -04:00
|
|
|
"""
|
|
|
|
return self._offset
|
|
|
|
|
|
|
|
@offset.setter
|
|
|
|
def offset(self, value):
|
|
|
|
"""
|
2021-08-30 14:39:24 -04:00
|
|
|
Set program initial time offset
|
2021-08-17 12:52:48 -04:00
|
|
|
:param value: int
|
|
|
|
"""
|
2021-09-14 13:46:48 -04:00
|
|
|
if value is not None:
|
|
|
|
self._offset = int(value)
|
2021-08-17 12:52:48 -04:00
|
|
|
|
|
|
|
@property
|
|
|
|
def phases(self) -> List[Phase]:
|
|
|
|
"""
|
2021-08-30 14:39:24 -04:00
|
|
|
Get traffic light logic phases
|
2021-08-17 12:52:48 -04:00
|
|
|
:return: [Phase]
|
|
|
|
"""
|
|
|
|
return self._phases
|
|
|
|
|
|
|
|
@phases.setter
|
|
|
|
def phases(self, value):
|
|
|
|
"""
|
2021-08-30 14:39:24 -04:00
|
|
|
Set traffic light logic phases
|
2021-08-17 12:52:48 -04:00
|
|
|
:param value: [Phase]
|
|
|
|
"""
|
|
|
|
self._phases = value
|