コード例 #1
0
def main():

    #directory containing simulation output files (relative or absolute path)
    directory = 'exampleSimulation'
    filenames = "SIR"
    plotStates = True  #set to False if you only want the visualisation
    animate = True  #set to False if you only want the plotting

    # Parameters for plotting of system states
    # define those states you wish to appear on the plot,
    # along with their colour and label
    statesToMonitor = [INFECTED, SUSCEPTIBLE]
    colours = ["r", "g"]
    labels = ["Infected", "Susceptible"]
    titlePlot = "Simulation of agent-based simple SIR"

    # Parameters for animated visualisations
    # define a mapping from state to colour
    # define the specific trial you wish to visualise. Default=0, first trial
    mapping = {SUSCEPTIBLE: "w", INFECTED: "r", RECOVERED: "0.4"}
    titleVisual = "Simulation of agent-based simple SIR"
    trialToVisualise = 0

    if animate:  #run visualisation
        visualiser = AnimationCreator(directory,
                                      filenames,
                                      titleVisual,
                                      mapping,
                                      trial=trialToVisualise)
        visualiser.create_gif(verbose=True)

    if plotStates:  #plot results
        p = PlotCreator(directory, filenames, titlePlot, statesToMonitor,
                        colours, labels)
        p.plotSimulation(show=False)
コード例 #2
0
def main(nodes=30):
    # Model parameters
    directory = 'test'
    globalSharedParameters = {}
    globalSharedParameters['infection_rate'] = 0.3
    globalSharedParameters['inf_dur'] = "self.r.gauss(7, 2)"

    # Output Parameters
    statesToMonitor = [INFECTED, SUSCEPTIBLE, RECOVERED]
    colours = ["r", "--g", ":k"]
    mapping = {SUSCEPTIBLE: "w", INFECTED: "r", RECOVERED: "0.4"}
    labels = ["Infected", "Susceptible", "Recovered"]
    name = "SIR_scale_free"
    titlePlot = "Simulation on scale free graph, %i trials, %i%% infection prob" \
                    % (TRIALS, 100 * globalSharedParameters['infection_rate'])
    titleVisual = ""

    # Network
    G = nx.scale_free_graph(nodes)
    states = [SUSCEPTIBLE for n in G.nodes()]

    # run simulation
    simulation = NetworkSimulation(G, states, agentClass, directory,
                                   MAX_SIMULATION_TIME, TRIALS,
                                   environmentAgent, **globalSharedParameters)
    simulation.runSimulation()

    # run visualisation
    gif = AnimationCreator(directory, name, titleVisual, mapping)
    gif.create_gif()

    # plot results
    p = PlotCreator(directory, name, titlePlot, statesToMonitor, colours,
                    labels)
    p.plotSimulation()
コード例 #3
0
def main():
    
    #directory containing simulation output files (relative or absolute path)
    directory = 'exampleSimulation'
    filenames = "SIR"    
    plotStates = True #set to False if you only want the visualisation  
    animate = True #set to False if you only want the plotting
    
    # Parameters for plotting of system states  
    # define those states you wish to appear on the plot,
    # along with their colour and label
    statesToMonitor = [INFECTED, SUSCEPTIBLE]
    colours = ["r", "g"]
    labels = ["Infected", "Susceptible"]
    titlePlot = "Simulation of agent-based simple SIR"
    
    # Parameters for animated visualisations
    # define a mapping from state to colour
    # define the specific trial you wish to visualise. Default=0, first trial
    mapping = {SUSCEPTIBLE:"w", INFECTED:"r", RECOVERED:"0.4"}
    titleVisual = "Simulation of agent-based simple SIR"    
    trialToVisualise = 0

    if animate: #run visualisation  
        visualiser = AnimationCreator(directory, filenames, titleVisual, mapping, trial=trialToVisualise)
        visualiser.create_gif(verbose=True)
    
    if plotStates: #plot results
        p = PlotCreator(directory, filenames, titlePlot, statesToMonitor, colours, labels)   
        p.plotSimulation(show=False)
