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

Last change on this file since 123 was 113, checked in by Tim Baarslag, 7 years ago

UncertaintyAgentExample
some extra info
Genius version fix

File size: 2.5 KB
RevLine 
[32]1package agents;
2
3import java.util.List;
4
[46]5import genius.core.Bid;
[113]6import genius.core.actions.Accept;
[32]7import genius.core.actions.Action;
[50]8import genius.core.actions.Offer;
[32]9import genius.core.parties.AbstractNegotiationParty;
[57]10import genius.core.uncertainty.AdditiveUtilitySpaceFactory;
[64]11import genius.core.uncertainty.ExperimentalUserModel;
[46]12import genius.core.utility.AbstractUtilitySpace;
[32]13
[113]14public class UncertaintyAgentExample extends AbstractNegotiationParty
15{
[32]16
17 @Override
18 public Action chooseAction(List<Class<? extends Action>> possibleActions)
19 {
[113]20 log("This is the UncertaintyAgentExample.");
21 log("The user model is: " + userModel);
22 log("The default estimated utility space is: " + getUtilitySpace());
[46]23
[50]24 Bid randomBid = getUtilitySpace().getDomain().getRandomBid(rand);
[113]25 log("The default estimate of the utility of a random bid + " + randomBid + " is: " + getUtility(randomBid));
[46]26
[64]27 if (userModel instanceof ExperimentalUserModel)
28 {
[113]29 log("You have given the agent access to the real utility space for debugging purposes.");
[64]30 ExperimentalUserModel e = (ExperimentalUserModel) userModel;
31 AbstractUtilitySpace realUSpace = e.getRealUtilitySpace();
[113]32
33 log("The real utility space is: " + realUSpace);
34 log("The real utility of the random bid is: " + realUSpace.getUtility(randomBid));
[64]35 }
[46]36
[113]37 // Sample code that accepts offers that appear in the top 10% of offers in the user model
38 if (getLastReceivedAction() instanceof Offer)
39 {
40 Bid receivedBid = ((Offer) getLastReceivedAction()).getBid();
41 List<Bid> bidOrder = userModel.getBidRanking().getBidOrder();
42
43 // If the rank of the received bid is known
44 if (bidOrder.contains(receivedBid))
45 {
46 double percentile = (bidOrder.size() - bidOrder.indexOf(receivedBid)) / (double) bidOrder.size();
47 if (percentile < 0.1)
48 return new Accept(getPartyId(), receivedBid);
49 }
50 }
51
52 // Otherwise, return a random offer
[50]53 return new Offer(getPartyId(), generateRandomBid());
[32]54 }
[46]55
[113]56 private void log(String s)
57 {
58 System.out.println(s);
59 }
60
[64]61 /**
62 * With this method, you can override the default estimate of the utility space given uncertain preferences specified by the user model.
63 * This example sets every value to zero.
64 */
[57]65 @Override
66 public AbstractUtilitySpace estimateUtilitySpace()
67 {
68 return new AdditiveUtilitySpaceFactory(getDomain()).getUtilitySpace();
69 }
70
[32]71
72 @Override
73 public String getDescription()
74 {
75 return "Example agent that can deal with uncertain preferences";
76 }
[113]77
[32]78}
Note: See TracBrowser for help on using the repository browser.