ml-trust-model

git clone git://git.codymlewis.com/ml-trust-model.git
Log | Files | Refs | README

commit 08c54d6582a75e5fd9058c784b5b9728c78bfe31
parent 6517f712182cef1c73beedfea34a5a268f2a3da5
Author: Cody Lewis <codymlewis@protonmail.com>
Date:   Wed, 13 Mar 2019 13:30:26 +1100

Added network assignment of malicious nodes

Diffstat:
MTest.py | 7++++++-
MTrustModel.py | 9++++++++-
2 files changed, 14 insertions(+), 2 deletions(-)

diff --git a/Test.py b/Test.py @@ -56,21 +56,26 @@ class TestTrustModel(unittest.TestCase): no_of_nodes = 200 constrained_nodes = 0.5 poor_witnesses = 0.2 + malicious_nodes = 0.1 trust_manager = TrustModel.TrustManager( - no_of_nodes, constrained_nodes, poor_witnesses + no_of_nodes, constrained_nodes, poor_witnesses, malicious_nodes ) self.assertEqual(len(trust_manager.network), no_of_nodes) num_constrained = 0 num_poor_witnesses = 0 + num_malicious = 0 for node in trust_manager.network: if (node.capability < 100) or (node.service < 100): num_constrained += 1 if node.note_taking_acc < 1.0: num_poor_witnesses += 1 + if isinstance(node, TrustModel.BadMouther): + num_malicious += 1 self.assertEqual(no_of_nodes * constrained_nodes, num_constrained) self.assertEqual(no_of_nodes * poor_witnesses, num_poor_witnesses) + self.assertEqual(no_of_nodes * malicious_nodes, num_malicious) def test_bad_mouther(self): ''' diff --git a/TrustModel.py b/TrustModel.py @@ -75,6 +75,10 @@ class TrustManager: poor_witness_list = [] for _ in range(int(no_of_nodes * poor_witnesses)): poor_witness_list.append(ids.pop(np.random.randint(len(ids)))) + ids = [i for i in range(no_of_nodes)] + malicious_list = [] + for _ in range(int(no_of_nodes * malicious_nodes)): + malicious_list.append(ids.pop(np.random.randint(len(ids)))) for i in range(no_of_nodes): if i in constrained_list: @@ -84,7 +88,10 @@ class TrustManager: service = 100 capability = 100 note_acc = np.random.rand() if i in poor_witness_list else 1.0 - self.network.append(Node(service, capability, note_acc)) + if i in malicious_list: + self.network.append(BadMouther(service, capability, note_acc)) + else: + self.network.append(Node(service, capability, note_acc)) self.reports = [ [[] for _ in range(no_of_nodes)] for _ in range(no_of_nodes)