Skip to content

Commit

Permalink
Small change
Browse files Browse the repository at this point in the history
  • Loading branch information
Wolf Zander committed Aug 12, 2018
1 parent 3c92749 commit eae29be
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 29 deletions.
7 changes: 4 additions & 3 deletions core.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@
# SIMULATION: MULTI AGENT
#############################################################################

#Parameters: no_of_transactions, lambda, no_of_agents, alpha, latency (h), distance, tip_selection_algo
#Parameters: no_of_transactions, lambda, no_of_agents, alpha, distance, tip_selection_algo
# latency (default value 1), agent_choice (default vlaue uniform distribution, printing)
#Tip selection algorithms: Choose among "random", "weighted", "unweighted" as input

partitioning_values = []
Expand All @@ -37,7 +38,7 @@
counter = 0
for i in range(runs):

simu2 = Multi_Agent_Simulation(1000, 15, 2, 0.001, 1, 0, "weighted", _printing=True)
simu2 = Multi_Agent_Simulation(10000, 50, 2, 0.005, 0.5, "weighted", _printing=True)
simu2.setup()
simu2.run()
#
Expand Down Expand Up @@ -70,7 +71,7 @@

# 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(simu2, simu2.no_of_transactions)

#Plotting the partitioning values for multiple simulations, cumulative mean and 95% confidence interval
# plt.plot(simu2.record_partitioning)
Expand Down
47 changes: 21 additions & 26 deletions simulation/simulation_multi_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

class Multi_Agent_Simulation:
def __init__(self, _no_of_transactions, _lambda, _no_of_agents, \
_alpha, _latency, _distance, _tip_selection_algo, \
_alpha, _distance, _tip_selection_algo, _latency = 1 \
_agent_choice=None, _printing=False):

#Use configuration file when provided
Expand Down Expand Up @@ -84,9 +84,8 @@ def setup(self):
self.DG = nx.DiGraph()

#Create random arrival times
random_values = np.random.exponential(1 / self.lam, self.no_of_transactions)
arrival_times = np.cumsum(random_values)
self.arrival_times = arrival_times
inter_arrival_times = np.random.exponential(1 / self.lam, self.no_of_transactions)
self.arrival_times = np.cumsum(inter_arrival_times)

#Create genesis transaction object, store in list and add to graph object
transaction_counter = 0
Expand Down Expand Up @@ -119,37 +118,16 @@ def run(self):
#Start with first transaction (NOT genesis)
for transaction in self.transactions[1:]:

#############################################################################
# START CHANGE EVENTS DURING SIMULATION
#############################################################################

#Execute simulation parameter changes when provided
if(len(sys.argv) != 1):
temp = (int(str(transaction)))
#If change event for a transaction is provided
if temp in dic:
#If change of distance is provided
if dic[temp][0] != None:
self.distances = create_distance_matrix(self, dic[temp][0])
#If change of agent probabilities is provided
if dic[temp][1] != None:
self.agent_choice = dic[temp][1]
print_tips_over_time_multiple_agents(self, int(str(transaction)))

self.calc_exit_probabilities_multiple_agents(transaction)
self.calc_confirmation_confidence_multiple_agents(transaction)
self.measure_partitioning()
self.check_parameters_changes(transaction, dic)

#Do something every 100th transition
# if (int(str(transaction)) % 100 == 0):
# self.calc_exit_probabilities_multiple_agents(transaction)
# self.calc_confirmation_confidence_multiple_agents(transaction)
# self.record_partitioning.append(self.measure_partitioning())

#############################################################################
# END CHANGE EVENTS DURING SIMULATION
#############################################################################

#Choose an agent
transaction.agent = np.random.choice(self.agents, p=self.agent_choice)

Expand Down Expand Up @@ -190,6 +168,23 @@ def tip_selection(self, transaction):
sys.exit()


def check_parameters_changes(self, transaction, dic):
temp = (int(str(transaction)))
#If change event for a transaction is provided
if temp in dic:
#If change of distance is provided
if dic[temp][0] != None:
self.distances = create_distance_matrix(self, dic[temp][0])
#If change of agent probabilities is provided
if dic[temp][1] != None:
self.agent_choice = dic[temp][1]
print_tips_over_time_multiple_agents(self, int(str(transaction)))

# self.calc_exit_probabilities_multiple_agents(transaction)
# self.calc_confirmation_confidence_multiple_agents(transaction)
# self.measure_partitioning()


#############################################################################
# SIMULATION: HELPERS
#############################################################################
Expand Down

0 comments on commit eae29be

Please sign in to comment.