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 LinearRespondentEvaluator extends StrategyEvaluator {
33     boolean first_response = true;
34  
35     double min;
36     double max;
37     double noquibble;
38  
39     // The Strategy Parameters
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        // set up parameters
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           // modify end_time to conclude  before real end_time
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 }