[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;
|
---|
[181] | 9 | import genius.core.issue.IssueDiscrete;
|
---|
| 10 | import genius.core.issue.ValueDiscrete;
|
---|
[127] | 11 | import genius.core.parties.AbstractNegotiationParty;
|
---|
| 12 | import genius.core.uncertainty.AdditiveUtilitySpaceFactory;
|
---|
| 13 | import genius.core.utility.AbstractUtilitySpace;
|
---|
| 14 |
|
---|
[182] | 15 | @SuppressWarnings("serial")
|
---|
[127] | 16 | public class UncertaintyAgentExample extends AbstractNegotiationParty
|
---|
| 17 | {
|
---|
| 18 |
|
---|
| 19 | @Override
|
---|
| 20 | public Action chooseAction(List<Class<? extends Action>> possibleActions)
|
---|
| 21 | {
|
---|
| 22 |
|
---|
| 23 | // Sample code that accepts offers that appear in the top 10% of offers in the user model
|
---|
[181] | 24 | if (getLastReceivedAction() instanceof Offer && hasPreferenceUncertainty())
|
---|
[127] | 25 | {
|
---|
| 26 | Bid receivedBid = ((Offer) getLastReceivedAction()).getBid();
|
---|
| 27 | List<Bid> bidOrder = userModel.getBidRanking().getBidOrder();
|
---|
| 28 |
|
---|
[256] | 29 | System.out.println("Bid order: " + bidOrder);
|
---|
| 30 | System.out.println("Low: " + userModel.getBidRanking().getLowUtility());
|
---|
| 31 | System.out.println("High: " + userModel.getBidRanking().getHighUtility());
|
---|
| 32 |
|
---|
| 33 | System.out.println("Received bid (which I will elicit against cost " + user.getElicitationCost() + "): " + receivedBid);
|
---|
| 34 | user.elicitRank(receivedBid, userModel);
|
---|
| 35 | System.out.println("Bother is now: " + user.getTotalBother());
|
---|
| 36 |
|
---|
| 37 | System.out.println("Updated bid order: " + bidOrder);
|
---|
| 38 | System.out.println("Updated low: " + userModel.getBidRanking().getLowUtility());
|
---|
| 39 | System.out.println("Updated high: " + userModel.getBidRanking().getHighUtility());
|
---|
| 40 |
|
---|
[127] | 41 | // If the rank of the received bid is known
|
---|
| 42 | if (bidOrder.contains(receivedBid))
|
---|
| 43 | {
|
---|
| 44 | double percentile = (bidOrder.size() - bidOrder.indexOf(receivedBid)) / (double) bidOrder.size();
|
---|
| 45 | if (percentile < 0.1)
|
---|
| 46 | return new Accept(getPartyId(), receivedBid);
|
---|
| 47 | }
|
---|
| 48 | }
|
---|
| 49 |
|
---|
| 50 | // Otherwise, return a random offer
|
---|
| 51 | return new Offer(getPartyId(), generateRandomBid());
|
---|
| 52 | }
|
---|
| 53 |
|
---|
| 54 | /**
|
---|
[181] | 55 | * Specific functionality, such as the estimate of the utility space in the
|
---|
| 56 | * face of preference uncertainty, can be specified by overriding the
|
---|
| 57 | * default behavior.
|
---|
| 58 | *
|
---|
| 59 | * This example estimator sets all weights uniformly
|
---|
[127] | 60 | */
|
---|
| 61 | @Override
|
---|
| 62 | public AbstractUtilitySpace estimateUtilitySpace()
|
---|
| 63 | {
|
---|
[181] | 64 | AdditiveUtilitySpaceFactory additiveUtilitySpaceFactory = new AdditiveUtilitySpaceFactory(getDomain());
|
---|
| 65 | List<IssueDiscrete> issues = additiveUtilitySpaceFactory.getIssues();
|
---|
| 66 | for (IssueDiscrete i : issues)
|
---|
| 67 | {
|
---|
| 68 | additiveUtilitySpaceFactory.setWeight(i, 1.0 / issues.size());
|
---|
| 69 | for (ValueDiscrete v : i.getValues())
|
---|
| 70 | {
|
---|
| 71 | int valueScore = 0;
|
---|
| 72 | for (Bid b : userModel.getBidRanking().getBidOrder())
|
---|
| 73 | if (b.containsValue(i, v))
|
---|
| 74 | valueScore ++;
|
---|
| 75 | additiveUtilitySpaceFactory.setUtility(i, v, valueScore);
|
---|
| 76 | }
|
---|
| 77 | }
|
---|
| 78 |
|
---|
| 79 | // Normalize the attribute functions, since we gave them integer scores
|
---|
| 80 | additiveUtilitySpaceFactory.scaleAllValuesFrom0To1();
|
---|
| 81 |
|
---|
| 82 | // Normalizing the weights might be needed if the above code is changed; uncomment when needed.
|
---|
| 83 | // additiveUtilitySpaceFactory.normalizeWeights();
|
---|
| 84 |
|
---|
| 85 | // The factory is done with setting all parameters, now return the estimated utility space
|
---|
| 86 | return additiveUtilitySpaceFactory.getUtilitySpace();
|
---|
[127] | 87 | }
|
---|
| 88 |
|
---|
| 89 |
|
---|
| 90 | @Override
|
---|
| 91 | public String getDescription()
|
---|
| 92 | {
|
---|
| 93 | return "Example agent that can deal with uncertain preferences";
|
---|
| 94 | }
|
---|
| 95 |
|
---|
[232] | 96 | public String getName(){
|
---|
| 97 | return "Uncertain.Agent";
|
---|
| 98 | }
|
---|
| 99 |
|
---|
[127] | 100 | }
|
---|