1 | package parties.in4010.q12015.group10;
|
---|
2 |
|
---|
3 | import java.util.List;
|
---|
4 |
|
---|
5 | import genius.core.AgentID;
|
---|
6 | import genius.core.actions.Accept;
|
---|
7 | import genius.core.actions.Action;
|
---|
8 | import genius.core.actions.Offer;
|
---|
9 | import genius.core.bidding.BidDetails;
|
---|
10 |
|
---|
11 | public class AcceptanceStrategy {
|
---|
12 | /**
|
---|
13 | * support function to create action
|
---|
14 | *
|
---|
15 | * @param validActions
|
---|
16 | * @param detailsOfPotentialBid
|
---|
17 | * @param detailsOfLatestBidOnTable
|
---|
18 | * @param agent
|
---|
19 | * the agent ID, needed to create the actions on behalf of this
|
---|
20 | * agent.
|
---|
21 | * @return
|
---|
22 | */
|
---|
23 | static Action getAction(List<Class<? extends Action>> validActions,
|
---|
24 | BidDetails detailsOfPotentialBid,
|
---|
25 | BidDetails detailsOfLatestBidOnTable, AgentID agent) {
|
---|
26 | // Check if we are allowed to accept. We're not allowed to do this when
|
---|
27 | // we are the first party to make a bid.
|
---|
28 | boolean acceptingIsAllowed = validActions.contains(Accept.class);
|
---|
29 |
|
---|
30 | double minUtilityAlwaysAccept = 0.95;
|
---|
31 |
|
---|
32 | if (acceptingIsAllowed) {
|
---|
33 | // We're not the first: So we can accept, offer, or deny.
|
---|
34 | double offeredUtilVal = detailsOfLatestBidOnTable
|
---|
35 | .getMyUndiscountedUtil();
|
---|
36 | double PotentialUtilVal = detailsOfPotentialBid
|
---|
37 | .getMyUndiscountedUtil();
|
---|
38 |
|
---|
39 | // If the value we are getting by accepting is higher than what we
|
---|
40 | // would get using our own new offer, we accept.
|
---|
41 | // We also accept if the utility is higher than our value that we
|
---|
42 | // also accept
|
---|
43 | if (offeredUtilVal >= PotentialUtilVal
|
---|
44 | || offeredUtilVal >= minUtilityAlwaysAccept) {
|
---|
45 | return new Accept(agent, detailsOfPotentialBid.getBid());
|
---|
46 | } else {
|
---|
47 | detailsOfLatestBidOnTable = detailsOfPotentialBid;
|
---|
48 | return new Offer(agent, detailsOfPotentialBid.getBid());
|
---|
49 | }
|
---|
50 | } else {
|
---|
51 | // We are not allowed to accept. We can still offer or deny. Right
|
---|
52 | // now only offering is implemented.
|
---|
53 | detailsOfLatestBidOnTable = detailsOfPotentialBid;
|
---|
54 | return new Offer(agent, detailsOfPotentialBid.getBid());
|
---|
55 | }
|
---|
56 | }
|
---|
57 | }
|
---|