Skip to content

Commit

Permalink
Github issues fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Manuel Zander authored and Manuel Zander committed Oct 9, 2018
1 parent 016ce78 commit f97f346
Show file tree
Hide file tree
Showing 8 changed files with 113 additions and 100 deletions.
15 changes: 13 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ These instructions will get you a copy of the project up and running on your loc

### Prerequisites

The code is run and tested with Python 3.6.3 on macOS 10.12.6.
The code is run and tested with Python 3.6.3 and 3.7 on macOS 10.12.6., 10.13 and 10.14.
Create a virtual environment for Python 3 with:

```
Expand All @@ -17,7 +17,14 @@ virtualenv -p python3 envname

### Installing packages

The used Python libraries/packages can be installed with:
Pip's install of pygraphviz is currently broken, thus run the following before using the makefile:

```
brew install graphviz
pip3 install pygraphviz
```

Then the used Python libraries/packages can be installed with:

```
make
Expand Down Expand Up @@ -54,4 +61,8 @@ In this file you can also change the configurations of the simulation.

## License

See LICENSE.txt

## Acknowledgments

Many thanks to Dominik Harz (nud3l) for his help and suggestions during development of this software.
11 changes: 3 additions & 8 deletions config.ini
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[PARAMETERS]
no_of_transactions = 22000
no_of_transactions = 2000
lambda = 50
no_of_agents = 2
alpha = 0.1
Expand All @@ -11,15 +11,10 @@ printing = True


[EVENT1]
step = 10000
step = 1000
agent_choice = [0.7,0.3]


[EVENT2]
step = 15000
step = 1500
distance = 1


[EVENT3]
step = 20000
agent_choice = [0.5,0.5]
14 changes: 5 additions & 9 deletions core.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,9 @@
start_time = timeit.default_timer()
runs = 1

number_of_agents = 10
distances = create_random_graph_distances(number_of_agents)

# distances = [[0.0, 80.0, 40.0, 60.0, 80.0, 40.0, 40.0, 20.0, 60.0, 40.0], [80.0, 0.0, 80.0, 60.0, 40.0, 80.0, 80.0, 60.0, 20.0, 40.0], [40.0, 80.0, 0.0, 60.0, 80.0, 40.0, 20.0, 20.0, 60.0, 40.0], [60.0, 60.0, 60.0, 0.0, 60.0, 60.0, 60.0, 40.0, 40.0, 20.0], [80.0, 40.0, 80.0, 60.0, 0.0, 80.0, 80.0, 60.0, 20.0, 40.0], [40.0, 80.0, 40.0, 60.0, 80.0, 0.0, 40.0, 20.0, 60.0, 40.0], [40.0, 80.0, 20.0, 60.0, 80.0, 40.0, 0.0, 20.0, 60.0, 40.0], [20.0, 60.0, 20.0, 40.0, 60.0, 20.0, 20.0, 0.0, 40.0, 20.0], [60.0, 20.0, 60.0, 40.0, 20.0, 60.0, 60.0, 40.0, 0.0, 20.0], [40.0, 40.0, 40.0, 20.0, 40.0, 40.0, 40.0, 20.0, 20.0, 0.0]]

for i in range(runs):

simu2 = Multi_Agent_Simulation(1000, 50, 2, 0.005, 1, "weighted", _agent_choice=[0.7,0.3], _printing=True)
simu2 = Multi_Agent_Simulation(800, 50, 2, 0.1, 1, "weighted", _printing=True)
simu2.setup()
simu2.run()
# csv_export(simu2)
Expand All @@ -53,7 +48,8 @@
# PLOTTING
#############################################################################

