1 | package geniusweb.boa.acceptancestrategy;
|
---|
2 |
|
---|
3 | import static org.junit.Assert.assertFalse;
|
---|
4 | import static org.junit.Assert.assertTrue;
|
---|
5 | import static org.mockito.Matchers.any;
|
---|
6 | import static org.mockito.Matchers.eq;
|
---|
7 | import static org.mockito.Mockito.mock;
|
---|
8 | import static org.mockito.Mockito.when;
|
---|
9 |
|
---|
10 | import java.math.BigDecimal;
|
---|
11 |
|
---|
12 | import org.junit.Before;
|
---|
13 | import org.junit.Test;
|
---|
14 |
|
---|
15 | import geniusweb.actions.Accept;
|
---|
16 | import geniusweb.actions.Offer;
|
---|
17 | import geniusweb.actions.PartyId;
|
---|
18 | import geniusweb.bidspace.BidsWithUtility;
|
---|
19 | import geniusweb.bidspace.Interval;
|
---|
20 | import geniusweb.boa.BoaState;
|
---|
21 | import geniusweb.inform.Settings;
|
---|
22 | import geniusweb.issuevalue.Bid;
|
---|
23 | import geniusweb.profile.Profile;
|
---|
24 | import geniusweb.profile.utilityspace.LinearAdditive;
|
---|
25 | import geniusweb.progress.Progress;
|
---|
26 | import geniusweb.progress.ProgressRounds;
|
---|
27 | import geniusweb.references.Parameters;
|
---|
28 |
|
---|
29 | public class TimeDepAccStratTest {
|
---|
30 | private static final Bid resbid = mock(Bid.class);
|
---|
31 | private final Progress progress = mock(ProgressRounds.class);
|
---|
32 | private final BidsWithUtility testbidspace = mock(BidsWithUtility.class);
|
---|
33 | private final BoaState state = mock(BoaState.class);
|
---|
34 | private final Bid bid1 = mock(Bid.class);
|
---|
35 | private final Settings settings = mock(Settings.class);
|
---|
36 | private final LinearAdditive linearprofile = mock(LinearAdditive.class);
|
---|
37 | private PartyId party = new PartyId("someparty");
|
---|
38 |
|
---|
39 | @Before
|
---|
40 | public void before() {
|
---|
41 | when(state.getSettings()).thenReturn(settings);
|
---|
42 | when(state.getProfile()).thenReturn(linearprofile);
|
---|
43 | when(state.getProgress()).thenReturn(progress);
|
---|
44 | when(settings.getParameters()).thenReturn(new Parameters());
|
---|
45 |
|
---|
46 | }
|
---|
47 |
|
---|
48 | @Test
|
---|
49 | public void testRoundsProgressAtStart() {
|
---|
50 | when(testbidspace.getRange())
|
---|
51 | .thenReturn(new Interval(BigDecimal.ZERO, BigDecimal.ONE));
|
---|
52 |
|
---|
53 | TimeDependentAcceptanceStrategy ac = new TimeDependentAcceptanceStrategy() {
|
---|
54 | @Override
|
---|
55 | protected BidsWithUtility getBidspace(Profile profile) {
|
---|
56 | return testbidspace;
|
---|
57 | }
|
---|
58 | };
|
---|
59 | // we use default e=1, k=0 which means p(0)=1
|
---|
60 |
|
---|
61 | when(progress.get(any())).thenReturn(0.0d);
|
---|
62 |
|
---|
63 | when(linearprofile.getUtility(eq(bid1)))
|
---|
64 | .thenReturn(BigDecimal.valueOf(0.4));
|
---|
65 |
|
---|
66 | assertFalse(ac.filter(new Offer(party, bid1), state) instanceof Accept);
|
---|
67 | }
|
---|
68 |
|
---|
69 | @Test
|
---|
70 | public void testRoundsProgressAtStart1() {
|
---|
71 | when(testbidspace.getRange()).thenReturn(
|
---|
72 | new Interval(BigDecimal.ZERO, new BigDecimal("0.4")));
|
---|
73 | // the max util in this space is 0.4
|
---|
74 |
|
---|
75 | TimeDependentAcceptanceStrategy ac = new TimeDependentAcceptanceStrategy() {
|
---|
76 | @Override
|
---|
77 | protected BidsWithUtility getBidspace(Profile profile) {
|
---|
78 | return testbidspace;
|
---|
79 | }
|
---|
80 | };
|
---|
81 | // we use default e=1, k=0 which means p(0)=1
|
---|
82 |
|
---|
83 | when(progress.get(any())).thenReturn(0.0d);
|
---|
84 |
|
---|
85 | when(linearprofile.getUtility(eq(bid1)))
|
---|
86 | .thenReturn(new BigDecimal("0.4")); // now =max util
|
---|
87 | when(state.getLastReceivedOffer()).thenReturn(new Offer(party, bid1));
|
---|
88 | assertTrue(ac.filter(new Offer(party, bid1), state) instanceof Accept);
|
---|
89 | }
|
---|
90 |
|
---|
91 | @Test
|
---|
92 | public void testRoundsProgressAtEnd() {
|
---|
93 | when(testbidspace.getRange())
|
---|
94 | .thenReturn(new Interval(BigDecimal.ZERO, BigDecimal.ONE));
|
---|
95 |
|
---|
96 | TimeDependentAcceptanceStrategy ac = new TimeDependentAcceptanceStrategy() {
|
---|
97 | @Override
|
---|
98 | protected BidsWithUtility getBidspace(Profile profile) {
|
---|
99 | return testbidspace;
|
---|
100 | }
|
---|
101 | };
|
---|
102 | // we use default e=1, k=0 which means p(1)=0
|
---|
103 |
|
---|
104 | when(progress.get(any())).thenReturn(1.0d);
|
---|
105 |
|
---|
106 | when(state.getLastReceivedOffer()).thenReturn(new Offer(party, bid1));
|
---|
107 | when(linearprofile.getUtility(eq(bid1)))
|
---|
108 | .thenReturn(BigDecimal.valueOf(0.4));
|
---|
109 |
|
---|
110 | when(state.getLastReceivedOffer()).thenReturn(new Offer(party, bid1));
|
---|
111 | assertTrue(ac.filter(new Offer(party, bid1), state) instanceof Accept);
|
---|
112 | }
|
---|
113 |
|
---|
114 | @Test
|
---|
115 | public void testRoundsProgressResValueIsUsed() {
|
---|
116 | // resbid should raise the minimum at the end.
|
---|
117 | // we check that at the end a bid with lower util than resbid is
|
---|
118 | // not accepted.
|
---|
119 | when(testbidspace.getRange())
|
---|
120 | .thenReturn(new Interval(BigDecimal.ZERO, BigDecimal.ONE));
|
---|
121 |
|
---|
122 | TimeDependentAcceptanceStrategy ac = new TimeDependentAcceptanceStrategy() {
|
---|
123 | @Override
|
---|
124 | protected BidsWithUtility getBidspace(Profile profile) {
|
---|
125 | return testbidspace;
|
---|
126 | }
|
---|
127 | };
|
---|
128 | // we use default e=1, k=0 which means p(1)=resValue.
|
---|
129 |
|
---|
130 | when(progress.get(any())).thenReturn(1.0d);
|
---|
131 |
|
---|
132 | when(linearprofile.getUtility(eq(bid1)))
|
---|
133 | .thenReturn(BigDecimal.valueOf(0.4));
|
---|
134 |
|
---|
135 | when(linearprofile.getReservationBid()).thenReturn(resbid);
|
---|
136 | when(linearprofile.getUtility(eq(resbid)))
|
---|
137 | .thenReturn(new BigDecimal("0.5"));
|
---|
138 |
|
---|
139 | // bid1 has util 0.4 which is below res value.
|
---|
140 | when(state.getLastReceivedOffer()).thenReturn(new Offer(party, bid1));
|
---|
141 | assertFalse(ac.filter(new Offer(party, bid1), state) instanceof Accept);
|
---|
142 | }
|
---|
143 |
|
---|
144 | }
|
---|