Skip to content

Commit

Permalink
Merge pull request #25 from scioip34/feature/disable-visualization
Browse files Browse the repository at this point in the history
Feature/disable visualization
  • Loading branch information
mezdahun authored Jan 14, 2022
2 parents cd1b66e + ad6b0e5 commit 060d256
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 4 deletions.
8 changes: 7 additions & 1 deletion .env
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,13 @@ N = 3
N_RESOURCES = 10

# Simulation time
T = 10000
T = 1000

# Framerate (only matter if visualization is turned on)
INIT_FRAMERATE = 25

# Visualization ON/OFF
WITH_VISUALIZATION = 1

# Resolution (px) of agents' visual projection fields
VISUAL_FIELD_RESOLUTION = 1200
Expand Down
2 changes: 2 additions & 0 deletions abm/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ def start():
T=int(envconf["T"]),
v_field_res=int(envconf["VISUAL_FIELD_RESOLUTION"]),
agent_fov=float(envconf['AGENT_FOV']),
framerate=int(envconf["INIT_FRAMERATE"]),
with_visualization=bool(int(envconf["WITH_VISUALIZATION"])),
width=int(envconf["ENV_WIDTH"]),
height=int(envconf["ENV_HEIGHT"]),
show_vis_field=bool(int(envconf["SHOW_VISUAL_FIELDS"])),
Expand Down
27 changes: 24 additions & 3 deletions abm/simulation/sims.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
from abm.monitoring import env_saver
from math import atan2

from datetime import datetime

# loading env variables from dotenv file
from dotenv import dotenv_values

Expand Down Expand Up @@ -49,7 +51,7 @@ def refine_ar_overlap_group(collision_group):

class Simulation:
def __init__(self, N, T, v_field_res=800, width=600, height=480,
framerate=25, window_pad=30, show_vis_field=False,
framerate=25, window_pad=30, with_visualization=True, show_vis_field=False,
pooling_time=3, pooling_prob=0.05, agent_radius=10,
N_resc=10, min_resc_perpatch=200, max_resc_perpatch=1000, min_resc_quality=0.1, max_resc_quality=1,
patch_radius=30, regenerate_patches=True, agent_consumption=1, teleport_exploit=True,
Expand All @@ -64,6 +66,8 @@ def __init__(self, N, T, v_field_res=800, width=600, height=480,
:param height: real height of environment (not window size)
:param framerate: framerate of simulation
:param window_pad: padding of the environment in simulation window in pixels
:param with_visualization: turns visualization on or off. For large batch autmatic simulation should be off so
that we can use a higher/maximal framerate.
:param show_vis_field: (Bool) turn on visualization for visual field of agents
:param pooling_time: time units for a single pooling events
:param pooling probability: initial probability of switching to pooling regime for any agent
Expand Down Expand Up @@ -102,7 +106,12 @@ def __init__(self, N, T, v_field_res=800, width=600, height=480,
self.N = N
self.T = T
self.t = 0
self.framerate_orig = framerate
self.with_visualization = with_visualization
if self.with_visualization:
self.framerate_orig = framerate
else:
# this is more than what is possible withy pygame so it will use the maximal framerate
self.framerate_orig = 200
self.framerate = self.framerate_orig
self.is_paused = False

Expand Down Expand Up @@ -461,6 +470,9 @@ def draw_frame(self, stats, stats_pos):
pygame.display.flip()

def start(self):

start_time = datetime.now()

# Creating N agents in the environment
self.create_agents()

Expand Down Expand Up @@ -603,7 +615,8 @@ def start(self):
ag.calc_social_V_proj(self.agents)

# Draw environment and agents
self.draw_frame(stats, stats_pos)
if self.with_visualization:
self.draw_frame(stats, stats_pos)

# Monitoring with IFDB
if self.save_in_ifd:
Expand All @@ -613,6 +626,10 @@ def start(self):
# Moving time forward
self.clock.tick(self.framerate)

end_time = datetime.now()
print("Total simulation time: ", (end_time-start_time).total_seconds())


# Saving data from IFDB when simulation time is over
if self.save_csv_files:
if self.save_in_ifd:
Expand All @@ -622,4 +639,8 @@ def start(self):
raise Exception("Tried to save simulation data as csv file due to env configuration, "
"but IFDB logging was turned off. Nothing to save! Please turn on IFDB logging"
" or turn off CSV saving feature.")

end_save_time = datetime.now()
print("Total saving time:", (end_save_time - end_time).total_seconds())

pygame.quit()

0 comments on commit 060d256

Please sign in to comment.