import org.JIFSA.*; import org.JIFSA.reasoning.*; import org.JIFSA.reasoning.actionselection.*; import org.JIFSA.reasoning.actionselection.actionestimation.*; import org.JIFSA.reasoning.casebasesearch.*; import org.JIFSA.reasoning.distance.*; import org.JIFSA.reasoning.distance.globaldistance.OrderIndexMatchingAlgorithm; import org.JIFSA.reasoning.distance.penalty.*; import org.JIFSA.reasoning.distance.spatial2D.*; import org.JIFSA.sensoryItems.*; import org.JIFSA.tools.*; public class SampleAgent { public static void main(String[] args) { //we load a casebase that we have previously created CaseBase casebase = CaseBaseIO.loadCaseBase("myCaseBase.cb"); //we create a 1-Nearest Neighbour Search CaseBaseSearch cbSearch = new NearestNeighbourSearch(1); //set the default distance calculation between SensoryItems to just // test to see if they are equal (EqualityDistanceAlgorithm) SensoryItem.setDistanceCalculation(new EqualityDistanceAlgorithm()); //set the penalty for unmatched SensoryItems to be a constant - 100 SensoryItem.setPenaltyDistanceCalculation(new ConstantPenalty(100)); //set SensoryItems of the Spatial2DObject type to use the PolarDistanceAlgorithm Spatial2DObject.setDistanceCalculation(new PolarDistanceAlgorithm()); //create the weights so that unspecified SensoryItems have a default value of 1.0 Weights w = new Weights(1.0f); //we set the distance measure between Cases to be OrderIndexMatching GlobalDistanceMeasure gd = new OrderIndexMatchingAlgorithm(w); Case.setGlobalDistanceCalculation(gd); //We set how actions are selected, based on the results from the NN search ActionEstimation ae = new LastActionEstimate(); ActionSelection actionSelection = new ClosestNeighbourSelection(ae); //now we put together what we have created and make an Agent Agent ag = new Agent(casebase,cbSearch,actionSelection); //the agent is now ready to go into action AgentInputs newInputs = new AgentInputs(); AgentAction act = ag.senseEnvironment(newInputs); System.out.println("My Agent performed the action: " + act.getActionName()); } } |
Research Projects > Software Agent Imitation > Developers > Software Agent Imitation - Code Examples >