Simulation
- class graph_tiger.simulations.Simulation(graph, runs, steps, **kwargs)
Bases:
object
The parent class for all simulation classes i.e., attack, defense, cascading failure and diffusion models. Provides a shared set of functions, largely for network visualization and plotting of results
- Parameters
graph – undirected NetworkX graph
runs – number of times to run the simulation
steps – number of time steps to run each simulation
kwargs – optional parameters to change visualization settings
- child_class()
Gets the child class name :return: string
- create_simulation_gif()
Draws and saves the network simulation to an MP4 file
- draw_graph(step)
Draws the graph
- Parameters
step – current iteration of the simulation
- Returns
matplotlib.collections.PathCollection PathCollection` of the nodes.
- get_effective_strength()
Implemented by child class
- get_graph_coordinates()
Gets the graph coordinates, which can be: (1) set in the graph itself with the ‘pos’ tag on the vertices, (2) positioned according to the force atlas2 algorithm, (3) positioned using a spectral layout.
Then lays out the edges, can be curved, bundled, or straight
- Returns
Tuple containing node and edge positions
- get_plot_title(step)
Gets the title for each plot
- Parameters
step – the current simulation iteration
- Returns
title string
- get_visual_settings(step)
Sets the visual settings for the network visualization
- Parameters
step – current iteration of the simulation
- Returns
four lists, each containing a number corresponding to the size or color of each node in the graph + cmap representing color scheme
- plot_graph_transition(sim_info)
Helper function to decide which snapshots to take for network visualization
- Parameters
sim_info – the information stored at each step in the simulation
- plot_network(step)
Plots the compiled simulation results
- Parameters
step – current iteration of the simulation
- plot_results(results)
Plots the compiled simulation results
- Parameters
results – a list of floats representing each simulation output
- reset_simulation()
Implemented by child class
- run_simulation()
Averages the simulation over the number of ‘runs’.
- Returns
a list containing the average value at each ‘step’ of the simulation.
- run_single_sim()
Implemented by child class