001 package aima.search.map; 002 003 import java.util.ArrayList; 004 import java.util.List; 005 006 import aima.basic.Percept; 007 import aima.search.framework.Successor; 008 import aima.search.framework.SuccessorFunction; 009 010 /** 011 * Implementation of SuccessorFunction interface that derives successors based on the 012 * locations linked/traversible to the current location. 013 */ 014 015 /** 016 * @author Ciaran O'Reilly 017 * 018 */ 019 public class MapSuccessorFunction implements SuccessorFunction { 020 021 private Map map = null; 022 023 public MapSuccessorFunction(Map aMap) { 024 this.map = aMap; 025 } 026 027 public List getSuccessors(Object currentState) { 028 List<Successor> successors = new ArrayList<Successor>(); 029 030 String location = currentState.toString(); 031 if (currentState instanceof Percept) { 032 location = (String) ((Percept) currentState) 033 .getAttribute(DynAttributeNames.PERCEPT_IN); 034 } 035 036 List<String> linkedLocations = map.getLocationsLinkedTo(location); 037 for (String linkLoc : linkedLocations) { 038 successors.add(new Successor(linkLoc, linkLoc)); 039 } 040 041 return successors; 042 } 043 }