コード例 #1
0
class AfterSimulationWeightedRandomWalkTestSuite(unittest.TestCase):
    def setUp(self):
        self.simu = Multi_Agent_Simulation(100,
                                           50,
                                           2,
                                           0.1,
                                           1,
                                           "weighted",
                                           _printing=True)
        self.simu.setup()
        self.simu.run()

    def tearDown(self):
        pass
        #self.simu.dispose()
        #self.simu = None

    def test_calculation_cum_weight(self):
        pass

    def test_calculation_exit_probabilities(self):
        for agent in self.simu.agents:
            self.assertAlmostEqual(
                sum(tip.exit_probability_multiple_agents[agent]
                    for tip in agent.tips), 1)
コード例 #2
0
 def setUp(self):
     self.simu = Multi_Agent_Simulation(100,
                                        50,
                                        2,
                                        0.1,
                                        1,
                                        "weighted",
                                        _printing=True)
コード例 #3
0
class SimulationSetupAndRunTestSuite(unittest.TestCase):
    def setUp(self):
        self.simu = Multi_Agent_Simulation(100,
                                           50,
                                           2,
                                           0.1,
                                           1,
                                           "weighted",
                                           _printing=True)

    def tearDown(self):
        pass
        #self.simu.dispose()
        #self.simu = None

    def test_simulation_setup(self):
        self.simu.setup()
        # Test to be written
        pass

    def test_simulation_run(self):
        self.simu.setup()
        self.simu.run()
        # Test to be written
        pass
コード例 #4
0
class AfterSimulationWeightedRandomWalkTestSuite(unittest.TestCase):
    def setUp(self):
        self.simu = Multi_Agent_Simulation(100, 10, 2, 0.005, 1, distances,
                                           "weighted")
        self.simu.setup()
        self.simu.run()

    def tearDown(self):
        pass
        #self.simu.dispose()
        #self.simu = None

    def test_calculation_cum_weight(self):
        for transaction in self.simu.DG.nodes:
            self.assertEqual(
                transaction.cum_weight,
                len(list(nx.ancestors(self.simu.DG, transaction))) + 1)

    def test_calculation_exit_probabilities(self):
        for agent in self.simu.agents:
            self.assertEqual(
                sum(tip.exit_probability_multiple_agents[agent]
                    for tip in agent.tips), 1)

    def test_calculation_conf_conf(self):
        self.simu.calc_confirmation_confidence_multiple_agents()
コード例 #5
0
def simulation(data):
    distance = 50000

    distances = [[0, distance, distance], [distance, 0, distance],
                 [distance, distance, 0]]

    simu = Multi_Agent_Simulation(300, 2, 2, 0.005, 1, distances, "weighted")
    simu.setup()
    simu.run()
    csv_export(simu)
    return (data, simu.measure_partitioning())
コード例 #6
0
class SimulationSetupAndRunTestSuite(unittest.TestCase):
    def setUp(self):
        self.simu = Multi_Agent_Simulation(100, 10, 2, 0.005, 1, distances,
                                           "weighted")

    def tearDown(self):
        pass
        #self.simu.dispose()
        #self.simu = None

    def test_simulation_setup(self):
        self.simu.setup()
        # Test to be written

    def test_simulation_run(self):
        self.simu.setup()
        self.simu.run()
