Пример #1
0
    def __init__(self, **args):

        defaults = {'L': None, 'net': None, 'sim': None}

        ##       initialize attributes
        for key, value in defaults.items():
            if key in args:
                setattr(self, key, args[key])
            else:
                setattr(self, key, value)
                args[key] = value
        self.args = args

        Process.__init__(self, name='save', sim=self.args['sim'])

        self.C = ConfigParser.ConfigParser()
        self.C.read(pyu.getlong('save.ini', 'ini'))
        self.opt = dict(self.C.items('config'))
        self.pos = dict(self.C.items('position'))
        self.ldp = dict(self.C.items('ldp'))
        self.wstd = dict(self.C.items('wstd'))
        self.lpos = eval(self.pos['position'])
        self.lldp = eval(self.ldp['ldp'])
        self.lwstd = eval(self.wstd['wstd'])

        self.sim = args['sim']
        self.net = args['net']
Пример #2
0
    def __init__(self, **args):

        defaults = {'L': None,
                    'net': None,
                    'sim': None}

##       initialize attributes
        for key, value in defaults.items():
            if key in args:
                setattr(self, key, args[key])
            else:
                setattr(self, key, value)
                args[key] = value
        self.args = args

        Process.__init__(self, name='save', sim=self.args['sim'])


        self.C = ConfigParser.ConfigParser()
        self.C.read(pyu.getlong('save.ini','ini'))
        self.opt = dict(self.C.items('config'))
        self.pos = dict(self.C.items('position'))
        self.ldp = dict(self.C.items('ldp'))
        self.rat = dict(self.C.items('rat'))
        self.lpos = eval(self.pos['position'])
        self.lldp = eval(self.ldp['ldp'])
        self.lrat = eval(self.rat['rat'])


        self.sim = args['sim']
        self.net = args['net']
Пример #3
0
    def __init__(self,**args):
        defaults={'net':Network(),
                  'L':[],
                  'net_updt_time':0.001,
                  'sim':None,
                  'show_sg':False,
                  'disp_inf':False,
                  'save':[]}

##       initialize attributes
        for key, value in defaults.items():
            if args.has_key(key):
                setattr(self, key, args[key])
            else:
                setattr(self, key, value)
                args[key]=value  
        self.args=args

        Process.__init__(self,name='PNetwork',sim=self.sim)
        self.cpt=self.sim.now()
        self.filename='pos'

        if 'mysql' in self.save:
           config = ConfigParser.ConfigParser()
           config.read(pyu.getlong('simulnet.ini','ini'))
           sql_opt = dict(config.items('Mysql'))
           self.net.db = Database(sql_opt['host'],sql_opt['user'],sql_opt['passwd'],sql_opt['dbname'])
Пример #4
0
    def __init__(self,**args):
        defaults={'net':Network(),
                  'L':[],
                  'net_updt_time':0.001,
                  'sim':None,
                  'show_sg':False,
                  'disp_inf':False,
                  'save':[]}

##       initialize attributes
        for key, value in defaults.items():
            if args.has_key(key):
                setattr(self, key, args[key])
            else:
                setattr(self, key, value)
                args[key]=value  
        self.args=args

        Process.__init__(self,name='PNetwork',sim=self.sim)
        self.cpt=self.sim.now()
        self.filename='pos'

        if 'mysql' in self.save:
           config = ConfigParser.ConfigParser()
           config.read(pyu.getlong('simulnet.ini','ini'))
           sql_opt = dict(config.items('Mysql'))
           self.net.db = Database(sql_opt['host'],sql_opt['user'],sql_opt['passwd'],sql_opt['dbname'])
Пример #5
0
 def __init__(self, loc=Localization(), tx=TX() ,loc_updt_time=.5, sim=None):
     Process.__init__(self, name='Location', sim=sim)
     self.loc = loc
     self.tx=tx
     self.loc_updt_time = loc_updt_time
     self.method = self.loc.method
     self.sim = sim
Пример #6
0
    def __init__(self, loc=Localization(), tx=TX() ,loc_updt_time=.5, sim=None):
        Process.__init__(self, name='Location', sim=sim)
        self.loc = loc
        self.tx=tx
        self.loc_updt_time = loc_updt_time
        self.method = self.loc.method
        self.sim = sim

        print('!!!!!! Warning Localization : No RSS only localization !!!!!')
Пример #7
0
    def __init__(self, loc=Localization(), tx=TX(), loc_updt_time=0.5, sim=None):
        Process.__init__(self, name="Location", sim=sim)
        self.loc = loc
        self.tx = tx
        self.loc_updt_time = loc_updt_time
        self.method = self.loc.method
        self.sim = sim

        print ("!!!!!! Warning Localization : No RSS only localization !!!!!")
Пример #8
0
    def __init__(self, **args):
        defaults = {
            'sim': None,
            'net': Network(),
            #'gcom': Gcom(),
            'gcom': [],  # Temporary
            'ID': 0,
            'dec': {},
            'devt': {},
            'lcst': []
        }
        ##       initialize attributes

        for key, value in defaults.items():
            if key in args:
                setattr(self, key, args[key])
            else:
                setattr(self, key, value)
                args[key] = value

        self.args = args
        self.gcom = self.args['gcom']

        if sys.version_info.major == 2:
            self.cmdrq = SimEvent('RQ' + str(self.ID),
                                  sim=self.sim)  # command request
        else:
            pass
            # Python3 implementation not done

        try:
            self.PN = self.net.node[self.ID]['PN']
        except:
            self.PN = Network()

