Skip to content

Adjustable display transparancy of snapshots #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added __pycache__/agent.cpython-36.pyc
Binary file not shown.
Binary file added __pycache__/simulation.cpython-36.pyc
Binary file not shown.
4 changes: 2 additions & 2 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
15 changes: 9 additions & 6 deletions simulation.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand Down Expand Up @@ -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):
Expand All @@ -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")