1 | package parties.in4010.q12015.group17;
|
---|
2 |
|
---|
3 | import genius.core.Bid;
|
---|
4 | import genius.core.timeline.TimeLineInfo;
|
---|
5 | import genius.core.utility.AbstractUtilitySpace;
|
---|
6 |
|
---|
7 | /**
|
---|
8 | * This class is responsible for determining whether to accept a bid or not.
|
---|
9 | * Though it is currently only a single method, for the sake of future expansion
|
---|
10 | * as well as proper segregation it has been placed in its own class.
|
---|
11 | */
|
---|
12 | public class AcceptStrategy {
|
---|
13 |
|
---|
14 | private final AbstractUtilitySpace utilitySpace;
|
---|
15 | private final TimeLineInfo timeline;
|
---|
16 |
|
---|
17 | public AcceptStrategy(AbstractUtilitySpace us, TimeLineInfo t) {
|
---|
18 | this.utilitySpace = us;
|
---|
19 | this.timeline = t;
|
---|
20 | }
|
---|
21 |
|
---|
22 | /**
|
---|
23 | * Determines if the given bid is acceptable according to the current time.
|
---|
24 | *
|
---|
25 | * @param b
|
---|
26 | * The {@link Bid} to evaluate.
|
---|
27 | * @return {@code TRUE} if this {@link Bid} should be accepted, otherwise
|
---|
28 | * {@code FALSE}.
|
---|
29 | */
|
---|
30 | public boolean determineAcceptability(Bid b) {
|
---|
31 | try {
|
---|
32 | double utility = utilitySpace.getUtility(b);
|
---|
33 | double time = timeline.getTime();
|
---|
34 |
|
---|
35 | // First part of concession. A sinoid decay from 1 to 0.8 utility
|
---|
36 | // over 0<t<0.8.
|
---|
37 | if (time <= 0.8)
|
---|
38 | return utility > 1 + (0.1 * ((Math.cos(time * Math.PI * 1.25) - 1)));
|
---|
39 | // Fourth part. A linear decay from 0.6 to 0.55 over 0.985 < t < 1.
|
---|
40 | else if (time > 0.985)
|
---|
41 | return utility > 0.6 - ((time - 0.985) / 0.015) * 0.05;
|
---|
42 | // Third part. A linear decay from 0.7 to 0.6 over 0.95<t<0.985.
|
---|
43 | else if (time > 0.95)
|
---|
44 | return utility > 0.7 - ((time - 0.95) / 0.035) * 0.1;
|
---|
45 | // Second part. A linear decay from 0.8 to 0.7 over 0.8<t<0.95.
|
---|
46 | else if (time > 0.8)
|
---|
47 | return utility > 0.8 - ((time - 0.8) / 0.15) * 0.1;
|
---|
48 | } catch (Exception e) {
|
---|
49 | e.printStackTrace();
|
---|
50 | }
|
---|
51 | return false;
|
---|
52 | }
|
---|
53 | }
|
---|