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