1 | package parties.in4010.q12015.group7;
|
---|
2 |
|
---|
3 | import java.util.ArrayList;
|
---|
4 | import java.util.List;
|
---|
5 |
|
---|
6 | import genius.core.Bid;
|
---|
7 | import genius.core.BidHistory;
|
---|
8 | import genius.core.bidding.BidDetails;
|
---|
9 | import genius.core.issue.Issue;
|
---|
10 |
|
---|
11 | /**
|
---|
12 | * Enhancement of the default BidHistory which in addition keeps record of the
|
---|
13 | * distance of every bid compared to the previous bid.
|
---|
14 | *
|
---|
15 | * @author svanbekhoven
|
---|
16 | *
|
---|
17 | */
|
---|
18 | public class EnhancedBidHistory extends BidHistory {
|
---|
19 | /**
|
---|
20 | * Serial for serializing purposes
|
---|
21 | */
|
---|
22 | private static final long serialVersionUID = 6182046030452141299L;
|
---|
23 |
|
---|
24 | /**
|
---|
25 | * ArrayList containing the distances of each bid towards the previous bid
|
---|
26 | */
|
---|
27 | private ArrayList<Double> bidDistances;
|
---|
28 |
|
---|
29 | /**
|
---|
30 | * Constructor
|
---|
31 | */
|
---|
32 | public EnhancedBidHistory() {
|
---|
33 | this.bidDistances = new ArrayList<Double>();
|
---|
34 | }
|
---|
35 |
|
---|
36 | /**
|
---|
37 | * Besides adding the bid to the BidHistory, also add the distance between
|
---|
38 | * the bid to be added and the previous bid to the ArrayList.
|
---|
39 | */
|
---|
40 | public void add(BidDetails details) {
|
---|
41 | if (this.getLastBid() != null) {
|
---|
42 | bidDistances.add(distance(details.getBid(), this.getLastBid()));
|
---|
43 | }
|
---|
44 | super.add(details);
|
---|
45 | }
|
---|
46 |
|
---|
47 | /**
|
---|
48 | * Return "toughness" of the bids in this BidHistory Toughness means the
|
---|
49 | * average distance of the last x bids
|
---|
50 | *
|
---|
51 | * @param numberOfBids
|
---|
52 | * @return toughness
|
---|
53 | */
|
---|
54 | public double getToughness(int numberOfBids) {
|
---|
55 | if (this.bidDistances.size() == 0)
|
---|
56 | return 1;
|
---|
57 |
|
---|
58 | double sum = 0.0;
|
---|
59 | int count = 0;
|
---|
60 | for (int i = this.bidDistances.size() - 1; i >= Math.max(0,
|
---|
61 | this.bidDistances.size() - numberOfBids - 1); i--) {
|
---|
62 | sum += this.bidDistances.get(i);
|
---|
63 | count += 1;
|
---|
64 | }
|
---|
65 |
|
---|
66 | return sum / ((double) count);
|
---|
67 | }
|
---|
68 |
|
---|
69 | /**
|
---|
70 | * Calculates the distance between two bids
|
---|
71 | *
|
---|
72 | * @param bid1
|
---|
73 | * @param bid2
|
---|
74 | * @return distance = (number of differing issues between bid1 and bid2) /
|
---|
75 | * (number of issues)
|
---|
76 | */
|
---|
77 | public double distance(Bid bid1, Bid bid2) {
|
---|
78 | double distance = 0;
|
---|
79 | List<Issue> issues = bid1.getIssues();
|
---|
80 | for (Issue issue : issues) {
|
---|
81 | try {
|
---|
82 | if (!bid1.getValue(issue.getNumber()).equals(
|
---|
83 | bid2.getValue(issue.getNumber()))) {
|
---|
84 | distance += 1.0 / ((double) issues.size());
|
---|
85 | }
|
---|
86 | } catch (Exception e) {
|
---|
87 | e.printStackTrace();
|
---|
88 | }
|
---|
89 | }
|
---|
90 | return distance;
|
---|
91 | }
|
---|
92 |
|
---|
93 | public String toString() {
|
---|
94 | String res = "EnhancedBidHistory[";
|
---|
95 | for (BidDetails bd : getHistory()) {
|
---|
96 | res += "(" + bd.getMyUndiscountedUtil() + ", " + bd.getBid()
|
---|
97 | + "\n\r";
|
---|
98 | }
|
---|
99 | return res + "]";
|
---|
100 | }
|
---|
101 | } |
---|