print_graph(simu2)
print_tips_over_time(simu2)
print_tips_over_time_multiple_agents(simu2, simu2.no_of_transactions)
# print_graph(simu2)
# print_tips_over_time(simu2)
# print_tips_over_time_multiple_agents(simu2, simu2.no_of_transactions)
print_tips_over_time_multiple_agents_with_tangle(simu2, simu2.no_of_transactions)
# print_attachment_probabilities_all_agents(simu2)
144 changes: 78 additions & 66 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,66 +1,78 @@
appnope==0.1.0
atomicwrites==1.1.5
attrs==18.1.0
bleach==2.1.3
coverage==4.5.1
cycler==0.10.0
decorator==4.3.0
entrypoints==0.2.3
flake8==2.6.2
hacking==1.1.0
html5lib==1.0.1
hypothesis==3.57.0
ipykernel==4.8.2
ipython==5.0.0
ipython-genutils==0.2.0
ipywidgets==7.2.1
Jinja2==2.10
jsonschema==2.6.0
jupyter==1.0.0
jupyter-client==5.2.3
jupyter-console==5.2.0
jupyter-core==4.4.0
kiwisolver==1.0.1
MarkupSafe==1.0
matplotlib==2.2.2
mccabe==0.5.3
mistune==0.8.3
more-itertools==4.2.0
nbconvert==5.3.1
nbformat==4.4.0
networkx==2.1
nose==1.3.7
notebook==5.5.0
numpy==1.14.3
pandocfilters==1.4.2
pbr==4.0.3
pexpect==4.6.0
pickleshare==0.7.4
pluggy==0.6.0
prompt-toolkit==1.0.15
ptyprocess==0.5.2
py==1.5.3
pycodestyle==2.0.0
pydot==1.2.4
pyflakes==1.2.3
Pygments==2.2.0
pygraphviz==1.3.1
pyparsing==2.2.0
pyprof2calltree==1.4.3
pysha3==1.0.2
pytest==3.6.0
python-dateutil==2.7.3
pytz==2018.4
pyzmq==17.0.0
qtconsole==4.3.1
Send2Trash==1.5.0
simplegeneric==0.8.1
six==1.11.0
terminado==0.8.1
testpath==0.3.1
tornado==5.0.2
traitlets==4.3.2
utils==0.9.0
wcwidth==0.1.7
webencodings==0.5.1
widgetsnbextension==3.2.1
Package Version
------------------ -------
appnope 0.1.0
astroid 2.0.4
atomicwrites 1.1.5
attrs 18.1.0
bleach 2.1.3
coverage 4.5.1
cycler 0.10.0
decorator 4.3.0
entrypoints 0.2.3
flake8 2.6.2
hacking 1.1.0
html5lib 1.0.1
hypothesis 3.57.0
ipykernel 4.8.2
ipython 5.0.0
ipython-genutils 0.2.0
ipywidgets 7.2.1
isort 4.3.4
Jinja2 2.10
jsonschema 2.6.0
jupyter 1.0.0
jupyter-client 5.2.3
jupyter-console 5.2.0
jupyter-core 4.4.0
kiwisolver 1.0.1
lazy-object-proxy 1.3.1
MarkupSafe 1.0
matplotlib 2.2.2
mccabe 0.5.3
mistune 0.8.3
more-itertools 4.2.0
nbconvert 5.3.1
nbformat 4.4.0
networkx 2.1
nose 1.3.7
notebook 5.5.0
numpy 1.14.3
pandocfilters 1.4.2
pbr 4.0.3
pexpect 4.6.0
pickleshare 0.7.4
pip 10.0.1
pluggy 0.6.0
prompt-toolkit 1.0.15
ptyprocess 0.5.2
py 1.5.3
pycodestyle 2.0.0
pydot 1.2.4
pyflakes 1.2.3
Pygments 2.2.0
pygraphviz 2.2
pylint 2.1.1
pyparsing 2.2.0
pyprof2calltree 1.4.3
pysha3 1.0.2
pytest 3.6.0
python-dateutil 2.7.3
pytz 2018.4
pyzmq 17.0.0
qtconsole 4.3.1
scipy 1.1.0
Send2Trash 1.5.0
setuptools 28.8.0
simplegeneric 0.8.1
six 1.11.0
terminado 0.8.1
testpath 0.3.1
tornado 5.0.2
traitlets 4.3.2
typed-ast 1.1.0
utils 0.9.0
virtualenv 16.0.0
wcwidth 0.1.7
webencodings 0.5.1
widgetsnbextension 3.2.1
wrapt 1.10.11
5 changes: 2 additions & 3 deletions simulation/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,10 @@ def create_random_graph_distances(no_of_agents):

distances = (nx.floyd_warshall_numpy(G)).tolist()

print(nx.closeness_centrality(G))

print("Closeness centrality per agent: " + str(nx.closeness_centrality(G)))

# print the random graph
# nx.draw(G, with_labels=True)
nx.draw(G, with_labels=True)
# plt.savefig('agent_graph.png')

