Beispiel #1
0
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See LICENSE.txt for more details.

import simx
from Person import *
from HelloHandler import *

random.seed(0)

num_entities = 32
end_time = 1000000

# initialize
simx.init("helloworldv2")
simx.set_end_time(end_time)
simx.set_min_delay(1)
simx.init_env()

# create Persons
for i in xrange(num_entities):
    simx.create_entity(('p', i), Person)


# create a message generation process
class MessageGen(simx.Process):
    """
    Schedule simple message sending and receiving
    """
    def run(self):
        for evt_time in xrange(1, end_time / 2 - 1):
            hello_rcvr = ('p', random.choice(xrange(num_entities)))
            reply_rcvr = ('p', random.choice(xrange(num_entities)))
Beispiel #2
0
        while(simx.get_now() < end_time):
            plt.clf()
            nx.draw_networkx_edges(G,Gpos,nodelist=[ncenter],alpha=0.4,edge_color='grey')
            nx.draw_networkx_nodes(G,Gpos,node_size=80,nodelist=p.keys(),node_color=p.values(),cmap=plt.cm.Reds_r)
            plt.xlim(-0.05,1.05)
            plt.ylim(-0.05,1.05)
            plt.axis('off')
            plt.draw()
            self.sleep(update_interval)


simx.init("consensus")
simx.set_end_time(end_time)
simx.set_min_delay(min_delay)
#simx.set_log_level("debug3")
simx.init_env()

for i in xrange(num_nodes):
    simx.create_entity(('n',i),Node,ent_data=({'gnode_id':i}))
    node_list.append(simx.get_entity(('n',i)))

#quit()
    
simx.get_controller().install_service(Receiver,eAddr_RECVR)
simx.schedule_process(Updater())

#only rank 0 does the plotting
if plot == True:
    import matplotlib.pyplot as plt
    if simx.get_rank() == 0:
        simx.schedule_process(Plotter())