View Javadoc

1   /*
2   * The contents of this file are subject to the BT "ZEUS" Open Source 
3   * Licence (L77741), Version 1.0 (the "Licence"); you may not use this file 
4   * except in compliance with the Licence. You may obtain a copy of the Licence
5   * from $ZEUS_INSTALL/licence.html or alternatively from
6   * http://www.labs.bt.com/projects/agents/zeus/licence.htm
7   * 
8   * Except as stated in Clause 7 of the Licence, software distributed under the
9   * Licence is distributed WITHOUT WARRANTY OF ANY KIND, either express or 
10  * implied. See the Licence for the specific language governing rights and 
11  * limitations under the Licence.
12  * 
13  * The Original Code is within the package zeus.*.
14  * The Initial Developer of the Original Code is British Telecommunications
15  * public limited company, whose registered office is at 81 Newgate Street, 
16  * London, EC1A 7AJ, England. Portions created by British Telecommunications 
17  * public limited company are Copyright 1996-9. All Rights Reserved.
18  * 
19  * THIS NOTICE MUST BE INCLUDED ON ANY COPY OF THIS FILE
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     // Strategy parameters
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        // set up parameters
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 }