generated from UnBParadigmas2024-2/RepositoryTemplate
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.py
104 lines (94 loc) · 2.8 KB
/
server.py
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
from mesa.visualization import SolaraViz, make_space_component, make_plot_component
from src.agents.car import CarAgent
from src.agents.pedestrian import PedestrianAgent
from src.agents.traffic_cell import TrafficCell
from src.agents.traffic_light import TrafficLightAgent
from src.traffic_model import TrafficModel
def agent_portrayal(agent):
if isinstance(agent, TrafficLightAgent): # Semaforos
if agent.state == "red":
color = "tab:red"
elif agent.state == "green":
color = "tab:green"
elif agent.state == "yellow":
color = "tab:orange"
return {"color": color, "size":50, "zorder": 1}
elif isinstance(agent, CarAgent): # Carros
car_color = "blue"
if agent.collision:
car_color="gray"
return {"color": f"tab:{car_color}", "marker": "h", "zorder": 0}
elif isinstance(agent, PedestrianAgent): # Pedestres
return {"color": "tab:pink", "marker": "p", "zorder": 0}
elif isinstance(agent, TrafficCell): # Terreno
if agent.cell_type == "building":
return {"color": "tab:gray", "marker": "s", "zorder": -1}
elif agent.cell_type == "intersection":
return {"marker": "", "zorder": -1}
model_params = {
"max_cars": {
"type": "SliderInt",
"value": 6,
"label": "Quantidade de carros",
"min": 4,
"max": 40,
"step": 1,
},
"max_pedestrians": {
"type": "SliderInt",
"value": 6,
"label": "Quantidade de pedestres",
"min": 4,
"max": 20,
"step": 1,
},
"size": {
"type": "SliderInt",
"value": 17,
"label": "Tamanho do mapa",
"min": 11,
"max": 30,
"step": 1,
},
"green_timer": {
"type": "SliderInt",
"value": 10,
"label": "Tempo do semáforo verde",
"min": 5,
"max": 100,
"step": 1,
},
"red_timer":{
"type": "SliderInt",
"value": 20,
"label": "Tempo do semáforo vermelho",
"min": 5,
"max": 100,
"step": 1,
},
"yellow_timer":{
"type": "SliderInt",
"value": 5,
"label": "Tempo do semáforo amarelo",
"min": 5,
"max": 100,
"step": 1,
},
"distraction":{
"type": "SliderFloat",
"value": 0.5,
"label": "Nível de distração dos pedestres",
"min": 0.01,
"max": 1,
"step": 0.01,
}
}
tr_model = TrafficModel()
spaceGraph = make_space_component(agent_portrayal)
pedestrianPlot = make_plot_component(["Número de carros","Número de pedestres","Número de colisões"])
page = SolaraViz(
tr_model,
components=[spaceGraph, pedestrianPlot],
model_params=model_params,
name="Modelo de tráfego",
)