source: src/test/java/bilateralexamples/ElicitationAgentExample.java

Last change on this file was 333, checked in by Adel Magra, 5 years ago

Added an example agent "ElicitationAgentExample" in the bilateralexamples package.

File size: 2.2 KB
Line 
1package bilateralexamples;
2
3import java.util.List;
4import java.util.Random;
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.parties.NegotiationInfo;
11
12/**
13 * This class implements an example of an agent that uses elicitation in its strategy under uncertainty.
14 * Note that the agent works exclusively under uncertainty.
15 * @author Adel Magra
16 *
17 */
18
19@SuppressWarnings("serial")
20public class ElicitationAgentExample extends AbstractNegotiationParty {
21
22 private Random random = new Random();
23 /**
24 * Initializes a new instance of the agent.
25 */
26 @Override
27 public void init(NegotiationInfo info)
28 {
29 super.init(info);
30 if (!hasPreferenceUncertainty())
31 {
32 log("There is no preference uncertainty. Try this agent with a negotiation scenario that has preference uncertainty enabled.");
33 return;
34 }
35 }
36
37 @Override
38
39 public Action chooseAction(List<Class<? extends Action>> possibleActions) {
40
41 List<Bid> bidOrder = userModel.getBidRanking().getBidOrder();
42
43 if (getLastReceivedAction() instanceof Offer) {
44 Bid receivedBid = ((Offer) getLastReceivedAction()).getBid();
45 //Elicit receivedBid if it is not in bidOrder and TBC < 0.15
46 if(!bidOrder.contains(receivedBid) && user.getTotalBother()<0.15) {
47 userModel = user.elicitRank(receivedBid,userModel);
48 bidOrder = userModel.getBidRanking().getBidOrder();
49 }
50 //Accept if and only if received bid is in top 10% of known bids
51 double percentile = (bidOrder.size() - bidOrder.indexOf(receivedBid)) / (double) bidOrder.size();
52 if (percentile < 0.1)
53 return new Accept(getPartyId(), receivedBid);
54
55 //Otherwise, offer a random bid in the top 10% of known bids
56 int threshold = (int) (0.9*bidOrder.size());
57 List<Bid> topList = bidOrder.subList(threshold, bidOrder.size());
58 int index = random.nextInt(topList.size());
59 return new Offer(getPartyId(), topList.get(index));
60 }
61 //First action
62 return new Offer(getPartyId(),bidOrder.get(bidOrder.size()-1));
63 }
64
65 @Override
66 public String getDescription() {
67 return "Elicitation Agent Example";
68 }
69
70 private void log(String string) {
71 System.out.println(string);
72 }
73
74
75}
76
Note: See TracBrowser for help on using the repository browser.