[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 | }
|
---|
[261] | 48 | // If it is not, then elicit the new user model augmented with the received bid
|
---|
| 49 | // provided the Total user bother doesn't exceed 0.1
|
---|
| 50 | else if(user.getTotalBother()<0.1)
|
---|
| 51 | {
|
---|
| 52 | userModel = user.elicitRank(receivedBid,userModel);
|
---|
| 53 | double percentile = (bidOrder.size() - bidOrder.indexOf(receivedBid)) / (double) bidOrder.size();
|
---|
| 54 | if (percentile < 0.1)
|
---|
| 55 | return new Accept(getPartyId(), receivedBid);
|
---|
| 56 | }
|
---|
[127] | 57 | }
|
---|
[261] | 58 | // Otherwise just offer a Random bid
|
---|
[127] | 59 | return new Offer(getPartyId(), generateRandomBid());
|
---|
| 60 | }
|
---|
| 61 |
|
---|
| 62 | /**
|
---|
[181] | 63 | * Specific functionality, such as the estimate of the utility space in the
|
---|
| 64 | * face of preference uncertainty, can be specified by overriding the
|
---|
| 65 | * default behavior.
|
---|
| 66 | *
|
---|
| 67 | * This example estimator sets all weights uniformly
|
---|
[127] | 68 | */
|
---|
| 69 | @Override
|
---|
| 70 | public AbstractUtilitySpace estimateUtilitySpace()
|
---|
| 71 | {
|
---|
[181] | 72 | AdditiveUtilitySpaceFactory additiveUtilitySpaceFactory = new AdditiveUtilitySpaceFactory(getDomain());
|
---|
| 73 | List<IssueDiscrete> issues = additiveUtilitySpaceFactory.getIssues();
|
---|
| 74 | for (IssueDiscrete i : issues)
|
---|
| 75 | {
|
---|
| 76 | additiveUtilitySpaceFactory.setWeight(i, 1.0 / issues.size());
|
---|
| 77 | for (ValueDiscrete v : i.getValues())
|
---|
| 78 | {
|
---|
| 79 | int valueScore = 0;
|
---|
| 80 | for (Bid b : userModel.getBidRanking().getBidOrder())
|
---|
| 81 | if (b.containsValue(i, v))
|
---|
| 82 | valueScore ++;
|
---|
| 83 | additiveUtilitySpaceFactory.setUtility(i, v, valueScore);
|
---|
| 84 | }
|
---|
| 85 | }
|
---|
| 86 |
|
---|
| 87 | // Normalize the attribute functions, since we gave them integer scores
|
---|
| 88 | additiveUtilitySpaceFactory.scaleAllValuesFrom0To1();
|
---|
| 89 |
|
---|
| 90 | // Normalizing the weights might be needed if the above code is changed; uncomment when needed.
|
---|
| 91 | // additiveUtilitySpaceFactory.normalizeWeights();
|
---|
| 92 |
|
---|
| 93 | // The factory is done with setting all parameters, now return the estimated utility space
|
---|
| 94 | return additiveUtilitySpaceFactory.getUtilitySpace();
|
---|
[127] | 95 | }
|
---|
| 96 |
|
---|
| 97 |
|
---|
| 98 | @Override
|
---|
| 99 | public String getDescription()
|
---|
| 100 | {
|
---|
| 101 | return "Example agent that can deal with uncertain preferences";
|
---|
| 102 | }
|
---|
| 103 |
|
---|
[232] | 104 | public String getName(){
|
---|
| 105 | return "Uncertain.Agent";
|
---|
| 106 | }
|
---|
| 107 |
|
---|
[127] | 108 | }
|
---|