-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathmain.py
56 lines (44 loc) · 2.27 KB
/
main.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
# python libraries
import mesa
from Canvas_Grid_Visualization import CanvasGrid
# own python modules
import wildfire_model
import agents
from common_fixed_variables import *
# creates agent dictionary for rendering it on Canvas Gird from Mesa framework
def agent_portrayal(agent):
portrayal = {"Shape": "rect", "Filled": True, "h": 1, "w": 1}
# showing the probability map
if PROBABILITY_MAP:
if type(agent) is agents.Fire:
idx = int(round(agent.get_prob(), 1) * 10)
portrayal.update({"Color": BLACK_AND_WHITE_COLORS[idx], "Layer": 0})
else:
if type(agent) is agents.Fire: # showing smoke
if agent.smoke.is_smoke_active():
# the two following lines of code could be used to set the normalized index for different smoke colors.
# only one color is used by default.
# idx = normalize_fuel_values(agent.smoke.get_dispelling_counter_value(),
# agent.smoke.get_dispelling_counter_start_value())
portrayal.update({"Color": SMOKE_COLORS[0], "Layer": 0})
else:
if agent.is_burning(): # showing fire
idx = normalize_fuel_values(agent.get_fuel(), FUEL_UPPER_LIMIT)
portrayal.update({"Color": FIRE_COLORS[idx], "Layer": 0})
else: # showing vegetation
idx = normalize_fuel_values(agent.get_fuel(), FUEL_UPPER_LIMIT)
portrayal.update({"Color": VEGETATION_COLORS[idx], "Layer": 0})
elif type(agent) is agents.UAV: # showing UAV
portrayal.update({"Color": "Black", "Layer": 1, "h": 0.8, "w": 0.8})
return portrayal
# function that holds the main logic, in which the wildfire simulation and the web page interface are launched
def main():
print('actions:', N_ACTIONS)
print('observations:', N_OBSERVATIONS)
# initialize CanvasGrid
grid = CanvasGrid(agent_portrayal, WIDTH, HEIGHT, 10 * WIDTH, 10 * HEIGHT)
# initialize Modular server for mesa Python visualization
server = mesa.visualization.ModularServer(wildfire_model.WildFireModel, [grid], "WildFire Model")
server.port = 8521 # default port, others can be set
server.launch()
main()