コード例 #4
0
def main(nodes=30):         
    # Model parameters
    directory = 'test'
    globalSharedParameters = {} 
    globalSharedParameters['infection_rate'] = 0.3
    globalSharedParameters['inf_dur'] = "self.r.gauss(7, 2)"
    
    # Output Parameters    
    statesToMonitor = [INFECTED, SUSCEPTIBLE, RECOVERED]
    colours = ["r", "--g", ":k"]
    mapping = {SUSCEPTIBLE:"w", INFECTED:"r", RECOVERED:"0.4"}
    labels = ["Infected", "Susceptible", "Recovered"]
    name = "SIR_scale_free"
    titlePlot = "Simulation on scale free graph, %i trials, %i%% infection prob" \
                    % (TRIALS, 100 * globalSharedParameters['infection_rate'])
    titleVisual = ""   
    
    # Network
    G = nx.scale_free_graph(nodes)    
    states = [SUSCEPTIBLE for n in G.nodes()]       
    
    # run simulation
    simulation = NetworkSimulation(G,
                                   states,
                                   agentClass,
                                   directory,
                                   MAX_SIMULATION_TIME,
                                   TRIALS,
                                   environmentAgent,
                                   **globalSharedParameters)
    simulation.runSimulation()

    # run visualisation    
    gif = AnimationCreator(directory, name, titleVisual, mapping)
    gif.create_gif()

    # plot results
    p = PlotCreator(directory, name, titlePlot, statesToMonitor, 
                    colours, labels) 
    p.plotSimulation()
コード例 #5
0
Complete code file only from ComplexNetworkSim's  "getting started" documentation section, for visualising a simulation. For explanations refer to the documentation page.
Current link: http://complexnetworksim.0sites.net/start.html (documentation hosting may change place - see the PyPi index page.)

@author: Joe Schaul <*****@*****.**>
'''

from ComplexNetworkSim import PlotCreator, AnimationCreator

directory = 'test' #location of simulation result files    
myName = "SIR" #name that you wish to give your image output files    
title = "Simulation of agent-based simple SIR"

#define three simulation-specific constants:
SUSCEPTIBLE = 0    
INFECTED = 1    
RECOVERED = 2

statesToMonitor = [INFECTED, SUSCEPTIBLE] #even if we have states 0,1,2,3,... plot only 1 and 0
colours = ["r", "g"] #state 1 in red, state 0 in green
labels = ["Infected", "Susceptible"] #state 1 named 'Infected', 0 named 'Susceptible'
mapping = {SUSCEPTIBLE:"w", INFECTED:"r", RECOVERED:"0.4"}
trialToVisualise = 0

p = PlotCreator(directory, myName, title, statesToMonitor, colours, labels)   
p.plotSimulation(show=False) 
#show=True shows the graph directly, 
#otherwise only a png file is created in the directory defined above.

visualiser = AnimationCreator(directory, myName, title, mapping, trial=trialToVisualise)
#gif speed can be changed by giving a parameter 'delay' (default=100) to AnimationCreator
visualiser.create_gif(verbose=True)
コード例 #6
0
from ComplexNetworkSim import PlotCreator, AnimationCreator

directory = 'test'  #location of simulation result files
myName = "SIR"  #name that you wish to give your image output files
title = "Simulation of agent-based simple SIR"

#define three simulation-specific constants:
SUSCEPTIBLE = 0
INFECTED = 1
RECOVERED = 2

statesToMonitor = [INFECTED, SUSCEPTIBLE
                   ]  #even if we have states 0,1,2,3,... plot only 1 and 0
colours = ["r", "g"]  #state 1 in red, state 0 in green
labels = ["Infected",
          "Susceptible"]  #state 1 named 'Infected', 0 named 'Susceptible'
mapping = {SUSCEPTIBLE: "w", INFECTED: "r", RECOVERED: "0.4"}
trialToVisualise = 0

p = PlotCreator(directory, myName, title, statesToMonitor, colours, labels)
p.plotSimulation(show=False)
#show=True shows the graph directly,
#otherwise only a png file is created in the directory defined above.

visualiser = AnimationCreator(directory,
                              myName,
                              title,
                              mapping,
                              trial=trialToVisualise)
#gif speed can be changed by giving a parameter 'delay' (default=100) to AnimationCreator
visualiser.create_gif(verbose=True)