#        self.create_evt()

#        self.c_init()

        if sys.version_info.major == 2:
            Process.__init__(self, name='Tx' + str(self.ID), sim=self.sim)
        else:
            pass
            #Process.__init__(self,env,generator)
            # Python3 implementation not done

        Cf = ConfigParser.ConfigParser()
        Cf.read(pyu.getlong('agent.ini', 'ini'))
        for s in Cf.sections():
            try:
                d = dict(Cf.items(s))
                if d['id'] == self.ID:
                    self.refreshTOA = eval(d['refreshtoa'])
                    break
            except:
                pass
Пример #9
0
 def __init__(self, sim, address, port, map_path, free_move_only, hmac_key=HMAC_KEY_DEFAULT):
     Process.__init__(self, name='ExternalDataManager', sim=sim)
     self.sim = sim
     self.conn, child_conn = Pipe()
     self.service = ConnectionService(address, port, child_conn, map_path, free_move_only, hmac_key)
     self.service_process = MultiProcess(target=cherrypy.quickstart, args=(self.service, ))
     #self.service_process.daemon = True
     self.service_process.start()
     self.running = True
     self.free_move_only = free_move_only
Пример #10
0
    def __init__(self,**args):
        defaults={'sim':None,
                  'net': Network(),
                  #'gcom': Gcom(),
                  'gcom': [], # Temporary
                  'ID': 0,
                  'dec':{},
                  'devt': {},
                  'lcst': []
                  }
##       initialize attributes

        for key, value in defaults.items():
            if key in args:
                setattr(self, key, args[key])
            else:
                setattr(self, key, value)
                args[key]=value

        self.args = args
        self.gcom = self.args['gcom']


        if sys.version_info.major==2:
            self.cmdrq =SimEvent('RQ'+str(self.ID),sim=self.sim) # command request
        else:
            pass
            # Python3 implementation not done

        try:
            self.PN = self.net.node[self.ID]['PN']
        except:
            self.PN = Network()

#        self.create_evt()

#        self.c_init()

        if sys.version_info.major==2:
            Process.__init__(self,name='Tx'+str(self.ID),sim=self.sim)
        else:
            pass
            #Process.__init__(self,env,generator)
            # Python3 implementation not done

        Cf = ConfigParser.ConfigParser()
        Cf.read(pyu.getlong('agent.ini','ini'))
        for s in Cf.sections():
            try:
                d= dict(Cf.items(s))
                if d['id']==self.ID:
                    self.refreshTOA=eval(d['refreshtoa'])
                    break
            except:
                pass
Пример #11
0
 def __init__(self, name, sim, tick, kwargs):
     """Initialize the monitor.
     
     tick specifies the duration in ticks between two monitoring actions.
     The monitor does something in Monitor.observe() every tick ticks.
     name is its name, sim is the simulation.
     @param name: unique string name of monitor
     @param sim: reference to simulation
     @param tick: monitoring is done every tick ticks
     @param kwargs: additional keyword arguments for monitor"""
     Process.__init__(self, name=name, sim=sim)
     list.__init__(self)
     self.tick = tick
Пример #12
0
    def __init__(self, **args):

        defaults = {
            'net': None,
            'fname': 'table',
            'lAg': None,
            'fig': None,
            'ax': None,
            'sim': None
        }

        ##       initialize attributes
        for key, value in defaults.items():
            if key in args:
                setattr(self, key, args[key])
            else:
                setattr(self, key, value)
                args[key] = value
        self.args = args
        self.fname = self.args['fname']

        self.fig = plt.figure(self.fname, figsize=(30, 15), dpi=50)
        self.fig.subplots_adjust(left=0.1, right=0.9, top=0.9, bottom=0.1)
        self.ax1 = self.fig.add_subplot(111, frame_on=False)
        self.ax1.xaxis.set_visible(False)
        self.ax1.yaxis.set_visible(False)

        self.fig2 = plt.figure(self.fname + str(2), figsize=(30, 15), dpi=50)
        self.ax2 = self.fig2.add_subplot(111, frame_on=False)
        self.ax2.xaxis.set_visible(False)
        self.ax2.yaxis.set_visible(False)

        self.coll_plot = {}
        self.colLabels1 = ('wstd', 'Node link', 'TOA ', 'TOA std', 'Pr',
                           'Pr std', 'distance')
        self.colLabels2 = ('name', 'pos x', 'pos y ', 'vel x', 'vel y',
                           'acc x', 'acc y')
        self.cellText = []
        self.C = ConfigParser.ConfigParser()
        self.C.read(pyu.getlong('show.ini', 'ini'))
        self.wstdcolor = dict(self.C.items('wstdcolor'))
        self.wstdes = dict(self.C.items('wstdestyle'))
        self.update = dict(self.C.items('update'))

        Process.__init__(self, name='PShowTable', sim=self.args['sim'])
Пример #13
0
    def __init__(self, **args):

        defaults = {'net': None,
                    'fname': 'table',
                    'lAg': None,
                    'fig': None,
                    'ax': None,
                    'sim': None}

