1 | package geniusweb.exampleparties.simpleshaop;
|
---|
2 |
|
---|
3 | import java.math.BigDecimal;
|
---|
4 |
|
---|
5 | import geniusweb.issuevalue.Bid;
|
---|
6 |
|
---|
7 |
|
---|
8 | public class NegotiationStrategy {
|
---|
9 | private CompRegress compRegress;
|
---|
10 | private NegotiationInfo negotiationInfo;
|
---|
11 |
|
---|
12 | private BigDecimal reserveValue;
|
---|
13 |
|
---|
14 | private BigDecimal A11 = BigDecimal.ZERO; // utility - A: hardliner, B: hardliner
|
---|
15 | private BigDecimal A12 = BigDecimal.ZERO; // utility - A: hardliner, B: conceder
|
---|
16 | private BigDecimal A21 = BigDecimal.ZERO; // utility - A: conceder, B; hardliner
|
---|
17 | private BigDecimal A22 = BigDecimal.ZERO; // utility - A: conceder, B: conceder
|
---|
18 |
|
---|
19 | //static private BigDecimal timeFinal = BigDecimal.ONE;
|
---|
20 | static private BigDecimal probFinal = BigDecimal.valueOf(0.5); // probability of own agent compromising first on last round when both agents concede
|
---|
21 |
|
---|
22 |
|
---|
23 | public NegotiationStrategy(CompRegress compRegress, NegotiationInfo negotiationInfo, Bid reserveBid) {
|
---|
24 | this.compRegress = compRegress;
|
---|
25 | this.negotiationInfo = negotiationInfo;
|
---|
26 | this.reserveValue = compRegress.getUtil(reserveBid);
|
---|
27 | }
|
---|
28 |
|
---|
29 | ////////////////////////////////////////////////////////////////////////////////
|
---|
30 | // select methods for accept and end negotiation
|
---|
31 | ////////////////////////////////////////////////////////////////////////////////
|
---|
32 |
|
---|
33 | /**
|
---|
34 | * selectAccept - decide whether to perform Action: Accept
|
---|
35 | *
|
---|
36 | * @param offeredBid - Bid; the bid offered by opponent
|
---|
37 | * @param time - double; time of negotiation
|
---|
38 | *
|
---|
39 | * @return boolean - true if our agent should accept the offered bid
|
---|
40 | */
|
---|
41 | public boolean selectAccept(Bid offeredBid, BigDecimal time) {
|
---|
42 | try {
|
---|
43 | BigDecimal offeredBidUtil = compRegress.getUtil(offeredBid);
|
---|
44 | return offeredBidUtil.compareTo(getThreshold(time)) >= 0;
|
---|
45 | } catch (Exception e) {
|
---|
46 | System.out.println("selectAccept failed");
|
---|
47 | e.printStackTrace();
|
---|
48 | return false;
|
---|
49 | }
|
---|
50 | }
|
---|
51 |
|
---|
52 | /**
|
---|
53 | * selectEndNegotiation - decide whether to end negotiation
|
---|
54 | */
|
---|
55 | public boolean selectEndNegotiation(BigDecimal time) {
|
---|
56 | return reserveValue.compareTo(getThreshold(time)) >= 0;
|
---|
57 | }
|
---|
58 |
|
---|
59 | ////////////////////////////////////////////////////////////////////////////////
|
---|
60 | // method getThreshold and its helper methods
|
---|
61 | ////////////////////////////////////////////////////////////////////////////////
|
---|
62 |
|
---|
63 | /**
|
---|
64 | * getThreshold - returns threshold
|
---|
65 | */
|
---|
66 | public BigDecimal getThreshold(BigDecimal time) {
|
---|
67 | BigDecimal threshold = BigDecimal.ONE;
|
---|
68 | updateGameMatrix();
|
---|
69 | BigDecimal target = getExpectedUtilInFinal();
|
---|
70 |
|
---|
71 | threshold = target.add((BigDecimal.ONE.subtract(target)).multiply(BigDecimal.ONE.subtract(time)));
|
---|
72 |
|
---|
73 | return threshold;
|
---|
74 | }
|
---|
75 |
|
---|
76 | /**
|
---|
77 | * updateGameMatrix - used in getThreshold
|
---|
78 | */
|
---|
79 | private void updateGameMatrix() {
|
---|
80 | BigDecimal utilConcede = negotiationInfo.getBestOfferedUtil();
|
---|
81 |
|
---|
82 | A11 = reserveValue;
|
---|
83 | A12 = BigDecimal.ONE;
|
---|
84 |
|
---|
85 | if (utilConcede.compareTo(reserveValue) >= 0) A21 = utilConcede;
|
---|
86 | else A21 = reserveValue;
|
---|
87 |
|
---|
88 | A22 = (probFinal.multiply(A21)).add((BigDecimal.ONE.subtract(probFinal)).multiply(A12));
|
---|
89 | }
|
---|
90 |
|
---|
91 | /**
|
---|
92 | * getExpectedUtilInFinal - used in getThreshold
|
---|
93 | */
|
---|
94 | private BigDecimal getExpectedUtilInFinal() {
|
---|
95 | BigDecimal q = getOpponentProbHardliner();
|
---|
96 | return (q.multiply(A21)).add((BigDecimal.ONE.subtract(q)).multiply(A22));
|
---|
97 | }
|
---|
98 |
|
---|
99 | /**
|
---|
100 | * getOpponentProbHardliner - used in getExpectedUtilInFinal, calculate opponent's probability of choosing hardliner strategy in final round
|
---|
101 | */
|
---|
102 | private BigDecimal getOpponentProbHardliner() {
|
---|
103 | double q = 1.0;
|
---|
104 | double A11d = A11.doubleValue();
|
---|
105 | double A12d = A12.doubleValue();
|
---|
106 | double A21d = A21.doubleValue();
|
---|
107 | double A22d = A22.doubleValue();
|
---|
108 |
|
---|
109 | if ((A12d - A22d != 0) && (1.0 - (A11d - A21d) / (A12d - A22d) != 0)) {
|
---|
110 | q = 1.0 / (1.0 - (A11d - A21d) / (A12d -A22d));
|
---|
111 | }
|
---|
112 | if (q < 0.0 || q > 1.0) {
|
---|
113 | q = 1.0;
|
---|
114 | }
|
---|
115 | return BigDecimal.valueOf(q);
|
---|
116 | }
|
---|
117 |
|
---|
118 |
|
---|
119 | }
|
---|