return distances
Expand Down
16 changes: 8 additions & 8 deletions simulation/plotting.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def print_graph(self):
col.append(self.DG.node[transaction]["node_color"])

#Creating figure
plt.figure(figsize=(14, 8))
plt.figure(figsize=(14, 7))
nx.draw_networkx(self.DG, pos, with_labels=True, node_size = 100, font_size=5.5, node_color = col)
# nx.draw_networkx_labels(self.DG, lower_pos, labels=labels, font_size=6)

Expand All @@ -68,7 +68,7 @@ def print_graph(self):

def print_tips_over_time(self):

plt.figure(figsize=(14, 8))
plt.figure(figsize=(14, 7))

#Get no of tips per time
no_tips = []
Expand Down Expand Up @@ -106,7 +106,7 @@ def print_tips_over_time(self):

def print_tips_over_time_multiple_agents_with_tangle(self, no_current_transactions):

plt.figure(figsize=(14, 8))
plt.figure(figsize=(14, 7))
plt.subplot(2, 1, 1)

#Get no of tips per time
Expand Down Expand Up @@ -187,7 +187,7 @@ def print_tips_over_time_multiple_agents_with_tangle(self, no_current_transactio

def print_tips_over_time_multiple_agents(self, no_current_transactions):

plt.figure(figsize=(14, 8))
plt.figure(figsize=(14, 7))

#Get no of tips per time
for agent in self.agents:
Expand Down Expand Up @@ -241,7 +241,7 @@ def print_attachment_probabilities_alone(self):
with open('subtangle_attach_prob.pkl', 'wb') as handle:
pickle.dump(self.record_attachment_probabilities, handle, protocol=pickle.HIGHEST_PROTOCOL)

plt.figure(figsize=(14, 8))
plt.figure(figsize=(14, 7))

x = np.squeeze([i[0] for i in self.record_attachment_probabilities])
y = np.squeeze([i[1] for i in self.record_attachment_probabilities])
Expand Down Expand Up @@ -299,15 +299,15 @@ def print_attachment_probabilities_all_agents(self):

data = []

for agent in range(10):
for agent in range(self.no_of_agents):
agent_data = [i[1][agent] for i in self.record_attachment_probabilities]
data.append(agent_data)

plt.boxplot(data, 0, '+')
plt.xlabel("Agents")
plt.xticks(np.arange(1, 11), np.arange(0, 10))
plt.xticks(np.arange(1, self.no_of_agents+1), np.arange(0, self.no_of_agents))
plt.suptitle(title)
plt.tight_layout()
plt.subplots_adjust(top=0.94)
# plt.show()
plt.show()
# plt.savefig(str(no) + '.png')
4 changes: 2 additions & 2 deletions simulation/simulation_multi_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ def run(self):

#Do something every 100th transition
if (transaction.id >= 0 and
transaction.id % 200 == 0):
transaction.id % 100 == 0):
self.record_attachment_probabilities.append((transaction.id,self.calc_attachment_probabilities(transaction)))
# self.record_attachment_probabilities.append(self.calc_attachment_probabilities(transaction))

Expand Down Expand Up @@ -517,7 +517,7 @@ def calc_attachment_probabilities(self, incoming_transaction):

# print(attachment_probabilities_without_main)
# print(attachment_probabilities_all)
return attachment_probabilities_without_main
return attachment_probabilities_all

#Performs 100 random walks per agent to caluclate attachment probabilities
def attachment_probabilities_2(self, incoming_transaction):
Expand Down
4 changes: 2 additions & 2 deletions tests/test_basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

class SimulationSetupAndRunTestSuite(unittest.TestCase):
def setUp(self):
self.simu = Multi_Agent_Simulation(100, 10, 2, 0.005, 1, distances, "weighted")
self.simu = Multi_Agent_Simulation(100, 50, 2, 0.1, 1, "weighted", _printing=True)

def tearDown(self):
pass
Expand All @@ -32,7 +32,7 @@ def test_simulation_run(self):

class AfterSimulationWeightedRandomWalkTestSuite(unittest.TestCase):
def setUp(self):
self.simu = Multi_Agent_Simulation(100, 10, 2, 0.005, 1, distances, "weighted")
self.simu = Multi_Agent_Simulation(100, 50, 2, 0.1, 1, "weighted", _printing=True)
self.simu.setup()
self.simu.run()

Expand Down

0 comments on commit f97f346

Please sign in to comment.