##       initialize attributes
        for key, value in defaults.items():
            if key in args:
                setattr(self, key, args[key])
            else:
                setattr(self, key, value)
                args[key] = value
        self.args = args
        self.fname = self.args['fname']

        self.fig = plt.figure(self.fname, figsize=(30, 15), dpi=50)
        self.fig.subplots_adjust(left=0.1, right=0.9, top=0.9, bottom=0.1)
        self.ax1 = self.fig.add_subplot(111, frame_on=False)
        self.ax1.xaxis.set_visible(False)
        self.ax1.yaxis.set_visible(False)

        self.fig2 = plt.figure(
            self.fname + str(2), figsize=(30, 15), dpi=50)
        self.ax2 = self.fig2.add_subplot(111, frame_on=False)
        self.ax2.xaxis.set_visible(False)
        self.ax2.yaxis.set_visible(False)

        self.coll_plot = {}
        self.colLabels1 = ('wstd', 'Node link', 'TOA ',
                           'TOA std', 'Pr', 'Pr std', 'distance')
        self.colLabels2 = ('name', 'pos x', 'pos y ',
                           'vel x', 'vel y', 'acc x', 'acc y')
        self.cellText = []
        self.C = ConfigParser.ConfigParser()
        self.C.read(pyu.getlong('show.ini','ini'))
        self.wstdcolor = dict(self.C.items('wstdcolor'))
        self.wstdes = dict(self.C.items('wstdestyle'))
        self.update = dict(self.C.items('update'))

        Process.__init__(self, name='PShowTable', sim=self.args['sim'])
Пример #14
0
    def __init__(self, **args):
        defaults = {
            'sim': None,
            'net': Network(),
            'gcom': Gcom(),
            'ID': 0,
            'dec': {},
            'devt': {},
            'lcst': []
        }
        ##       initialize attributes
        for key, value in defaults.items():
            if args.has_key(key):

                setattr(self, key, args[key])
            else:
                setattr(self, key, value)
                args[key] = value
        self.args = args
        self.gcom = self.args['gcom']

        self.cmdrq = SimEvent('RQ' + str(self.ID),
                              sim=self.sim)  # command request

        try:
            self.PN = self.net.node[self.ID]['PN']
        except:
            self.PN = Network()

#        self.create_evt()

#        self.c_init()
        Process.__init__(self, name='Tx' + str(self.ID), sim=self.sim)
        Cf = ConfigParser.ConfigParser()
        Cf.read(pyu.getlong('agent.ini', 'ini'))
        for s in Cf.sections():
            try:
                d = dict(Cf.items(s))
                if d['id'] == self.ID:
                    self.refreshTOA = eval(d['refreshtoa'])
                    break
            except:
                pass
Пример #15
0
    def __init__(self, **args):
        defaults = {'L': None,
                    'net': None,
                    'sim': None}


##       initialize attributes
        for key, value in defaults.items():
            if key in args:
                setattr(self, key, args[key])
            else:
                setattr(self, key, value)
                args[key] = value
        self.args = args

        Process.__init__(self, name='save', sim=self.args['sim'])


        self.C = ConfigParser.ConfigParser()
        self.C.read(pyu.getlong('save.ini','ini'))
        self.opt = dict(self.C.items('config'))
        self.pos = dict(self.C.items('position'))
        self.ldp = dict(self.C.items('ldp'))
        self.rat = dict(self.C.items('rat'))
        self.lpos=eval(self.pos['position'])
        self.lldp=eval(self.ldp['ldp'])
        self.lrat=eval(self.rat['rat'])


        self.sim=args['sim']
        self.net=args['net']


        self.save={}
        self.filename = eval(self.opt['filename'])
        self.file=open(basename+'/' + pstruc['DIRNETSAVE'] +'/' +self.filename,'write')
        self.save['saveopt']={}
        self.save['saveopt']['lpos']=self.lpos
        self.save['saveopt']['lldp']=self.lldp
        self.save['saveopt']['lrat']=self.lrat
        pickle.dump(self.save, self.file)
        self.file.close()
        self.idx=0
Пример #16
0
    def __init__(self,**args):
        defaults={'sim':None,
                  'net': Network(),
                  'gcom': Gcom(),
                  'ID': 0,
                  'dec':{},
                  'devt': {},
                  'lcst': []
                  }
##       initialize attributes
        for key, value in defaults.items():
            if args.has_key(key):

                setattr(self, key, args[key])
            else:
                setattr(self, key, value)
                args[key]=value
        self.args=args
        self.gcom=self.args['gcom']


        self.cmdrq=SimEvent('RQ'+str(self.ID),sim=self.sim) # command request

        try:
            self.PN=self.net.node[self.ID]['PN']
        except:
            self.PN=Network()

#        self.create_evt()

#        self.c_init()
        Process.__init__(self,name='Tx'+str(self.ID),sim=self.sim)
        Cf = ConfigParser.ConfigParser()
        Cf.read(pyu.getlong('agent.ini','ini'))
        for s in Cf.sections():
            try:
                d= dict(Cf.items(s))
                if d['id']==self.ID:
                    self.refreshTOA=eval(d['refreshtoa'])
                    break
            except:
                pass
