package negotiator.parties; import java.util.List; import genius.core.Bid; import genius.core.Domain; import genius.core.actions.Action; import genius.core.actions.Offer; import genius.core.parties.AbstractNegotiationParty; import genius.core.parties.NegotiationInfo; import genius.core.uncertainty.BidRanking; import genius.core.uncertainty.ExperimentalUserModel; import genius.core.utility.AbstractUtilitySpace; import genius.core.utility.CustomUtilitySpace; /** * Example of a party that deals with preference uncertainty by defining a custom UtilitySpace * based on the closest known bid. * * Given a bid b and a preference ranking o1 <= o2 <= ... < on from the user model, it does the following: * It finds the outcome oi that is 'most similar' to b (in terms of overlapping values) * It then estimates u(b) to be: (i / n) * (highestUtil - lowestUtil) * * Note that this agent's estimate of the utility function is not linear additive. */ public class CustomUtilitySpaceExampleParty extends AbstractNegotiationParty { @Override public void init(NegotiationInfo info) { super.init(info); log("This is an example of a party that deals with preference uncertainty by defining with a Custom UtilitySpace estimate."); log("The user model is: " + userModel); if (userModel == null) { log("There is no preference uncertainty. Try this agent with a negotiation scenario that has preference uncertainty enabled."); return; } log("Lowest util: " + userModel.getBidRanking().getLowUtility() + ". Highest util: " + userModel.getBidRanking().getHighUtility()); log("The estimated utility space is: " + getUtilitySpace()); Bid randomBid = getUtilitySpace().getDomain().getRandomBid(rand); log("The estimate of the utility of a random bid (" + randomBid + ") is: " + getUtility(randomBid)); if (userModel instanceof ExperimentalUserModel) { log("You have given the agent access to the real utility space for debugging purposes."); ExperimentalUserModel e = (ExperimentalUserModel) userModel; AbstractUtilitySpace realUSpace = e.getRealUtilitySpace(); log("The real utility space is: " + realUSpace); log("The real utility of the random bid is: " + realUSpace.getUtility(randomBid)); } } /** * A simple concession function over time */ @Override public Action chooseAction(List> possibleActions) { double target = 1; // Return a random, conceding offer Bid randomBid; do { randomBid = generateRandomBid(); target *= 0.999; } while (getUtility(randomBid) < target); return new Offer(getPartyId(), randomBid); } /** * We override the default estimate of the utility * space by using {@link ClosestKnownBid} defined below. */ @Override public AbstractUtilitySpace estimateUtilitySpace() { return new ClosestKnownBid(getDomain()); } @Override public String getDescription() { return "Example agent with a custom utility space"; } private class ClosestKnownBid extends CustomUtilitySpace { public ClosestKnownBid(Domain dom) { super(dom); } @Override public double getUtility(Bid bid) { Bid closestRankedBid = getClosestBidRanked(bid); System.out.println("Closest bid: " + closestRankedBid); return estimateUtilityOfRankedBid(closestRankedBid); } public double estimateUtilityOfRankedBid(Bid b) { BidRanking bidRanking = getUserModel().getBidRanking(); int i = bidRanking.indexOf(b); System.out.println("Index: " + i); // index:0 has utility 0, index n-1 has utility 1 return i / (double) bidRanking.getSize(); } /** * Finds the bid in the bid ranking that is most similar to bid given in the argument bid */ public Bid getClosestBidRanked(Bid bid) { List bidOrder = getUserModel().getBidRanking().getBidOrder(); Bid closestBid = null; double closestDistance = Double.MAX_VALUE; for (Bid b : bidOrder) { double d = 1 / (double) b.countEqualValues(bid); if (d < closestDistance) { closestDistance = d; closestBid = b; } } return closestBid; } } private static void log(String s) { System.out.println(s); } }