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

Last change on this file since 256 was 256, checked in by Tim Baarslag, 5 years ago

UncertaintyAgentExample now shows a simple usecase of the elicitation framework; to be extended

File size: 3.5 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 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
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 /**
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
60 */
61 @Override
62 public AbstractUtilitySpace estimateUtilitySpace()
63 {
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();
87 }
88
89
90 @Override
91 public String getDescription()
92 {
93 return "Example agent that can deal with uncertain preferences";
94 }
95
96 public String getName(){
97 return "Uncertain.Agent";
98 }
99
100}
Note: See TracBrowser for help on using the repository browser.