Пример #17
0
    def __init__(self, **args):
        defaults = {
            'sim': None,
            'ID': '1',
            'net': Network(),
            #'gcom': Gcom(),
            'gcom': [],
            'devt': {},
            'refreshRSS': 0.3,
            'refreshTOA': 0.3,
            'mp': False
        }
        ##       initialize attributes
        for key, value in defaults.items():
            if key in args:

                setattr(self, key, args[key])
            else:
                setattr(self, key, value)
                args[key] = value
        self.args = args
        try:
            self.PN = self.net.node[self.ID]['PN']
        except:
            self.PN = Network()
        self.create_evt()

        Process.__init__(self, name='Rx-' + str(self.ID), sim=self.sim)

        Cf = ConfigParser.ConfigParser()
        Cf.read(pyu.getlong('agent.ini', 'ini'))
        for s in Cf.sections():
            try:
                d = dict(Cf.items(s))
                if d['id'] == self.ID:
                    self.refreshRSS = eval(d['refreshrss'])
                    self.refreshTOA = eval(d['refreshtoa'])
                    break

            except:
                pass
Пример #18
0
    def __init__(self,**args):
        defaults={'sim':None,
                  'ID':'1',
                  'net':Network(),
                  #'gcom': Gcom(),
                  'gcom': [],
                  'devt': {},
                  'refreshRSS':0.3,
                  'refreshTOA':0.3,
                  'mp':False
                  }
##       initialize attributes
        for key, value in defaults.items():
            if key in args:

                setattr(self, key, args[key])
            else:
                setattr(self, key, value)
                args[key]=value
        self.args=args
        try:
            self.PN = self.net.node[self.ID]['PN']
        except:
            self.PN = Network()
        self.create_evt()

        Process.__init__(self,name='Rx-'+str(self.ID),sim=self.sim)

        Cf = ConfigParser.ConfigParser()
        Cf.read(pyu.getlong('agent.ini','ini'))
        for s in Cf.sections():
            try:
                d= dict(Cf.items(s))
                if d['id']==self.ID:
                    self.refreshRSS=eval(d['refreshrss'])
                    self.refreshTOA=eval(d['refreshtoa'])
                    break

            except:
                pass
Пример #19
0
    def __init__(self, **args):
        defaults = {
            'net': None,
            'L': None,
            'fname': 'network',
            'fig': None,
            'ax': None,
            'notebook': False,
            'sim': None
        }

        ##       initialize attributes
        for key, value in defaults.items():
            if key in args:
                setattr(self, key, args[key])
            else:
                setattr(self, key, value)
                args[key] = value
        self.args = args
        self.fname = self.args['fname']

        Process.__init__(self, name='shownet', sim=self.args['sim'])

        self.fig = plt.figure(self.fname, figsize=(20, 5), dpi=100)
        self.fig.subplots_adjust(left=0.1, right=0.9, top=0.9, bottom=0.1)
        self.fig, self.ax = self.L.showGs(fig=self.fig)

        self.legend = True
        self.ion = True
        self.info = False

        self.coll_plot = {}
        self.C = ConfigParser.ConfigParser(inline_comment_prefixes=(';', ),
                                           comment_prefixes=('#', ';'))
        self.C.read(pyu.getlong('show.ini', 'ini'))
        self.wstdcolor = dict(self.C.items('wstdcolor'))
        self.wstdes = dict(self.C.items('wstdestyle'))
        self.update = dict(self.C.items('update'))
        self.option = dict(self.C.items('option'))
        self.cpt = self.sim.now()
Пример #20
0
    def __init__(self, **args):
        defaults = {'L': None, 'net': None, 'sim': None}

        ##       initialize attributes
        for key, value in defaults.items():
            if key in args:
                setattr(self, key, args[key])
            else:
                setattr(self, key, value)
                args[key] = value
        self.args = args

        Process.__init__(self, name='save', sim=self.args['sim'])

        self.C = ConfigParser.ConfigParser()
        self.C.read(pyu.getlong('save.ini', 'ini'))
        self.opt = dict(self.C.items('config'))
        self.pos = dict(self.C.items('position'))
        self.ldp = dict(self.C.items('ldp'))
        self.rat = dict(self.C.items('rat'))
        self.lpos = eval(self.pos['position'])
        self.lldp = eval(self.ldp['ldp'])
        self.lrat = eval(self.rat['rat'])

        self.sim = args['sim']
        self.net = args['net']

        self.save = {}
        self.filename = eval(self.opt['filename'])
        self.file = open(
            basename + '/' + pstruc['DIRNETSAVE'] + '/' + self.filename,
            'write')
        self.save['saveopt'] = {}
        self.save['saveopt']['lpos'] = self.lpos
        self.save['saveopt']['lldp'] = self.lldp
        self.save['saveopt']['lrat'] = self.lrat
        pickle.dump(self.save, self.file)
        self.file.close()
        self.idx = 0
Пример #21
0
    def __init__(self, **args):
        defaults = {'net': None,
                    'L': None,
                    'fname': 'network',
                    'fig': None,
                    'ax': None,
                    'notebook':False,
                    'sim': None}

