1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24 package zeus.actors.graphs;
25
26 import java.util.*;
27 import zeus.util.*;
28 import zeus.actors.*;
29 import zeus.actors.rtn.util.*;
30 import zeus.concepts.*;
31
32 public class LinearRespondentEvaluator extends StrategyEvaluator {
33 boolean first_response = true;
34
35 double min;
36 double max;
37 double noquibble;
38
39
40 double price = 0;
41 double min_price = 0;
42 double max_price = 0;
43 double offer = 0;
44 double start_time = 0;
45 double end_time = 0;
46 double actual_cost = 0;
47 double reserve_price = 0;
48 double default_step = 0;
49 double step = 0;
50 double dt = 0;
51
52 public int evaluateFirst(Vector goals, ProtocolDbResult info) {
53 this.goals = goals;
54 this.protocolInfo = info;
55
56
57 max = getDoubleParam("max.percent",120)/100.0;
58 min = getDoubleParam("min.percent",103)/100.0;
59 noquibble = getDoubleParam("noquibble.range",1);
60
61 default_step = getDoubleParam("step.default",0.2);
62 reserve_price = getDoubleParam("reservation.price",Double.MIN_VALUE);
63
64 Goal g = (Goal)goals.elementAt(0);
65 actual_cost = g.getCost();
66
67 start_time = context.now();
68 end_time = g.getReplyTime().getTime();
69
70 max_price = max*Math.max(reserve_price,actual_cost);
71 min_price = Math.max(min*actual_cost,reserve_price);
72
73 price = max_price;
74
75 g.setCost(price);
76 return MESSAGE;
77 }
78
79 public int evaluateNext(DelegationStruct ds) {
80 this.goals = ds.goals;
81 Goal g = (Goal)ds.goals.elementAt(0);
82
83 if ( ds.msg_type.equals("accept-proposal") ) {
84 return OK;
85 }
86 else if ( ds.msg_type.equals("reject-proposal") ) {
87 return FAIL;
88 }
89
90 offer = g.getCost();
91 double now = context.now();
92
93 if ( first_response ) {
94 first_response = false;
95
96 dt = now - start_time;
97
98 end_time = end_time - dt;
99
100 step = (max_price-min_price)*dt/(end_time-start_time);
101 step = Math.max(step,default_step);
102 }
103
104 price -= step;
105 price = Math.max(price,0);
106
107 if ( price < min_price )
108 price = min_price;
109
110 if ( offer >= price )
111 price = offer + step;
112
113 g.setCost(price);
114 return MESSAGE;
115 }
116 }