1 | package negotiator.boaframework.sharedagentstate.anac2010;
|
---|
2 |
|
---|
3 | import java.util.LinkedList;
|
---|
4 | import java.util.Random;
|
---|
5 |
|
---|
6 | import genius.core.bidding.BidDetails;
|
---|
7 | import genius.core.boaframework.NegotiationSession;
|
---|
8 | import genius.core.boaframework.SharedAgentState;
|
---|
9 |
|
---|
10 | /**
|
---|
11 | * This is the shared code of the acceptance condition and bidding strategy of ANAC 2010 Yushu.
|
---|
12 | * The code was taken from the ANAC2010 Yushu and adapted to work within the BOA framework.
|
---|
13 | *
|
---|
14 | * @author Mark Hendrikx
|
---|
15 | */
|
---|
16 | public class YushuSAS extends SharedAgentState {
|
---|
17 |
|
---|
18 | private NegotiationSession negotiationSession;
|
---|
19 | private double previousTime;
|
---|
20 | private double totalOppBidUtil = 0;
|
---|
21 | private double eagerness = 1.2;
|
---|
22 | private double minimumBidUtil;
|
---|
23 | private LinkedList<BidDetails> bestTenBids;
|
---|
24 | private double highPosUtil; //the highest utility that can be achieved
|
---|
25 | private double roundleft;
|
---|
26 | private double acceptableUtil;
|
---|
27 | private LinkedList<Double> timeBetweenRounds;
|
---|
28 | private BidDetails suggestBid;
|
---|
29 | private double targetUtil;
|
---|
30 | private Random random100;
|
---|
31 | private final boolean TEST_EQUIVALENCE = false;
|
---|
32 |
|
---|
33 | public YushuSAS (NegotiationSession negoSession) {
|
---|
34 | negotiationSession = negoSession;
|
---|
35 | NAME = "Yushu";
|
---|
36 |
|
---|
37 | totalOppBidUtil = 0;
|
---|
38 | previousTime = 0;
|
---|
39 | minimumBidUtil = 0.95;
|
---|
40 | bestTenBids = new LinkedList<BidDetails>();
|
---|
41 | timeBetweenRounds = new LinkedList<Double>();
|
---|
42 | try {
|
---|
43 | highPosUtil = negoSession.getUtilitySpace().getUtility(negoSession.getUtilitySpace().getMaxUtilityBid());
|
---|
44 | } catch (Exception e) {
|
---|
45 | e.printStackTrace();
|
---|
46 | }
|
---|
47 | acceptableUtil = 1.0;
|
---|
48 | if (TEST_EQUIVALENCE) {
|
---|
49 | random100 = new Random(100);
|
---|
50 | } else {
|
---|
51 | random100 = new Random();
|
---|
52 | }
|
---|
53 | }
|
---|
54 |
|
---|
55 | public void updateBelief(BidDetails opponentBid){
|
---|
56 | totalOppBidUtil += opponentBid.getMyUndiscountedUtil();
|
---|
57 | if(bestTenBids.size()==0)
|
---|
58 | bestTenBids.add(opponentBid);
|
---|
59 | else{
|
---|
60 | LinkedList<BidDetails> newlist = new LinkedList<BidDetails>();
|
---|
61 |
|
---|
62 | if(opponentBid.getMyUndiscountedUtil() > bestTenBids.getFirst().getMyUndiscountedUtil()){
|
---|
63 | newlist.add(opponentBid);
|
---|
64 | for(int j=0; j < bestTenBids.size(); j++)
|
---|
65 | newlist.add(bestTenBids.get(j));
|
---|
66 | bestTenBids = newlist;
|
---|
67 | }
|
---|
68 | else if(opponentBid.getMyUndiscountedUtil() <= bestTenBids.getLast().getMyUndiscountedUtil())
|
---|
69 | bestTenBids.add(opponentBid);
|
---|
70 | else{
|
---|
71 | for(int i=1;i<bestTenBids.size();i++){
|
---|
72 | if((opponentBid.getMyUndiscountedUtil() <= bestTenBids.get(i-1).getMyUndiscountedUtil()) &
|
---|
73 | (opponentBid.getMyUndiscountedUtil() > bestTenBids.get(i).getMyUndiscountedUtil())){
|
---|
74 | for(int j=0;j<i;j++)
|
---|
75 | newlist.add(bestTenBids.get(j));
|
---|
76 | newlist.add(opponentBid);
|
---|
77 | for(int j=i;j<bestTenBids.size();j++)
|
---|
78 | newlist.add(bestTenBids.get(j));
|
---|
79 | break;
|
---|
80 | }
|
---|
81 | }
|
---|
82 | bestTenBids=newlist;
|
---|
83 | }
|
---|
84 | }
|
---|
85 | if(bestTenBids.size() > 10)
|
---|
86 | bestTenBids.removeLast();
|
---|
87 | }
|
---|
88 |
|
---|
89 | public double calculateTargetUtility() {
|
---|
90 | timeBetweenRounds.add(negotiationSession.getTime() - previousTime);
|
---|
91 | previousTime = negotiationSession.getTime();
|
---|
92 |
|
---|
93 | double tround = Math.max(averResT(), averLastTResT(3));
|
---|
94 | double lefttime = 1 - negotiationSession.getTime();
|
---|
95 | roundleft = lefttime / tround;
|
---|
96 |
|
---|
97 |
|
---|
98 |
|
---|
99 | if(roundleft > 6.7) {
|
---|
100 | minimumBidUtil = 0.93 * highPosUtil;
|
---|
101 | } else if (roundleft>5) {
|
---|
102 | minimumBidUtil = 0.90 * highPosUtil;
|
---|
103 | } else if (lefttime> 3 * tround) {
|
---|
104 | minimumBidUtil = 0.86 * highPosUtil;
|
---|
105 | } else if (lefttime>2.3*tround) {
|
---|
106 | minimumBidUtil =0.8 * highPosUtil;
|
---|
107 | } else {
|
---|
108 | minimumBidUtil =0.6 * highPosUtil;
|
---|
109 | }
|
---|
110 | if(lefttime<15*tround) {
|
---|
111 | acceptableUtil = 0.92 * highPosUtil;
|
---|
112 | } else {
|
---|
113 | acceptableUtil = 0.96 * highPosUtil;
|
---|
114 | }
|
---|
115 |
|
---|
116 | // consider the domain competition
|
---|
117 | double averopu=0, averopui=0;
|
---|
118 | if (negotiationSession.getOpponentBidHistory().size() > 0) {
|
---|
119 | averopui = totalOppBidUtil / negotiationSession.getOpponentBidHistory().size();
|
---|
120 | }
|
---|
121 | averopu=Math.max(0.30, averopui);
|
---|
122 |
|
---|
123 | double rte=20+(1-averopu)/0.10*20;
|
---|
124 | if((lefttime<rte*tround) && (negotiationSession.getOpponentBidHistory().size()>3) && (averopu<0.75)) {
|
---|
125 | minimumBidUtil = minimumBidUtil -(0.75-averopu) / 2.5;
|
---|
126 | }
|
---|
127 |
|
---|
128 | minimumBidUtil =Math.max(0.50, minimumBidUtil); // no less than 0.5
|
---|
129 | double time= negotiationSession.getTime();
|
---|
130 |
|
---|
131 | minimumBidUtil = minimumBidUtil * (Math.min(0.75, averopu) / 3 + 0.75);
|
---|
132 | minimumBidUtil =Math.max(minimumBidUtil, averopu);
|
---|
133 | double targetuti = highPosUtil -(highPosUtil - minimumBidUtil)*Math.pow(time, eagerness);
|
---|
134 |
|
---|
135 | if(lefttime<1.6*tround) {
|
---|
136 | suggestBid = this.bestTenBids.getFirst();
|
---|
137 |
|
---|
138 | this.targetUtil = targetuti;
|
---|
139 | return targetuti;
|
---|
140 | }
|
---|
141 |
|
---|
142 | //consider op's best past offer
|
---|
143 | if (lefttime > 50 * tround) {
|
---|
144 | targetuti=Math.max(targetuti, bestTenBids.getFirst().getMyUndiscountedUtil() * 1.001);
|
---|
145 | }
|
---|
146 | if (((lefttime < 10 * tround) & (bestTenBids.getFirst().getMyUndiscountedUtil() > targetuti * 0.95)) |
|
---|
147 | bestTenBids.getFirst().getMyUndiscountedUtil() >= targetuti) {
|
---|
148 | double newtargetuti=targetuti;
|
---|
149 | if ((lefttime < 10 * tround) & (bestTenBids.getFirst().getMyUndiscountedUtil() > targetuti * 0.95)) {
|
---|
150 | newtargetuti=targetuti * 0.95;
|
---|
151 | }
|
---|
152 |
|
---|
153 | //check whether the best op bid was offered in the last 4 rouds
|
---|
154 | boolean offered=false;
|
---|
155 | int length = Math.min(negotiationSession.getOwnBidHistory().size(), 4);
|
---|
156 |
|
---|
157 | for(int i = negotiationSession.getOwnBidHistory().size() - 1; i >= negotiationSession.getOwnBidHistory().size() - length; i--){
|
---|
158 | if (negotiationSession.getOwnBidHistory().getHistory().get(i).getBid().equals(bestTenBids.getFirst().getBid())) {
|
---|
159 | offered=true;
|
---|
160 | }
|
---|
161 | }
|
---|
162 | if(offered){
|
---|
163 | LinkedList<BidDetails> candidates = new LinkedList<BidDetails>();
|
---|
164 | for(int b=0; b < bestTenBids.size(); b++)
|
---|
165 | if(bestTenBids.get(b).getMyUndiscountedUtil() >= newtargetuti)
|
---|
166 | candidates.add(bestTenBids.get(b));
|
---|
167 | int indexc = (int)(random100.nextDouble() * candidates.size());
|
---|
168 | suggestBid = candidates.get(indexc);
|
---|
169 | }
|
---|
170 | else {
|
---|
171 | suggestBid = bestTenBids.getFirst();
|
---|
172 | }
|
---|
173 | targetuti=newtargetuti;
|
---|
174 | }
|
---|
175 |
|
---|
176 | targetUtil = targetuti;
|
---|
177 | return targetuti;
|
---|
178 | }
|
---|
179 |
|
---|
180 | public double averResT(){
|
---|
181 | if (timeBetweenRounds.size()==0) {
|
---|
182 | return 0;
|
---|
183 | }
|
---|
184 | double total=0;
|
---|
185 | for(int i=0; i < timeBetweenRounds.size();i++)
|
---|
186 | total = total + timeBetweenRounds.get(i);
|
---|
187 | return total / timeBetweenRounds.size();
|
---|
188 | }
|
---|
189 |
|
---|
190 | public double averLastTResT(int length){
|
---|
191 | if(timeBetweenRounds.size()<length)
|
---|
192 | return 0;
|
---|
193 | double total=0;
|
---|
194 | for(int i = (timeBetweenRounds.size()-1); i > timeBetweenRounds.size() - length - 1; i--)
|
---|
195 | total = total + timeBetweenRounds.get(i);
|
---|
196 | return total/length;
|
---|
197 | }
|
---|
198 |
|
---|
199 | public BidDetails getSuggestBid() {
|
---|
200 | return suggestBid;
|
---|
201 | }
|
---|
202 |
|
---|
203 | public double getRoundLeft() {
|
---|
204 | return roundleft;
|
---|
205 | }
|
---|
206 |
|
---|
207 | public LinkedList<BidDetails> getBestTenBids(){
|
---|
208 | return bestTenBids;
|
---|
209 | }
|
---|
210 |
|
---|
211 | public double getMinimumBidUtil() {
|
---|
212 | return minimumBidUtil;
|
---|
213 | }
|
---|
214 |
|
---|
215 | public double getTargetUtil(){
|
---|
216 | return targetUtil;
|
---|
217 | }
|
---|
218 |
|
---|
219 | public double getAcceptableUtil() {
|
---|
220 | return acceptableUtil;
|
---|
221 | }
|
---|
222 |
|
---|
223 | public void setPreviousTime(double time) {
|
---|
224 | previousTime = time;
|
---|
225 | }
|
---|
226 | }
|
---|