##       initialize attributes
        for key, value in defaults.items():
            if key in args:
                setattr(self, key, args[key])
            else:
                setattr(self, key, value)
                args[key] = value
        self.args = args
        self.fname = self.args['fname']

        Process.__init__(self, name='shownet', sim=self.args['sim'])

        self.fig = plt.figure(self.fname, figsize=(20, 5), dpi=100)
        self.fig.subplots_adjust(left=0.1, right=0.9, top=0.9, bottom=0.1)
        self.fig, self.ax = self.L.showGs(fig=self.fig)

        self.legend = True
        self.ion = True
        self.info = False

        self.coll_plot = {}
        self.C = ConfigParser.ConfigParser()
        self.C.read(pyu.getlong('show.ini','ini'))
        self.wstdcolor = dict(self.C.items('wstdcolor'))
        self.wstdes = dict(self.C.items('wstdestyle'))
        self.update = dict(self.C.items('update'))
        self.option= dict(self.C.items('option'))
        self.cpt = self.sim.now()
Пример #22
0
    def __init__(self, ID = 0, interval=0.05,roomId=0, L=[], net=Network(),
        wld = world(),sim=None,moving=True,froom=[],wait=1.0,cdest='random',save=[]):
        """ Class Person
            inherits of Simpy.SimulationRT
        Attributes
        ----------
            ID    : float/hex/str/...
                    agent Id
            interval : float
                    refresh interval of agent mobility
            roomId : int
                    room ID where agent start when simulation is launched
            L : pylayers.gis.layout.Layout()
                Layout instance, in which the agent is moving
            net : pylayers.network.Network()
                Network instance, in which network agent are communicating.
                This is used for fill the true position filed of the graph
                It must be removed in a further version ( when a proper save instance
                would be created)
            wld : pylayers.mobility.transit.world.world()
                world instance. equivalent to layout but in the pytk framework. 
                TODO : remove in a further version
            sim : SimPy.Simulation.Simulation.RT()
                Simulation instance share by all the pylayer project. 
            moving : bool 
                indicate if the agent is moving or not ( relevant for acces poitns)
            froom : list
                list of forbiden rooms. 
            wait : float
                wait time of the agent when he has reach teh desitaion
            cdest : str
                method for choosing setination 'random ' of file read
            save : list
                list of save option type .
                It will be removed in a further version ( when a proper save instance
                would be created)


        Method
        ------
            Move : make the agent move
            update : DEPRECATED used for Tkinter plot

    """
        #GeomNetType = np.dtype([('Id',int), 
        #        ('time',int), 
        #           ('p',float,(1,3)),
        #           ('v',float,(1,3)),
        #           ('a',float,(1,3))])
        Person.npers +=1
        Process.__init__(self,name='Person_ID'+str(ID),sim=sim)
        self.ID=ID
        self.L = L 
        self.world = wld
        self.interval = interval
        self.manager = None
        self.manager_args = []
        self.waypoints = []
        self.moving=moving
        self.roomId    = roomId
        self.forbidroomId = froom 
        self.cdest = cdest # choose tdestination type
        if self.cdest == 'random':
            self.nextroomId   = int(np.floor(uniform(0,self.L.Gr.size())))
            while self.nextroomId == self.roomId or (self.nextroomId in self.forbidroomId): # or (self.nextroomId in self.sim.roomlist): # test destination different de l'arrive
                self.nextroomId   = int(np.floor(uniform(0,self.L.Gr.size())))
            #self.sim.roomlist.append(self.nextroomId) # list of all destiantion of all nodes in object sim
        elif self.cdest == 'file':
           cfg = ConfigParser.ConfigParser()
           cfg.read(pyu.getlong('nodes_destination.ini','ini'))
           self.room_seq=eval(dict(cfg.items(self.ID))['room_seq'])
           self.room_wait=eval(dict(cfg.items(self.ID))['room_wait'])
           print 'WARNING: when nodes_destination ini file is read:'
           print '1) the room initialization starts in the first room of the list, not in the room configured in agent.ini'
           print '2) forbiden rooms are neglected'
           self.room_counter=1
           self.nb_room=len(self.room_seq)
           self.roomId=self.room_seq[0]
           self.nextroomId=self.room_seq[self.room_counter]
           self.wait=self.room_wait[self.room_counter]
        #self.sim.roomlist.append(self.nextroomId) # list of all destiantion of all nodes in object sim
        self.wp       =  self.L.waypointGw(self.roomId,self.nextroomId)
        for tup in self.wp[1:]:
                self.waypoints.append(vec3(tup)  ) 
        try:
            self.position = vec3(L.Gr.pos[self.roomId][0],L.Gr.pos[self.roomId][1])
        except:     
            self.position = vec3()
#           self.old_pos = vec3()
        self.stuck = 0           
        self.destination = self.waypoints[0]
        self.velocity = vec3()
        self.localx = vec3(1, 0)
        self.localy = vec3(0, 1)
        self.world.add_boid(self)


        # from Helbing, et al "Self-organizing pedestrian movement"
        self.max_speed = 1.2#normalvariate(1.0, 0.26)
        self.desired_speed = self.max_speed
        self.radius = normalvariate(self.average_radius, 0.025) / 2
        self.intersection = vec3()
        self.arrived = False 
        self.endpoint = False 
        self.behaviors = []
        self.steering_mind = default_steering_mind
        self.cancelled = 0
        self.net=net
        self.wait=wait
        self.save=save



        if 'mysql' in self.save:
           config = ConfigParser.ConfigParser()
           config.read(pyu.getlong('simulnet.ini','ini'))
           sql_opt = dict(config.items('Mysql'))
           self.db = Database(sql_opt['host'],sql_opt['user'],sql_opt['passwd'],sql_opt['dbname'])
           self.date = datetime.datetime.now()
