Ejemplo n.º 1
0
def main():
	import networkx as nx
	from complex_systems.pgg import PublicGoodGames
	import pylab as plt
	import numpy as np
	
	nb_node = 1000
	edge_prob = 10.0/nb_node
	coop_ratio = 0.5
	synergy = 8
	nb_round = 100
	nb_game_per_round = 10
	nb_def = []
	nb_coop = []
	
	# Generate a Random Graph 
	G = nx.fast_gnp_random_graph(nb_node, edge_prob)
	# initialize the game 
	PGG = PublicGoodGames(G=G, synergy=synergy,nb_simulation_step=nb_game_per_round, cooperator_ratio=coop_ratio)
	for i in range(nb_round):
		PGG.run_game()
		nb_def.append(PGG.defector_counter())
		nb_coop.append(PGG.cooperator_counter())
		#print nb_coop, nb_def
	plt.figure()
	plt.plot(nb_def,'b-*')
	plt.plot(nb_coop,'r-*')
	plt.figure()
	print np.mean([val for key, val in G.degree().iteritems()])
	nx.draw_networkx(G, node_size=20, with_labels = False)
	plt.show()
Ejemplo n.º 2
0
def main():
    from complex_systems.dygraph import DyGraph
    from complex_systems.pgg import PublicGoodGames
    from complex_systems.quasi_unit_disk_graph import gen_quasi_unit_disk_weight
    from complex_systems.quasi_unit_disk_graph import remove_edges_from_graph
    import networkx as nx
    import pylab as plt

    outer_radius = 75
    inner_radius = 40
    alpha_quasi_unit_disk = 0.9
    synergy = 8
    coop_ratio = 0.5
    noise_var = 1
    nb_node = 400
    time_step = 5.0
    G = DyGraph(time_stop=2000.0, time_step=time_step)
    G.generate_mobility_levy_walk(
        alpha=0.9,
        beta=0.9,
        size_max=1000,
        f_min=10,
        f_max=1000,
        s_min=5,
        s_max=1000.0,
        b_c=2,
        radius=200.0,
        nb_node=nb_node,
    )
    first_run = True
    resultats = []
    for g in G:
        g = gen_quasi_unit_disk_weight(G=g,
                                       outer_radius=outer_radius,
                                       inner_radius=inner_radius,
                                       alpha=alpha_quasi_unit_disk)
        g = remove_edges_from_graph(g)
        if first_run == True:
            PGG = PublicGoodGames(G=g,
                                  synergy=synergy,
                                  cooperator_ratio=coop_ratio,
                                  noise_var=noise_var)
            nb_coop = PGG.run_game(time_step)
            resultats.append(nb_coop)
            strategies = PGG.get_strategies()
            first_run = False
        else:
            PGG = PublicGoodGames(G=g,
                                  synergy=synergy,
                                  cooperator_ratio=coop_ratio,
                                  noise_var=noise_var)
            PGG.set_strategies(strategies)
            nb_coop = PGG.run_game(time_step)
            strategies = PGG.get_strategies()
            resultats.append(nb_coop)
    plt.figure()
    plt.plot(resultats, '-o')
    plt.show()
def main():
    from complex_systems.dygraph import DyGraph
    from complex_systems.pgg import PublicGoodGames
    from complex_systems.quasi_unit_disk_graph import gen_quasi_unit_disk_weight
    from complex_systems.quasi_unit_disk_graph import remove_edges_from_graph
    import networkx as nx
    import pylab as plt

    outer_radius = 75
    inner_radius = 40
    alpha_quasi_unit_disk = 0.9
    synergy = 8
    coop_ratio = 0.5
    noise_var = 1
    nb_node = 400
    time_step = 5.0
    G = DyGraph(time_stop=2000.0, time_step=time_step)
    G.generate_mobility_levy_walk(
        alpha=0.9,
        beta=0.9,
        size_max=1000,
        f_min=10,
        f_max=1000,
        s_min=5,
        s_max=1000.0,
        b_c=2,
        radius=200.0,
        nb_node=nb_node,
        )
    first_run = True
    resultats = []
    for g in G:
        g = gen_quasi_unit_disk_weight(G=g, outer_radius=outer_radius,
                inner_radius=inner_radius, alpha=alpha_quasi_unit_disk)
        g = remove_edges_from_graph(g)
        if first_run == True:
            PGG = PublicGoodGames(G=g, synergy=synergy,
                                  cooperator_ratio=coop_ratio,
                                  noise_var=noise_var)
            nb_coop = PGG.run_game(time_step)
            resultats.append(nb_coop)
            strategies = PGG.get_strategies()
            first_run = False
        else:
            PGG = PublicGoodGames(G=g, synergy=synergy,
                                  cooperator_ratio=coop_ratio,
                                  noise_var=noise_var)
            PGG.set_strategies(strategies)
            nb_coop = PGG.run_game(time_step)
            strategies = PGG.get_strategies()
            resultats.append(nb_coop)
    plt.figure()
    plt.plot(resultats, '-o')
    plt.show()
Ejemplo n.º 4
0
def main():
    import networkx as nx
    from complex_systems.pgg import PublicGoodGames
    import pylab as plt
    import numpy as np

    nb_node = 1000
    edge_prob = 10.0 / nb_node
    coop_ratio = 0.5
    synergy = 8
    nb_round = 100
    nb_game_per_round = 10
    nb_def = []
    nb_coop = []

    # Generate a Random Graph
    G = nx.fast_gnp_random_graph(nb_node, edge_prob)
    # initialize the game
    PGG = PublicGoodGames(G=G,
                          synergy=synergy,
                          nb_simulation_step=nb_game_per_round,
                          cooperator_ratio=coop_ratio)
    for i in range(nb_round):
        PGG.run_game()
        nb_def.append(PGG.defector_counter())
        nb_coop.append(PGG.cooperator_counter())
        #print nb_coop, nb_def
    plt.figure()
    plt.plot(nb_def, 'b-*')
    plt.plot(nb_coop, 'r-*')
    plt.figure()
    print np.mean([val for key, val in G.degree().iteritems()])
    nx.draw_networkx(G, node_size=20, with_labels=False)
    plt.show()
