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 SimpleRespondentEvaluator extends StrategyEvaluator {
33 protected static final double round_time = 0.1;
34
35
36 double max;
37 double min;
38 double noquibble;
39
40 double cost = 0;
41 double price = 0;
42 double offer = 0;
43 double rate;
44 double start_time = 0;
45 double end_time = 0;
46
47 public int evaluateFirst(Vector goals, ProtocolDbResult info) {
48 Core.DEBUG(3,"SimpleRespondentEvaluator:EvaluateFirst entry\n" +
49 goals + "\n" + info);
50 this.goals = goals;
51 this.protocolInfo = info;
52
53
54 max = getDoubleParam("max.percent",120)/100.0;
55 min = getDoubleParam("min.percent",103)/100.0;
56 noquibble = getDoubleParam("noquibble.range",1);
57
58 Goal g = (Goal)goals.elementAt(0);
59 Core.DEBUG(3,"SimpleRespondentEvaluator:EvaluateFirst g = " + g);
60
61 end_time = g.getReplyTime().getTime() - round_time;
62 start_time = context.now();
63 cost = g.getCost();
64
65 max *= cost;
66 min *= cost;
67 double r_price = getDoubleParam("reservation.price",Double.MIN_VALUE);
68 min = Math.max(min,r_price);
69
70 price = (int)max;
71 rate = Math.log(max/min)/(end_time-start_time);
72
73 price = Math.max(price,0);
74 g.setCost(price);
75 Core.DEBUG(3,context.whoami() + " EvaluateFirst: " + start_time +", " + end_time + ", " + price);
76
77 return MESSAGE;
78 }
79
80 public int evaluateNext(DelegationStruct ds) {
81 Core.DEBUG(3,"SimpleRespondentEvaluator:EvaluateNext: " + ds);
82 this.goals = ds.goals;
83 if ( ds.msg_type.equals("accept-proposal") ) {
84 System.out.println("OK 0");
85 return OK;
86 }
87 if ( ds.msg_type.equals("reject-proposal") ) {
88 System.out.println("Fail 0");
89 return FAIL;
90 }
91
92 Goal g = (Goal)ds.goals.elementAt(0);
93
94 offer = g.getCost();
95
96 double dt = context.now() - start_time;
97 System.out.println("dt = " + dt + " rate = " + rate);
98
99 price = (int)(max*Math.exp(-1.0*rate*dt));
100
101 Core.DEBUG(3,context.whoami() + " EvaluateNext: " + offer + " " + price);
102
103 if ( price < min ) {
104 System.out.println("Fail 1");
105 return FAIL;
106 }
107
108 if ( offer >= price )
109 price = offer + 1;
110
111 price = Math.max(price,0);
112 g.setCost(price);
113
114 return MESSAGE;
115 }
116 }