source: src/main/java/negotiator/boaframework/omstrategy/NTFTstrategy.java@ 326

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

Cleanup of BOA repository

File size: 3.7 KB
Line 
1package negotiator.boaframework.omstrategy;
2
3import java.util.List;
4
5import java.util.ArrayList;
6import java.util.Collections;
7import java.util.HashMap;
8import java.util.Map;
9import java.util.Random;
10
11import genius.core.Bid;
12import genius.core.bidding.BidDetails;
13import genius.core.bidding.BidDetailsSorterUtility;
14import genius.core.boaframework.NegotiationSession;
15import genius.core.boaframework.OMStrategy;
16import genius.core.boaframework.OpponentModel;
17
18/**
19 * Implements the opponent model strategy used by the NiceTitForTat agent in the
20 * ANAC2011. The strategy selects a random bid from the best N bids. What is
21 * special in comparison to OfferBestN, is that N depends on the domain size.
22 * Furthermore, the strategy stops updating the opponent model before the
23 * deadline. The time at which the updating stops depends on the domain size.
24 *
25 * This component is part of the NiceTitForTat strategy introduced by T.
26 * Baarslag in the ANAC 2011.
27 *
28 * @author Mark Hendrikx
29 */
30public class NTFTstrategy extends OMStrategy {
31
32 private boolean domainIsBig;
33 private long possibleBids;
34 private Random random;
35 private BidDetailsSorterUtility comp = new BidDetailsSorterUtility();
36
37 @Override
38 public void init(NegotiationSession negotiationSession, OpponentModel model, Map<String, Double> parameters) {
39 initializeAgent(negotiationSession, model);
40 }
41
42 private void initializeAgent(NegotiationSession negoSession, OpponentModel model) {
43 this.negotiationSession = negoSession;
44 try {
45 super.init(negotiationSession, model, new HashMap<String, Double>());
46 } catch (Exception e) {
47 e.printStackTrace();
48 }
49 this.possibleBids = negotiationSession.getUtilitySpace().getDomain().getNumberOfPossibleBids();
50 domainIsBig = (possibleBids > 10000);
51 random = new Random();
52 }
53
54 /**
55 * Selects a random bid from the best N bids, where N depends on the domain
56 * size.
57 *
58 * @param set
59 * of similarly preferred bids.
60 * @return nextBid to be offered
61 */
62 @Override
63 public BidDetails getBid(List<BidDetails> bidsInRange) {
64 ArrayList<BidDetails> bidsOM = new ArrayList<BidDetails>();
65 for (BidDetails bid : bidsInRange) {
66 double utility;
67 try {
68 utility = model.getBidEvaluation(bid.getBid());
69 BidDetails bidDetails = new BidDetails(bid.getBid(), utility);
70 bidsOM.add(bidDetails);
71 } catch (Exception e) {
72 e.printStackTrace();
73 }
74 }
75
76 // Pick the top 3 to 20 bids, depending on the domain size
77 int n = (int) Math.round(bidsOM.size() / 10.0);
78 if (n < 3)
79 n = 3;
80 if (n > 20)
81 n = 20;
82
83 Collections.sort(bidsOM, comp);
84
85 int entry = random.nextInt(Math.min(bidsOM.size(), n));
86 Bid opponentBestBid = bidsOM.get(entry).getBid();
87 BidDetails nextBid = null;
88 try {
89 nextBid = new BidDetails(opponentBestBid, negotiationSession.getUtilitySpace().getUtility(opponentBestBid),
90 negotiationSession.getTime());
91 } catch (Exception e) {
92 e.printStackTrace();
93 }
94 return nextBid;
95 }
96
97 /**
98 * Method which specifies when the opponent model may be updated. In small
99 * domains the model may be updated up till 0.99 of the time. In large
100 * domains the updating process stops half way.
101 *
102 * @return true if the opponent model may be updated
103 */
104 @Override
105 public boolean canUpdateOM() {
106 // in the last seconds we don't want to lose any time
107 if (negotiationSession.getTime() > 0.99)
108 return false;
109
110 // in a big domain, we stop updating half-way
111 if (domainIsBig) {
112 if (negotiationSession.getTime() > 0.5) {
113 return false;
114 }
115 }
116 return true;
117 }
118
119 @Override
120 public String getName() {
121 return "Offer Best Bids";
122 }
123}
Note: See TracBrowser for help on using the repository browser.