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

Last change on this file since 346 was 261, checked in by Adel Magra, 5 years ago

Corrected mistakes in the user guide.

File size: 3.9 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 // 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 }
57 }
58 // Otherwise just offer a Random bid
59 return new Offer(getPartyId(), generateRandomBid());
60 }
61
62 /**
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
68 */
69 @Override
70 public AbstractUtilitySpace estimateUtilitySpace()
71 {
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();
95 }
96
97
98 @Override
99 public String getDescription()
100 {
101 return "Example agent that can deal with uncertain preferences";
102 }
103
104 public String getName(){
105 return "Uncertain.Agent";
106 }
107
108}
Note: See TracBrowser for help on using the repository browser.