/** * */ package agents; import java.util.ArrayList; import master.Product; /** * @author mbilgic * */ public class AgentPhase25405 extends RationalBaselineAgent { //This agent learns only the market condition double marketCondition = 0.5; /** * @param id */ public AgentPhase25405(String id) { super(id); } public class goodVtotal{ int good = 0; int total = 0; public goodVtotal(boolean first){ incrementer(first); } public goodVtotal(){ } public int getGood(){ return good; } public int getTotal(){ return total; } public void incrementer(boolean in){ good += in?1:0; ++total; } public String toString(){ return good+ " / " + total; } } goodVtotal[] typearray = null; /* (non-Javadoc) * @see agents.Agent#learn(java.util.ArrayList) */ @Override public void learn(ArrayList> trainingInstances) { if (typearray == null){ typearray = new goodVtotal[1< j : trainingInstances){ typearray[indexShifter(j)].incrementer(j.get(j.size()-1).equals("G")?true:false); } } public int indexShifter(ArrayList in){ if(in.get(in.size()-1).equals("G") || in.get(in.size()-1).equals("B")){ in = (ArrayList)in.clone(); in.remove(in.size()-1); } int out = 0; for(int spot = 0; spot < in.size(); ++spot){ if(in.get(spot).equals("T")){ out += 1<<(in.size()-1)-spot; } } return out; } /* (non-Javadoc) * @see agents.Agent#computeProbOfGood(java.util.ArrayList) */ @Override public double computeProbOfGood(ArrayList prodFeatures) { return typearray[indexShifter(prodFeatures)].getGood()/(double)typearray[indexShifter(prodFeatures)].getTotal(); } }