1 | package agents.anac.y2019.minf.etc;
|
---|
2 |
|
---|
3 | import java.util.Random;
|
---|
4 |
|
---|
5 | public class NegotiationInfo {
|
---|
6 | private double alpha = 1.0D;
|
---|
7 |
|
---|
8 | private double OpponentAve = 0.0D;
|
---|
9 | private double OpponentSum = 0.0D;
|
---|
10 | private double OpponentPowSum = 0.0D;
|
---|
11 | private double OpponentVar = 0.0D;
|
---|
12 | private double OpponentStdDev = 0.0D;
|
---|
13 | private int OpponentNum = 0;
|
---|
14 |
|
---|
15 | private double OpponentOwnAve = 0.0D;
|
---|
16 | private double OpponentOwnSum = 0.0D;
|
---|
17 | private double OpponentOwnPowSum = 0.0D;
|
---|
18 | private double OpponentOwnVar = 0.0D;
|
---|
19 | private double OpponentOwnStdDev = 0.0D;
|
---|
20 | private double OpponentMinUtil = 1.0D;
|
---|
21 | private int OpponentOwnNum = 0;
|
---|
22 |
|
---|
23 |
|
---|
24 | private double MyAve = 0.0D;
|
---|
25 | private double MySum = 0.0D;
|
---|
26 | private double MyPowSum = 0.0D;
|
---|
27 | private double MyVar = 0.0D;
|
---|
28 | private double MyStdDev = 0.0D;
|
---|
29 | private int MyNum = 0;
|
---|
30 |
|
---|
31 | private boolean isDiscounted = false;
|
---|
32 | private double df = 1.0D;
|
---|
33 | private double rv = 0.0D;
|
---|
34 |
|
---|
35 | private boolean isFirst = false;
|
---|
36 |
|
---|
37 | private Random rand = new Random();
|
---|
38 |
|
---|
39 | public NegotiationInfo(){
|
---|
40 | }
|
---|
41 |
|
---|
42 | public NegotiationInfo(double df, double rv){
|
---|
43 | this.df = df;
|
---|
44 | this.rv = rv;
|
---|
45 | this.isDiscounted = df != 1.0;
|
---|
46 | }
|
---|
47 |
|
---|
48 | public void updateInfo(double lastOpponentBidUtil){
|
---|
49 | this.OpponentNum += 1;
|
---|
50 | this.OpponentSum += lastOpponentBidUtil;
|
---|
51 | this.OpponentPowSum += Math.pow(lastOpponentBidUtil, 2.0D);
|
---|
52 | this.OpponentAve = this.OpponentSum / (double)OpponentNum;
|
---|
53 | this.OpponentVar = this.OpponentPowSum / (double)OpponentNum - Math.pow(this.OpponentAve, 2.0D);
|
---|
54 | if (this.OpponentVar < 1.0E-8) this.OpponentVar = 0.0D;
|
---|
55 | this.OpponentStdDev = Math.sqrt(this.OpponentVar);
|
---|
56 | }
|
---|
57 |
|
---|
58 | public void updateOwnInfo(double lastOpponentOwnBidUtil){
|
---|
59 | this.OpponentOwnNum += 1;
|
---|
60 | this.OpponentOwnSum += lastOpponentOwnBidUtil;
|
---|
61 | this.OpponentOwnPowSum += Math.pow(lastOpponentOwnBidUtil, 2.0D);
|
---|
62 | this.OpponentOwnAve = this.OpponentOwnSum / (double)OpponentOwnNum;
|
---|
63 | this.OpponentOwnVar = this.OpponentOwnPowSum / (double)OpponentOwnNum - Math.pow(this.OpponentOwnAve, 2.0D);
|
---|
64 | if (this.OpponentOwnVar < 1.0E-8) this.OpponentOwnVar = 0.0D;
|
---|
65 | this.OpponentOwnStdDev = Math.sqrt(this.OpponentOwnVar);
|
---|
66 | this.OpponentMinUtil = Math.min(this.OpponentMinUtil, lastOpponentOwnBidUtil);
|
---|
67 | }
|
---|
68 |
|
---|
69 | public void updateMyInfo(double lastMyBidUtil){
|
---|
70 | this.MyNum += 1;
|
---|
71 | this.MySum += lastMyBidUtil;
|
---|
72 | this.MyPowSum += Math.pow(lastMyBidUtil, 2.0D);
|
---|
73 | this.MyAve = this.MySum / (double)MyNum;
|
---|
74 | this.MyVar = this.MyPowSum / (double)MyNum - Math.pow(this.MyAve, 2.0D);
|
---|
75 | if (this.MyVar < 1.0E-8) this.MyVar = 0.0D;
|
---|
76 | this.MyStdDev = Math.sqrt(this.MyVar);
|
---|
77 | }
|
---|
78 |
|
---|
79 | public double getRandomThreshold(double t){
|
---|
80 | double threshold = getThreshold(t);
|
---|
81 |
|
---|
82 | return threshold + (isDiscounted ? 0.0D : rand.nextDouble() * (1.0D - threshold));
|
---|
83 | }
|
---|
84 |
|
---|
85 | public double getThreshold(double t){
|
---|
86 | double lower = this.LowerLimitThreshold(t);
|
---|
87 | double stastical = this.isDiscounted ? this.discount_target(t) : this.target(t);
|
---|
88 |
|
---|
89 | if (calcAlpha() >= 0.3D && this.OpponentVar != 0.0D) {
|
---|
90 | return Math.max(lower, stastical);
|
---|
91 | } else {
|
---|
92 | return 1.0D;
|
---|
93 | }
|
---|
94 | }
|
---|
95 |
|
---|
96 | private double LowerLimitThreshold(double t){
|
---|
97 | double ret = this.rv * 0.2D + (this.isDiscounted ? 0.3D : 0.55D);
|
---|
98 | ret = Math.max(ret, Math.min(1.0D, emax()));
|
---|
99 |
|
---|
100 | if (this.rv == 0.0D && t > 0.99D) { ret *= 0.85D; }
|
---|
101 | return ret;
|
---|
102 | }
|
---|
103 |
|
---|
104 | private double discount_target(double t){
|
---|
105 | return Math.min(0.95D, 1.0D - (1.0D - this.df) * Math.log1p(t * 1.718281828459045D));
|
---|
106 | }
|
---|
107 |
|
---|
108 | private double target(double t){
|
---|
109 | this.alpha = Math.max(0.1D, 3.5D + this.rv - this.calcAlpha());
|
---|
110 | return 1 - (1 - emax()) * Math.pow(t, this.alpha);
|
---|
111 | }
|
---|
112 |
|
---|
113 | private double emax(){
|
---|
114 | return this.OpponentAve + (1 - this.OpponentAve) * d();
|
---|
115 | }
|
---|
116 |
|
---|
117 | private double d(){
|
---|
118 | double ave = this.OpponentAve;
|
---|
119 | double StdDev = this.OpponentStdDev;
|
---|
120 | if(ave <= 0.0D || ave >= 1.0D){
|
---|
121 | return Math.sqrt(12.0D) * StdDev;
|
---|
122 | }else {
|
---|
123 | return Math.sqrt(3.0D / (ave - ave * ave)) * StdDev;
|
---|
124 | }
|
---|
125 | }
|
---|
126 |
|
---|
127 | private double calcAlpha() {
|
---|
128 | return this.calcCooperativeness() - this.calcAssertiveness();
|
---|
129 | }
|
---|
130 |
|
---|
131 | private double calcAssertiveness() {
|
---|
132 | return this.MyVar - this.OpponentVar;
|
---|
133 | }
|
---|
134 |
|
---|
135 | private double calcCooperativeness() {
|
---|
136 | return this.MyAve - this.OpponentAve;
|
---|
137 | }
|
---|
138 |
|
---|
139 | public double getAlpha(){ return calcAlpha(); }
|
---|
140 |
|
---|
141 | public void setFirst(boolean bool) { this.isFirst = bool; }
|
---|
142 |
|
---|
143 | public double getOpponentOwnAve() { return this.OpponentOwnAve; }
|
---|
144 |
|
---|
145 | public double getOpponentOwnVar() { return this.OpponentOwnVar; }
|
---|
146 |
|
---|
147 | public double getOpponentMinUtil() { return this.OpponentMinUtil; }
|
---|
148 |
|
---|
149 | public boolean isFirst() { return this.isFirst; }
|
---|
150 |
|
---|
151 | public double getAssertiveness() { return this.calcAssertiveness(); }
|
---|
152 |
|
---|
153 | public double getCooperativeness() { return this.calcCooperativeness(); }
|
---|
154 | }
|
---|