Пример #23
0
 def __init__(self, random, sim, sleeptime=10):
     """Inits the Exit."""
     Process.__init__(self, name='Exit handler', sim=sim)
     set.__init__(self)
     self.random = random
     self.sleeptime = sleeptime  #: time between two go()s
Пример #24
0
 def __init__(self, loc=Localization(), loc_updt_time=.5, sim=None):
     Process.__init__(self, name='Location', sim=sim)
     self.loc = loc
     self.loc_updt_time = loc_updt_time
     self.method = self.loc.method
     self.sim = sim
Пример #25
0
 def __init__(self, name, sim, tick, playerMonitor):
     """Inits the clock."""
     Process.__init__(self, name=name, sim=sim)
     self.playerMonitor = playerMonitor
     self.tick = tick
Пример #26
0
    def __init__(self, ID = 0, interval=0.05,roomId=-1, L=[], net=Network(),
        wld = world(),seed=0,sim=None,moving=True,froom=[],wait=1.0,cdest='random',
        save=[],color='k',pdshow=False):
        """ Class Person
            inherits of Simpy.SimulationRT
            """
        #GeomNetType = np.dtype([('Id',int), 
        #        ('time',int), 
        #           ('p',float,(1,3)),
        #           ('v',float,(1,3)),
        #           ('a',float,(1,3))])
        Person.npers +=1
        Process.__init__(self,name='Person_ID'+str(ID),sim=sim)
        self.ID=ID
        self.color=color
        self.pdshow=pdshow
        self.L = L 
        self.world = wld
        self.interval = interval
        self.manager = None
        self.manager_args = []
        self.waypoints = []
        self.moving=moving
        # random.seed(seed)
        if roomId < 0:
            try :
                self.roomId   = random.sample(self.L.Gr.nodes(),1)[0]
            except: 
                raise NameError('This error is due to the lack of Gr graph in the Layout argument passed to Person(Object)')
        else:
            self.roomId    = roomId
        self.forbidroomId = froom 
        self.cdest = cdest # choose tdestination type
        if self.cdest == 'random':
            # self.nextroomId   = int(np.floor(random.uniform(0,self.L.Gr.size())))
            try :
                self.nextroomId   = random.sample(self.L.Gr.nodes(),1)[0]
            except: 
                raise NameError('This error is due to the lack of Gr graph in the Layout argument passed to Person(Object)')
            while self.nextroomId == self.roomId or (self.nextroomId in self.forbidroomId): # or (self.nextroomId in self.sim.roomlist): # test destination different de l'arrive
                # self.nextroomId   = int(np.floor(random.uniform(0,self.L.Gr.size())))
                self.nextroomId   = random.sample(self.L.Gr.nodes(),1)[0]
            #self.sim.roomlist.append(self.nextroomId) # list of all destiantion of all nodes in object sim
        elif self.cdest == 'file':
           cfg = ConfigParser.ConfigParser()
           cfg.read(pyu.getlong('nodes_destination.ini','ini'))
           self.room_seq=eval(dict(cfg.items(self.ID))['room_seq'])
           self.room_wait=eval(dict(cfg.items(self.ID))['room_wait'])
           print 'WARNING: when nodes_destination ini file is read:'
           print '1) the room initialization starts in the first room of the list, not in the room configured in agent.ini'
           print '2) forbiden rooms are neglected'
           self.room_counter=1
           self.nb_room=len(self.room_seq)
           self.roomId=self.room_seq[0]
           self.nextroomId=self.room_seq[self.room_counter]
           self.wait=self.room_wait[self.room_counter]
        #self.sim.roomlist.append(self.nextroomId) # list of all destiantion of all nodes in object sim
        self.rooms, self.wp =  self.L.waypointGw(self.roomId,self.nextroomId)
        # self.dlist =  [i in self.L.Gw.ldo for i in self.rooms]
        for tup in self.wp[1:]:
                self.waypoints.append(vec3(tup))
        try:
            self.position = vec3(L.Gr.pos[self.roomId][0],L.Gr.pos[self.roomId][1])
        except:     
            self.position = vec3()
#           self.old_pos = vec3()
        self.stuck = 0
        self.destination = self.waypoints[0]
        self.arrived_in = False
        self.velocity = vec3()
        self.acceleration = vec3()
        self.localx = vec3(1, 0)
        self.localy = vec3(0, 1)
        self.world.add_boid(self)

        # from Helbing, et al "Self-organizing pedestrian movement"
        maxspeed = 0.8
        self.max_speed = maxspeed#random.normalvariate(maxspeed, 0.1)
        self.desired_speed = maxspeed
        self.radius = self.average_radius#random.normalvariate(self.average_radius, 0.025) / 2
        self.intersection = vec3()
        self.arrived = False 
        self.endpoint = False 
        self.behaviors = []
        self.steering_mind = default_steering_mind
        self.cancelled = 0
        self.net=net
        self.wait=wait
        self.df = pd.DataFrame(columns=['t','x','y','vx','vy','ax','ay'])
        self.df._metadata = self.ID
        self.save=save



        if 'mysql' in self.save:
           config = ConfigParser.ConfigParser()
           config.read(pyu.getlong('simulnet.ini','ini'))
           sql_opt = dict(config.items('Mysql'))
           self.db = Database(sql_opt['host'],sql_opt['user'],sql_opt['passwd'],sql_opt['dbname'])
           self.date = datetime.datetime.now()
