[127] | 1 | package agents;
|
---|
| 2 |
|
---|
| 3 | import java.util.List;
|
---|
| 4 |
|
---|
| 5 | import genius.core.Bid;
|
---|
| 6 | import genius.core.actions.Accept;
|
---|
| 7 | import genius.core.actions.Action;
|
---|
| 8 | import genius.core.actions.Offer;
|
---|
| 9 | import genius.core.parties.AbstractNegotiationParty;
|
---|
| 10 | import genius.core.uncertainty.AdditiveUtilitySpaceFactory;
|
---|
| 11 | import genius.core.uncertainty.ExperimentalUserModel;
|
---|
| 12 | import genius.core.utility.AbstractUtilitySpace;
|
---|
| 13 |
|
---|
| 14 | public class UncertaintyAgentExample extends AbstractNegotiationParty
|
---|
| 15 | {
|
---|
| 16 |
|
---|
| 17 | @Override
|
---|
| 18 | public Action chooseAction(List<Class<? extends Action>> possibleActions)
|
---|
| 19 | {
|
---|
| 20 | log("This is the UncertaintyAgentExample.");
|
---|
| 21 | log("The user model is: " + userModel);
|
---|
| 22 | log("The default estimated utility space is: " + getUtilitySpace());
|
---|
| 23 |
|
---|
| 24 | Bid randomBid = getUtilitySpace().getDomain().getRandomBid(rand);
|
---|
| 25 | log("The default estimate of the utility of a random bid + " + randomBid + " is: " + getUtility(randomBid));
|
---|
| 26 |
|
---|
| 27 | if (userModel instanceof ExperimentalUserModel)
|
---|
| 28 | {
|
---|
| 29 | log("You have given the agent access to the real utility space for debugging purposes.");
|
---|
| 30 | ExperimentalUserModel e = (ExperimentalUserModel) userModel;
|
---|
| 31 | AbstractUtilitySpace realUSpace = e.getRealUtilitySpace();
|
---|
| 32 |
|
---|
| 33 | log("The real utility space is: " + realUSpace);
|
---|
| 34 | log("The real utility of the random bid is: " + realUSpace.getUtility(randomBid));
|
---|
| 35 | }
|
---|
| 36 |
|
---|
| 37 | // Sample code that accepts offers that appear in the top 10% of offers in the user model
|
---|
| 38 | if (getLastReceivedAction() instanceof Offer)
|
---|
| 39 | {
|
---|
| 40 | Bid receivedBid = ((Offer) getLastReceivedAction()).getBid();
|
---|
| 41 | List<Bid> bidOrder = userModel.getBidRanking().getBidOrder();
|
---|
| 42 |
|
---|
| 43 | // If the rank of the received bid is known
|
---|
| 44 | if (bidOrder.contains(receivedBid))
|
---|
| 45 | {
|
---|
| 46 | double percentile = (bidOrder.size() - bidOrder.indexOf(receivedBid)) / (double) bidOrder.size();
|
---|
| 47 | if (percentile < 0.1)
|
---|
| 48 | return new Accept(getPartyId(), receivedBid);
|
---|
| 49 | }
|
---|
| 50 | }
|
---|
| 51 |
|
---|
| 52 | // Otherwise, return a random offer
|
---|
| 53 | return new Offer(getPartyId(), generateRandomBid());
|
---|
| 54 | }
|
---|
| 55 |
|
---|
| 56 | private void log(String s)
|
---|
| 57 | {
|
---|
| 58 | System.out.println(s);
|
---|
| 59 | }
|
---|
| 60 |
|
---|
| 61 | /**
|
---|
| 62 | * With this method, you can override the default estimate of the utility space given uncertain preferences specified by the user model.
|
---|
| 63 | * This example sets every value to zero.
|
---|
| 64 | */
|
---|
| 65 | @Override
|
---|
| 66 | public AbstractUtilitySpace estimateUtilitySpace()
|
---|
| 67 | {
|
---|
| 68 | return new AdditiveUtilitySpaceFactory(getDomain()).getUtilitySpace();
|
---|
| 69 | }
|
---|
| 70 |
|
---|
| 71 |
|
---|
| 72 | @Override
|
---|
| 73 | public String getDescription()
|
---|
| 74 | {
|
---|
| 75 | return "Example agent that can deal with uncertain preferences";
|
---|
| 76 | }
|
---|
| 77 |
|
---|
| 78 | }
|
---|