package onetomany.bargainingchipsgame; import java.util.List; import java.util.ArrayList; import onetomany.bargainingchipsgame.players.utilityfunction.UtilityFunction; /** * This class generates the complete outcome space and is therefore useful if * someone wants to quickly implement an agent. Note that working with a sorted * outcomespace class would be faster during the negotiation. */ public class OutcomeSpace { /** List of all possible bids in the domain */ protected List allBids = new ArrayList(); /** * Creates an unsorted outcome space. Warning: this call iterates over ALL * possible bids. * * @param utilSpace */ public OutcomeSpace(Domain domain) { generateAllBids(); } /** * Generates all the possible bids in the domain * * @param utilSpace */ public void generateAllBids() { } /** * @return list of all possible bids */ public List getAllOutcomes() { return allBids; } /** * gets a BidDetails which is closest to the given utility * * @param utility * to which the found bid must be closest. * @return BidDetails */ public Bundle getBidNearUtility(double utility, UtilityFunction u) { return allBids.get(getIndexOfBidNearUtility(utility, u)); } /** * @return best bid in the domain. */ public Bundle getMaxBidPossible(UtilityFunction u) { Bundle maxBid = allBids.get(0); for (Bundle bid : allBids) { if (u.getUtility(bid) > u.getUtility(maxBid)) { maxBid = bid; } } return maxBid; } /** * @return worst bid in the domain. */ public Bundle getMinBidPossible(UtilityFunction u) { Bundle minBid = allBids.get(0); for (Bundle bid : allBids) { if (u.getUtility(bid) < u.getUtility(minBid)) { minBid = bid; } } return minBid; } /** * @param utility * to which the found bid must be closest. * @return index of the bid with the utility closest to the given utilty. */ public int getIndexOfBidNearUtility(double utility, UtilityFunction u) { double closesDistance = 1; int best = 0; for (int i = 0; i < allBids.size(); i++) { if (Math.abs(u.getUtility(allBids.get(i)) - utility) < closesDistance) { closesDistance = Math.abs(u.getUtility(allBids.get(i)) - utility); best = i; } } return best; } @Override public String toString() { String all = ""; for (Bundle b : allBids) { all += b.toString() + "\n,"; } return "OutcomeSpace[" + all + "]"; } }