Пример #27
0
 def __init__(self, loc=Localization(), loc_updt_time=0.5, sim=None):
     Process.__init__(self, name="Location", sim=sim)
     self.loc = loc
     self.loc_updt_time = loc_updt_time
     self.method = self.loc.method
     self.sim = sim
Пример #28
0
    def __init__(self,
                 ID=0,
                 interval=0.05,
                 roomId=0,
                 L=[],
                 net=Network(),
                 wld=world(),
                 sim=None,
                 moving=True,
                 froom=[],
                 wait=1.0,
                 cdest='random',
                 save=[]):
        """ Class Person
            inherits of Simpy.SimulationRT
        Attributes
        ----------
            ID    : float/hex/str/...
                    agent Id
            interval : float
                    refresh interval of agent mobility
            roomId : int
                    room ID where agent start when simulation is launched
            L : pylayers.gis.layout.Layout()
                Layout instance, in which the agent is moving
            net : pylayers.network.Network()
                Network instance, in which network agent are communicating.
                This is used for fill the true position filed of the graph
                It must be removed in a further version ( when a proper save instance
                would be created)
            wld : pylayers.mobility.transit.world.world()
                world instance. equivalent to layout but in the pytk framework. 
                TODO : remove in a further version
            sim : SimPy.Simulation.Simulation.RT()
                Simulation instance share by all the pylayer project. 
            moving : bool 
                indicate if the agent is moving or not ( relevant for acces poitns)
            froom : list
                list of forbiden rooms. 
            wait : float
                wait time of the agent when he has reach teh desitaion
            cdest : str
                method for choosing setination 'random ' of file read
            save : list
                list of save option type .
                It will be removed in a further version ( when a proper save instance
                would be created)


        Method
        ------
            Move : make the agent move
            update : DEPRECATED used for Tkinter plot

    """
        #GeomNetType = np.dtype([('Id',int),
        #        ('time',int),
        #           ('p',float,(1,3)),
        #           ('v',float,(1,3)),
        #           ('a',float,(1,3))])
        Person.npers += 1
        Process.__init__(self, name='Person_ID' + str(ID), sim=sim)
        self.ID = ID
        self.L = L
        self.world = wld
        self.interval = interval
        self.manager = None
        self.manager_args = []
        self.waypoints = []
        self.moving = moving
        self.roomId = roomId
        self.forbidroomId = froom
        self.cdest = cdest  # choose tdestination type
        if self.cdest == 'random':
            self.nextroomId = int(np.floor(uniform(0, self.L.Gr.size())))
            while self.nextroomId == self.roomId or (
                    self.nextroomId in self.forbidroomId
            ):  # or (self.nextroomId in self.sim.roomlist): # test destination different de l'arrive
                self.nextroomId = int(np.floor(uniform(0, self.L.Gr.size())))
            #self.sim.roomlist.append(self.nextroomId) # list of all destiantion of all nodes in object sim
        elif self.cdest == 'file':
            cfg = ConfigParser.ConfigParser()
            cfg.read(pyu.getlong('nodes_destination.ini', 'ini'))
            self.room_seq = eval(dict(cfg.items(self.ID))['room_seq'])
            self.room_wait = eval(dict(cfg.items(self.ID))['room_wait'])
            print 'WARNING: when nodes_destination ini file is read:'
            print '1) the room initialization starts in the first room of the list, not in the room configured in agent.ini'
            print '2) forbiden rooms are neglected'
            self.room_counter = 1
            self.nb_room = len(self.room_seq)
            self.roomId = self.room_seq[0]
            self.nextroomId = self.room_seq[self.room_counter]
            self.wait = self.room_wait[self.room_counter]
        #self.sim.roomlist.append(self.nextroomId) # list of all destiantion of all nodes in object sim
        self.wp = self.L.waypointGw(self.roomId, self.nextroomId)
        for tup in self.wp[1:]:
            self.waypoints.append(vec3(tup))
        try:
            self.position = vec3(L.Gr.pos[self.roomId][0],
                                 L.Gr.pos[self.roomId][1])
        except:
            self.position = vec3()
#           self.old_pos = vec3()
        self.stuck = 0
        self.destination = self.waypoints[0]
        self.velocity = vec3()
        self.localx = vec3(1, 0)
        self.localy = vec3(0, 1)
        self.world.add_boid(self)

        # from Helbing, et al "Self-organizing pedestrian movement"
        self.max_speed = 1.2  #normalvariate(1.0, 0.26)
        self.desired_speed = self.max_speed
        self.radius = normalvariate(self.average_radius, 0.025) / 2
        self.intersection = vec3()
        self.arrived = False
        self.endpoint = False
        self.behaviors = []
        self.steering_mind = default_steering_mind
        self.cancelled = 0
        self.net = net
        self.wait = wait
        self.save = save

        if 'mysql' in self.save:
            config = ConfigParser.ConfigParser()
            config.read(pyu.getlong('simulnet.ini', 'ini'))
            sql_opt = dict(config.items('Mysql'))
            self.db = Database(sql_opt['host'], sql_opt['user'],
                               sql_opt['passwd'], sql_opt['dbname'])
            self.date = datetime.datetime.now()
