def test_network(): algorithmList = [traversal.DF_STAR, traversal.DFT] for algorithm in algorithmList: networks = [one_node(), line(), triangle(), small_random(), medium_random(), big_random(), square(), square_x(), my_random(), tree()] for net in networks: net.algorithms = (algorithm, ) sim = Simulation(net) try: sim.run() except Exception, e: import pdb pdb.set_trace() write_pickle(net, 'net_exception.npc.gz') raise e for node in net.nodes(): try: assert node.status == 'DONE' assert len(node.memory['unvisitedNodes']) == 0 except AssertionError: write_pickle(net, 'net_assertion_error.npc.gz')
def test_niculescu2003_sim(self): """Test niculescu2003 default simulation.""" sim = Simulation(self.net) sim.run() for node in self.net.nodes(): self.assertTrue(len(node.memory.get('pos', [None, None])) == 2\ or 'tp' in node.memory)
def test_niculescu2003_sim(self): """Test niculescu2003 default simulation.""" sim = Simulation(self.net) sim.run() i=0; for node in self.net.nodes(): i += 1 self.assertTrue(len(node.memory.get('pos', [None, None])) == 2\ or 'tp' in node.memory) self.net.savefig(fname=get_path(DATETIME_DIR, "dv-%s" %self.n), title="DV hop Default Simulation - %s nodes" % self.n, x_label="X", y_label="Y") print i, self.net.__len__() print self.net.nodes()[1].get_dic() print self.net.nodes()[20].get_dic() #print self.net.get_dic() print self.net.nodes()[0].type, \ self.net.nodes()[0].get_dic()['Info']['position'],\ self.net.nodes()[0].memory['tp'] for node in self.net.nodes(): act = node.get_dic()['Info']['position'] est = node.memory['pos'] if node.type=='C': err = sqrt(sum(pow(act - est, 2))) print node.type, act, est, err
def test_niculescu2003_sim(self): """Test niculescu2003 default simulation.""" sim = Simulation(self.net) sim.run() i = 0 for node in self.net.nodes(): i += 1 self.assertTrue(len(node.memory.get('pos', [None, None])) == 2\ or 'tp' in node.memory) self.net.savefig(fname=get_path(DATETIME_DIR, "dv-%s" % self.n), title="DV hop Default Simulation - %s nodes" % self.n, x_label="X", y_label="Y") print i, self.net.__len__() print self.net.nodes()[1].get_dic() print self.net.nodes()[20].get_dic() #print self.net.get_dic() print self.net.nodes()[0].type, \ self.net.nodes()[0].get_dic()['Info']['position'],\ self.net.nodes()[0].memory['tp'] for node in self.net.nodes(): act = node.get_dic()['Info']['position'] est = node.memory['pos'] if node.type == 'C': err = sqrt(sum(pow(act - est, 2))) print node.type, act, est, err
class DFTestRunner(unittest.TestCase): def __init__(self, testname, algorithm): super(DFTestRunner, self).__init__(testname) self.algorithm = algorithm self.test_name = testname def test_line(self): self.net = NetArch.get_line() self.run_test() def test_arch_unique1(self): self.net = NetArch.get_arch_unique1() self.run_test() def test_arch_unique2(self): self.net = NetArch.get_arch_unique2() self.run_test() def test_arch_unique3(self): self.net = NetArch.get_arch_unique3() self.run_test() def test_arch_random1(self): self.net = NetArch.get_arch_random1() self.run_test() def test_arch_random2(self): self.net = NetArch.get_arch_random2() self.run_test() def test_arch_random3(self): self.net = NetArch.get_arch_random3() self.run_test() def test_arch_random4(self): self.net = NetArch.get_arch_random4() self.run_test() def run_test(self): self.net.algorithms = (self.algorithm,) self.sim = Simulation(self.net) try: self.sim.run() except Exception, e: write_pickle(self.net, "{}_{}_exception.npc.gz".format(self.algorithm.__class__.__name__, self.test_name)) pdb.set_trace() traceback.print_exc(file=sys.stdout) raise e for node in self.net.nodes(): try: self.assertEqual(node.status, 'DONE') self.assertEqual(len(node.memory['unvisited_nodes']), 0) except AssertionError: write_pickle(self.net, "{}_{}_asserterror.npc.gz".format(self.algorithm.__class__.__name__, self.test_name))
def test_network(): net = node_network() net.algorithms = (DFstar, ) net.nodes()[0].memory['I']= 'information' sim = Simulation(net) try: sim.run() except Exception, e: write_pickle(net, 'net_exception.npc.gz') raise e
def test_sim(self): netgen = NetworkGenerator(degree=9, n_min=100, n_max=300) for lm_pct in [5, 10, 20, 33]: for net_count in range(100): net = netgen.generate() for node in net.nodes()[:int(lm_pct * len(net.nodes())/100)]: node.compositeSensor = CompositeSensor(('TruePosSensor')) net.algorithms = ALGORITHMS sim = Simulation(net) sim.run() write_npickle(net, '%d-%d.gz' % (net_count,lm_pct))
def test_sim(self): netgen = NetworkGenerator(degree=9, n_min=100, n_max=300) for lm_pct in [5, 10, 20, 33]: for net_count in range(100): net = netgen.generate() for node in net.nodes()[:int(lm_pct * len(net.nodes()) / 100)]: node.compositeSensor = CompositeSensor(('TruePosSensor')) net.algorithms = ALGORITHMS sim = Simulation(net) sim.run() write_npickle(net, '%d-%d.gz' % (net_count, lm_pct))
def run_test(self): self.net.algorithms = (self.algorithm,) self.sim = Simulation(self.net) try: self.sim.run() except Exception, e: write_pickle(self.net, "{}_{}_exception.npc.gz".format(self.algorithm.__class__.__name__, self.test_name)) pdb.set_trace() traceback.print_exc(file=sys.stdout) raise e
def test_network(): algorithmsList = [dfstar.DFStar, traversal.DFT] for algorithm in algorithmsList: netList = [network1(), network2(), network3(), network4(), network5(), network6(), network7(), network8(), network9(), network10()] for net in netList: net.algorithms = (algorithm, ) sim = Simulation(net) try: sim.run() except Exception, e: import pdb; pdb.set_trace() write_pickle(net, 'net_exception.npc.gz') raise e for node in net.nodes(): try: assert node.status == 'DONE' assert len(node.memory['unvisitedNodes']) == 0 except AssertionError: write_pickle(net, 'net_assertion_error.npc.gz')
# Now select the algorithm for simulation net.algorithms = ((DVHop, {'truePositionKey': 'tp', 'hopsizeKey': 'hs', 'dataKey': 'I' }), (Trilaterate, {'truePositionKey': 'tp', 'hopsizeKey': 'hs', 'positionKey': 'pos'+str(region), 'dataKey': 'I'}), ) start_time = time.time() # simulation start sim = Simulation(net) sim.run() # simulation ends end_time = time.time() - start_time print("Execution time: %s seconds ---" % round(end_time,2) ) # Now data capturing/analysis and visualization k=0 err_sum=0.0 total_tx = 0 # Total number of Tx by all nodes total_rx = 0 # Total number of Rx by all nodes total_energy = 0 # Total energy consumption by all nodes k2=0 err_sum2=0 for node in net.nodes():