コード例 #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 simulate(**kwargs):        
    
    # Model parameters
    directory = kwargs.get("directory", 'skype')    
    agentClass = kwargs.get("agentClass", Skype)    
    environmentAgent = kwargs.get("environmentAgent", crash)
    NUMBER_SUPERNODES = kwargs.get("supernodes", 90)
    NUMBER_NODES = kwargs.get("nodes", 600)
    NUMBER_PERMANENT_SUPERNODES = kwargs.get("permanent_supernodes", 1)    
    globalSharedParameters = {} 
    globalSharedParameters['supernodes'] = list(range(NUMBER_SUPERNODES)) 
    globalSharedParameters['permanent_supernodes'] = list(range(NUMBER_PERMANENT_SUPERNODES)) 
    globalSharedParameters['threshold'] = kwargs.get("threshold", 12)
    globalSharedParameters['cache_size'] = kwargs.get("cache_size", 20)
    globalSharedParameters['kills'] = kwargs.get("kills", 30)
    globalSharedParameters['restart_time'] = kwargs.get('restart_time', "4.0")
    
    
    # Output Parameters    
    statesToMonitor = [ENABLED, ENABLED_S]
    colours = ["g", "^b", "0.5"]
    mapping = {ENABLED:"g", ENABLED_S: "b", DISABLED:"0.2", DISABLED_S: "0.4"}
    labels = ["Online nodes", "Online supernodes", "Offline"]
    name = "skype"
    titlePlot = "Skype simulation, %i trials, threshold=%i, cacheSize=%i \n supernode_restart_distr=%s" % \
      (TRIALS, globalSharedParameters['threshold'], globalSharedParameters['cache_size'],
       str(globalSharedParameters['restart_time']))
    titleVisual = "Skype visualisation"
    
    
#####topology####
    G = nx.Graph(nx.complete_graph(NUMBER_SUPERNODES))
    G.add_nodes_from(range(NUMBER_SUPERNODES,NUMBER_NODES+NUMBER_SUPERNODES))
    
    states = [DISABLED for node in G.nodes_iter()]
    
    
    # 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
def simulate(**kwargs):        
    
    # Model parameters
    directory = kwargs.get("directory", 'skype')    
    agentClass = kwargs.get("agentClass", Skype)    
    environmentAgent = kwargs.get("environmentAgent", crash)
    NUMBER_SUPERNODES = kwargs.get("supernodes", 90)
    NUMBER_NODES = kwargs.get("nodes", 600)
    NUMBER_PERMANENT_SUPERNODES = kwargs.get("permanent_supernodes", 1)    
    globalSharedParameters = {} 
    globalSharedParameters['supernodes'] = range(NUMBER_SUPERNODES) 
    globalSharedParameters['permanent_supernodes'] = range(NUMBER_PERMANENT_SUPERNODES) 
    globalSharedParameters['threshold'] = kwargs.get("threshold", 12)
    globalSharedParameters['cache_size'] = kwargs.get("cache_size", 20)
    globalSharedParameters['kills'] = kwargs.get("kills", 30)
    globalSharedParameters['restart_time'] = kwargs.get('restart_time', "4.0")
    
    
    # Output Parameters    
    statesToMonitor = [ENABLED, ENABLED_S]
    colours = ["g", "^b", "0.5"]
    mapping = {ENABLED:"g", ENABLED_S: "b", DISABLED:"0.2", DISABLED_S: "0.4"}
    labels = ["Online nodes", "Online supernodes", "Offline"]
    name = "skype"
    titlePlot = "Skype simulation, %i trials, threshold=%i, cacheSize=%i \n supernode_restart_distr=%s" % \
      (TRIALS, globalSharedParameters['threshold'], globalSharedParameters['cache_size'],
       str(globalSharedParameters['restart_time']))
    titleVisual = "Skype visualisation"
    
    
#####topology####
    G = nx.Graph(nx.complete_graph(NUMBER_SUPERNODES))
    G.add_nodes_from(xrange(NUMBER_SUPERNODES,NUMBER_NODES+NUMBER_SUPERNODES))
    
    states = [DISABLED for node in G.nodes_iter()]
    
    
    # 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()
コード例 #6
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()
コード例 #7
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)
コード例 #8
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)