1 | import geniusweb.actions.ActionWithBid;
|
---|
2 | import geniusweb.actions.Offer;
|
---|
3 | import geniusweb.boa.BoaState;
|
---|
4 | import geniusweb.boa.acceptancestrategy.AcceptanceStrategy;
|
---|
5 | import geniusweb.issuevalue.Bid;
|
---|
6 | import geniusweb.profile.Profile;
|
---|
7 | import geniusweb.profile.utilityspace.LinearAdditive;
|
---|
8 | import geniusweb.actions.Action;
|
---|
9 |
|
---|
10 | import java.math.BigDecimal;
|
---|
11 | import java.util.Date;
|
---|
12 |
|
---|
13 | public class Group5AcceptanceStrategy implements AcceptanceStrategy {
|
---|
14 | private LinearAdditive utilspace;
|
---|
15 |
|
---|
16 | /**
|
---|
17 | * Implements our own acceptance strategy that combines ACnext and ACtime as failsafe.
|
---|
18 | *
|
---|
19 | * @param bid The bid that we want to know if it is acceptable or not.
|
---|
20 | * @param negoState Current state of the negotiations so far.
|
---|
21 | * @return Returns a boolean to indicate whether the current bid is acceptable.
|
---|
22 | */
|
---|
23 | @Override
|
---|
24 | public Boolean isAcceptable(Bid bid, BoaState negoState) {
|
---|
25 | // Do not accept if there is no offer
|
---|
26 | if (bid == null) {
|
---|
27 | return false;
|
---|
28 | }
|
---|
29 |
|
---|
30 | // The ACtime part of the strategy
|
---|
31 | double currenttimeFraction = negoState.getProgress().get(System.currentTimeMillis());
|
---|
32 |
|
---|
33 | // Calculate the utility of their bid and our reservation bid.
|
---|
34 | BigDecimal bidUtil = getUtilityOfBid(bid, negoState);
|
---|
35 | BigDecimal reservationValue;
|
---|
36 | if (currenttimeFraction > 0.90) {
|
---|
37 | if (utilspace.getReservationBid() == null) {
|
---|
38 | return true;
|
---|
39 | }
|
---|
40 | reservationValue = utilspace.getUtility(utilspace.getReservationBid());
|
---|
41 | if (bidUtil.compareTo(reservationValue) > 0) {
|
---|
42 | return true;
|
---|
43 | }
|
---|
44 | }
|
---|
45 |
|
---|
46 | //Now implement the ACnext part, so compare the utility of the bid to utility of our next bid.
|
---|
47 | Group5BiddingStrategy biddingStrategy = new Group5BiddingStrategy();
|
---|
48 | Action nextAction = biddingStrategy.getAction(negoState);
|
---|
49 | if (nextAction instanceof ActionWithBid) {
|
---|
50 | Bid futureBid = ((ActionWithBid) nextAction).getBid();
|
---|
51 | BigDecimal utilOfNextBid = getUtilityOfBid(futureBid, negoState);
|
---|
52 | return bidUtil.compareTo(utilOfNextBid) > 0;
|
---|
53 | }
|
---|
54 |
|
---|
55 | // If it is not better than the bid we are going to do and still have time, then dont accept.
|
---|
56 | return false;
|
---|
57 | }
|
---|
58 |
|
---|
59 | /**
|
---|
60 | * Function that calculates the utility of a bid for our profile.
|
---|
61 | * @param bid The bid of which we want to know the utility.
|
---|
62 | * @param negoState The state in which we want to know the utility.
|
---|
63 | * @return a BigDecimal with the utility.
|
---|
64 | */
|
---|
65 | public BigDecimal getUtilityOfBid(Bid bid, BoaState negoState) {
|
---|
66 | Profile newUtilspace = negoState.getProfile();
|
---|
67 | if (!newUtilspace.equals(this.utilspace)) {
|
---|
68 | this.utilspace = (LinearAdditive) newUtilspace;
|
---|
69 | }
|
---|
70 | // Calculate the utility of their bid.
|
---|
71 | return this.utilspace.getUtility(bid);
|
---|
72 | }
|
---|
73 | }
|
---|