Example #1
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()
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()
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()
def main(nodes=30):
    # Model parameters
    directory = 'test'
    globalSharedParameters = {}
    globalSharedParameters['infection_rate'] = 0.3
    globalSharedParameters['inf_dur'] = "7"

    # Network and initial states
    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()
Example #5
0
def main():
    directory = 'test' #output directory

    # run simulation with parameters
    # - complex network structure
    # - initial state list
    # - agent behaviour class
    # - output directory
    # - maximum simulation time
    # - number of trials
    simulation = NetworkSimulation(G,
                                   states,
                                   SIRSimple,
                                   directory,
                                   MAX_SIMULATION_TIME,
                                   TRIALS)
    simulation.runSimulation()
Example #6
0
def main():         
    directory = 'test' #output directory         
    
    # run simulation with parameters 
    # - complex network structure
    # - initial state list
    # - agent behaviour class
    # - output directory
    # - maximum simulation time
    # - number of trials
    simulation = NetworkSimulation(G,        
                                   states,
                                   SIRSimple,   
                                   directory,
                                   MAX_SIMULATION_TIME,
                                   TRIALS)
    simulation.runSimulation()
def main(nodes=30):         
    # Model parameters
    directory = 'test'
    globalSharedParameters = {} 
    globalSharedParameters['infection_rate'] = 0.3
    globalSharedParameters['inf_dur'] = "7"
        
    # Network and initial states
    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()
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()