source: src/main/java/agents/anac/y2019/harddealer/HardDealer_OMS.java

Last change on this file was 200, checked in by Katsuhide Fujita, 5 years ago

Add ANAC 2019 agents

  • Property svn:executable set to *
File size: 3.2 KB
Line 
1package agents.anac.y2019.harddealer;
2
3import java.util.ArrayList;
4import java.util.HashSet;
5import java.util.List;
6import java.util.Map;
7import java.util.Random;
8import java.util.Set;
9
10import genius.core.bidding.BidDetails;
11import genius.core.boaframework.BOAparameter;
12import genius.core.boaframework.NegotiationSession;
13import genius.core.boaframework.OMStrategy;
14import genius.core.boaframework.OpponentModel;
15
16/**
17 * This implementation is based on the code provided in the Boaexamples directory. Specifically the code of BestBid has been used and altered.
18 * @author svenhendrikx
19 *
20 */
21public class HardDealer_OMS extends OMStrategy {
22
23 double updateThreshold = 1.1;
24
25 @Override
26 public void init(NegotiationSession negotiationSession, OpponentModel model, Map<String, Double> parameters) {
27 super.init(negotiationSession, model, parameters);
28 if (parameters.get("t") != null) {
29 updateThreshold = parameters.get("t").doubleValue();
30 } else {
31 System.out.println("OMStrategy assumed t = 1.1");
32 }
33 }
34
35 @Override
36 public BidDetails getBid(List<BidDetails> allBids) {
37 if (allBids.size() == 1) {
38 return allBids.get(0);
39 }
40
41 // Check if the model is working, i.e. not returning only zeroes.
42 boolean allWereZero = true;
43
44 // Will contain x best bids
45 List<BidDetails> bestbids = new ArrayList<BidDetails>();
46 for (BidDetails bid : allBids) {
47
48 double evaluation = model.getBidEvaluation(bid.getBid());
49
50 // model works
51 if (evaluation > 0.0001)
52 {
53 allWereZero = false;
54 }
55
56 // bestbids's allowed size will decrease during negotiation. For more info, see OMstrategy part in report
57 if (bestbids.size() < (int)(5 * (1 - negotiationSession.getTime())) + 1)
58 {
59 bestbids.add(bid);
60 }
61 else
62 {
63 // Find the five best bids according to the opponent model
64 bestbids.sort(new SortBidsOpponent(model));
65
66 if (model.getBidEvaluation(bestbids.get(0).getBid()) < evaluation)
67 bestbids.set(0, bid);
68 }
69
70 }
71
72 // 4. The opponent model did not work, therefore, offer a random bid.
73 if (allWereZero) {
74 Random r = new Random();
75 return allBids.get(r.nextInt(allBids.size()));
76 }
77
78
79 bestbids.sort(new SortBids());
80 // Find the best bid from the bids the opponent model selected.
81 BidDetails myBid = bestbids.get(bestbids.size() - 1);
82
83 if (negotiationSession.getOpponentBidHistory().isEmpty())
84 {
85 return myBid;
86 }
87 else
88 {
89 // If the opponent has offered something before with a better utility than our current selected bid, return their best bid.
90 BidDetails theirBestBid = negotiationSession.getOpponentBidHistory().getBestBidDetails();
91
92 if (myBid.getMyUndiscountedUtil() >= theirBestBid.getMyUndiscountedUtil())
93 {
94 return myBid;
95 }
96 else
97 {
98 return theirBestBid;
99 }
100 }
101
102
103 }
104
105 @Override
106 public boolean canUpdateOM() {
107 return negotiationSession.getTime() < updateThreshold;
108 }
109
110 @Override
111 public Set<BOAparameter> getParameterSpec() {
112 Set<BOAparameter> set = new HashSet<BOAparameter>();
113 set.add(new BOAparameter("t", 1.1, "Time after which the OM should not be updated"));
114 return set;
115 }
116
117 @Override
118 public String getName() {
119 return "HardDealer_OMS";
120 }
121
122}
Note: See TracBrowser for help on using the repository browser.