hub/city_model_structure/transport/traffic_light.py

76 lines
1.8 KiB
Python
Raw Normal View History

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]:
"""
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-17 12:52:48 -04:00
return self._right_on_red
@right_on_red.setter
def right_on_red(self, value):
"""
Get if is possible to turn right when the traffic light is red
:param value: Boolean
"""
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
"""
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):
"""
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]:
"""
Get traffic light logic phases
2021-08-17 12:52:48 -04:00
:return: [Phase]
"""
return self._phases
@phases.setter
def phases(self, value):
"""
Set traffic light logic phases
2021-08-17 12:52:48 -04:00
:param value: [Phase]
"""
self._phases = value