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

Last change on this file since 127 was 127, checked in by Wouter Pasman, 6 years ago

#41 ROLL BACK of rev.126 . So this version is equal to rev. 125

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