Ejemplo n.º 5
0
def run_simu(parameters, synergy):
    import numpy as np
    import networkx as nx
    from complex_systems.dygraph import DyGraph
    from complex_systems.pgg import PublicGoodGames
    from complex_systems.quasi_unit_disk_graph import gen_quasi_unit_disk_weight
    from complex_systems.quasi_unit_disk_graph import remove_edges_from_graph

    number_of_node = parameters['number_of_node']
    size_of_simulation_area = parameters['size_of_simulation_area']
    outer_radius = parameters['outer_radius']
    inner_radius = parameters['inner_radius']
    alpha_quasi_unit_disk = parameters['alpha_quasi_unit_disk']
    coop_ratio = parameters['initial_cooperator_ratio']
    simulation_length = parameters['simulation_length']
    sampling_interval = parameters['sampling_interval']
    alpha_levy = parameters['alpha_levy']
    noise_var = parameters['noise_variance']
    beta = parameters['beta']
    f_min = parameters['f_min']
    f_max = parameters['f_max']
    s_min = parameters['s_min']
    s_max = parameters['s_max']
    velocity = parameters['velocity']

    G = DyGraph(time_stop=simulation_length, time_step=sampling_interval)
    G.generate_mobility_levy_walk(
        alpha=alpha_levy,
        beta=beta,
        size_max=size_of_simulation_area,
        f_min=f_min,
        f_max=f_max,
        s_min=s_min,
        s_max=s_max,
        b_c=2,
        radius=outer_radius,
        nb_node=number_of_node,
        velocity=velocity,
    )

    first_run = True
    resultats = []
    for g in G:
        g = gen_quasi_unit_disk_weight(G=g,
                                       outer_radius=outer_radius,
                                       inner_radius=inner_radius,
                                       alpha=alpha_quasi_unit_disk)
        g = remove_edges_from_graph(g)
        if first_run == True:
            PGG = PublicGoodGames(G=g,
                                  synergy=synergy,
                                  cooperator_ratio=coop_ratio,
                                  noise_var=noise_var)
            nb_coop = PGG.run_game(sampling_interval)
            resultats.append(nb_coop)
            strategies = PGG.get_strategies()
            first_run = False
        else:
            PGG = PublicGoodGames(G=g,
                                  synergy=synergy,
                                  cooperator_ratio=coop_ratio,
                                  noise_var=noise_var)
            PGG.set_strategies(strategies)
            nb_coop = PGG.run_game(sampling_interval)
            strategies = PGG.get_strategies()
            resultats.append(nb_coop)

    return (synergy, nb_coop, np.mean(G.avg_degree()))
def run_simu(parameters, synergy):
    import numpy as np
    import networkx as nx
    from complex_systems.dygraph import DyGraph
    from complex_systems.pgg import PublicGoodGames
    from complex_systems.quasi_unit_disk_graph import gen_quasi_unit_disk_weight
    from complex_systems.quasi_unit_disk_graph import remove_edges_from_graph


    number_of_node = parameters['number_of_node']
    size_of_simulation_area = parameters['size_of_simulation_area']
    outer_radius = parameters['outer_radius']
    inner_radius = parameters['inner_radius']
    alpha_quasi_unit_disk = parameters['alpha_quasi_unit_disk']
    coop_ratio = parameters['initial_cooperator_ratio']
    simulation_length = parameters['simulation_length']
    sampling_interval = parameters['sampling_interval']
    alpha_levy = parameters['alpha_levy']
    noise_var = parameters['noise_variance']
    beta = parameters['beta']
    f_min = parameters['f_min']
    f_max = parameters['f_max']
    s_min = parameters['s_min']
    s_max = parameters['s_max']
    velocity = parameters['velocity']

    G = DyGraph(time_stop=simulation_length, time_step=sampling_interval)
    G.generate_mobility_levy_walk(
        alpha=alpha_levy,
        beta=beta,
        size_max=size_of_simulation_area,
        f_min=f_min,
        f_max=f_max,
        s_min=s_min,
        s_max=s_max,
        b_c=2,
        radius=outer_radius,
        nb_node=number_of_node,
        velocity=velocity,
        )

    first_run = True
    resultats = []
    for g in G:
        g = gen_quasi_unit_disk_weight(G=g, outer_radius=outer_radius,
                inner_radius=inner_radius, alpha=alpha_quasi_unit_disk)
        g = remove_edges_from_graph(g)
        if first_run == True:
            PGG = PublicGoodGames(G=g, synergy=synergy,
                                  cooperator_ratio=coop_ratio,
                                  noise_var=noise_var)
            nb_coop = PGG.run_game(sampling_interval)
            resultats.append(nb_coop)
            strategies = PGG.get_strategies()
            first_run = False
        else:
            PGG = PublicGoodGames(G=g, synergy=synergy,
                                  cooperator_ratio=coop_ratio,
                                  noise_var=noise_var)
            PGG.set_strategies(strategies)
            nb_coop = PGG.run_game(sampling_interval)
            strategies = PGG.get_strategies()
            resultats.append(nb_coop)

    return (synergy, nb_coop, np.mean(G.avg_degree()))