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

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

Improved CustomUtilitySpacePartyExample

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
15@SuppressWarnings("serial")
16public 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
24 if (getLastReceivedAction() instanceof Offer && hasPreferenceUncertainty())
25 {
26 Bid receivedBid = ((Offer) getLastReceivedAction()).getBid();
27 List<Bid> bidOrder = userModel.getBidRanking().getBidOrder();
28
29 // If the rank of the received bid is known
30 if (bidOrder.contains(receivedBid))
31 {
32 double percentile = (bidOrder.size() - bidOrder.indexOf(receivedBid)) / (double) bidOrder.size();
33 if (percentile < 0.1)
34 return new Accept(getPartyId(), receivedBid);
35 }
36 }
37
38 // Otherwise, return a random offer
39 return new Offer(getPartyId(), generateRandomBid());
40 }
41
42 /**
43 * Specific functionality, such as the estimate of the utility space in the
44 * face of preference uncertainty, can be specified by overriding the
45 * default behavior.
46 *
47 * This example estimator sets all weights uniformly
48 */
49 @Override
50 public AbstractUtilitySpace estimateUtilitySpace()
51 {
52 AdditiveUtilitySpaceFactory additiveUtilitySpaceFactory = new AdditiveUtilitySpaceFactory(getDomain());
53 List<IssueDiscrete> issues = additiveUtilitySpaceFactory.getIssues();
54 for (IssueDiscrete i : issues)
55 {
56 additiveUtilitySpaceFactory.setWeight(i, 1.0 / issues.size());
57 for (ValueDiscrete v : i.getValues())
58 {
59 int valueScore = 0;
60 for (Bid b : userModel.getBidRanking().getBidOrder())
61 if (b.containsValue(i, v))
62 valueScore ++;
63 additiveUtilitySpaceFactory.setUtility(i, v, valueScore);
64 }
65 }
66
67 // Normalize the attribute functions, since we gave them integer scores
68 additiveUtilitySpaceFactory.scaleAllValuesFrom0To1();
69
70 // Normalizing the weights might be needed if the above code is changed; uncomment when needed.
71 // additiveUtilitySpaceFactory.normalizeWeights();
72
73 // The factory is done with setting all parameters, now return the estimated utility space
74 return additiveUtilitySpaceFactory.getUtilitySpace();
75 }
76
77
78 @Override
79 public String getDescription()
80 {
81 return "Example agent that can deal with uncertain preferences";
82 }
83
84}
Note: See TracBrowser for help on using the repository browser.