def get_closest_exit(self,hotspot): pos = self.get_position() exits = [] distances = [] #if hotspot == 2001: exits = [[-36,-192],[35,-138],[131,-78],[235,-5]] #if hotspot == 2003: exits = [[235,-5],[178,68],[122,154],[59,244]] #if hotspot == 2004: exits = [[59,244],[-38,182],[-121,125],[-211,67]] #if hotspot == 2002: exits = [[-211,67],[-149,-26],[-97,-112],[-44,-192]] #if hotspot == 2001: exits = [[75,-560],[144,-560],[172,-560],[195,-561],[274,-559],[427,-558],[598,-560],[680,-460],[679,-429],[678,-392],[681,-232],[675,-160],[675,-106]] #if hotspot == 2002: exits = [[-617,-561],[-218,-554],[-199,559],[-86,-560],[-356,-560],[-698,-474],[-696,-376]] #if hotspot == 2003: exits = [[681,26],[676,271],[677,384],[676,440],[264,713],[386,716],[427,716],[427,714],[622,729]] #if hotspot == 2004: exits = [[-698,181],[-696,206],[-695,262],[-695,334],[-695,262],[-696,333],[-697,385],[-612,714],[-579,715],[-487,716],[-362,708],[233,713],[-98,717],[40,716],[161,718]] if hotspot == 2001: exits = [[-86,-559],[76,-560], [143,-559], [173,-560], [195,-554], [273,-560], [427,-559], [598,-562], [861,-515], [866,-468], [862,-198]] if hotspot == 2002: exits = [[-199,-560], [-219,-560], [-356,-560], [-617,-563], [-631,-558], [-927,-514], [-882,-513]] if hotspot == 2003: exits = [[864,130], [864,165], [868,387], [868,473], [867,786], [866,820], [866,874], [837,1084], [778,1093], [605,1085], [582,1091], [482,1085], [421,1086], [338,1087], [308,1086], [141,1083], [111,1087], [89,1086]] if hotspot == 2004: exits = [[-1016,801], [-1031,918], [-1028,1080], [-848,1084], [-728,1104], [-585,1086], [-440,1085], [-347,1076], [-231,1090], [-150,1085], [-44,1094]] for r in range(len(exits)): distances.append([vdistsqr(pos,exits[r]),r]) #print 'not sorted: ',distances distances.sort() self.set_goal_by_coordinates(exits[distances[0][1]])
def get_closest_exit(self, hotspot): pos = self.get_position() exits = [] distances = [] #if hotspot == 2001: exits = [[-36,-192],[35,-138],[131,-78],[235,-5]] #if hotspot == 2003: exits = [[235,-5],[178,68],[122,154],[59,244]] #if hotspot == 2004: exits = [[59,244],[-38,182],[-121,125],[-211,67]] #if hotspot == 2002: exits = [[-211,67],[-149,-26],[-97,-112],[-44,-192]] #if hotspot == 2001: exits = [[75,-560],[144,-560],[172,-560],[195,-561],[274,-559],[427,-558],[598,-560],[680,-460],[679,-429],[678,-392],[681,-232],[675,-160],[675,-106]] #if hotspot == 2002: exits = [[-617,-561],[-218,-554],[-199,559],[-86,-560],[-356,-560],[-698,-474],[-696,-376]] #if hotspot == 2003: exits = [[681,26],[676,271],[677,384],[676,440],[264,713],[386,716],[427,716],[427,714],[622,729]] #if hotspot == 2004: exits = [[-698,181],[-696,206],[-695,262],[-695,334],[-695,262],[-696,333],[-697,385],[-612,714],[-579,715],[-487,716],[-362,708],[233,713],[-98,717],[40,716],[161,718]] if hotspot == 2001: exits = [[-86, -559], [76, -560], [143, -559], [173, -560], [195, -554], [273, -560], [427, -559], [598, -562], [861, -515], [866, -468], [862, -198]] if hotspot == 2002: exits = [[-199, -560], [-219, -560], [-356, -560], [-617, -563], [-631, -558], [-927, -514], [-882, -513]] if hotspot == 2003: exits = [[864, 130], [864, 165], [868, 387], [868, 473], [867, 786], [866, 820], [866, 874], [837, 1084], [778, 1093], [605, 1085], [582, 1091], [482, 1085], [421, 1086], [338, 1087], [308, 1086], [141, 1083], [111, 1087], [89, 1086]] if hotspot == 2004: exits = [[-1016, 801], [-1031, 918], [-1028, 1080], [-848, 1084], [-728, 1104], [-585, 1086], [-440, 1085], [-347, 1076], [-231, 1090], [-150, 1085], [-44, 1094]] for r in range(len(exits)): distances.append([vdistsqr(pos, exits[r]), r]) #print 'not sorted: ',distances distances.sort() self.set_goal_by_coordinates(exits[distances[0][1]])
def update(self): if len(self.path) > 0 and self.path != None: if self.destnumber == len(self.path): if self.exiting == True: self.to_be_destroyed = True return del self.path[:] #print self.hotspot #print self.destweights AHS_MODE = False if AHS_MODE == True: raffle = randint(1,10) #Picking random walkers to exit if raffle == 10: self.exiting = True passage = choice([2001,2002,2003,2004]) self.get_closest_exit(passage) self.set_path() if raffle == 9: self.set_random_goal() self.set_path() else: print 'ped aorigins',self.aorigins atype = weighted_choice(self.aorigins) #print atype ahs = pick_with_type(atype) print ahs goals = find_n_closest_w_distance(ahs,150,atype) #print goals goal = choice(goals) #print goal self.set_goal(goal) self.set_path() return RANDOM_MODE = True if RANDOM_MODE == False: if self.destweights[self.hotspot]==[]: hs,gl = pick_first(self.origins) else: hs, gl = pick_second(self.hotspot, self.destweights) #print 'going random' if hs == 2001 or hs == 2002 or hs == 2003 or hs == 2004: self.exiting = True self.get_closest_exit(hs) self.set_path() return #print 'Im exiting' self.hotspot = hs self.set_goal(gl) else: raffle = randint(1,10) #Picking random walkers to exit if raffle == 10: self.exiting = True passage = choice([2001,2002,2003,2004]) self.get_closest_exit(passage) else: self.set_random_goal() self.set_path() if len(self.path) == 0: return self.speed = 6 #self.get_close_neighbors() if len(self.close_neighbors) >0: changeforce = self.velocity_change() changenorm = normalize_vector(changeforce) #change = multiply_with_scalar(changenorm,self.speed) change = multiply_with_scalar(changenorm,1.5) self.x = self.x+((self.velocity[0]+changenorm[0])/2) self.y = self.y+((self.velocity[1]+changenorm[1])/2) loc = [self.x,self.y] self.velocity = change #print change #print "Got neighbors" return current_destination = self.path[self.destnumber] dy = self.y-float(current_destination[1]) dx = self.x-float(current_destination[0]) dx = dx*-1 dy = dy*-1 angle = atan2(dy,dx) angle = degrees(angle) self.rotation = angle self.heading = [cos(angle),sin(angle)] vector_to_goal = [dx,dy] distance_to_goal = sqrt((dx**2)+(dy**2)) if distance_to_goal > 0: direction = [dx/distance_to_goal,dy/distance_to_goal] else: direction = vector_to_goal new_velocity = multiply_with_scalar(self.heading,self.speed) self.x = self.x+((self.velocity[0]+direction[0])/2) self.y = self.y+((self.velocity[1]+direction[1])/2) self.velocity = direction loc = [self.x,self.y] #location = mesh_grid5.find_node(self.x,self.y) #self.node = location #print vdistsqr(loc,current_destination) if vdistsqr(loc,current_destination) < 0.5: #print self.destnumber self.destnumber = self.destnumber +1 #self.draw() else: self.set_random_goal() self.set_path() #print "Checking again" if self.path == None: print "waaat"
def update(self): if len(self.path) > 0 and self.path != None: if self.destnumber == len(self.path): if self.exiting == True: self.to_be_destroyed = True return del self.path[:] #print self.hotspot #print self.destweights AHS_MODE = False if AHS_MODE == True: raffle = randint(1, 10) #Picking random walkers to exit if raffle == 10: self.exiting = True passage = choice([2001, 2002, 2003, 2004]) self.get_closest_exit(passage) self.set_path() if raffle == 9: self.set_random_goal() self.set_path() else: print 'ped aorigins', self.aorigins atype = weighted_choice(self.aorigins) #print atype ahs = pick_with_type(atype) print ahs goals = find_n_closest_w_distance(ahs, 150, atype) #print goals goal = choice(goals) #print goal self.set_goal(goal) self.set_path() return RANDOM_MODE = True if RANDOM_MODE == False: if self.destweights[self.hotspot] == []: hs, gl = pick_first(self.origins) else: hs, gl = pick_second(self.hotspot, self.destweights) #print 'going random' if hs == 2001 or hs == 2002 or hs == 2003 or hs == 2004: self.exiting = True self.get_closest_exit(hs) self.set_path() return #print 'Im exiting' self.hotspot = hs self.set_goal(gl) else: raffle = randint(1, 10) #Picking random walkers to exit if raffle == 10: self.exiting = True passage = choice([2001, 2002, 2003, 2004]) self.get_closest_exit(passage) else: self.set_random_goal() self.set_path() if len(self.path) == 0: return self.speed = 6 #self.get_close_neighbors() if len(self.close_neighbors) > 0: changeforce = self.velocity_change() changenorm = normalize_vector(changeforce) #change = multiply_with_scalar(changenorm,self.speed) change = multiply_with_scalar(changenorm, 1.5) self.x = self.x + ((self.velocity[0] + changenorm[0]) / 2) self.y = self.y + ((self.velocity[1] + changenorm[1]) / 2) loc = [self.x, self.y] self.velocity = change #print change #print "Got neighbors" return current_destination = self.path[self.destnumber] dy = self.y - float(current_destination[1]) dx = self.x - float(current_destination[0]) dx = dx * -1 dy = dy * -1 angle = atan2(dy, dx) angle = degrees(angle) self.rotation = angle self.heading = [cos(angle), sin(angle)] vector_to_goal = [dx, dy] distance_to_goal = sqrt((dx**2) + (dy**2)) if distance_to_goal > 0: direction = [dx / distance_to_goal, dy / distance_to_goal] else: direction = vector_to_goal new_velocity = multiply_with_scalar(self.heading, self.speed) self.x = self.x + ((self.velocity[0] + direction[0]) / 2) self.y = self.y + ((self.velocity[1] + direction[1]) / 2) self.velocity = direction loc = [self.x, self.y] #location = mesh_grid5.find_node(self.x,self.y) #self.node = location #print vdistsqr(loc,current_destination) if vdistsqr(loc, current_destination) < 0.5: #print self.destnumber self.destnumber = self.destnumber + 1 #self.draw() else: self.set_random_goal() self.set_path() #print "Checking again" if self.path == None: print "waaat"