Example #1
0
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)))
            #print evt_time,hello_rcvr,reply_rcvr
            simx.schedule_event(simx.get_now() + evt_time, hello_rcvr,
                                eAddr_HelloHandlerPerson,
                                HelloMessage(source_id=reply_rcvr))
Example #2
0
            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())

simx.run()
Example #3
0
        targetId = random.randrange(count)
        offset = int(exponential(1) + min_delay)
        #print "node ",self.get_entity_id()," sending message with offset ",\
        #    offset," at time ",simx.get_now(), "to target ", targetId
        self.send_info(None, offset, ('n', targetId), addr_RECEIVER)


simx.register_service(Receiver)
simx.register_address("addr_RECEIVER", addr_RECEIVER)


class Node(simx.PyEntity):
    def __init__(self, ID, lp, entity_input, py_obj=None):
        super(Node, self).__init__(ID, lp, entity_input, self)
        self.install_service(Receiver, addr_RECEIVER)
        #print "node ",ID," being created"


simx.init("phold")
simx.set_end_time(500000)
simx.set_min_delay(1)
simx.init_env()

for i in xrange(count):
    simx.create_entity(('n', i), Node)

for i in xrange(count):
    simx.schedule_event(0, ('n', i), addr_RECEIVER, None)

simx.run()
Example #4
0
File: hello.py Project: thulas/simx
##### Add services to be used in the simulation ########
# the second argument is a profile (should be dictionary (can be empty) or None)
hh = simx.add_service('HelloHandlerPerson',None,[]) 

##### Create Entities ##########

# create an entity profile (optional)
ep = { 'SERVICES':{eAddr_HelloHandlerPerson:hh}}

num_entities = 2**5

#num_entities = 2

for i in xrange(num_entities):
    # the third argument is a profile (should be dictionary (can be empty) or None)
    simx.create_entity(('p',i),Person,ep,[('p',1-i)])

########## Schedule initial events, if any ###############
import random
def create_events():
    for evt_time in xrange(end_time):
        # pick a random entity for receiving hello
        hello_rcpt = random.choice(xrange(num_entities))
        # who should the reply be sent to ?
        reply_rcpt = random.choice(xrange(num_entities))
        simx.schedule_event( evt_time, ('p',hello_rcpt), eAddr_HelloHandlerPerson, 
                        HelloMessage(source_id=('p',reply_rcpt)))
        
    
#schedule_events()
es = simx.EventScheduler(create_events)
Example #5
0
File: ossim.py Project: gaber/simx
            " at time ", simx.get_now()



#initialize
simx.init("ossim")
simx.set_end_time(1000)
simx.set_min_delay(1)
simx.set_log_level("debug3")
simx.init_env()

num_nodes = 1

#create nodes
for i in xrange(num_nodes):
    simx.create_entity(('n',i), os.Node,ent_data=({'num_cores':1}))

num_processes = 1
#on each node create foo processes
for i in xrange(num_nodes):
    node = simx.get_entity(('n',i))
    # the node might not live in this memory space
    # in a distributed memory simulation

    if node is not None: 
         
         for j in range(num_processes):
              fp = node.os.create_process(FooProcess)
              node.os.schedule_process(fp)

simx.run()
Example #6
0
                                   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())

simx.run()
Example #7
0
from HelloHandler import *

num_entities = 32
end_time = 1024

# 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 range(1,end_time):
            hello_rcvr = ('p',random.choice(xrange(num_entities)))
            reply_rcvr = ('p',random.choice(xrange(num_entities)))
            simx.schedule_event(evt_time, hello_rcvr, eAddr_HelloHandlerPerson,
                                HelloMessage(source_id=reply_rcvr))
            #schedule in chunks of 10 time units
            if (evt_time % 10 == 0):
                # go to sleep, and wake up in time to schedule
Example #8
0
##### Add services to be used in the simulation ########
# the second argument is a profile (should be dictionary (can be empty) or None)
hh = simx.add_service('HelloHandlerPerson', None, [])

##### Create Entities ##########

# create an entity profile (optional)
ep = {'SERVICES': {eAddr_HelloHandlerPerson: hh}}

num_entities = 2**5

#num_entities = 2

for i in xrange(num_entities):
    # the third argument is a profile (should be dictionary (can be empty) or None)
    simx.create_entity(('p', i), Person, ep, [('p', 1 - i)])

########## Schedule initial events, if any ###############
import random


def create_events():
    for evt_time in xrange(end_time):
        # pick a random entity for receiving hello
        hello_rcpt = random.choice(xrange(num_entities))
        # who should the reply be sent to ?
        reply_rcpt = random.choice(xrange(num_entities))
        simx.schedule_event(evt_time, ('p', hello_rcpt),
                            eAddr_HelloHandlerPerson,
                            HelloMessage(source_id=('p', reply_rcpt)))
Example #9
0
    def recv(self, msg):
        targetId = random.randrange(count)
        offset = int(exponential(1) + min_delay)
        #print "node ",self.get_entity_id()," sending message with offset ",\
        #    offset," at time ",simx.get_now(), "to target ", targetId
        self.send_info(None,offset,('n',targetId),
                       addr_RECEIVER)
                       
simx.register_service(Receiver)
simx.register_address("addr_RECEIVER",addr_RECEIVER)
        
class Node(simx.PyEntity):
    def __init__(self,ID,lp,entity_input,py_obj=None):
        super(Node,self).__init__(ID,lp,entity_input,self)
        self.install_service(Receiver, addr_RECEIVER)
        #print "node ",ID," being created"


simx.init("phold")
simx.set_end_time(500000)
simx.set_min_delay(1)
simx.init_env()
        
for i in xrange(count):
    simx.create_entity(('n',i),Node)

for i in xrange(count):
    simx.schedule_event(0,('n',i),addr_RECEIVER,None)

simx.run()
Example #10
0
            " at time ", simx.get_now()



#initialize
simx.init("ossim")
simx.set_end_time(1000)
simx.set_min_delay(1)
simx.set_log_level("debug3")
simx.init_env()

num_nodes = 2

#create nodes
for i in xrange(num_nodes):
    simx.create_entity(('n',i), os.Node,ent_data=({'num_cores':1}))

num_processes = 1
#on each node create foo processes
for i in xrange(num_nodes):
    node = simx.get_entity(('n',i))
    # the node might not live in this memory space
    # in a distributed memory simulation

    if node is not None: 
         
         for j in range(num_processes):
              fp = node.os.create_process(FooProcess)
              node.os.schedule_process(fp)

simx.run()