001 package aima.search.framework; 002 003 import java.util.Iterator; 004 import java.util.List; 005 import java.util.Properties; 006 007 import aima.basic.Agent; 008 import aima.basic.Percept; 009 010 /** 011 * @author Ravi Mohan 012 * 013 */ 014 015 public class SearchAgent extends Agent { 016 List actionList; 017 018 private Iterator actionIterator; 019 020 private Metrics searchMetrics; 021 022 public SearchAgent(Problem p, Search search) throws Exception { 023 actionList = search.search(p); 024 actionIterator = actionList.iterator(); 025 searchMetrics = search.getMetrics(); 026 027 } 028 029 @Override 030 public String execute(Percept p) { 031 if (actionIterator.hasNext()) { 032 return (String) actionIterator.next(); 033 } else { 034 return "NoOp"; 035 } 036 } 037 038 public List getActions() { 039 return actionList; 040 } 041 042 public Properties getInstrumentation() { 043 Properties retVal = new Properties(); 044 Iterator iter = searchMetrics.keySet().iterator(); 045 while (iter.hasNext()) { 046 String key = (String) iter.next(); 047 String value = searchMetrics.get(key); 048 retVal.setProperty(key, value); 049 } 050 return retVal; 051 } 052 053 }