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 LinearInitiatorEvaluator 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 expected_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 min = getDoubleParam("min.percent",80)/100.0;
57 max = getDoubleParam("max.percent",120)/100.0;
58 noquibble = getDoubleParam("noquibble.range",2);
59
60 default_step = getDoubleParam("step.default",0.2);
61 reserve_price = getDoubleParam("reservation.price",Double.MAX_VALUE);
62
63 Goal g = (Goal)goals.elementAt(0);
64 expected_cost = g.getCost();
65
66 start_time = context.now();
67 end_time = g.getReplyTime().getTime();
68
69 g.setCost(0);
70
71 return MESSAGE;
72 }
73
74 public int evaluateNext(DelegationStruct ds) {
75 this.goals = ds.goals;
76 if ( !ds.msg_type.equals("propose") )
77 return FAIL;
78
79 Goal g = (Goal)ds.goals.elementAt(0);
80 offer = g.getCost();
81 double now = context.now();
82
83 if ( first_response ) {
84 first_response = false;
85
86 dt = now - start_time;
87
88 end_time = end_time - dt;
89
90 expected_cost = Math.max(offer,expected_cost);
91
92 min_price = min*Math.min(reserve_price,expected_cost);
93 max_price = Math.min(max*expected_cost,reserve_price);
94
95 price = min_price;
96 step = (max_price-min_price)*dt/(end_time-start_time);
97 step = Math.max(step,default_step);
98 }
99
100 if ( offer < price + noquibble )
101 return OK;
102
103 if ( !first_response ) price += step;
104
105 if ( price < min_price )
106 return FAIL;
107 else if ( offer < price + noquibble )
108 return OK;
109
110 if ( now + dt >= end_time )
111 {
112
113 if ( offer < max_price )
114 return OK;
115 else
116 return FAIL;
117 }
118
119 g.setCost(price);
120 return MESSAGE;
121 }
122 }