source: src/main/java/agents/anac/y2012/OMACagent/TimeBidHistory.java@ 84

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

Initial import : Genius 9.0.0

File size: 4.3 KB
Line 
1package agents.anac.y2012.OMACagent;
2
3import java.util.ArrayList;
4import java.util.List;
5
6import genius.core.Bid;
7import genius.core.issue.Issue;
8import genius.core.utility.AdditiveUtilitySpace;
9
10//ver. 1.06
11public class TimeBidHistory {
12 private List<Bid> fMyBids;
13 private List<Bid> fOpponentBids;
14 public List<Double> fTimes; // new, record the time of receiving
15 // counter-offers
16
17 public int curIndex = 0; // new, refer to the current position of opp bid
18 // history
19 public int curLength = 0; // new, the size of current bid window
20 private double discount = 0;
21 protected AdditiveUtilitySpace fUtilitySpace;
22 public double est_t = 0;
23 public double est_u = 0;
24 public double maxU = -1;
25 public int pMaxIndex = 0;
26 public Bid bestOppBid = null;
27 public double[] maxBlock; // record max
28 public List<Integer> newMC; // times where new maximum concession is given
29
30 public TimeBidHistory(AdditiveUtilitySpace pUtilitySpace, double dis) {
31 discount = dis;
32 fMyBids = new ArrayList<Bid>();
33 fTimes = new ArrayList<Double>(); // new
34 newMC = new ArrayList<Integer>();
35 this.fUtilitySpace = pUtilitySpace;
36
37 maxBlock = new double[100];
38 for (int i = 0; i < 100; i++) {
39 maxBlock[i] = 0.0;
40 }
41
42 }
43
44 /*
45 * Add our own bid to the list
46 */
47 public void addMyBid(Bid pBid) {
48 if (pBid == null)
49 throw new IllegalArgumentException("pBid can't be null.");
50 fMyBids.add(pBid);
51
52 }
53
54 /*
55 * returns the size (number) of offers already made
56 */
57 public int getMyBidCount() {
58 return fMyBids.size();
59 }
60
61 /*
62 * returns a bid from the list
63 */
64 public Bid getMyBid(int pIndex) {
65 return fMyBids.get(pIndex);
66 }
67
68 /*
69 * returns the last offer made
70 */
71 public Bid getMyLastBid() {
72 Bid result = null;
73 if (getMyBidCount() > 0) {
74 result = fMyBids.get(getMyBidCount() - 1);
75 }
76 return result;
77 }
78
79 /*
80 * returns true if a bid has already been made before
81 */
82 public boolean isInsideMyBids(Bid a) {
83 boolean result = false;
84 for (int i = 0; i < getMyBidCount(); i++) {
85 if (a.equals(getMyBid(i))) {
86 result = true;
87 }
88 }
89 return result;
90 }
91
92 /*
93 * add the bid the oppponent to his list
94 */
95 public void addOpponentBidnTime(double oppU, Bid pBid, double time) {
96 double undisOppU = oppU / Math.pow(discount, time);
97 double nTime = time;
98
99 if (pBid == null)
100 throw new IllegalArgumentException("vBid can't be null.");
101
102 fTimes.add(time);
103
104 if (undisOppU > maxU) {
105 maxU = undisOppU; // prabably not useful in some sense
106 // pMaxIndex = getOpponentBidCount()-1;
107 pMaxIndex = fTimes.size() - 1;
108 bestOppBid = pBid;
109 newMC.add(pMaxIndex);
110 }
111
112 if (nTime >= 1.0)
113 nTime = 0.99999;
114
115 if (maxBlock[(int) Math.floor(nTime * 100)] < undisOppU)
116 maxBlock[(int) Math.floor(nTime * 100)] = undisOppU;
117
118 }
119
120 public double[] getTimeBlockList() {
121 return maxBlock;
122 }
123
124 /*
125 * returns the number of bids the opponent has made
126 */
127 public int getOpponentBidCount() {
128 return fOpponentBids.size();
129 }
130
131 /*
132 * returns the bid at a given index
133 */
134 public Bid getOpponentBid(int pIndex) {
135 return fOpponentBids.get(pIndex);
136 }
137
138 /*
139 * returns the opponents' last bid
140 */
141 public Bid getOpponentLastBid() {
142 Bid result = null;
143 if (getOpponentBidCount() > 0) {
144 result = fOpponentBids.get(getOpponentBidCount() - 1);
145 }
146 return result;
147 }
148
149 public double getMyUtility(Bid b) {
150 try {
151 return this.fUtilitySpace.getUtility(b);
152 } catch (Exception e) {
153 return 0;
154 }
155 }
156
157 public double getOpponentUtility(Bid b) {
158 try {
159 return this.fUtilitySpace.getUtility(b);
160 } catch (Exception e) {
161 return 0;
162 }
163 }
164
165 /*
166 * returns the list of issues in the domain
167 */
168 public List<Issue> getIssues() {
169 return this.fUtilitySpace.getDomain().getIssues();
170 }
171
172 public double getFeaMC(double time) {
173 int len = newMC.size();
174 double dif = 1.0;
175
176 if (len >= 3) {
177 dif = fTimes.get(newMC.get(len - 1))
178 - fTimes.get(newMC.get(len - 3));
179 dif = dif / 2.0;
180 } else if (len >= 2) {
181 dif = fTimes.get(newMC.get(len - 1))
182 - fTimes.get(newMC.get(len - 2));
183 } else {
184 dif = 0D;
185 }
186
187 // newmark("a-dif.txt",""+dif+","+len+","+time);
188 return dif;
189 }
190
191 public double getMCtime() {
192 if (newMC.size() == 0)
193 return 0.0;
194
195 return fTimes.get(newMC.get(newMC.size() - 1));
196 }
197
198}
Note: See TracBrowser for help on using the repository browser.