Skip to content

Commit

Permalink
More comments and output
Browse files Browse the repository at this point in the history
  • Loading branch information
chadsr committed Jan 6, 2018
1 parent 05a2648 commit 72b558e
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 4 deletions.
6 changes: 5 additions & 1 deletion fire_evacuation/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from .agent import FireExit, Wall, Furniture, Fire, Smoke, Human, Sight, Door, DeadHuman


# Creates a visual portrayal of our model in the browser interface
def fire_evacuation_portrayal(agent):
if agent is None:
return
Expand Down Expand Up @@ -66,9 +67,10 @@ def fire_evacuation_portrayal(agent):
return portrayal


# Was hoping floorplan could dictate the size of the grid, but seems the grid needs to be specified first :/
# Was hoping floorplan could dictate the size of the grid, but seems the grid needs to be specified first, so the size is fixed to 50x50
canvas_element = CanvasGrid(fire_evacuation_portrayal, 50, 50, 800, 800)

# Define the charts on our web interface visualisation
status_chart = ChartModule([{"Label": "Alive", "Color": "blue"},
{"Label": "Dead", "Color": "red"},
{"Label": "Escaped", "Color": "green"}])
Expand All @@ -84,6 +86,7 @@ def fire_evacuation_portrayal(agent):
# Get list of available floorplans
floor_plans = [f for f in listdir("fire_evacuation/floorplans") if path.isfile(path.join("fire_evacuation/floorplans", f))]

# Specify the parameters changeable by the user, in the web interface
model_params = {
"floor_plan_file": UserSettableParameter("choice", "Floorplan", value=floor_plans[0], choices=floor_plans),
"human_count": UserSettableParameter("number", "Number Of Human Agents", value=10),
Expand All @@ -94,5 +97,6 @@ def fire_evacuation_portrayal(agent):
"save_plots": UserSettableParameter('checkbox', 'Save plots to file', value=True)
}

# Start the visual server with the model
server = ModularServer(FireEvacuation, [canvas_element, status_chart, mobility_chart, collaboration_chart], "Fire Evacuation",
model_params)
1 change: 1 addition & 0 deletions run.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from fire_evacuation.server import server

# Starts a visual server with our model
server.launch()
18 changes: 15 additions & 3 deletions run_batch.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@
GRAPH_WIDTH = 1920
GRAPH_HEIGHT = 1080

"""
This script starts a batch run of our model, without visualisation, for obtaining the final statistics we require, over multiple iterations
"""


# Concatenate all of the dataframe files found in the OUTPUT_DIR
def merge_dataframes():
Expand Down Expand Up @@ -73,20 +77,24 @@ def merge_dataframes():
# Create the batch runner
print("Running batch test with %i runs for each parameter and %i human agents." % (runs, human_count))

start = time.time() # Time the batch run
batch_start = time.time() # Time the batch run

# Run the batch runner 'runs' times (the number of iterations to make) and output a dataset and graphs each iteration
for i in range(1, runs + 1):
iteration_start = time.time() # Time the iteration

param_run = BatchRunner(FireEvacuation, variable_parameters=variable_params, fixed_parameters=fixed_params, model_reporters=model_reporter)

param_run.run_all() # Run all simulations

end = time.time()
iteration_end = time.time()
end_timestamp = time.strftime("%Y%m%d-%H%M%S")

# Save the dataframe to a file so we have the oppurtunity to concatenate separate dataframes from separate runs
dataframe = param_run.get_model_vars_dataframe()
dataframe.to_pickle(path=OUTPUT_DIR + "/batch_results/dataframe_" + end_timestamp + ".pickle")

elapsed = end - start # Get the elapsed time in seconds
elapsed = iteration_end - iteration_start # Get the elapsed time in seconds
print("Batch runner finished iteration %i. Took: %s" % (i, str(timedelta(seconds=elapsed))))

dataframe, count = merge_dataframes()
Expand All @@ -113,3 +121,7 @@ def merge_dataframes():
plt.ylim(0, 100)
plt.savefig(OUTPUT_DIR + "/batch_graphs/batch_run_boxplot_" + end_timestamp + ".png", dpi=GRAPH_DPI)
plt.close(fig)

batch_end = time.time()
elapsed = batch_end - batch_start # Get the elapsed time in seconds
print("Batch runner finished all iterations. Took: %s" % str(timedelta(seconds=elapsed)))

0 comments on commit 72b558e

Please sign in to comment.