[151] | 1 | package negotiator.parties;
|
---|
| 2 |
|
---|
| 3 | import java.util.List;
|
---|
| 4 |
|
---|
| 5 | import genius.core.Bid;
|
---|
| 6 | import genius.core.Domain;
|
---|
| 7 | import genius.core.actions.Action;
|
---|
| 8 | import genius.core.actions.Offer;
|
---|
| 9 | import genius.core.parties.AbstractNegotiationParty;
|
---|
| 10 | import genius.core.parties.NegotiationInfo;
|
---|
| 11 | import genius.core.uncertainty.BidRanking;
|
---|
| 12 | import genius.core.uncertainty.ExperimentalUserModel;
|
---|
| 13 | import genius.core.utility.AbstractUtilitySpace;
|
---|
| 14 | import genius.core.utility.CustomUtilitySpace;
|
---|
| 15 |
|
---|
[166] | 16 | /**
|
---|
[167] | 17 | * Example of a party that deals with preference uncertainty by defining a custom UtilitySpace
|
---|
| 18 | * based on the closest known bid.
|
---|
| 19 | *
|
---|
| 20 | * Given a bid b and a preference ranking o1 <= o2 <= ... < on from the user model, it does the following:
|
---|
| 21 | * It finds the outcome oi that is 'most similar' to b (in terms of overlapping values)
|
---|
| 22 | * It then estimates u(b) to be: (i / n) * (highestUtil - lowestUtil)
|
---|
| 23 | *
|
---|
| 24 | * Note that this agent's estimate of the utility function is not linear additive.
|
---|
[166] | 25 | */
|
---|
| 26 | public class CustomUtilitySpaceExampleParty extends AbstractNegotiationParty
|
---|
[151] | 27 | {
|
---|
| 28 |
|
---|
| 29 | @Override
|
---|
| 30 | public void init(NegotiationInfo info)
|
---|
| 31 | {
|
---|
| 32 | super.init(info);
|
---|
[167] | 33 | log("This is an example of a party that deals with preference uncertainty by defining with a Custom UtilitySpace estimate.");
|
---|
[151] | 34 | log("The user model is: " + userModel);
|
---|
[167] | 35 | if (userModel == null)
|
---|
| 36 | {
|
---|
| 37 | log("There is no preference uncertainty. Try this agent with a negotiation scenario that has preference uncertainty enabled.");
|
---|
| 38 | return;
|
---|
| 39 | }
|
---|
| 40 |
|
---|
| 41 | log("Lowest util: " + userModel.getBidRanking().getLowUtility()
|
---|
| 42 | + ". Highest util: " + userModel.getBidRanking().getHighUtility());
|
---|
| 43 | log("The estimated utility space is: " + getUtilitySpace());
|
---|
[151] | 44 |
|
---|
| 45 | Bid randomBid = getUtilitySpace().getDomain().getRandomBid(rand);
|
---|
[167] | 46 | log("The estimate of the utility of a random bid (" + randomBid + ") is: " + getUtility(randomBid));
|
---|
[151] | 47 |
|
---|
[167] | 48 | if (userModel instanceof ExperimentalUserModel)
|
---|
| 49 | {
|
---|
[151] | 50 | log("You have given the agent access to the real utility space for debugging purposes.");
|
---|
| 51 | ExperimentalUserModel e = (ExperimentalUserModel) userModel;
|
---|
| 52 | AbstractUtilitySpace realUSpace = e.getRealUtilitySpace();
|
---|
| 53 |
|
---|
| 54 | log("The real utility space is: " + realUSpace);
|
---|
| 55 | log("The real utility of the random bid is: "
|
---|
| 56 | + realUSpace.getUtility(randomBid));
|
---|
| 57 | }
|
---|
| 58 | }
|
---|
| 59 |
|
---|
[167] | 60 | /**
|
---|
| 61 | * A simple concession function over time
|
---|
| 62 | */
|
---|
[151] | 63 | @Override
|
---|
| 64 | public Action chooseAction(List<Class<? extends Action>> possibleActions)
|
---|
| 65 | {
|
---|
[166] | 66 | double target = 1;
|
---|
| 67 | // Return a random, conceding offer
|
---|
[151] | 68 | Bid randomBid;
|
---|
| 69 | do
|
---|
| 70 | {
|
---|
| 71 | randomBid = generateRandomBid();
|
---|
[166] | 72 | target *= 0.999;
|
---|
[151] | 73 | }
|
---|
[166] | 74 | while (getUtility(randomBid) < target);
|
---|
[151] | 75 | return new Offer(getPartyId(), randomBid);
|
---|
| 76 | }
|
---|
| 77 |
|
---|
| 78 | /**
|
---|
| 79 | * We override the default estimate of the utility
|
---|
| 80 | * space by using {@link ClosestKnownBid} defined below.
|
---|
| 81 | */
|
---|
| 82 | @Override
|
---|
| 83 | public AbstractUtilitySpace estimateUtilitySpace()
|
---|
| 84 | {
|
---|
| 85 | return new ClosestKnownBid(getDomain());
|
---|
| 86 | }
|
---|
| 87 |
|
---|
| 88 | @Override
|
---|
| 89 | public String getDescription() {
|
---|
| 90 | return "Example agent with a custom utility space";
|
---|
| 91 | }
|
---|
| 92 |
|
---|
| 93 | private class ClosestKnownBid extends CustomUtilitySpace
|
---|
| 94 | {
|
---|
| 95 |
|
---|
| 96 | public ClosestKnownBid(Domain dom) {
|
---|
| 97 | super(dom);
|
---|
| 98 | }
|
---|
| 99 |
|
---|
| 100 | @Override
|
---|
| 101 | public double getUtility(Bid bid)
|
---|
| 102 | {
|
---|
| 103 | Bid closestRankedBid = getClosestBidRanked(bid);
|
---|
| 104 | System.out.println("Closest bid: " + closestRankedBid);
|
---|
| 105 | return estimateUtilityOfRankedBid(closestRankedBid);
|
---|
| 106 | }
|
---|
| 107 |
|
---|
| 108 | public double estimateUtilityOfRankedBid(Bid b)
|
---|
| 109 | {
|
---|
| 110 | BidRanking bidRanking = getUserModel().getBidRanking();
|
---|
| 111 | int i = bidRanking.indexOf(b);
|
---|
| 112 |
|
---|
| 113 | System.out.println("Index: " + i);
|
---|
| 114 | // index:0 has utility 0, index n-1 has utility 1
|
---|
| 115 | return i / (double) bidRanking.getSize();
|
---|
| 116 | }
|
---|
| 117 |
|
---|
[167] | 118 | /**
|
---|
| 119 | * Finds the bid in the bid ranking that is most similar to bid given in the argument bid
|
---|
| 120 | */
|
---|
[151] | 121 | public Bid getClosestBidRanked(Bid bid)
|
---|
| 122 | {
|
---|
| 123 | List<Bid> bidOrder = getUserModel().getBidRanking().getBidOrder();
|
---|
| 124 | Bid closestBid = null;
|
---|
| 125 | double closestDistance = Double.MAX_VALUE;
|
---|
| 126 |
|
---|
| 127 | for (Bid b : bidOrder)
|
---|
| 128 | {
|
---|
| 129 | double d = 1 / (double) b.countEqualValues(bid);
|
---|
| 130 | if (d < closestDistance)
|
---|
| 131 | {
|
---|
| 132 | closestDistance = d;
|
---|
| 133 | closestBid = b;
|
---|
| 134 | }
|
---|
| 135 | }
|
---|
| 136 | return closestBid;
|
---|
| 137 | }
|
---|
| 138 |
|
---|
| 139 | }
|
---|
[167] | 140 |
|
---|
| 141 | private static void log(String s)
|
---|
| 142 | {
|
---|
| 143 | System.out.println(s);
|
---|
| 144 | }
|
---|
[151] | 145 |
|
---|
| 146 | }
|
---|