def logicStillValid(self, verbose=False): # Check if we still have new places to explore if self._spots: if not self.hasNewPlacesToExplore(): if verbose: print("Can no longer find new locations to explore") return False # Check if we can still place all our items if not self.canStillPlaceItemPool(): if verbose: print("Can no longer place our item pool") return False # Finally, check if the logic still makes everything accessible when we have all the items. e = explorer.Explorer() for item_pool_item, count in self._item_pool.items(): e.addItem(item_pool_item, count) e.visit(self._logic.start) if self._accessibility_rule == "goal": return self._logic.windfish in e.getAccessableLocations() else: if len(e.getAccessableLocations()) != len( self._logic.location_list): if verbose: for loc in self._logic.location_list: if loc not in e.getAccessableLocations(): print("Cannot access: ", loc.items) print( "Not all locations are accessible anymore with the full item pool" ) return False return True
def hasNewPlacesToExplore(self): e = explorer.Explorer() e.visit(self.__logic.start) for loc in e.getAccessableLocations(): for spot in loc.items: if spot.item is None: return True return False
def __placeItem(self, rnd): e = explorer.Explorer() e.visit(self.__logic.start) if self.__accessibility_rule == "goal" and self.__logic.windfish in e.getAccessableLocations( ): spots = self.__spots req_items = [] else: spots = [ spot for loc in e.getAccessableLocations() for spot in loc.items if spot.item is None ] req_items = [ item for item in sorted(e.getRequiredItemsForNextLocations()) if item in self.__item_pool ] if not req_items: for di in self.DUNGEON_ITEMS: if di in self.__item_pool: req_items = [ item for item in self.DUNGEON_ITEMS if item in self.__item_pool ] break if req_items: if "RUPEES" in req_items: req_items += [ RUPEES_20, RUPEES_50, RUPEES_100, RUPEES_200, RUPEES_500 ] else: req_items = [item for item in sorted(self.__item_pool.keys())] item = rnd.choice(req_items) spots = list( sorted([spot for spot in spots if item in spot.getOptions()], key=lambda spot: spot.nameId)) if not spots: return False spot = rnd.choices(spots, [spot.weight for spot in spots])[0] spot.item = item if self.__accessibility_rule != "goal" or self.__logic.windfish not in e.getAccessableLocations( ): if e.getRequiredItemsForNextLocations( ) and not self.hasNewPlacesToExplore(): spot.item = None return False self.removeItem(spot.item) self.removeSpot(spot) if not self.canStillPlaceItemPool(): self.addItem(spot.item) self.addSpot(spot) spot.item = None return False # For each item placed, make all accessible locations less likely to be picked for spot in spots: spot.weight *= self.__forwardfactor return True
def create_ant(self, loc): """ Create an Explorer ant if needed. Returns the new ant if it has been created, None otherwise """ ant_loc = self.find_available_pos(loc) if ant_loc is None: ant_loc = self.random_location() newant = explorer.Explorer(loc, self.bot, self.world, self, ant_loc, self.food_range) self.ants.append(newant) self.log.info("Creating new explorer %s with area %s", newant, ant_loc) return newant
def __init__(self): """ Setup the MovementNode: - Initialises the state - Gathers the maps and creates their models - Creates all publishers and subscribers """ self.pose = Pose() # The robots believed pose # Wait for the maps to be broadcast rospy.loginfo("Waiting for a map...") try: occupancy_map = rospy.wait_for_message("/map", OccupancyGrid, 20) available_space = rospy.wait_for_message("/available_space", OccupancyGrid, 20) except: rospy.logerr( "Problem getting maps. Check that you have a map_server" " running: rosrun map_server map_server <mapname> ") sys.exit(1) rospy.loginfo("Maps received. %d X %d, %f px/m." % (occupancy_map.info.width, occupancy_map.info.height, occupancy_map.info.resolution)) # Create the map models from the received maps self.occ_map_model = map_model.MapModel(occupancy_map) self.avail_space_model = map_model.MapModel(available_space) self.explorer = explorer.Explorer(self.avail_space_model) # Listen for estimated poses from amcl self.estimatedPoseListener = rospy.Subscriber( "/amcl_pose", PoseWithCovarianceStamped, self.estimated_pose_listener, queue_size=100) rospy.loginfo("Init complete!") # Wait for the initial pose and trigger when it's received rospy.loginfo("Waiting for initial pose...") try: pose_message = rospy.wait_for_message("/initialpose", PoseWithCovarianceStamped) except: rospy.logerr("Failed to receive initial pose!") rospy.loginfo("Received initial pose!") self.pose = pose_message
def _loadItems(self, args, roms): remainingItems = set(self.logic.iteminfo_list) currentSphere = 0 lastAccessibleLocations = set() itemContents = {} for ii in self.logic.iteminfo_list: if not hasattr(ii, "world"): ii.world = 0 itemContents[ii] = ii.read(roms[ii.world]) # Feed the logic items one sphere at a time while remainingItems: e = explorer.Explorer() e.visit(self.logic.start) newLocations = e.getAccessableLocations() - lastAccessibleLocations if not newLocations: # Some locations must be inaccessible, stop counting spheres break for location in newLocations: for ii in location.items: ii.metadata.sphere = currentSphere ii.item = itemContents[ii] if ii in remainingItems: remainingItems.remove(ii) lastAccessibleLocations = e.getAccessableLocations() currentSphere += 1 for ii in remainingItems: ii.item = itemContents[ii] for location in e.getAccessableLocations(): for ii in location.items: self.accessibleItems.append( SpoilerItemInfo(ii, roms[ii.world], args.multiworld)) if len(e.getAccessableLocations()) != len(self.logic.location_list): self.inaccessibleItems = [] for loc in self.logic.location_list: if loc not in e.getAccessableLocations(): for ii in loc.items: self.inaccessibleItems.append( SpoilerItemInfo(ii, roms[ii.world], args.multiworld))
def _loadItems(self, args, rom): my_logic = logic.Logic(args, None, entranceMapping=self.dungeonOrder) remainingItems = set(my_logic.iteminfo_list) currentSphere = 0 lastAccessibleLocations = set() itemContents = {} for ii in my_logic.iteminfo_list: itemContents[ii] = ii.read(rom) # Feed the logic items one sphere at a time while remainingItems: e = explorer.Explorer() e.visit(my_logic.start) newLocations = e.getAccessableLocations() - lastAccessibleLocations if not newLocations: # Some locations must be inaccessible, stop counting spheres break for location in newLocations: for ii in location.items: ii.metadata.sphere = currentSphere ii.item = itemContents[ii] remainingItems.remove(ii) lastAccessibleLocations = e.getAccessableLocations() currentSphere += 1 for ii in remainingItems: ii.item = itemContents[ii] for location in e.getAccessableLocations(): for ii in location.items: self.accessibleItems.append(SpoilerItemInfo(ii, rom, args.multiworld)) if len(e.getAccessableLocations()) != len(my_logic.location_list): self.inaccessibleItems = [] for loc in my_logic.location_list: if loc not in e.getAccessableLocations(): for ii in loc.items: self.inaccessibleItems.append(SpoilerItemInfo(ii, rom, args.multiworld))
def __init__(self, *args, **kwargs): wx.Dialog.__init__(self, *args, **kwargs) sizer = wx.BoxSizer(wx.VERTICAL) self.SetSizer(sizer) sizer.SetSizeHints(self) self._explorer = explorer.Explorer(self) sizer.Add(self._explorer, 1, wx.EXPAND) buttons_sizer = wx.BoxSizer(wx.HORIZONTAL) sizer.Add(buttons_sizer, 0, wx.EXPAND) self._import_button = wx.Button(self, wx.ID_OK, "&Import") buttons_sizer.Add(self._import_button, 0) self._cancel_button = wx.Button(self, wx.ID_CANCEL, "&Cancel") buttons_sizer.Add(self._cancel_button, 0) self._explorer.hierarchy_tree.Bind(wx.EVT_TREE_SEL_CHANGED, self.OnInformationEntitySelected) self._cancel_button.Bind(wx.EVT_BUTTON, self.OnClose) self.Bind(wx.EVT_CLOSE, self.OnClose)
logger.save_model_info(dict(model=(args.model, model_kwargs))) first_epoch = 1 if args.initialize_from_model != '': print('Trying to load model weights from', args.initialize_from_model) model.load_state_dict(logger.load_model_state_dict( path=os.path.join(args.initialize_from_model, 'current_model.pt')), strict=False) print(logger.logdir) ############################################################################### # Explore ? ############################################################################### if explorer_mode: explorer = explorer.Explorer(args, dataset, model, optimizer, logger) explorer.analyze() sys.exit(0) ############################################################################### # Training code ############################################################################### # At any point you can hit Ctrl + C to break out of training early. try: for epoch in range(first_epoch - args.eval_first, args.epochs+1): logger.mark_epoch_start(epoch) if epoch >= first_epoch: model.train_on(dataset.train.iter_epoch(args.batch_size), optimizer,
def __init__(self, desiredCapabilities): self.explorer = explorer.Explorer(desiredCapabilities) self.test_num = 0 self.MAX_TEST_NUM = 3