Пример #29
0
    def __init__(self,
                 ID=0,
                 interval=0.05,
                 roomId=-1,
                 L=[],
                 net=Network(),
                 wld=world(),
                 seed=0,
                 sim=None,
                 moving=True,
                 froom=[],
                 wait=1.0,
                 cdest='random',
                 save=[],
                 color='k',
                 pdshow=False):
        """ Class Person
            inherits of Simpy.SimulationRT
            """
        #GeomNetType = np.dtype([('Id',int),
        #        ('time',int),
        #           ('p',float,(1,3)),
        #           ('v',float,(1,3)),
        #           ('a',float,(1,3))])
        Person.npers += 1
        Process.__init__(self, name='Person_ID' + str(ID), sim=sim)
        self.ID = ID
        self.color = color
        self.pdshow = pdshow
        self.L = L
        self.world = wld
        self.interval = interval
        self.manager = None
        self.manager_args = []
        self.waypoints = []
        self.moving = moving
        # random.seed(seed)

        if roomId < 0:
            try:
                self.roomId = random.sample(self.L.Gr.nodes(), 1)[0]
            except:
                raise NameError(
                    'This error is due to the lack of Gr graph in the Layout argument passed to Person(Object)'
                )
        else:
            self.roomId = roomId
        self.forbidroomId = froom
        self.cdest = cdest  # choose tdestination type
        if self.cdest == 'random':
            # self.nextroomId   = int(np.floor(random.uniform(0,self.L.Gr.size())))
            try:
                self.nextroomId = random.sample(self.L.Gr.nodes(), 1)[0]
            except:
                raise NameError(
                    'This error is due to the lack of Gr graph in the Layout argument passed to Person(Object)'
                )
            while self.nextroomId == self.roomId or (
                    self.nextroomId in self.forbidroomId
            ):  # or (self.nextroomId in self.sim.roomlist): # test destination different de l'arrive
                # self.nextroomId   = int(np.floor(random.uniform(0,self.L.Gr.size())))
                self.nextroomId = random.sample(self.L.Gr.nodes(), 1)[0]
            #self.sim.roomlist.append(self.nextroomId) # list of all destiantion of all nodes in object sim
        elif self.cdest == 'file':
            cfg = ConfigParser.ConfigParser()
            cfg.read(pyu.getlong('nodes_destination.ini', 'ini'))
            self.room_seq = eval(dict(cfg.items(self.ID))['room_seq'])
            self.room_wait = eval(dict(cfg.items(self.ID))['room_wait'])
            print 'WARNING: when nodes_destination ini file is read:'
            print '1) the room initialization starts in the first room of the list, not in the room configured in agent.ini'
            print '2) forbiden rooms are neglected'
            self.room_counter = 1
            self.nb_room = len(self.room_seq)
            self.roomId = self.room_seq[0]
            self.nextroomId = self.room_seq[self.room_counter]
            self.wait = self.room_wait[self.room_counter]
        #self.sim.roomlist.append(self.nextroomId) # list of all destiantion of all nodes in object sim

        self.rooms, self.wp = self.L.waypointGw(self.roomId, self.nextroomId)
        # self.dlist =  [i in self.L.Gw.ldo for i in self.rooms]
        for tup in self.wp[1:]:
            self.waypoints.append(vec3(tup))
        try:
            self.position = vec3(L.Gr.pos[self.roomId][0],
                                 L.Gr.pos[self.roomId][1])
        except:
            self.position = vec3()
#           self.old_pos = vec3()
        self.stuck = 0
        self.destination = self.waypoints[0]
        self.arrived_in = False
        self.velocity = vec3()
        self.acceleration = vec3()
        self.localx = vec3(1, 0)
        self.localy = vec3(0, 1)
        self.world.add_boid(self)

        # from Helbing, et al "Self-organizing pedestrian movement"
        maxspeed = 0.8
        self.max_speed = maxspeed  #random.normalvariate(maxspeed, 0.1)
        self.desired_speed = maxspeed
        self.radius = self.average_radius  #random.normalvariate(self.average_radius, 0.025) / 2
        self.intersection = vec3()
        self.arrived = False
        self.endpoint = False
        self.behaviors = []
        self.steering_mind = default_steering_mind
        self.cancelled = 0
        self.net = net
        self.wait = wait
        self.df = pd.DataFrame(columns=['t', 'x', 'y', 'vx', 'vy', 'ax', 'ay'])
        self.df._metadata = self.ID
        self.save = save

        if 'mysql' in self.save:
            config = ConfigParser.ConfigParser()
            config.read(pyu.getlong('simulnet.ini', 'ini'))
            sql_opt = dict(config.items('Mysql'))
            self.db = Database(sql_opt['host'], sql_opt['user'],
                               sql_opt['passwd'], sql_opt['dbname'])
            self.date = datetime.datetime.now()