コード例 #7
0
def simulation(data):

    number_of_agents = 10
    distances = [[0.0, 10.0, 30.0, 20.0, 10.0, 10.0, 40.0, 10.0, 20.0, 20.0],
                 [10.0, 0.0, 40.0, 30.0, 20.0, 20.0, 50.0, 20.0, 30.0, 30.0],
                 [30.0, 40.0, 0.0, 30.0, 40.0, 20.0, 10.0, 40.0, 30.0, 10.0],
                 [20.0, 30.0, 30.0, 0.0, 30.0, 10.0, 40.0, 30.0, 20.0, 20.0],
                 [10.0, 20.0, 40.0, 30.0, 0.0, 20.0, 50.0, 20.0, 30.0, 30.0],
                 [10.0, 20.0, 20.0, 10.0, 20.0, 0.0, 30.0, 20.0, 10.0, 10.0],
                 [40.0, 50.0, 10.0, 40.0, 50.0, 30.0, 0.0, 50.0, 40.0, 20.0],
                 [10.0, 20.0, 40.0, 30.0, 20.0, 20.0, 50.0, 0.0, 10.0, 30.0],
                 [20.0, 30.0, 30.0, 20.0, 30.0, 10.0, 40.0, 10.0, 0.0, 20.0],
                 [20.0, 30.0, 10.0, 20.0, 30.0, 10.0, 20.0, 30.0, 20.0, 0.0]]

    simu = Multi_Agent_Simulation(10000, 50, number_of_agents, 0.1, distances,
                                  "weighted")
    simu.setup()
    simu.run()

    averages = []

    print("Done with one simu")

    return (data, simu.record_attachment_probabilities)
コード例 #8
0
# SIMULATION: MULTI AGENT
#############################################################################

#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

start_time = timeit.default_timer()
runs = 1

for i in range(runs):

    simu2 = Multi_Agent_Simulation(800,
                                   50,
                                   2,
                                   0.1,
                                   1,
                                   "weighted",
                                   _printing=True)
    simu2.setup()
    simu2.run()
    # csv_export(simu2)

print("TOTAL simulation time: " +
      str(np.round(timeit.default_timer() - start_time, 3)) + " seconds\n")

#############################################################################
# PLOTTING
#############################################################################

# print_graph(simu2)
コード例 #9
0
ファイル: core.py プロジェクト: pacslab/iota_simulation
netsize = 20
lam_m = 0
alpha = 0.001
txs = 1200

dir_name = './SimuData/2021-06'
suffix = '.csv'
for lam in my_lambda:
    timestr = time.strftime("%Y%m%d-%H%M")
    base_name = '{}lam_{}_txs_{}_tsa_{}_size_{}' \
                .format(timestr, lam, txs, tsa, netsize)
    simu2 = Multi_Agent_Simulation(_no_of_transactions=txs,
                                   _lambda=lam,
                                   _no_of_agents=netsize,
                                   _alpha=alpha,
                                   _distance=1,
                                   _tip_selection_algo=tsa,
                                   _latency=1,
                                   _agent_choice=None,
                                   _printing=True,
                                   _lambda_m=lam_m)
    simu2.setup()
    simu2.run()
    file_name = os.path.join(dir_name, base_name + suffix)
    csv_export(simu2, file_name)

print("TOTAL simulation time: " +
      str(np.round(timeit.default_timer() - start_time, 3)) + " seconds\n")

#############################################################################
# PLOTTING
#############################################################################
コード例 #10
0
ファイル: core.py プロジェクト: anyazz/iota_simulation
#############################################################################
# SIMULATION: MULTI AGENT
#############################################################################

#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

start_time = timeit.default_timer()
runs = 100
data = []
for i in range(runs):
    run_data = []
    simu2 = Multi_Agent_Simulation(_no_of_transactions=50, _lambda=2, _no_of_agents=2, \
                 _alpha=0.5, _distance=1, _tip_selection_algos=["selfish", "weighted"], \
                 _conflict_coefficient=0.1, _conflicts=False, _printing=False)
    simu2.setup()
    simu2.run()
    # print(simu2.get_heaviest_chain())
    # print_confirmation_confidences_all_agents_with_tangle(simu2)
    attachment = simu2.attachment_probabilities
    data.append(attachment)

data = np.mean(data, axis=0)
print("OVERALL ATTACHMENT:", data)

# csv_export(simu2)

print("TOTAL simulation time: " +
      str(np.round(timeit.default_timer() - start_time, 3)) + " seconds\n")
コード例 #11
0
 def setUp(self):
     self.simu = Multi_Agent_Simulation(100, 10, 2, 0.005, 1, distances,
                                        "weighted")
     self.simu.setup()
     self.simu.run()