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

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

Improved examples on how to use BOA components and how to combine them into a single party using BoaParty

File size: 1.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.parties.AbstractNegotiationParty;
10import genius.core.uncertainty.AdditiveUtilitySpaceFactory;
11import genius.core.utility.AbstractUtilitySpace;
12
13public class UncertaintyAgentExample extends AbstractNegotiationParty
14{
15
16 @Override
17 public Action chooseAction(List<Class<? extends Action>> possibleActions)
18 {
19
20 // Sample code that accepts offers that appear in the top 10% of offers in the user model
21 if (getLastReceivedAction() instanceof Offer)
22 {
23 Bid receivedBid = ((Offer) getLastReceivedAction()).getBid();
24 List<Bid> bidOrder = userModel.getBidRanking().getBidOrder();
25
26 // If the rank of the received bid is known
27 if (bidOrder.contains(receivedBid))
28 {
29 double percentile = (bidOrder.size() - bidOrder.indexOf(receivedBid)) / (double) bidOrder.size();
30 if (percentile < 0.1)
31 return new Accept(getPartyId(), receivedBid);
32 }
33 }
34
35 // Otherwise, return a random offer
36 return new Offer(getPartyId(), generateRandomBid());
37 }
38
39 private void log(String s)
40 {
41 System.out.println(s);
42 }
43
44 /**
45 * With this method, you can override the default estimate of the utility space given uncertain preferences specified by the user model.
46 * This example sets every value to zero.
47 */
48 @Override
49 public AbstractUtilitySpace estimateUtilitySpace()
50 {
51 return new AdditiveUtilitySpaceFactory(getDomain()).getUtilitySpace();
52 }
53
54
55 @Override
56 public String getDescription()
57 {
58 return "Example agent that can deal with uncertain preferences";
59 }
60
61}
Note: See TracBrowser for help on using the repository browser.