source: src/main/java/agents/UncertaintyAgentExample.java@ 181

Last change on this file since 181 was 181, checked in by Tim Baarslag, 6 years ago

Extended UncertaintyAgentExample

File size: 2.7 KB
Line 
1package agents;
2
3import java.util.List;
4
5import genius.core.Bid;
6import genius.core.actions.Accept;
7import genius.core.actions.Action;
8import genius.core.actions.Offer;
9import genius.core.issue.IssueDiscrete;
10import genius.core.issue.ValueDiscrete;
11import genius.core.parties.AbstractNegotiationParty;
12import genius.core.uncertainty.AdditiveUtilitySpaceFactory;
13import genius.core.utility.AbstractUtilitySpace;
14
15public class UncertaintyAgentExample extends AbstractNegotiationParty
16{
17
18 @Override
19 public Action chooseAction(List<Class<? extends Action>> possibleActions)
20 {
21
22 // Sample code that accepts offers that appear in the top 10% of offers in the user model
23 if (getLastReceivedAction() instanceof Offer && hasPreferenceUncertainty())
24 {
25 Bid receivedBid = ((Offer) getLastReceivedAction()).getBid();
26 List<Bid> bidOrder = userModel.getBidRanking().getBidOrder();
27
28 // If the rank of the received bid is known
29 if (bidOrder.contains(receivedBid))
30 {
31 double percentile = (bidOrder.size() - bidOrder.indexOf(receivedBid)) / (double) bidOrder.size();
32 if (percentile < 0.1)
33 return new Accept(getPartyId(), receivedBid);
34 }
35 }
36
37 // Otherwise, return a random offer
38 return new Offer(getPartyId(), generateRandomBid());
39 }
40
41 /**
42 * Specific functionality, such as the estimate of the utility space in the
43 * face of preference uncertainty, can be specified by overriding the
44 * default behavior.
45 *
46 * This example estimator sets all weights uniformly
47 */
48 @Override
49 public AbstractUtilitySpace estimateUtilitySpace()
50 {
51 AdditiveUtilitySpaceFactory additiveUtilitySpaceFactory = new AdditiveUtilitySpaceFactory(getDomain());
52 List<IssueDiscrete> issues = additiveUtilitySpaceFactory.getIssues();
53 for (IssueDiscrete i : issues)
54 {
55 additiveUtilitySpaceFactory.setWeight(i, 1.0 / issues.size());
56 for (ValueDiscrete v : i.getValues())
57 {
58 int valueScore = 0;
59 for (Bid b : userModel.getBidRanking().getBidOrder())
60 if (b.containsValue(i, v))
61 valueScore ++;
62 additiveUtilitySpaceFactory.setUtility(i, v, valueScore);
63 }
64 }
65
66 // Normalize the attribute functions, since we gave them integer scores
67 additiveUtilitySpaceFactory.scaleAllValuesFrom0To1();
68
69 // Normalizing the weights might be needed if the above code is changed; uncomment when needed.
70 // additiveUtilitySpaceFactory.normalizeWeights();
71
72 // The factory is done with setting all parameters, now return the estimated utility space
73 return additiveUtilitySpaceFactory.getUtilitySpace();
74 }
75
76
77 @Override
78 public String getDescription()
79 {
80 return "Example agent that can deal with uncertain preferences";
81 }
82
83}
Note: See TracBrowser for help on using the repository browser.