[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.utility.AbstractUtilitySpace;
|
---|
| 12 |
|
---|
| 13 | public class UncertaintyAgentExample extends AbstractNegotiationParty
|
---|
| 14 | {
|
---|
| 15 |
|
---|
| 16 | @Override
|
---|
| 17 | public Action chooseAction(List<Class<? extends Action>> possibleActions)
|
---|
| 18 | {
|
---|
| 19 |
|
---|
| 20 | // Sample code that accepts offers that appear in the top 10% of offers in the user model
|
---|
| 21 | if (getLastReceivedAction() instanceof Offer)
|
---|
| 22 | {
|
---|
| 23 | Bid receivedBid = ((Offer) getLastReceivedAction()).getBid();
|
---|
| 24 | List<Bid> bidOrder = userModel.getBidRanking().getBidOrder();
|
---|
| 25 |
|
---|
| 26 | // If the rank of the received bid is known
|
---|
| 27 | if (bidOrder.contains(receivedBid))
|
---|
| 28 | {
|
---|
| 29 | double percentile = (bidOrder.size() - bidOrder.indexOf(receivedBid)) / (double) bidOrder.size();
|
---|
| 30 | if (percentile < 0.1)
|
---|
| 31 | return new Accept(getPartyId(), receivedBid);
|
---|
| 32 | }
|
---|
| 33 | }
|
---|
| 34 |
|
---|
| 35 | // Otherwise, return a random offer
|
---|
| 36 | return new Offer(getPartyId(), generateRandomBid());
|
---|
| 37 | }
|
---|
| 38 |
|
---|
| 39 | private void log(String s)
|
---|
| 40 | {
|
---|
| 41 | System.out.println(s);
|
---|
| 42 | }
|
---|
| 43 |
|
---|
| 44 | /**
|
---|
| 45 | * With this method, you can override the default estimate of the utility space given uncertain preferences specified by the user model.
|
---|
| 46 | * This example sets every value to zero.
|
---|
| 47 | */
|
---|
| 48 | @Override
|
---|
| 49 | public AbstractUtilitySpace estimateUtilitySpace()
|
---|
| 50 | {
|
---|
| 51 | return new AdditiveUtilitySpaceFactory(getDomain()).getUtilitySpace();
|
---|
| 52 | }
|
---|
| 53 |
|
---|
| 54 |
|
---|
| 55 | @Override
|
---|
| 56 | public String getDescription()
|
---|
| 57 | {
|
---|
| 58 | return "Example agent that can deal with uncertain preferences";
|
---|
| 59 | }
|
---|
| 60 |
|
---|
| 61 | }
|
---|