1 | package agents.anac.y2018.lancelot.etc;
|
---|
2 |
|
---|
3 | import java.util.List;
|
---|
4 |
|
---|
5 | import java.util.ArrayList;
|
---|
6 |
|
---|
7 | import genius.core.Bid;
|
---|
8 | import genius.core.parties.NegotiationInfo;
|
---|
9 | import genius.core.timeline.TimeLineInfo;
|
---|
10 | import genius.core.utility.AbstractUtilitySpace;
|
---|
11 |
|
---|
12 | public class strategy {
|
---|
13 | private boolean DEBUG = true;
|
---|
14 | private AbstractUtilitySpace utilitySpace;
|
---|
15 | private TimeLineInfo timeLine;
|
---|
16 | private NegotiationInfo negotiationInfo;
|
---|
17 | private double eval_opponent = 0.0;
|
---|
18 | private int eval_cnt = 0;
|
---|
19 | private double my_last_util_ave = 0;
|
---|
20 | private double my_last_util_sum = 0;
|
---|
21 | private int last_cnt = 0;
|
---|
22 | private List<Double> my_util_list;
|
---|
23 |
|
---|
24 | public strategy(AbstractUtilitySpace utilitySpace, TimeLineInfo timeLine, NegotiationInfo negotiationInfo){
|
---|
25 | this.utilitySpace = utilitySpace;
|
---|
26 | this.timeLine = timeLine;
|
---|
27 | this.negotiationInfo = negotiationInfo;
|
---|
28 | my_util_list = new ArrayList<Double>();
|
---|
29 | }
|
---|
30 |
|
---|
31 | // When my turn comes, the method is called and decide accept or offer.
|
---|
32 | // return true: Accept
|
---|
33 | // return false: Offer
|
---|
34 | public Boolean decideAcceptOrOffer(Bid lastReceivedBid,double opponent_eval,double my_util){
|
---|
35 | double util = 0.0;
|
---|
36 | double time = 0.0;
|
---|
37 | try {
|
---|
38 | time = timeLine.getTime();
|
---|
39 | util = utilitySpace.getUtilityWithDiscount(lastReceivedBid,time);
|
---|
40 |
|
---|
41 | } catch(Exception e){
|
---|
42 | System.out.println("Utilityもしくはtimeを取得できませんでした");
|
---|
43 | }
|
---|
44 | if (util > getUtilThreshold2(time,opponent_eval,my_util)){
|
---|
45 | return true;
|
---|
46 | }
|
---|
47 | return false;
|
---|
48 | }
|
---|
49 |
|
---|
50 | //return my threshold of utility at current time
|
---|
51 | public double getUtilThreshold2(double time, double opponent_value, double my_util){
|
---|
52 | Bid max_bid = null;
|
---|
53 | double max_util = 0;
|
---|
54 | try {
|
---|
55 | max_bid = utilitySpace.getMaxUtilityBid();
|
---|
56 | } catch(Exception e){
|
---|
57 | System.out.println("max_bidを得ることができませんでした.");
|
---|
58 | }
|
---|
59 | max_util = utilitySpace.getUtilityWithDiscount(max_bid,time);
|
---|
60 | // System.out.println("opponent_value = " + opponent_value);
|
---|
61 | double threshold = 1.0;
|
---|
62 | double sep_point = 0.7;
|
---|
63 | if(time < sep_point){
|
---|
64 | threshold = (max_util - opponent_value) / (Math.pow(sep_point,2)) * Math.pow(time-sep_point,2) + opponent_value;
|
---|
65 | } else if(time < 0.99){
|
---|
66 | threshold = (opponent_value - max_util) / Math.pow(1-sep_point,2) * Math.pow(time-1,2) + max_util;
|
---|
67 | }else{
|
---|
68 | threshold = max_util * 0.75 * time;
|
---|
69 | }
|
---|
70 |
|
---|
71 | // if(time > 0.99){
|
---|
72 | // last_cnt ++;
|
---|
73 | // my_last_util_sum += my_util;
|
---|
74 | // threshold = Math.min(getMyUtilAve() - getStandardDeviation() ,1);
|
---|
75 | // System.out.println("***************************************last threshold*************************************** = " + threshold);
|
---|
76 | // }
|
---|
77 | // System.out.println("lancelot's threshold = " + threshold + ": opponent_value = " + opponent_value);
|
---|
78 | return threshold;
|
---|
79 | }
|
---|
80 |
|
---|
81 | public double getUtilThreshold3(double time, double opponent_value, double my_util){
|
---|
82 | // System.out.println("opponent_value = " + opponent_value);
|
---|
83 | double threshold = 1.0;
|
---|
84 | double sep_point = 0.7;
|
---|
85 | if(time < sep_point){
|
---|
86 | threshold = (1 - opponent_value) / (Math.pow(sep_point,2)) * Math.pow(time-sep_point,2) + opponent_value;
|
---|
87 | } else if(time < 0.99){
|
---|
88 | threshold = (opponent_value - 1) / Math.pow(1-sep_point,2) * Math.pow(time-1,2) + 1;
|
---|
89 | }else{
|
---|
90 | threshold = 0.75 * time;
|
---|
91 | }
|
---|
92 |
|
---|
93 | // if(time > 0.99){
|
---|
94 | // last_cnt ++;
|
---|
95 | // my_last_util_sum += my_util;
|
---|
96 | // threshold = Math.min(getMyUtilAve() + getStandardDeviation()*2 ,1);
|
---|
97 | // System.out.println("***************************************last threshold*************************************** = " + threshold);
|
---|
98 | // }
|
---|
99 | // System.out.println("lancelot's threshold = " + threshold + ": opponent_value = " + opponent_value);
|
---|
100 | return threshold;
|
---|
101 | }
|
---|
102 |
|
---|
103 | public double getUtilThresholdForOffer(){
|
---|
104 | return 0.90;
|
---|
105 | }
|
---|
106 |
|
---|
107 | public double evaluateOpponent(Bid lastRecievedBid){
|
---|
108 | eval_cnt++;
|
---|
109 | // double my_util = utilitySpace.getUtility(lastRecievedBid);
|
---|
110 | double my_util = utilitySpace.getUtilityWithDiscount(lastRecievedBid,timeLine.getTime());
|
---|
111 | eval_opponent += my_util;
|
---|
112 | my_util_list.add(my_util);
|
---|
113 | // getStandardDeviation();
|
---|
114 | return getEvalAve() + getStandardDeviation();
|
---|
115 | }
|
---|
116 |
|
---|
117 | private double getEvalAve(){
|
---|
118 | return eval_opponent / eval_cnt;
|
---|
119 | }
|
---|
120 |
|
---|
121 | private double getMyUtilAve(){
|
---|
122 | return my_last_util_sum / last_cnt;
|
---|
123 | }
|
---|
124 |
|
---|
125 | private double getStandardDeviation(){
|
---|
126 | double deviation_sum = 0;
|
---|
127 | double ave = getEvalAve();
|
---|
128 | for(double my_util : my_util_list){
|
---|
129 | deviation_sum += Math.pow((my_util-ave),2);
|
---|
130 | }
|
---|
131 | // System.out.println("StandardDeviation : " + Math.sqrt(deviation_sum / eval_cnt));
|
---|
132 | return Math.sqrt(deviation_sum / eval_cnt);
|
---|
133 | }
|
---|
134 | }
|
---|