source: src/main/java/agents/anac/y2011/HardHeaded/BidHistory.java

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

Initial import : Genius 9.0.0

File size: 4.4 KB
Line 
1package agents.anac.y2011.HardHeaded;
2
3import java.util.ArrayList;
4import java.util.HashMap;
5import java.util.List;
6import java.util.Map.Entry;
7
8import genius.core.Bid;
9import genius.core.issue.Issue;
10import genius.core.issue.ValueDiscrete;
11import genius.core.utility.AdditiveUtilitySpace;
12import genius.core.utility.UtilitySpace;
13
14/**
15 * Keeps track of all bids exchanged by both the agent and its opponent. Also
16 * has some tools that work on history of exchanged bids.
17 *
18 */
19public class BidHistory {
20 private List<Entry<Double, Bid>> myBids;
21 private List<Bid> opponentBids;
22 private UtilitySpace utilitySpace;
23
24 /**
25 * BidHistory class constructor.
26 *
27 * @param utilSpace
28 * a {@link AdditiveUtilitySpace} to be set for utility
29 * calculations of stored bids.
30 * @return An object of this type used to keep track of exchanged bids.
31 */
32 public BidHistory(UtilitySpace utilSpace) {
33
34 utilitySpace = utilSpace;
35 myBids = new ArrayList<Entry<Double, Bid>>();
36 opponentBids = new ArrayList<Bid>();
37
38 }
39
40 /**
41 * Adds a new bid {@link Entry} to the end of agent's own bids.
42 *
43 * @param pBid
44 * passed bid entry
45 */
46 public void addMyBid(Entry<Double, Bid> pBid) {
47 if (pBid == null)
48 throw new IllegalArgumentException("pBid can't be null.");
49 myBids.add(pBid);
50
51 }
52
53 /**
54 * @return the size (number) of offers already made
55 */
56 public int getMyBidCount() {
57 return myBids.size();
58 }
59
60 /**
61 * retrieves a bid {@link Entry} from the agent's bid list
62 *
63 * @param pIndex
64 * index of the bid
65 * @return a bid from the list
66 */
67 public Entry<Double, Bid> getMyBid(int pIndex) {
68 return myBids.get(pIndex);
69 }
70
71 /**
72 * retrieves last bid {@link Entry} from the agent's bid list
73 *
74 * @return a bid from the list
75 */
76 public Entry<Double, Bid> getMyLastBid() {
77 Entry<Double, Bid> result = null;
78 if (getMyBidCount() > 0) {
79 result = myBids.get(getMyBidCount() - 1);
80 }
81 return result;
82 }
83
84 /**
85 * Adds a new bid {@link Entry} to the end of oppenent's bids.
86 *
87 * @param pBid
88 * passed bid entry
89 */
90 public void addOpponentBid(Bid pBid) {
91 if (pBid == null)
92 throw new IllegalArgumentException("vBid can't be null.");
93 opponentBids.add(pBid);
94 }
95
96 /**
97 * @return the number of bids the opponent has made
98 */
99 public int getOpponentBidCount() {
100 return opponentBids.size();
101 }
102
103 /**
104 * retrieves a bid from the opponent's bid list
105 *
106 * @param pIndex
107 * index of the bid
108 * @return a bid from the list
109 */
110 public Bid getOpponentBid(int pIndex) {
111 return opponentBids.get(pIndex);
112 }
113
114 /**
115 * retrieves last bid from the opponent's bid list
116 *
117 * @return a bid from the list
118 */
119 public Bid getOpponentLastBid() {
120 Bid result = null;
121 if (getOpponentBidCount() > 0) {
122 result = opponentBids.get(getOpponentBidCount() - 1);
123 }
124 return result;
125 }
126
127 /**
128 * retrieves second last bid from the opponent's bid list
129 *
130 * @return a bid from the list
131 */
132 public Bid getOpponentSecondLastBid() {
133 Bid result = null;
134 if (getOpponentBidCount() > 1) {
135 result = opponentBids.get(getOpponentBidCount() - 2);
136 }
137 return result;
138 }
139
140 /**
141 * receives two bids as arguments and returns a {@link HashMap} that
142 * contains for each issue whether or not its value is different between the
143 * two bids.
144 *
145 * @param first
146 * @param second
147 * @return a {@link HashMap} with keys equal to issue IDs and with values 1
148 * if different issue value observed and 0 if not.
149 */
150 public HashMap<Integer, Integer> BidDifference(Bid first, Bid second) {
151
152 HashMap<Integer, Integer> diff = new HashMap<Integer, Integer>();
153 try {
154 for (Issue i : utilitySpace.getDomain().getIssues()) {
155 diff.put(i.getNumber(), (((ValueDiscrete) first.getValue(i
156 .getNumber())).equals((ValueDiscrete) second.getValue(i
157 .getNumber()))) ? 0 : 1);
158 }
159 } catch (Exception ex) {
160 ex.printStackTrace();
161 }
162
163 return diff;
164 }
165
166 /**
167 * For the last two bids of the opponent returns a {@link HashMap} that
168 * contains for each issue whether or not its value is different between the
169 * two bids.
170 *
171 * @return a {@link HashMap} with keys equal to issue IDs and with values 1
172 * if different issue value observed and 0 if not.
173 */
174 public HashMap<Integer, Integer> BidDifferenceofOpponentsLastTwo() {
175
176 if (getOpponentBidCount() < 2)
177 throw new ArrayIndexOutOfBoundsException();
178 return BidDifference(getOpponentLastBid(), getOpponentSecondLastBid());
179 }
180
181}
Note: See TracBrowser for help on using the repository browser.