source: src/main/java/genius/core/bidding/BidDetails.java

Last change on this file was 187, checked in by Tim Baarslag, 6 years ago

CustomUtilitySpacePartyExample now works for all settings

File size: 4.3 KB
Line 
1package genius.core.bidding;
2
3import java.io.Serializable;
4
5import genius.core.Bid;
6
7/**
8 * The BidDetails class is used to store a bid with it's corresponding utility and time it was offered.
9 * In this way constant re-computation of the utility values is avoided.
10 *
11 * @author Tim Baarslag, Alex Dirkzwager, Mark Hendrikx
12 */
13public class BidDetails implements Comparable<BidDetails>, Serializable{
14
15 /**
16 *
17 */
18 private static final long serialVersionUID = -6111983303592311613L;
19 /** the bid of an agent */
20 private Bid bid;
21 /** the utility corresponding to the bid */
22 private double myUndiscountedUtil;
23 /** time the bid was offered (so the discounted utility can be calculated at that time) */
24 private double time;
25
26 /**
27 * Creates a BidDetails-object which stores a bid with its corresponding utility.
28 *
29 * @param bid of an agent
30 * @param myUndiscountedUtil utility of the bid
31 */
32 public BidDetails(Bid bid, double myUndiscountedUtil) {
33 this.bid = bid;
34 this.myUndiscountedUtil = myUndiscountedUtil;
35 }
36
37 /**
38 * Creates a BidDetails-object which stores a bid with it's corresponding
39 * utility and the time it was offered.
40 *
41 * @param bid of an agent
42 * @param myUndiscountedUtil of the bid
43 * @param time of offering
44 */
45 public BidDetails(Bid bid, double myUndiscountedUtil, double time) {
46 this.bid = bid;
47 this.myUndiscountedUtil = myUndiscountedUtil;
48 this.time = time;
49 }
50
51 /**
52 * Returns the bid.
53 * @return bid.
54 */
55 public Bid getBid() {
56 return bid;
57 }
58
59 /**
60 * Set the bid.
61 * @param bid to be set in this object.
62 */
63 public void setBid(Bid bid) {
64 this.bid = bid;
65 }
66
67 /**
68 * Returns the undiscounted utility of the bid as supplied in the
69 * constructor. Depending on the usage this can also be the utility
70 * of the opponent if the BidDetails object was constructed by
71 * the opponent model.
72 *
73 * @return undiscounted utility of bid.
74 */
75 public double getMyUndiscountedUtil() {
76 return myUndiscountedUtil;
77 }
78
79 /**
80 * Set the undiscounted utility of the bid.
81 * @param utility of the bid.
82 */
83 public void setMyUndiscountedUtil(double utility) {
84 this.myUndiscountedUtil = utility;
85 }
86
87 /**
88 * Return the time at which this bid was offered.
89 * @return time of offering.
90 */
91 public double getTime(){
92 return time;
93 }
94
95 /**
96 * Set the time at which this bid was offered.
97 * @param time of offering.
98 */
99 public void setTime(double time){
100 this.time = time;
101 }
102
103 /**
104 * @return string representation of the object (u=UTILITY, t=TIME).
105 */
106 @Override
107 public String toString()
108 {
109 return "(u=" + myUndiscountedUtil + ", t=" + time + ")";
110 }
111
112 /**
113 * A comparator for BidDetails which order the bids in
114 * reverse natural order of utility.
115 *
116 * @param other bid to which this bid is compared.
117 * @return order of this bid relative to the given bid.
118 */
119 public int compareTo(BidDetails other) {
120 double otherUtil = other.getMyUndiscountedUtil();
121
122 int value = 0;
123 if (this.myUndiscountedUtil < otherUtil) {
124 value = 1;
125 } else if (this.myUndiscountedUtil > otherUtil) {
126 value = -1;
127 }
128 return value;
129 }
130
131 /**
132 * @return hashcode of this object.
133 */
134 @Override
135 public int hashCode() {
136 final int prime = 31;
137 int result = 1;
138 result = prime * result + ((bid == null) ? 0 : bid.hashCode());
139 long temp;
140 temp = Double.doubleToLongBits(myUndiscountedUtil);
141 result = prime * result + (int) (temp ^ (temp >>> 32));
142 temp = Double.doubleToLongBits(time);
143 result = prime * result + (int) (temp ^ (temp >>> 32));
144 return result;
145 }
146
147 /**
148 * @param obj object to which this object is compared.
149 * @return true if this object is equal to the given object.
150 */
151 @Override
152 public boolean equals(Object obj) {
153 if (this == obj)
154 return true;
155 if (obj == null)
156 return false;
157 if (getClass() != obj.getClass())
158 return false;
159 BidDetails other = (BidDetails) obj;
160 if (bid == null) {
161 if (other.bid != null)
162 return false;
163 } else if (!bid.equals(other.bid))
164 return false;
165 if (Double.doubleToLongBits(myUndiscountedUtil) != Double
166 .doubleToLongBits(other.myUndiscountedUtil))
167 return false;
168 if (Double.doubleToLongBits(time) != Double
169 .doubleToLongBits(other.time))
170 return false;
171 return true;
172 }
173}
Note: See TracBrowser for help on using the repository browser.