def rail_draw(last_x, last_y, platform_center_y=100): tk = world().tk canvas, x_, y_ = tk.canvas, tk.x_, tk.y_ # destinations (car 1 and 2) if os.environ.has_key("DESTINATIONS"): tk.canvas.create_line(x_(last_x - 2), y_(last_y + 86), x_(last_x + 2), y_(last_y + 86), fill="#000") tk.canvas.create_line(x_(last_x - 2), y_(last_y + 114), x_(last_x + 2), y_(last_y + 114), fill="#000") # rails tk.canvas.create_line(x_(last_x - 0.717), y_(last_y), x_(last_x - 0.717), y_(last_y + 200), fill="#888") tk.canvas.create_line(x_(last_x + 0.717), y_(last_y), x_(last_x + 0.717), y_(last_y + 200), fill="#888") # platform warning_strip_width = 0.610 # 24 inches warning_strip_color = "#ccc" # '#ff6' for a darker yellow, '#ccc' to hide plat_top = platform_center_y + Railcar.platform_length / 2 plat_bot = platform_center_y - Railcar.platform_length / 2 tk.canvas.create_rectangle( x_(last_x - 5), y_(plat_top), x_(last_x - Railcar.width / 2 - warning_strip_width), y_(plat_bot), fill="#ccc", outline="", ) tk.canvas.create_rectangle( x_(last_x - Railcar.width / 2 - warning_strip_width), y_(plat_bot), x_(last_x - Railcar.width / 2), y_(plat_top), fill=warning_strip_color, outline="", )
def create_layout(self): """ Create Layout in Simpy the_world thanks to Tk backend """ self.the_world = world(width = float(self.lay_opt['the_world_width']), height = float(self.lay_opt['the_world_height']), scale=float(self.lay_opt['the_world_scale'])) # tk = self.the_world.tk # canvas, x_, y_ = tk.canvas, tk.x_, tk.y_ # canvas.create_rectangle(x_(-1), y_(-1), x_(100), y_(100), fill='white') _filename = self.lay_opt['filename'] #sl=Slab.SlabDB(self.lay_opt['slab'],self.lay_opt['slabmat']) #G1 = Graph.Graph(sl=sl,filename=_filename) self.L = Layout(_filename) #if _filename.split('.')[1] == 'str': # self.L.loadstr(_filename) #elif _filename.split('.')[1] == 'str2': # self.L.loadstr2(_filename) #elif _filename.split('.')[1] == 'ini': # self.L.loadini(_filename) try: self.L.dumpr() print 'Layout graphs are loaded from ',basename,'/struc/ini' except: #self.L.sl = sl #self.L.loadGr(G1) print 'This is the first time the layout file is used\ Layout graphs are curently being built, it may take few minutes.' self.L.build() self.L.dumpw() x_offset = 0 # float(self.lay_opt['x_offset']) y_offset = 0 # float(self.lay_opt['y_offset']) for ks in self.L.Gs.pos.keys(): self.L.Gs.pos[ks] = (self.L.Gs.pos[ks][0] + x_offset, self.L.Gs.pos[ks][1] + y_offset) for ks in self.L.Gr.pos.keys(): self.L.Gr.pos[ks] = (self.L.Gr.pos[ks][0] + x_offset, self.L.Gr.pos[ks][1] + y_offset) for ks in self.L.Gw.pos.keys(): self.L.Gw.pos[ks] = (self.L.Gw.pos[ks][0] + x_offset, self.L.Gw.pos[ks][1] + y_offset) # # Create Layout # walls = self.L.thwall(0, 0) for wall in walls: points = [] # for point in wall: # points.append(x_(point[0])) # points.append(y_(point[1])) # canvas.create_polygon(points, fill='maroon', outline='black') for ii in range(0, len(wall) - 1): self.the_world.add_wall(wall[ii], wall[ii + 1])
def create_layout(self): """ create Layout in Simpy the_world thanks to Tk backend """ _filename = self.lay_opt['filename'] self.L = Layout(_filename) self.L.build() self.L.buildGr() self.L.buildGw() self.the_world = world() try: self.L.dumpr() print('Layout graphs are loaded from ' + basename + '/struc/ini') except: #self.L.sl = sl # self.L.loadGr(G1) print('This is the first time the layout file is used\ Layout graphs are curently being built, it may take few minutes.') self.L.build() self.L.dumpw() # # Create Layout # walls = self.L.thwall(0, 0) for wall in walls: for ii in range(0, len(wall) - 1): self.the_world.add_wall(wall[ii], wall[ii + 1])
def create_layout(self): """ create Layout in Simpy the_world thanks to Tk backend """ _filename = self.lay_opt['filename'] self.L = Layout(_filename) self.the_world = world() try: self.L.dumpr() print 'Layout graphs are loaded from ',basename,'/struc/ini' except: #self.L.sl = sl #self.L.loadGr(G1) print 'This is the first time the layout file is used\ Layout graphs are curently being built, it may take few minutes.' self.L.build() self.L.dumpw() # # Create Layout # walls = self.L.thwall(0, 0) for wall in walls: for ii in range(0, len(wall) - 1): self.the_world.add_wall(wall[ii], wall[ii + 1])
def __init__(self): Process.__init__(self) self.world = world() self.state = "waiting for train" self.boarders = [] self.boarded = 0 self.mode = "normal" # or "stadium" self.destination_x = 81
def __init__(self, name, interval): Process.__init__(self) self.world = world() self.interval = interval self.name = name self.x = 35 self.position = 0 self.speed = 24.6 # m/s self.destination = 240.0 self.departing = [] self.station_manager = None self.state_generator = self.cruising()
def __init__(self, interval=0.5,roomId=0, L=[],sim=None): """ boid is initialized in a room of Layout L """ #GeomNetType = np.dtype([('Id',int), # ('time',int), # ('p',float,(1,3)), # ('v',float,(1,3)), # ('a',float,(1,3))]) Person2.npers +=1 Process.__init__(self,sim=sim) self.L = L self.world = world() self.interval = interval self.manager = None self.manager_args = [] self.waypoints = [] self.roomId = roomId self.nextroomId = int(np.floor(uniform(0,self.L.Gr.size()))) while self.nextroomId == self.roomId : # test destination different de l'arrive self.nextroomId = int(np.floor(uniform(0,self.L.Gr.size()))) print "nextroom : ", self.nextroomId self.wp = self.L.waypoint(roomId,self.nextroomId) for tup in self.wp[1:]: self.waypoints.append(vec3(tup)) try: self.position = vec3(L.Gr.pos[roomId]) 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) # GeomNet = np.vstack((GeomNet,np.array((Nnodes,0,[list(self.position)],[list(self.velocity)],[list(self.velocity)]),dtype=GeomNetType))) # from Helbing, et al "Self-organizing pedestrian movement" self.max_speed = normalvariate(1.36, 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
def __init__(self, interval=0.5): Process.__init__(self) self.world = world() self.interval = interval self.manager = None self.manager_args = [] self.waypoints = [] self.position = vec3() 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 = normalvariate(1.36, 0.26) self.desired_speed = self.max_speed self.radius = normalvariate(self.average_radius, 0.025) / 2 self.intersection = vec3() self.arrived = False self.behaviors = [] self.steering_mind = default_steering_mind self.cancelled = 0
def __init__(self, interval, segment, distance): Process.__init__(self) self.world = world() self.interval = interval self.segment = segment self.distance = distance # along segment self.speed = PRT.max_speed self.desired_speed = PRT.max_speed self.acceleration = 0.0 self.switch = 'right' self.occupied = False self.ready_to_depart = False self.waiting_to_depart = False self.boarding = False self.tangent = 0.0 self.door_opening = False self.door_closing = False self.prt_ahead = None self.point_segment = None self.point_distance = 0.0 self.manager = None self.manager_args = []
def prt_draw(segment, last_x, last_y): tk = world().tk canvas, x_, y_, s_ = tk.canvas, tk.x_, tk.y_, tk.s_ if segment.type == 'decision': prt_draw(segment.next, last_x, last_y) elif segment.type == 'diverge': prt_draw(segment.left, last_x, last_y) prt_draw(segment.right, last_x, last_y) else: for ii in range(0, 10): xx, yy, tangent = segment.position(segment.length * float(ii) / 10) canvas.create_line(x_(last_x), y_(last_y), x_(xx), y_(yy), fill='#888', width=s_(0.914)) last_x, last_y = xx, yy if hasattr(segment, 'platform'): platform = segment.platform canvas.create_rectangle(x_(platform[0].x), y_(platform[0].y), x_(platform[1].x), y_(platform[1].y), fill='#ccc', outline="") if os.environ.has_key('DESTINATIONS'): for destination in segment.destinations: canvas.create_line(x_(destination.x-1), y_(destination.y), x_(destination.x+1), y_(destination.y)) if hasattr(segment, 'next'): prt_draw(segment.next, last_x, last_y)
def __init__(self, **args): """ Mobile Agent Init Parameters ---------- 'ID': 0, 'name': 'johndoe' 'type':'ag' 'pos':np.array([]) 'roomId':0, 'meca_updt':0.1, 'loc':False, 'loc_updt':0.5, 'Layout':Layout(), 'net':Network(), 'RAT':['wifi'], 'world':world(), 'save':[], 'sim':Simulation(), 'epwr':{}, 'sens':{}, 'dcond':{}, 'gcom':Gcom() """ defaults = { "ID": 0, "name": "johndoe", "type": "ag", "pos": np.array([]), "roomId": 0, "froom": [], "wait": [], "meca_updt": 0.1, "loc": False, "loc_updt": 0.5, "loc_method": ["geo"], "Layout": Layout(), "net": Network(), "RAT": ["wifi"], "world": world(), "save": [], "sim": Simulation(), "epwr": {}, "sens": {}, "dcond": {}, "gcom": Gcom(), } for key, value in defaults.items(): if key not in args: args[key] = value self.args = args self.ID = args["ID"] self.name = args["name"] self.type = args["type"] # Create Network self.net = args["net"] self.epwr = args["epwr"] self.gcom = args["gcom"] try: self.dcond = args["dcond"] except: pass # mecanique if self.type == "ag": self.meca = Person3( ID=self.ID, roomId=args["roomId"], L=args["Layout"], net=self.net, interval=args["meca_updt"], wld=args["world"], sim=args["sim"], moving=True, froom=args["froom"], wait=args["wait"], save=args["save"], ) self.meca.behaviors = [Queuing(), Seek(), Containment(), Separation(), InterpenetrationConstraint()] self.meca.steering_mind = queue_steering_mind # self.meca.steering_mind = queue_steering_mind # filll in network self.node = Node( ID=self.ID, p=conv_vecarr(self.meca.position), t=time.time(), RAT=args["RAT"], epwr=args["epwr"], sens=args["sens"], type=self.type, ) self.net.add_nodes_from(self.node.nodes(data=True)) self.sim = args["sim"] self.sim.activate(self.meca, self.meca.move(), 0.0) self.PN = self.net.node[self.ID]["PN"] self.rxr = RX(net=self.net, ID=self.ID, dcond=self.dcond, gcom=self.gcom, sim=self.sim) self.rxt = RX(net=self.net, ID=self.ID, dcond=self.dcond, gcom=self.gcom, sim=self.sim) self.sim.activate(self.rxr, self.rxr.refresh_RSS(), 0.0) self.sim.activate(self.rxt, self.rxt.refresh_TOA(), 0.0) elif self.type == "ap": # self.meca=Person3(ID=self.ID,roomId=args['roomId'],L=args['Layout'],net=self.net,interval=args['meca_updt'],sim=args['sim'],moving=False) # self.meca.behaviors = [] if args["roomId"] == -1: self.node = Node( ID=self.ID, p=self.args["pos"], t=time.time(), RAT=args["RAT"], epwr=args["epwr"], sens=args["sens"], type=self.type, ) else: pp = np.array(args["Layout"].Gr.pos[self.args["roomId"]]) self.node = Node( ID=self.ID, p=pp, t=time.time(), RAT=args["RAT"], epwr=args["epwr"], sens=args["sens"], type=self.type, ) self.net.add_nodes_from(self.node.nodes(data=True)) self.sim = args["sim"] # self.sim.activate(self.meca, self.meca.move(),0.0) self.PN = self.net.node[self.ID]["PN"] self.PN.node[self.ID]["pe"] = self.net.node[self.ID]["p"] else: raise NameError("wrong agent type, it must be either agent (ag) or acces point (ap) ") if self.type == "ap": self.MoA = 1 else: self.MoA = 0 if "mysql" in args["save"]: config = ConfigParser.ConfigParser() config.read(pyu.getlong("simulnet.ini", "ini")) sql_opt = dict(config.items("Mysql")) db = Database(sql_opt["host"], sql_opt["user"], sql_opt["passwd"], sql_opt["dbname"]) db.writenode(self.ID, self.name, self.MoA) if "txt" in args["save"]: pyu.writenode(self) if args["loc"] and self.type != "ap": self.loc = Localization(net=self.net, ID=self.ID, method=args["loc_method"]) self.Ploc = PLocalization(loc=self.loc, loc_updt_time=args["loc_updt"], sim=args["sim"]) self.sim.activate(self.Ploc, self.Ploc.run(), 1.5)
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()
def __init__(self, **args): """ Mobile Agent Init Parameters ---------- 'ID': string agent ID 'name': string Agent name 'type': string agent type . 'ag' for moving agent, 'ap' for static acces point 'pos' : np.array([]) numpy array containing the initial position of the agent 'roomId': int Room number where the agent is initialized (Layout.Gr) 'meca_updt': float update time interval for the mechanical process 'loc': bool enable/disable localization process of the agent 'loc_updt': float update time interval for localization process 'Layout': pylayers.gis.Layout() 'net':pylayers.network.Network(), 'RAT': list of string list of used radio access techology of the agent 'world': transit.world() Soon deprecated 'save': list of string list of save method ( soon deprecated) 'sim':Simpy.SimulationRT.Simulation(), 'epwr': dictionnary dictionnary of emmited power of transsmitter{'rat#':epwr value} 'sens': dictionnary dictionnary of sensitivity of reveicer {'rat#':sens value} 'dcond': dictionnary Not used yet 'gcom':pylayers.communication.Gcom() Communication graph 'comm_mod': string Communication between nodes mode: 'autonomous': all TOAs are refreshed regulary 'synchro' : only visilbe TOAs are refreshed """ defaults = {'ID': 0, 'name': 'johndoe', 'type': 'ag', 'pos': np.array([]), 'roomId': 0, 'froom':[], 'wait':[], 'cdest':'random', 'meca_updt': 0.1, 'loc': False, 'loc_updt': 0.5, 'loc_method': ['geo'], 'Layout': Layout(), 'net': Network(), 'RAT': ['wifi'], 'world': world(), 'save': [], 'sim': Simulation(), 'epwr':{}, 'sens': {}, 'dcond': {}, 'gcom': Gcom(), 'comm_mode':'autonomous'} for key, value in defaults.items(): if key not in args: args[key] = value self.args = args self.ID = args['ID'] self.name = args['name'] self.type = args['type'] # Create Network self.net = args['net'] self.epwr = args['epwr'] self.gcom = args['gcom'] try: self.dcond = args['dcond'] except: pass if self.type == 'ag': # mechanical init self.meca = Person(ID=self.ID, roomId=args['roomId'], L=args['Layout'], net=self.net, interval=args['meca_updt'], wld=args['world'], sim=args['sim'], moving=True, froom=args['froom'], wait=args['wait'], cdest=args['cdest'], save=args['save']) self.meca.behaviors = [Queuing(),Seek(), Containment(),\ Separation(), InterpenetrationConstraint()] self.meca.steering_mind = queue_steering_mind # self.meca.steering_mind = queue_steering_mind # filll in network ## Network init self.node = Node(ID=self.ID, p=conv_vecarr(self.meca.position), t=time.time(), RAT=args['RAT'], epwr=args['epwr'], sens=args['sens'], type=self.type) self.net.add_nodes_from(self.node.nodes(data=True)) self.sim = args['sim'] self.sim.activate(self.meca, self.meca.move(), 0.0) self.PN = self.net.node[self.ID]['PN'] ## Communication init if args['comm_mode'] == 'synchro': ## The TOA requests are made every refreshTOA time ( can be modified in agent.ini) self.rxr = RX(net=self.net, ID=self.ID, dcond=self.dcond, gcom=self.gcom, sim=self.sim) self.rxt = RX(net=self.net, ID=self.ID, dcond=self.dcond, gcom=self.gcom, sim=self.sim) self.sim.activate(self.rxr, self.rxr.refresh_RSS(), 0.0) self.sim.activate(self.rxt, self.rxt.refresh_TOA(), 0.0) elif args['comm_mode'] == 'autonomous': ## The TOA requests are made by node only when they are in visibility of pairs. self.rxr = RX(net=self.net, ID=self.ID, dcond=self.dcond, gcom=self.gcom, sim=self.sim) self.rxt = RX(net=self.net, ID=self.ID, dcond=self.dcond, gcom=self.gcom, sim=self.sim) self.txt = TX(net=self.net, ID=self.ID, dcond=self.dcond, gcom=self.gcom, sim=self.sim) self.sim.activate(self.rxr, self.rxr.refresh_RSS(), 0.0) self.sim.activate(self.rxt, self.rxt.wait_TOArq(), 0.0) self.sim.activate(self.txt, self.txt.request_TOA(), 0.0) elif self.type == 'ap': if args['roomId'] == -1: self.node = Node(ID=self.ID, p=self.args['pos'], t=time.time(), RAT=args['RAT'], epwr=args['epwr'], sens=args['sens'], type=self.type) else: pp = np.array(args['Layout'].Gr.pos[self.args['roomId']]) self.node = Node(ID=self.ID, p=pp, t=time.time(), RAT=args['RAT'], epwr=args['epwr'], sens=args['sens'], type=self.type) self.net.add_nodes_from(self.node.nodes(data=True)) self.sim = args['sim'] # self.sim.activate(self.meca, self.meca.move(),0.0) self.PN = self.net.node[self.ID]['PN'] self.PN.node[self.ID]['pe'] = self.net.node[self.ID]['p'] else: raise NameError('wrong agent type, it must be either agent (ag) or acces point (ap) ') if self.type == 'ap': self.MoA = 1 else: self.MoA = 0 if 'mysql' in args['save']: config = ConfigParser.ConfigParser() config.read(pyu.getlong('simulnet.ini', 'ini')) sql_opt = dict(config.items('Mysql')) db = Database(sql_opt['host'], sql_opt['user'], sql_opt['passwd'], sql_opt['dbname']) db.writenode(self.ID, self.name, self.MoA) if 'txt' in args['save']: pyu.writenode(self) if args['loc'] and self.type != 'ap': self.loc = Localization(net=self.net, ID=self.ID, method=args['loc_method']) self.Ploc = PLocalization(loc=self.loc, loc_updt_time=args['loc_updt'], sim=args['sim']) self.sim.activate(self.Ploc, self.Ploc.run(), 1.5)
def __init__(self, ID = 0, interval=0.05,roomId=0, L=[], net=Network(), wld = world(),sim=None,moving=True,froom=[],wait=1.0,save=[]): """ boid is initialized in a room of Layout L """ #GeomNetType = np.dtype([('Id',int), # ('time',int), # ('p',float,(1,3)), # ('v',float,(1,3)), # ('a',float,(1,3))]) Person3.npers +=1 Process.__init__(self,name='Person3_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.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 self.wp = self.L.waypoint(roomId,self.nextroomId) for tup in self.wp[1:]: self.waypoints.append(vec3(tup) ) try: self.position = vec3(L.Gr.pos[roomId][0],L.Gr.pos[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) # GeomNet = np.vstack((GeomNet,np.array((Nnodes,0,[list(self.position)],[list(self.velocity)],[list(self.velocity)]),dtype=GeomNetType))) # 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()
def __init__(self, **args): """ Mobile Agent Init Parameters ---------- 'ID': string agent ID 'name': string Agent name 'typ': string agent typ . 'ag' for moving agent, 'ap' for static acces point 'pos' : np.array([]) numpy array containing the initial position of the agent 'roomId': int Room number where the agent is initialized (Layout.Gr) 'meca_updt': float update time interval for the mechanical process 'loc': bool enable/disable localization process of the agent 'loc_updt': float update time interval for localization process 'L': pylayers.gis.Layout() 'net':pylayers.network.Network(), 'wstd': list of string list of used radio access techology of the agent 'world': transit.world() Soon deprecated 'save': list of string list of save method ( soon deprecated) 'sim':Simpy.SimulationRT.Simulation(), 'epwr': dictionnary dictionnary of emmited power of transsmitter{'wstd#':epwr value} 'sens': dictionnary dictionnary of sensitivity of reveicer {'wstd#':sens value} 'dcond': dictionnary Not used yet 'gcom':pylayers.communication.Gcom() Communication graph 'comm_mod': string Communication between nodes mode: 'autonomous': all TOAs are refreshed regulary 'synchro' : only visilbe TOAs are refreshed """ defaults = {'ID': '0', 'name': 'johndoe', 'typ': 'ag', 'color': 'k', 'pdshow': False, 'pos': np.array([]), 'roomId': -1, 'froom': [], 'wait': [], 'seed': 0, 'cdest': 'random', 'meca_updt': 0.1, 'loc': False, 'loc_updt': 0.5, 'loc_method': ['geo'], 'L': Layout(), 'network': True, 'net': Network(), 'wstd': ['rat1'], 'world': world(), 'save': [], 'sim': Simulation(), 'epwr': {}, 'sens': {}, 'dcond': {}, 'gcom': Gcom(), 'comm_mode': 'autonomous'} for key, value in defaults.items(): if key not in args: args[key] = value self.args = args self.ID = args['ID'] self.name = args['name'] self.typ = args['typ'] # Create Network self.net = args['net'] self.epwr = args['epwr'] self.gcom = args['gcom'] self.sim = args['sim'] self.wstd = args['wstd'] if args['epwr'] == {}: self.epwr = {x: 0 for x in self.wstd} else: self.epwr = args['epwr'] if args['sens'] == {}: self.sens = {x: -180 for x in self.wstd} else: self.sens = args['sens'] try: self.dcond = args['dcond'] except: pass # check if node id already given if self.ID in self.net.nodes(): raise NameError( 'another agent has the ID: ' + self.ID + ' .Please use an other ID') if self.typ == 'ag': # mechanical init self.meca = Person(ID=self.ID, color=args['color'], pdshow=args['pdshow'], roomId=args['roomId'], L=args['L'], net=self.net, interval=args['meca_updt'], wld=args['world'], sim=args['sim'], seed=args['seed'], moving=True, froom=args['froom'], wait=args['wait'], cdest=args['cdest'], save=args['save'] ) self.meca.behaviors = [Seek(), Containment(), Separation(), InterpenetrationConstraint()] self.meca.steering_mind = queue_steering_mind # Network init self.node = Node(ID=self.ID,name=self.name, p=conv_vecarr(self.meca.position), t=self.sim.now(), wstd=args['wstd'], epwr=self.epwr, sens=self.sens, typ=self.typ) self.net.add_nodes_from(self.node.nodes(data=True)) self.sim.activate(self.meca, self.meca.move(), 0.0) self.PN = self.net.node[self.ID]['PN'] # Communication init if args['comm_mode'] == 'synchro' and args['network']: # The TOA requests are made every refreshTOA time ( can be modified in agent.ini) # This Mode will be deprecated in future version self.rxr = RX(net=self.net, ID=self.ID, dcond=self.dcond, gcom=self.gcom, sim=self.sim) self.rxt = RX(net=self.net, ID=self.ID, dcond=self.dcond, gcom=self.gcom, sim=self.sim) self.sim.activate(self.rxr, self.rxr.refresh_RSS(), 0.0) self.sim.activate(self.rxt, self.rxt.refresh_TOA(), 0.0) elif args['comm_mode'] == 'autonomous' and args['network']: # The requests are made by node only when they are in # visibility of pairs. # self.rxr only manage a refresh RSS process self.rxr = RX(net=self.net, ID=self.ID, gcom=self.gcom, sim=self.sim) # self.tx manage all requests to other nodes self.tx = TX(net=self.net, ID=self.ID, gcom=self.gcom, sim=self.sim) # self.tx replies to requests from self.tx self.rx = RX(net=self.net, ID=self.ID, gcom=self.gcom, sim=self.sim) self.sim.activate(self.rxr, self.rxr.refresh_RSS(), 0.0) self.sim.activate(self.tx, self.tx.request(), 0.0) self.sim.activate(self.rx, self.rx.wait_request(), 0.0) elif self.typ == 'ap': if args['roomId'] == -1: self.node = Node(ID=self.ID, p=self.args['pos'], t=self.sim.now(), wstd=args['wstd'], epwr=self.epwr, sens=self.sens, typ=self.typ) else: pp = np.array(args['L'].Gr.pos[self.args['roomId']]) self.node = Node( ID=self.ID, p=pp, t=self.sim.now(), wstd=args['wstd'], epwr=self.epwr, sens=self.sens, typ=self.typ) self.net.add_nodes_from(self.node.nodes(data=True)) self.sim = args['sim'] self.PN = self.net.node[self.ID]['PN'] self.PN.node[self.ID]['pe'] = self.net.node[self.ID]['p'] if args['comm_mode'] == 'autonomous' and args['network']: self.rx = RX(net=self.net, ID=self.ID, gcom=self.gcom, sim=self.sim) self.sim.activate(self.rx, self.rx.wait_request(), 0.0) p = self.args['pos'] self.posdf = pd.DataFrame( {'t': pd.Timestamp(0), 'x': p[0], 'y': p[1], 'z': p[2], 'vx': np.array([0.0]), 'vy': np.array([0.0]), 'ax': np.array([0.0]), 'ay': np.array([0.0]), }, columns=['t', 'x', 'y', 'z', 'vx', 'vy', 'ax', 'ay'], index=np.array([0])) else: raise NameError( 'wrong agent typ, it must be either agent (ag) or acces point (ap) ') if self.typ == 'ap': self.MoA = 1 else: self.MoA = 0 if 'mysql' in args['save']: config = ConfigParser.ConfigParser() config.read(pyu.getlong('simulnet.ini', 'ini')) sql_opt = dict(config.items('Mysql')) db = Database(sql_opt['host'], sql_opt['user'], sql_opt['passwd'], sql_opt['dbname']) db.writenode(self.ID, self.name, self.MoA) if 'txt' in args['save']: pyu.writenode(self) if self.typ != 'ap' and args['loc']: self.loc = Localization(net=self.net, ID=self.ID, method=args['loc_method']) self.Ploc = PLocalization(loc=self.loc, loc_updt_time=args['loc_updt'], tx=self.tx, sim=args['sim']) self.sim.activate(self.Ploc, self.Ploc.run(), 1.5)
def create_layout(self): """ Create Layout in Simpy the_world thantks to Tk backend """ self.the_world = world(width=float(self.lay_opt['the_world_width']), height=float(self.lay_opt['the_world_height']), scale=float(self.lay_opt['the_world_scale'])) # tk = self.the_world.tk # canvas, x_, y_ = tk.canvas, tk.x_, tk.y_ # canvas.create_rectangle(x_(-1), y_(-1), x_(100), y_(100), fill='white') _filename = self.lay_opt['filename'] #sl=Slab.SlabDB(self.lay_opt['slab'],self.lay_opt['slabmat']) #G1 = Graph.Graph(sl=sl,filename=_filename) self.L = Layout() if _filename.split('.')[1] == 'str': self.L.loadstr(_filename) elif _filename.split('.')[1] == 'str2': self.L.loadstr2(_filename) elif _filename.split('.')[1] == 'ini': self.L.loadini(_filename) try: self.L.dumpr() print 'Layout graphs are loaded from ', basename, '/struc' except: #self.L.sl = sl #self.L.loadGr(G1) print 'This is the first time your use this layout file.\ Layout graphs are curently being built, it may take few minutes.' self.L.buildGt() self.L.buildGr() self.L.buildGw() self.L.buildGv() self.L.buildGi() self.L.dumpw() x_offset = 0 # float(self.lay_opt['x_offset']) y_offset = 0 # float(self.lay_opt['y_offset']) for ks in self.L.Gs.pos.keys(): self.L.Gs.pos[ks] = (self.L.Gs.pos[ks][0] + x_offset, self.L.Gs.pos[ks][1] + y_offset) for ks in self.L.Gr.pos.keys(): self.L.Gr.pos[ks] = (self.L.Gr.pos[ks][0] + x_offset, self.L.Gr.pos[ks][1] + y_offset) for ks in self.L.Gw.pos.keys(): self.L.Gw.pos[ks] = (self.L.Gw.pos[ks][0] + x_offset, self.L.Gw.pos[ks][1] + y_offset) # # Create Layout # walls = self.L.thwall(0, 0) for wall in walls: points = [] # for point in wall: # points.append(x_(point[0])) # points.append(y_(point[1])) # canvas.create_polygon(points, fill='maroon', outline='black') for ii in range(0, len(wall) - 1): self.the_world.add_wall(wall[ii], wall[ii + 1])
def __init__(self, interval, sim=None): Process.__init__(self, sim=sim) self.world = world() self.interval = interval self.display_interval = 60.0
def __init__(self, **args): """ Mobile Agent Init Parameters ---------- 'ID': string agent ID 'name': string Agent name 'type': string agent type . 'ag' for moving agent, 'ap' for static acces point 'pos' : np.array([]) numpy array containing the initial position of the agent 'roomId': int Room number where the agent is initialized (Layout.Gr) 'meca_updt': float update time interval for the mechanical process 'loc': bool enable/disable localization process of the agent 'loc_updt': float update time interval for localization process 'Layout': pylayers.gis.Layout() 'net':pylayers.network.Network(), 'RAT': list of string list of used radio access techology of the agent 'world': transit.world() Soon deprecated 'save': list of string list of save method ( soon deprecated) 'sim':Simpy.SimulationRT.Simulation(), 'epwr': dictionnary dictionnary of emmited power of transsmitter{'rat#':epwr value} 'sens': dictionnary dictionnary of sensitivity of reveicer {'rat#':sens value} 'dcond': dictionnary Not used yet 'gcom':pylayers.communication.Gcom() Communication graph 'comm_mod': string Communication between nodes mode: 'autonomous': all TOAs are refreshed regulary 'synchro' : only visilbe TOAs are refreshed """ defaults = { 'ID': 0, 'name': 'johndoe', 'type': 'ag', 'pos': np.array([]), 'roomId': 0, 'froom': [], 'wait': [], 'cdest': 'random', 'meca_updt': 0.1, 'loc': False, 'loc_updt': 0.5, 'loc_method': ['geo'], 'Layout': Layout(), 'net': Network(), 'RAT': ['wifi'], 'world': world(), 'save': [], 'sim': Simulation(), 'epwr': {}, 'sens': {}, 'dcond': {}, 'gcom': Gcom(), 'comm_mode': 'autonomous' } for key, value in defaults.items(): if key not in args: args[key] = value self.args = args self.ID = args['ID'] self.name = args['name'] self.type = args['type'] # Create Network self.net = args['net'] self.epwr = args['epwr'] self.gcom = args['gcom'] try: self.dcond = args['dcond'] except: pass if self.type == 'ag': # mechanical init self.meca = Person(ID=self.ID, roomId=args['roomId'], L=args['Layout'], net=self.net, interval=args['meca_updt'], wld=args['world'], sim=args['sim'], moving=True, froom=args['froom'], wait=args['wait'], cdest=args['cdest'], save=args['save']) self.meca.behaviors = [Queuing(),Seek(), Containment(),\ Separation(), InterpenetrationConstraint()] self.meca.steering_mind = queue_steering_mind # self.meca.steering_mind = queue_steering_mind # filll in network ## Network init self.node = Node(ID=self.ID, p=conv_vecarr(self.meca.position), t=time.time(), RAT=args['RAT'], epwr=args['epwr'], sens=args['sens'], type=self.type) self.net.add_nodes_from(self.node.nodes(data=True)) self.sim = args['sim'] self.sim.activate(self.meca, self.meca.move(), 0.0) self.PN = self.net.node[self.ID]['PN'] ## Communication init if args['comm_mode'] == 'synchro': ## The TOA requests are made every refreshTOA time ( can be modified in agent.ini) self.rxr = RX(net=self.net, ID=self.ID, dcond=self.dcond, gcom=self.gcom, sim=self.sim) self.rxt = RX(net=self.net, ID=self.ID, dcond=self.dcond, gcom=self.gcom, sim=self.sim) self.sim.activate(self.rxr, self.rxr.refresh_RSS(), 0.0) self.sim.activate(self.rxt, self.rxt.refresh_TOA(), 0.0) elif args['comm_mode'] == 'autonomous': ## The TOA requests are made by node only when they are in visibility of pairs. self.rxr = RX(net=self.net, ID=self.ID, dcond=self.dcond, gcom=self.gcom, sim=self.sim) self.rxt = RX(net=self.net, ID=self.ID, dcond=self.dcond, gcom=self.gcom, sim=self.sim) self.txt = TX(net=self.net, ID=self.ID, dcond=self.dcond, gcom=self.gcom, sim=self.sim) self.sim.activate(self.rxr, self.rxr.refresh_RSS(), 0.0) self.sim.activate(self.rxt, self.rxt.wait_TOArq(), 0.0) self.sim.activate(self.txt, self.txt.request_TOA(), 0.0) elif self.type == 'ap': if args['roomId'] == -1: self.node = Node(ID=self.ID, p=self.args['pos'], t=time.time(), RAT=args['RAT'], epwr=args['epwr'], sens=args['sens'], type=self.type) else: pp = np.array(args['Layout'].Gr.pos[self.args['roomId']]) self.node = Node(ID=self.ID, p=pp, t=time.time(), RAT=args['RAT'], epwr=args['epwr'], sens=args['sens'], type=self.type) self.net.add_nodes_from(self.node.nodes(data=True)) self.sim = args['sim'] # self.sim.activate(self.meca, self.meca.move(),0.0) self.PN = self.net.node[self.ID]['PN'] self.PN.node[self.ID]['pe'] = self.net.node[self.ID]['p'] else: raise NameError( 'wrong agent type, it must be either agent (ag) or acces point (ap) ' ) if self.type == 'ap': self.MoA = 1 else: self.MoA = 0 if 'mysql' in args['save']: config = ConfigParser.ConfigParser() config.read(pyu.getlong('simulnet.ini', 'ini')) sql_opt = dict(config.items('Mysql')) db = Database(sql_opt['host'], sql_opt['user'], sql_opt['passwd'], sql_opt['dbname']) db.writenode(self.ID, self.name, self.MoA) if 'txt' in args['save']: pyu.writenode(self) if args['loc'] and self.type != 'ap': self.loc = Localization(net=self.net, ID=self.ID, method=args['loc_method']) self.Ploc = PLocalization(loc=self.loc, loc_updt_time=args['loc_updt'], sim=args['sim']) self.sim.activate(self.Ploc, self.Ploc.run(), 1.5)
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()
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()
def __init__(self, **kw_args): self.__dict__ = kw_args self.world = world()
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()