1 | package genius.core.analysis;
|
---|
2 |
|
---|
3 | import java.io.Serializable;
|
---|
4 | import java.util.Arrays;
|
---|
5 |
|
---|
6 | import genius.core.Bid;
|
---|
7 |
|
---|
8 | /**
|
---|
9 | * A BidPoint is a tuple which contains the utility of a particular bid for each
|
---|
10 | * agent.
|
---|
11 | *
|
---|
12 | * @author Tim Baarslag, Dmytro Tykhonov, Mark Hendrikx
|
---|
13 | */
|
---|
14 | public class BidPoint implements Serializable {
|
---|
15 |
|
---|
16 | /**
|
---|
17 | *
|
---|
18 | */
|
---|
19 | private static final long serialVersionUID = 6111098452770804678L;
|
---|
20 | /** Bid of which the utilities are shown. */
|
---|
21 | private Bid bid;
|
---|
22 | /** Array holding the utility of the bid for each agent. */
|
---|
23 | private Double[] utility;
|
---|
24 |
|
---|
25 | /**
|
---|
26 | * Create a BidPoint by given the bid and the tuple of utilities for that
|
---|
27 | * bid.
|
---|
28 | *
|
---|
29 | * @param bid
|
---|
30 | * from which the utilities are stored.
|
---|
31 | * @param utility
|
---|
32 | * tuple of utilities of the bid.
|
---|
33 | */
|
---|
34 | public BidPoint(Bid bid, Double... utility) {
|
---|
35 | this.bid = bid;
|
---|
36 | this.utility = utility.clone();
|
---|
37 | }
|
---|
38 |
|
---|
39 | /**
|
---|
40 | * @return string representation of the object.
|
---|
41 | */
|
---|
42 | @Override
|
---|
43 | public String toString() {
|
---|
44 | String result = "BidPoint [" + bid + ",";
|
---|
45 | for (int i = 0; i < utility.length; i++) {
|
---|
46 | result += "util" + i + "[" + utility[i] + "],";
|
---|
47 | }
|
---|
48 | return result;
|
---|
49 | }
|
---|
50 |
|
---|
51 | /**
|
---|
52 | * @param obj
|
---|
53 | * object to which this object is compared.
|
---|
54 | * @return true if this object is equal to the given object.
|
---|
55 | */
|
---|
56 | @Override
|
---|
57 | public boolean equals(Object obj) {
|
---|
58 | if (this == obj)
|
---|
59 | return true;
|
---|
60 | if (obj == null)
|
---|
61 | return false;
|
---|
62 | if (getClass() != obj.getClass())
|
---|
63 | return false;
|
---|
64 | BidPoint other = (BidPoint) obj;
|
---|
65 | if (bid == null) {
|
---|
66 | if (other.bid != null)
|
---|
67 | return false;
|
---|
68 | } else if (!bid.equals(other.bid))
|
---|
69 | return false;
|
---|
70 | if (this.utility.length != other.utility.length) {
|
---|
71 | return false;
|
---|
72 | }
|
---|
73 |
|
---|
74 | for (int i = 0; i < this.utility.length; i++) {
|
---|
75 | if (!this.utility[i].equals(other.utility[i])) {
|
---|
76 | return false;
|
---|
77 | }
|
---|
78 | }
|
---|
79 | return true;
|
---|
80 | }
|
---|
81 |
|
---|
82 | /**
|
---|
83 | * @return hashcode of this object.
|
---|
84 | */
|
---|
85 | @Override
|
---|
86 | public int hashCode() {
|
---|
87 | final int prime = 31;
|
---|
88 | int result = 1;
|
---|
89 | result = prime * result + ((bid == null) ? 0 : bid.hashCode());
|
---|
90 | result = prime * result + Arrays.hashCode(utility);
|
---|
91 | return result;
|
---|
92 | }
|
---|
93 |
|
---|
94 | /**
|
---|
95 | * Bid from which the utilities are represented. This bid may be null to
|
---|
96 | * save memory.
|
---|
97 | *
|
---|
98 | * @return bid which utilities are represented.
|
---|
99 | */
|
---|
100 | public Bid getBid() {
|
---|
101 | return bid;
|
---|
102 | }
|
---|
103 |
|
---|
104 | /**
|
---|
105 | * Returns the utility of the bid for the i'th agent (agent A = 0, etc.).
|
---|
106 | *
|
---|
107 | * @param index
|
---|
108 | * of the agent of which the utility should be returned.
|
---|
109 | * @return utility of the bid for the i'th agent.
|
---|
110 | */
|
---|
111 | public Double getUtility(int index) {
|
---|
112 | return utility[index];
|
---|
113 | }
|
---|
114 |
|
---|
115 | /**
|
---|
116 | * Returns the utility of the bid for agent A.
|
---|
117 | *
|
---|
118 | * @return utility for agent A.
|
---|
119 | */
|
---|
120 | public Double getUtilityA() {
|
---|
121 | return utility[0];
|
---|
122 | }
|
---|
123 |
|
---|
124 | /**
|
---|
125 | * Returns the utility of the bid for agent B.
|
---|
126 | *
|
---|
127 | * @return utility for agent B.
|
---|
128 | */
|
---|
129 | public Double getUtilityB() {
|
---|
130 | return utility[1];
|
---|
131 | }
|
---|
132 |
|
---|
133 | /**
|
---|
134 | * Returns true if this BidPoint is strictly dominated by another BidPoint.
|
---|
135 | * A BidPoint is dominated when the utility of the other bid for at least
|
---|
136 | * one agent is higher and equal for the other agent.
|
---|
137 | *
|
---|
138 | * @param other
|
---|
139 | * BidPoint.
|
---|
140 | * @return true if "other" dominates "this".
|
---|
141 | */
|
---|
142 | public boolean isStrictlyDominatedBy(BidPoint other) {
|
---|
143 | if (this == other) {
|
---|
144 | return false;
|
---|
145 | }
|
---|
146 |
|
---|
147 | boolean atleastOneBetter = false;
|
---|
148 |
|
---|
149 | for (int i = 0; i < utility.length; i++) {
|
---|
150 | if (other.utility[i] >= this.utility[i]) {
|
---|
151 | if (other.utility[i] > this.utility[i]) {
|
---|
152 | atleastOneBetter = true;
|
---|
153 | }
|
---|
154 | } else {
|
---|
155 | return false;
|
---|
156 | }
|
---|
157 | }
|
---|
158 | return atleastOneBetter;
|
---|
159 | }
|
---|
160 |
|
---|
161 | /**
|
---|
162 | * Returns the distance between this BidPoint and another BidPoint. sqrt((Tx
|
---|
163 | * - Ox) ^ 2 + (Ty - Oy) ^ 2 + ...).
|
---|
164 | *
|
---|
165 | * @param other
|
---|
166 | * bidpoint to which the distance is calculated.
|
---|
167 | * @return distance to the given bidpoint.
|
---|
168 | */
|
---|
169 | public double getDistance(BidPoint other) {
|
---|
170 | double sum = 0;
|
---|
171 | for (int i = 0; i < utility.length; i++) {
|
---|
172 | sum += Math.pow(this.utility[i] - other.utility[i], 2);
|
---|
173 | }
|
---|
174 | return Math.sqrt(sum);
|
---|
175 | }
|
---|
176 |
|
---|
177 | /**
|
---|
178 | *
|
---|
179 | * @return sum of utilities of all parties for this bid
|
---|
180 | */
|
---|
181 | public double getSocialWelfare() {
|
---|
182 | double sum = 0;
|
---|
183 | for (double util : utility) {
|
---|
184 | sum += util;
|
---|
185 | }
|
---|
186 | return sum;
|
---|
187 | }
|
---|
188 | } |
---|