package geniusweb.exampleparties.simpleshaop; import java.util.HashMap; import java.util.Map.Entry; import geniusweb.issuevalue.Bid; import geniusweb.issuevalue.DiscreteValue; import geniusweb.issuevalue.Domain; import geniusweb.issuevalue.Value; /** * This class contains main agent methods and algorithms that agent uses in a * negotiation session based on Alternating Offers protocol. * * @author Siamak Hajizadeh, Thijs van Krimpen, Daphne Looije * */ public class FrequencyModel { private BidHistory bidHistory; private final double LEARNING_COEF = 0.2D; private final int LEARNING_VALUE_ADDITION = 1; private Bid opponentLastBid = null; private Domain domain = null; private USpace oppUtility = null; private int numberOfIssues = 0; /** * handles some initializations. it is called when agent object is created * to start a negotiation session * */ public FrequencyModel(USpace utilitySpace) { bidHistory = new BidHistory(utilitySpace); oppUtility = utilitySpace; domain = utilitySpace.getDomain(); numberOfIssues = domain.getIssues().size(); /* double w = 1D / numberOfIssues; for ( String e : oppUtility.getEvals().keySet()) { oppUtility.setWeight(e, w); try { // set the initial weight for each value of each issue to 1. for ( String issue : oppUtility.getEvals().keySet() ) for ( Value val : oppUtility.getValues(issue).keySet() ) oppUtility.setEval(issue, val, 1.0); } catch (Exception ex) { ex.printStackTrace(); } } */ } /** * Contains an object of type {@link AdditiveUtilitySpace} that is updated * over time and as bids are received, to match the preference profile of * the opponent. * */ public void updateLearner(Bid bid) { opponentLastBid = bid; bidHistory.addOpponentBid(opponentLastBid); if (bidHistory.getOpponentBidCount() < 2) return; int numberOfUnchanged = 0; HashMap lastDiffSet = bidHistory .BidDifferenceofOpponentsLastTwo(); // counting the number of unchanged issues for (String i : lastDiffSet.keySet()) { if (lastDiffSet.get(i) == 0) numberOfUnchanged++; } // This is the value to be added to weights of unchanged issues before // normalization. // Also the value that is taken as the minimum possible weight, // (therefore defining the maximum possible also). double goldenValue = LEARNING_COEF / numberOfIssues; // The total sum of weights before normalization. double totalSum = 1D + goldenValue * numberOfUnchanged; // The maximum possible weight double maximumWeight = 1D - (numberOfIssues) * goldenValue / totalSum; // re-weighing issues while making sure that the sum remains 1 for (String issue : lastDiffSet.keySet()) { if (lastDiffSet.get(issue) == 0 && oppUtility.getWeight(issue) < maximumWeight) oppUtility.setWeight(issue, (oppUtility.getWeight(issue) + goldenValue) / totalSum); else oppUtility.setWeight(issue, oppUtility.getWeight(issue) / totalSum); } // اضافه کردن مقدار یک به ولیو ها بدون نرمالایز for ( String issue : bid.getIssueValues().keySet() ) { Value val = bid.getValue(issue); oppUtility.setEval(issue, val, (oppUtility.getValue(issue, val)+LEARNING_VALUE_ADDITION) ); } } public USpace getOpponentUtilitySpace() { return oppUtility; } }