def __init__(self,envrionment,person_tag=0,important_loc=[]): self.person_tag=person_tag self.Envir=Environment.Envronment([],1) self.Envir.copy_environment(envrionment) # Environment.Envronment([],1) #self.Envir.copy_environment(envrionment) self.Envir.grid.set_grid(self.Envir.PointList) self.route=[] self.important_loc=important_loc
def read_txt_step(self, path, temp_envir, offset): if self.mid: self.mid = None temp_mid = [] with open(path, 'r+') as f: f.seek(offset) temp_str = f.readline() if (temp_str): temp_route2 = [] person_tag = 0 temp_str = temp_str.rstrip('\n') if (temp_str == 'People'): person_tag = int(f.readline().rstrip('\n')) temp_str = f.readline() important_loc = [] temp = temp_str.rstrip('\n') if not (temp == '0'): temp = temp.split(" ") for i in range(int(len(temp))): index = int(temp[i]) point = temp_envir.PointList[index] important_loc.append(point) while (True): temp_str = f.readline() temp_str = temp_str.rstrip('\n') if (temp_str != str(0)): temp_str = temp_str.split(' ') tempx = float(temp_str[0]) tempy = float(temp_str[1]) ID = int(temp_str[2]) state = int(temp_str[3]) weight = float(temp_str[4]) gridID1 = int(temp_str[5]) gridID2 = int(temp_str[6]) t = float(temp_str[7]) weight2 = float(temp_str[8]) point = Point.Point(tempx, tempy, gridid=(gridID1, gridID2), ID=ID, state=state, weight=weight) point.weight2 = weight2 point.t = t temp_route2.append(point) else: offset = f.tell() break temp_envir = Environment.Envronment([], 1) temp_mid = data_mid.data_mid(temp_envir, person_tag=person_tag, important_loc=important_loc) temp_mid.add_location(temp_route2) return temp_mid, offset
def __init__(self,args_model,environment,homeposition,workposition,visited_Place=[]): self.Envir=Environment.Envronment([],1) self.args_model = args_model self.visited_Place = visited_Place self.HomePosition = homeposition self.WorkPosition = workposition self.Envir.copy_environment(environment) #time constrains self.args_t =[] self.t_now=-1 self.t_end=-1 #space constrains self.args_step=[] self.speed=-1
def read_Envr(self, path): temp_route = [] dimension_x = 0 dimension_y = 0 with open(path, 'r') as f: temp_str = f.readline() temp_str = temp_str.rstrip('\n') if (temp_str == 'Environment'): temp_str = f.readline() temp_str = temp_str.rstrip('\n') temp_str = temp_str.split(' ') temp_int = [int(temp_str[0]), int(temp_str[1])] dimension_x, dimmension_y = temp_int[0], temp_int[1] tag = True while (tag): temp_str = f.readline() temp_str = temp_str.rstrip('\n') if (temp_str != str(0)): temp_str = temp_str.split(' ') tempx = float(temp_str[0]) tempy = float(temp_str[1]) ID = int(temp_str[2]) state = int(temp_str[3]) weight = float(temp_str[4]) gridID1 = int(temp_str[5]) gridID2 = int(temp_str[6]) t = float(temp_str[7]) weight2 = float(temp_str[8]) # t=float(temp_str[6]) point = Point.Point(tempx, tempy, ID=ID, state=state, weight=weight, gridid=(gridID1, gridID2)) point.weight2 = weight2 point.t = t temp_route.append(point) else: offset = f.tell() break temp_envir = Environment.Envronment(temp_route, dimension_x=dimension_x, dimmension_y=dimension_y) temp_envir.cal_dis_dict(temp_envir.dis_func1) return temp_envir, offset
def __init__(self, args_model, args_step, args_t, simulate_time, environment): self.speed = 30000 self.Envir = Environment.Envronment([], 1) self.Envir.copy_environment(environment) if (not environment.dis_dict): self.Envir.cal_dis_dict(self.Envir.dis_func1) self.set_args(args_model, args_step, args_t, simulate_time) self.data_mid = data_mid.data_mid(environment, person_tag=0) self.set_home_loc() self.set_work_loc(beta=args_step[0]) self.home_locationList = [] self.work_locatonList = [] self.commute_LocationList = [] for i in range(1): self.home_locationList.append(self.home_loc) self.work_locatonList.append(self.work_loc) self.data_mid.add_location([self.home_loc, self.work_loc]) self.data_mid.important_loc = [self.home_loc, self.work_loc]
r2 = (Point1.x - Point2.x) * (Point1.x - Point2.x) + ( Point1.y - Point2.y) * (Point1.y - Point2.y) return math.sqrt(r2) path = "E:/data/shenzhen/shenzhen.mdb" name = "shenzhen_random_split" field = ["PN_INHABIT"] io_dealer = IO_shp.IO() xy_list = io_dealer.read_shp(path=path, name=name, fied_list=field) Point_List = [] for i, xy in enumerate(xy_list): temp_Point = Point.Point(xy[1][0], xy[1][1], gridid=-1, ID=i, weight=xy[0]) Point_List.append(temp_Point) Envir = Environment.Envronment(Point_List=Point_List, dimension_x=10) Envir.cal_dis_dict(dis_function=dis_func1) simulate_time = 400 temp_routeList = [] for i in range(0, 10): #model=Model5.HomeOrWork_Model(args_model=args_model,args_t=args_time,args_steps=args_steps,environment=Envir,visited_Place=[],homeposition=random.choice(Envir.locations),workposition=random.choice(Envir.locations)) model = agent.Nomal_Individual(args_model=args_model, args_t=args_time, args_step=args_steps, simulate_time=simulate_time, environment=Envir) model.simulate() mid = model.data_mid mid.person_tag = i write = IO.IO(mid)
def __init__(self, PointList, Envir): self.PointList = PointList self.Envir = Environment.Envronment([], 10) self.Envir.copy_environment(Envir)
def read_txt(self, path): if self.mid: self.mid = None temp_route = [] dimension_x = 0 dimension_y = 0 with open(path, 'r') as f: temp_str = f.readline() temp_str = temp_str.rstrip('\n') if (temp_str == 'Environment'): temp_str = f.readline() temp_str = temp_str.rstrip('\n') temp_str = temp_str.split(' ') temp_int = [int(temp_str[0]), int(temp_str[1])] dimension_x, dimmension_y = temp_int[0], temp_int[1] tag = True while (tag): temp_str = f.readline() temp_str = temp_str.rstrip('\n') if (temp_str != str(0)): temp_str = temp_str.split(' ') tempx = float(temp_str[0]) tempy = float(temp_str[1]) ID = int(temp_str[2]) state = int(temp_str[3]) weight = float(temp_str[4]) gridID1 = int(temp_str[5]) gridID2 = int(temp_str[6]) t = float(temp_str[7]) weight2 = float(temp_str[8]) point = Point.Point(tempx, tempy, ID=ID, state=state, weight=weight, gridid=(gridID1, gridID2)) point.weight2 = weight2 point.t = t temp_route.append(point) else: break temp_envir = Environment.Envronment(temp_route, dimension_x=dimension_x, dimmension_y=dimension_y) temp_envir.cal_dis_dict(temp_envir.dis_func1) data_mid_list = [] temp_str = f.readline() while (temp_str): temp_route2 = [] person_tag = 0 temp_str = temp_str.rstrip('\n') if (temp_str == 'People'): person_tag = int(f.readline().rstrip('\n')) temp_str = f.readline() important_loc = [] temp = temp_str.rstrip('\n') if not (temp == '0'): temp = temp.split(" ") for i in range(int(len(temp))): index = int(temp[i]) point = temp_envir.PointList[index] important_loc.append(point) while (True): temp_str = f.readline() temp_str = temp_str.rstrip('\n') if (temp_str != str(0)): temp_str = temp_str.split(' ') tempx = float(temp_str[0]) tempy = float(temp_str[1]) ID = int(temp_str[2]) state = int(temp_str[3]) weight = float(temp_str[4]) gridID1 = int(temp_str[5]) gridID2 = int(temp_str[6]) t = float(temp_str[7]) weight2 = float(temp_str[8]) point = Point.Point(tempx, tempy, gridid=(gridID1, gridID2), ID=ID, state=state, weight=weight) point.weight2 = weight2 point.t = t temp_route2.append(point) else: break temp_mid = data_mid.data_mid(temp_envir, person_tag=person_tag, important_loc=important_loc) temp_mid.add_location(temp_route2) data_mid_list.append(temp_mid) temp_str = f.readline() return data_mid_list