1 | package agents.anac.y2011.TheNegotiator;
|
---|
2 |
|
---|
3 | import genius.core.Bid;
|
---|
4 |
|
---|
5 | /**
|
---|
6 | * The UTBid class is used to store a bid with it's corresponding utility.
|
---|
7 | * In this way constant recomputation of the utility values is avoided.
|
---|
8 | *
|
---|
9 | * @author Alex Dirkzwager, Mark Hendrikx, Julian de Ruiter
|
---|
10 | */
|
---|
11 | public class UTBid implements Comparable<UTBid>{
|
---|
12 |
|
---|
13 | // the bid of an agent
|
---|
14 | private Bid bid;
|
---|
15 | // the utility corresponding to the bid
|
---|
16 | private double utility;
|
---|
17 | //indicates if the bid has already been offered
|
---|
18 | private boolean alreadyOffered;
|
---|
19 |
|
---|
20 | /**
|
---|
21 | * Creates a UTBid-object which stores a bid with it's corresponding
|
---|
22 | * utility.
|
---|
23 | *
|
---|
24 | * @param bid of an agent
|
---|
25 | * @param utility of the bid
|
---|
26 | */
|
---|
27 | public UTBid(Bid bid, double utility) {
|
---|
28 | this.bid = bid;
|
---|
29 | this.utility = utility;
|
---|
30 | alreadyOffered = false;
|
---|
31 | }
|
---|
32 |
|
---|
33 | /**
|
---|
34 | * Method which returns the bid.
|
---|
35 | *
|
---|
36 | * @return bid
|
---|
37 | */
|
---|
38 | public Bid getBid() {
|
---|
39 | return bid;
|
---|
40 | }
|
---|
41 |
|
---|
42 | /**
|
---|
43 | * Method which sets the bid.
|
---|
44 | *
|
---|
45 | * @param bid
|
---|
46 | */
|
---|
47 | public void setBid(Bid bid) {
|
---|
48 | this.bid = bid;
|
---|
49 | }
|
---|
50 |
|
---|
51 | /**
|
---|
52 | * Method which returns the utility.
|
---|
53 | *
|
---|
54 | * @return utility
|
---|
55 | */
|
---|
56 | public double getUtility() {
|
---|
57 | return utility;
|
---|
58 | }
|
---|
59 |
|
---|
60 | /**
|
---|
61 | * Method which sets the utility.
|
---|
62 | *
|
---|
63 | * @param utility
|
---|
64 | */
|
---|
65 | public void setUtility(double utility) {
|
---|
66 | this.utility = utility;
|
---|
67 | }
|
---|
68 |
|
---|
69 | /**
|
---|
70 | * checks whether the bid has already been made
|
---|
71 | * @return boolean
|
---|
72 | */
|
---|
73 | public boolean getAlreadyOffered(){
|
---|
74 | return alreadyOffered;
|
---|
75 | }
|
---|
76 |
|
---|
77 | /**
|
---|
78 | * sets the the bid as offered or not
|
---|
79 | * @param offered
|
---|
80 | */
|
---|
81 | public void setAlreadyOffered(boolean offered){
|
---|
82 | alreadyOffered = offered;
|
---|
83 | }
|
---|
84 |
|
---|
85 | /**
|
---|
86 | * compareTo is used to compare UTbids. The comparision is made
|
---|
87 | * in such a way that the result is in reverse natural order.
|
---|
88 | *
|
---|
89 | * @param another utbid
|
---|
90 | */
|
---|
91 | public int compareTo(UTBid utbid) {
|
---|
92 | double otherUtil = utbid.getUtility();
|
---|
93 |
|
---|
94 | int value = 0;
|
---|
95 | if (this.utility < otherUtil) {
|
---|
96 | value = 1;
|
---|
97 | } else if (this.utility > otherUtil) {
|
---|
98 | value = -1;
|
---|
99 | }
|
---|
100 | return value;
|
---|
101 | }
|
---|
102 | } |
---|