diff --git a/__pycache__/agent.cpython-36.pyc b/__pycache__/agent.cpython-36.pyc new file mode 100644 index 0000000..4a51564 Binary files /dev/null and b/__pycache__/agent.cpython-36.pyc differ diff --git a/__pycache__/simulation.cpython-36.pyc b/__pycache__/simulation.cpython-36.pyc new file mode 100644 index 0000000..3d76c3d Binary files /dev/null and b/__pycache__/simulation.cpython-36.pyc differ diff --git a/main.py b/main.py index 87240ab..eca66ba 100644 --- a/main.py +++ b/main.py @@ -9,8 +9,8 @@ def main(): average_degree = 8 # Average degree of social network num_episode = 2 # Number of total episode in a single simulation for taking ensemble average network_type = "lattice" # topology of social network - - simulation = Simulation(population, average_degree, network_type) + display_transparency = 0.7 + simulation = Simulation(population, average_degree, network_type,display_transparency) for episode in range(num_episode): random.seed() diff --git a/simulation.py b/simulation.py index 6221391..c8d05b2 100644 --- a/simulation.py +++ b/simulation.py @@ -7,7 +7,7 @@ class Simulation: - def __init__(self, population, average_degree, network_type): + def __init__(self, population, average_degree, network_type,display_transparency): """ network_type has several options, give following network type as string; 1. lattice @@ -22,7 +22,7 @@ def __init__(self, population, average_degree, network_type): self.network = None self.agents = self.__generate_agents(population, average_degree) self.initial_cooperators = self.__choose_initial_cooperators() - + self.display_transparency = display_transparency def __generate_agents(self, population, average_degree): if self.network_type == "lattice": self.network = self.__generate_lattice(population) @@ -245,12 +245,15 @@ def color(i): else: pos = nx.spring_layout(self.network) - nx.draw_networkx_edges(self.network, pos) - nx.draw_networkx_nodes(self.network, pos, node_color = list(color.values()), node_size = 10) + nx.draw_networkx_edges(self.network, pos,alpha=self.display_transparency) + nx.draw_networkx_nodes(self.network, pos, node_color = list(color.values()), node_size = 10,alpha=self.display_transparency) plt.title('t={}'.format(timestep), fontsize=20) plt.xticks([]) plt.yticks([]) - plt.savefig(f"snapshot_t={timestep}.png") + if self.display_transparency==1: + plt.savefig(f"snapshot_t={timestep}.png",transparent=False) + else: + plt.savefig(f"snapshot_t={timestep}.png",transparent=True) plt.close() def one_episode(self, episode): @@ -264,5 +267,5 @@ def one_episode(self, episode): fc_converged = self.__play_game(episode, Dg, Dr) new_result = pd.DataFrame([[format(Dg, '.1f'), format(Dr, '.1f'), fc_converged]], columns = ['Dg', 'Dr', 'Fc']) result = result.append(new_result) - + self.__take_snapshot(1) result.to_csv(f"phase_diagram{episode}.csv") \ No newline at end of file