Esempio n. 1
0
def main():
    #Inicijaliziraj mrezu
    net_gen = NetworkGenerator(n_min=3, n_count=5, n_max=10)   # broj nodova
    net = net_gen.generate_random_network()

    #Add distance sensor
    for node in net.nodes():
        node.compositeSensor = (NeighborsSensor, DistSensor)

    #Postavi algoritam i INITIATOR node
    net.algorithms = ((PTConstruction, {'informationKey': 'I'}),)

    #Samo jedan node je INITIATOR!
    some_node = net.nodes()[0]
    some_node.memory['I'] = 'Hello distributed world'

    write_npickle(net, 'PTConstruction.tar.gz')

    #Napravi simulaciju 
    sim = Simulation(net)
    # sim.reset()

    #Debug
    print "Prije pokretanja!"

    #Pokreni
    sim.run()

    for node in net.nodes():
        print node.memory

    net.show(savefig="image.png")
def main():
    """ Definiranje main funkcije .... """

    #Inicijaliziraj mrezu
    net_gen = NetworkGenerator(100)   # implementirat broj nodova
    net = net_gen.generate_random_network()

    #Postavi algoritam i INITIATOR node
    net.algorithms = ((ShoutAlgorithm, {'informationKey': 'I'}),)


    # Zamjena range(1) za jedan node(Shout) ili vise(10) za multishout.
    # Definiranje random INIT nodova
    # for random_counter in range(1):

    for random_counter in range(1):
        rand_number = randrange(0, 100)
        some_node = net.nodes()[rand_number]
        some_node.memory['I'] = 'Slanje vremena'


    #Napravi simulaciju, spremi u datoteku "Shout.tar.gz"
    sim = Simulation(net)
    write_npickle(net, 'Shout.tar.gz')
    #sim.reset()

    #Pokreni
    sim.run()

    # print memorije nodova ... 
    for node in net.nodes():
        print node.memory

    #Spremanje dijagrama nodova kao slika u png formatu
    net.show(savefig="image.png")
Esempio n. 3
0
def get_tree_network(n):
    net_gen = NetworkGenerator(n, commRange=0)
    net = net_gen.generate_random_network()
    for (n1, p1), (n2, p2) in product(net.pos.items(), net.pos.items()):
        Graph.add_edge(net, n1, n2, {'weight': sqrt(dot(p1 - p2, p1 - p2))})
    graph_tree = minimum_spanning_tree(net, 'weight')
    net.adj = graph_tree.adj
    return net
Esempio n. 4
0
#%load_ext autoreload
#%autoreload 2
#%reload_ext autoreload
from pymote import NetworkGenerator
from pymote import Network
from pymote.npickle import write_pickle, read_pickle
from pymote.simulation import Simulation
from networkx import minimum_spanning_tree
#from pymote.algorithms.turk2018.megamerge_p import MegaMerger
from pymote.algorithms.turk2018.megamerge import MegaMerger

##RANDOM
net_gen = NetworkGenerator(3)
net = net_gen.generate_random_network()
#write_pickle(net,'mreza.tar.gz')

#graph_tree = minimum_spanning_tree(net)
#net.adj = graph_tree.adj

##READ
net = Network()
read_pickle(net, "all.tar.gz")
net.show()

net.algorithms = (MegaMerger, )

sim = Simulation(net)
sim.run()

exclude = list()
exclude.append('Neighbors')
Esempio n. 5
0
    def test_santoro2007(self):
        N_ITERS = 5
        N_NETWORKS = 15
        N_NODES_STEP = 5

        node_range = 100
        nets = [
            [(100, 100)],
            [(100, 100), (175, 250), (250, 175), (100, 250),
                (175, 175), (100, 175)],
            [(100, 100), (150, 200), (175, 175), (175, 100),
                (250, 175), (250, 250), (325, 250), (325, 325), (325, 400)]
        ]

        for i, node_positions in enumerate(nets, start=1):
            net = Network()
            for node_pos in node_positions:
                net.add_node(pos=node_pos, commRange=node_range)

            name = 'Special %d' % i

            net.algorithms = (YoYo, )
            sim = Simulation(net, logLevel='WARNING')
            sim.run()

            min_id = min(sim.network.nodes(), key=lambda node: node.id).id
            for node in sim.network.nodes():
                if node.id == min_id:
                    # Check if the node with the smallest ID is the LEADER
                    assert node.status == 'LEADER', \
                        '%s: Node %d has status %s, not LEADER' % \
                        (name, node.id, node.status)
                else:
                    # Check if every other node is PRUNED
                    assert node.status == 'PRUNED', \
                        '%s: Node %d has status %s, not PRUNED' % \
                        (name, node.id, node.status)

        for i in range(N_ITERS):
            for n_nodes in range(N_NODES_STEP,
                                 N_NETWORKS*N_NODES_STEP+N_NODES_STEP,
                                 N_NODES_STEP):

                net_gen = NetworkGenerator(n_nodes)
                net = net_gen.generate_random_network()

                name = 'Random %d, %d nodes' % (i, n_nodes)

                net.algorithms = (YoYo, )
                sim = Simulation(net, logLevel='WARNING')
                sim.run()

                min_id = min(sim.network.nodes(), key=lambda node: node.id).id
                for node in sim.network.nodes():
                    if node.id == min_id:
                        # Check if the node with the smallest ID is the LEADER
                        assert node.status == 'LEADER', \
                            '%s: Node %d has status %s, not LEADER' % \
                            (name, node.id, node.status)
                    else:
                        # Check if every other node is PRUNED
                        assert node.status == 'PRUNED', \
                            '%s: Node %d has status %s, not PRUNED' % \
                            (name, node.id, node.status)