[127] | 1 | package agents.anac.y2015.cuhkagent2015;
|
---|
| 2 |
|
---|
| 3 | import java.io.FileNotFoundException;
|
---|
| 4 | import java.io.FileOutputStream;
|
---|
| 5 | import java.io.PrintStream;
|
---|
| 6 | import java.util.ArrayList;
|
---|
| 7 | import java.util.HashMap;
|
---|
| 8 | import java.util.Iterator;
|
---|
| 9 | import java.util.List;
|
---|
| 10 | import java.util.Random;
|
---|
| 11 |
|
---|
| 12 | import genius.core.AgentID;
|
---|
| 13 | import genius.core.Bid;
|
---|
| 14 | import genius.core.BidIterator;
|
---|
| 15 | import genius.core.actions.Accept;
|
---|
| 16 | import genius.core.actions.Action;
|
---|
| 17 | import genius.core.actions.ActionWithBid;
|
---|
| 18 | import genius.core.actions.EndNegotiation;
|
---|
| 19 | import genius.core.actions.Offer;
|
---|
| 20 | import genius.core.issue.Issue;
|
---|
| 21 | import genius.core.issue.IssueDiscrete;
|
---|
| 22 | import genius.core.issue.IssueInteger;
|
---|
| 23 | import genius.core.issue.IssueReal;
|
---|
| 24 | import genius.core.issue.Value;
|
---|
| 25 | import genius.core.issue.ValueDiscrete;
|
---|
| 26 | import genius.core.issue.ValueInteger;
|
---|
| 27 | import genius.core.issue.ValueReal;
|
---|
| 28 | import genius.core.parties.AbstractNegotiationParty;
|
---|
| 29 | import genius.core.parties.NegotiationInfo;
|
---|
| 30 | import genius.core.utility.AdditiveUtilitySpace;
|
---|
| 31 |
|
---|
| 32 | /**
|
---|
| 33 | *
|
---|
| 34 | * @author Tom
|
---|
| 35 | */
|
---|
| 36 | public class CUHKAgent2015 extends AbstractNegotiationParty {
|
---|
| 37 | boolean debug = false;
|
---|
| 38 |
|
---|
| 39 | private final double totalTime = 180;
|
---|
| 40 | // private Action ActionOfOpponent = null;
|
---|
| 41 | private double maximumOfBid;
|
---|
| 42 | private OwnBidHistory ownBidHistory;
|
---|
| 43 | private OpponentBidHistory opponentBidHistory1;
|
---|
| 44 | private OpponentBidHistory opponentBidHistory2;
|
---|
| 45 | private double minimumUtilityThreshold;
|
---|
| 46 | private double AvgUtilitythreshold;
|
---|
| 47 | private double AvgConcedeTime;
|
---|
| 48 | private double MaximumUtility;
|
---|
| 49 | private int limit;// the maximimum number of trials for each searching range
|
---|
| 50 | private double numberOfRounds;
|
---|
| 51 | private double timeLeftBefore;
|
---|
| 52 | private double timeLeftAfter;
|
---|
| 53 | private double maximumTimeOfOpponent;
|
---|
| 54 | private double maximumTimeOfOwn;
|
---|
| 55 | private double discountingFactor;
|
---|
| 56 | private double concedeToDiscountingFactor;
|
---|
| 57 | private double concedeToDiscountingFactor_original;
|
---|
| 58 | private double minConcedeToDiscountingFactor;
|
---|
| 59 | private ArrayList<ArrayList<Bid>> bidsBetweenUtility;
|
---|
| 60 | private double previousToughnessDegree;
|
---|
| 61 | private boolean concedeToOpponent;
|
---|
| 62 | private boolean toughAgent; // if we propose a bid that was proposed by the
|
---|
| 63 | // opponnet, then it should be accepted.
|
---|
| 64 | private double alpha1;// the larger alpha is, the more tough the agent is.
|
---|
| 65 | private Bid bid_maximum_utility;// the bid with the maximum utility over the
|
---|
| 66 | // utility space.
|
---|
| 67 | private double reservationValue;
|
---|
| 68 |
|
---|
| 69 | /* UpdateConcede function's Constant */
|
---|
| 70 | private double k = 1;
|
---|
| 71 | private double N = 0;
|
---|
| 72 | private int FirstTimeInterval;
|
---|
| 73 | private int SecondTimeInterval;
|
---|
| 74 | private int ThirdTimeInterval;
|
---|
| 75 |
|
---|
| 76 | /* Agent 1 Analysis */
|
---|
| 77 | private double utility_maximum_from_opponent_Session1_Agent1 = 0;
|
---|
| 78 | private double utility_maximum_from_opponent_Session2_Agent1 = 0;
|
---|
| 79 | private double utility_maximum_from_opponent_Session3_Agent1 = 0;
|
---|
| 80 | private double count_Agent1 = -1;
|
---|
| 81 | private double concedePartOfdiscountingFactor_Agent1 = 0;
|
---|
| 82 | private double concedePartOfOppBehaviour_Agent1 = 0;
|
---|
| 83 | private double minThreshold_Agent1;
|
---|
| 84 | private double oppFirstBidUtility_Agent1;
|
---|
| 85 | private Bid oppFirstBid_Agent1;
|
---|
| 86 | private double relstdevUtility_Agent1;
|
---|
| 87 | private boolean startConcede_Agent1 = false;
|
---|
| 88 | private double relcountUpperBoundMid1_Agent1;
|
---|
| 89 | private double relcountLowerBoundMid1_Agent1;
|
---|
| 90 | private double relcountUpperBoundMid2_Agent1;
|
---|
| 91 | private double relcountLowerBoundMid2_Agent1;
|
---|
| 92 | private double relsumUtility_Agent1 = 0;
|
---|
| 93 | private double relcountUtility_Agent1 = 0;
|
---|
| 94 | private double relavgUtility_Agent1 = 0;
|
---|
| 95 | private double relSqRootOfAvgUtility_Agent1 = 0;
|
---|
| 96 | private double relcountUtilityInSmallSD_Agent1 = 0;
|
---|
| 97 | private double utility_FirstMaximum_Agent1 = 0;
|
---|
| 98 | private double utility_SecondMaximum_Agent1 = 0;
|
---|
| 99 | private double midPointOfSlopeSessionMax1_Agent1 = 0;
|
---|
| 100 | private double midPointOfSlopeSessionMax2_Agent1 = 0;
|
---|
| 101 | private double slopeOfSlopeOfSessionMax1_Agent1 = 0;
|
---|
| 102 | private double slopeOfSlopeOfSessionMax2_Agent1 = 0;
|
---|
| 103 | private boolean IsOppFirstBid_Agent1;
|
---|
| 104 | private Bid oppPreviousBid_Agent1;
|
---|
| 105 | private Bid minAcceptableBid;
|
---|
| 106 | private double opponentFirstBidUtility_Agent;
|
---|
| 107 | private double concedeTime_Agent1;
|
---|
| 108 | private double MinimumUtility_Agent1;
|
---|
| 109 | private double utilitythreshold_Agent1;
|
---|
| 110 |
|
---|
| 111 | /* Agent 2 Analysis */
|
---|
| 112 | private double utility_maximum_from_opponent_Session1_Agent2 = 0;
|
---|
| 113 | private double utility_maximum_from_opponent_Session2_Agent2 = 0;
|
---|
| 114 | private double utility_maximum_from_opponent_Session3_Agent2 = 0;
|
---|
| 115 | private double count_Agent2 = -1;
|
---|
| 116 | private double concedePartOfdiscountingFactor_Agent2 = 0;
|
---|
| 117 | private double concedePartOfOppBehaviour_Agent2 = 0;
|
---|
| 118 | private double minThreshold_Agent2;
|
---|
| 119 | private Bid oppFirstBid_Agent2;
|
---|
| 120 | private double oppFirstBidUtility_Agent2;
|
---|
| 121 | private double relstdevUtility_Agent2;
|
---|
| 122 | private boolean startConcede_Agent2 = false;
|
---|
| 123 | private double relcountUpperBoundMid1_Agent2;
|
---|
| 124 | private double relcountLowerBoundMid1_Agent2;
|
---|
| 125 | private double relcountUpperBoundMid2_Agent2;
|
---|
| 126 | private double relcountLowerBoundMid2_Agent2;
|
---|
| 127 | private double relsumUtility_Agent2 = 0;
|
---|
| 128 | private double relcountUtility_Agent2 = 0;
|
---|
| 129 | private double relavgUtility_Agent2 = 0;
|
---|
| 130 | private double relSqRootOfAvgUtility_Agent2 = 0;
|
---|
| 131 | private double relcountUtilityInSmallSD_Agent2 = 0;
|
---|
| 132 | private double utility_FirstMaximum_Agent2 = 0;
|
---|
| 133 | private double utility_SecondMaximum_Agent2 = 0;
|
---|
| 134 | private double midPointOfSlopeSessionMax1_Agent2 = 0;
|
---|
| 135 | private double midPointOfSlopeSessionMax2_Agent2 = 0;
|
---|
| 136 | private double slopeOfSlopeOfSessionMax1_Agent2 = 0;
|
---|
| 137 | private double slopeOfSlopeOfSessionMax2_Agent2 = 0;
|
---|
| 138 | private boolean IsOppFirstBid_Agent2;
|
---|
| 139 | private Bid oppPreviousBid_Agent2;
|
---|
| 140 | private double concedeTime_Agent2;
|
---|
| 141 | private double MinimumUtility_Agent2;
|
---|
| 142 | private double utilitythreshold_Agent2;
|
---|
| 143 |
|
---|
| 144 | private double MinimumUtility;
|
---|
| 145 | private AgentID partyId;
|
---|
| 146 | private final double domainthreshold = 2000;
|
---|
| 147 | private final double totaltime = 180;
|
---|
| 148 | private Action ActionOfOpponent = null;
|
---|
| 149 | private double NumberOfBid;
|
---|
| 150 | private final int NumberofDivisions = 20;
|
---|
| 151 | private double SpacebetweenDivisions;
|
---|
| 152 | private int CurrentrangeNumber;
|
---|
| 153 | private int maximumOfRound;
|
---|
| 154 | private final int limitValue = 5;// 10;
|
---|
| 155 | private double delta; // searching range
|
---|
| 156 | private double concedeTime_original;
|
---|
| 157 | private double minConcedeTime;
|
---|
| 158 | private List<Issue> Issues;
|
---|
| 159 | private Bid bid_minimum_utility;// the bid with the minimum utility over the
|
---|
| 160 | // utility space.
|
---|
| 161 | private Bid mylastBid = this.bid_maximum_utility;
|
---|
| 162 | private ArrayList<Bid> OppBids1;
|
---|
| 163 | private ArrayList<Bid> OppBids2;
|
---|
| 164 | private int storingcapacity = 500;
|
---|
| 165 |
|
---|
| 166 | private double nextbidutil;
|
---|
| 167 | private double mindistance;
|
---|
| 168 | private double averagedistance;
|
---|
| 169 | private int test = 0;
|
---|
| 170 | private int test2 = 0;
|
---|
| 171 | private int test3 = 0;
|
---|
| 172 | private int except = 0;
|
---|
| 173 | private int size;
|
---|
| 174 | private double minUtilityUhreshold = 1.1;
|
---|
| 175 | private double oppbid;
|
---|
| 176 | private int countOpp;
|
---|
| 177 | private int EachRoundCount;
|
---|
| 178 | private Bid myLastBid;
|
---|
| 179 |
|
---|
| 180 | PrintStream file, SysOut;
|
---|
| 181 | String fileName;
|
---|
| 182 |
|
---|
| 183 | @Override
|
---|
| 184 | public void init(NegotiationInfo info) {
|
---|
| 185 | super.init(info);
|
---|
| 186 | try {
|
---|
| 187 | this.NumberOfBid = this.utilitySpace.getDomain()
|
---|
| 188 | .getNumberOfPossibleBids();
|
---|
| 189 | this.ownBidHistory = new OwnBidHistory();
|
---|
| 190 | this.opponentBidHistory1 = new OpponentBidHistory();
|
---|
| 191 | this.opponentBidHistory2 = new OpponentBidHistory();
|
---|
| 192 | this.Issues = this.utilitySpace.getDomain().getIssues();
|
---|
| 193 | this.bidsBetweenUtility = new ArrayList<ArrayList<Bid>>();
|
---|
| 194 | this.OppBids1 = new ArrayList<Bid>();
|
---|
| 195 | this.OppBids2 = new ArrayList<Bid>();
|
---|
| 196 | for (int i = 0; i < this.storingcapacity; i++) {
|
---|
| 197 | this.OppBids1.add(i, null);
|
---|
| 198 | this.OppBids2.add(i, null);
|
---|
| 199 | }
|
---|
| 200 | this.bid_maximum_utility = this.utilitySpace.getMaxUtilityBid();
|
---|
| 201 | this.bid_minimum_utility = this.utilitySpace.getMinUtilityBid();
|
---|
| 202 | this.MaximumUtility = this.utilitySpace
|
---|
| 203 | .getUtility(this.bid_maximum_utility);
|
---|
| 204 | this.reservationValue = utilitySpace.getReservationValue();
|
---|
| 205 | this.MinimumUtility_Agent1 = this.reservationValue;
|
---|
| 206 | this.MinimumUtility_Agent2 = this.reservationValue;
|
---|
| 207 | this.delta = 0.01; // searching range
|
---|
| 208 | this.limit = 10;
|
---|
| 209 | this.previousToughnessDegree = 0;
|
---|
| 210 | this.numberOfRounds = 0;
|
---|
| 211 | this.timeLeftAfter = 0;
|
---|
| 212 | this.timeLeftBefore = 0;
|
---|
| 213 | this.maximumTimeOfOpponent = 0;
|
---|
| 214 | this.maximumTimeOfOwn = 0;
|
---|
| 215 | this.minConcedeTime = 0.08;// 0.1;
|
---|
| 216 | this.discountingFactor = 1;
|
---|
| 217 | if (utilitySpace.getDiscountFactor() <= 1D
|
---|
| 218 | && utilitySpace.getDiscountFactor() > 0D) {
|
---|
| 219 | this.discountingFactor = utilitySpace.getDiscountFactor();
|
---|
| 220 | }
|
---|
| 221 | this.calculateBidsBetweenUtility();
|
---|
| 222 | if (this.discountingFactor <= 0.5D) {
|
---|
| 223 | this.chooseConcedeToDiscountingDegree();
|
---|
| 224 | }
|
---|
| 225 | if (debug) {
|
---|
| 226 | fileName = "plotData" + hashCode() + ".txt";
|
---|
| 227 | file = new PrintStream(new FileOutputStream(fileName, false));
|
---|
| 228 | file.println("\n");
|
---|
| 229 | }
|
---|
| 230 | this.opponentBidHistory1
|
---|
| 231 | .initializeDataStructures(utilitySpace.getDomain());
|
---|
| 232 | this.opponentBidHistory2
|
---|
| 233 | .initializeDataStructures(utilitySpace.getDomain());
|
---|
| 234 | this.timeLeftAfter = timeline.getCurrentTime();
|
---|
| 235 | this.concedeToOpponent = false;
|
---|
| 236 | this.toughAgent = false;
|
---|
| 237 | this.alpha1 = 2;
|
---|
| 238 |
|
---|
| 239 | if (this.NumberOfBid < 100) {
|
---|
| 240 | this.k = 1;
|
---|
| 241 | } else if (this.NumberOfBid < 1000) {
|
---|
| 242 | this.k = 2;
|
---|
| 243 | } else if (this.NumberOfBid < 10000) {
|
---|
| 244 | this.k = 3;
|
---|
| 245 | } else {
|
---|
| 246 | this.k = 4;
|
---|
| 247 | }
|
---|
| 248 | this.concedeTime_Agent1 = 0.5;
|
---|
| 249 | this.concedeTime_Agent2 = 0.5;
|
---|
| 250 | this.oppFirstBid_Agent1 = null;
|
---|
| 251 | this.oppFirstBidUtility_Agent1 = 0;
|
---|
| 252 | this.oppFirstBid_Agent2 = null;
|
---|
| 253 | this.oppFirstBidUtility_Agent2 = 0;
|
---|
| 254 | this.IsOppFirstBid_Agent1 = true;
|
---|
| 255 | this.IsOppFirstBid_Agent2 = true;
|
---|
| 256 | this.FirstTimeInterval = 20;
|
---|
| 257 | this.SecondTimeInterval = 40;
|
---|
| 258 | this.ThirdTimeInterval = 60;
|
---|
| 259 | this.utilitythreshold_Agent1 = 0.5;
|
---|
| 260 | this.utilitythreshold_Agent2 = 0.5;
|
---|
| 261 | this.AvgUtilitythreshold = 0.5;
|
---|
| 262 | this.AvgConcedeTime = 0.5;
|
---|
| 263 | this.EachRoundCount = 0;
|
---|
| 264 | this.myLastBid = this.bid_maximum_utility;
|
---|
| 265 | } catch (Exception e) {
|
---|
| 266 | System.out.println("initialization error" + e.getMessage());
|
---|
| 267 | }
|
---|
| 268 | }
|
---|
| 269 |
|
---|
| 270 | public String getVersion() {
|
---|
| 271 | return "CUHKAgent2015";
|
---|
| 272 | }
|
---|
| 273 |
|
---|
| 274 | public String getName() {
|
---|
| 275 | return "CUHKAgent2015 Test Temp";
|
---|
| 276 | }
|
---|
| 277 |
|
---|
| 278 | @Override
|
---|
| 279 | public Action chooseAction(List<Class<? extends Action>> possibleActions) {
|
---|
| 280 | Action action = null;
|
---|
| 281 | this.EachRoundCount = this.countOpp;
|
---|
| 282 | try {
|
---|
| 283 | // System.out.println("i propose " + debug + " bid at time " +
|
---|
| 284 | // timeline.getTime());
|
---|
| 285 | this.timeLeftBefore = timeline.getCurrentTime();
|
---|
| 286 | Bid bid = null;
|
---|
| 287 | // we propose first and propose the bid with maximum utility
|
---|
| 288 | if ((!possibleActions.contains(Accept.class))
|
---|
| 289 | || (this.oppFirstBid_Agent1 == null)
|
---|
| 290 | || (this.oppFirstBid_Agent2 == null)) {
|
---|
| 291 | bid = this.bid_maximum_utility;
|
---|
| 292 | action = new Offer(getPartyId(), bid);
|
---|
| 293 | }
|
---|
| 294 | // else if (ActionOfOpponent instanceof Offer)
|
---|
| 295 | else {
|
---|
| 296 | // the opponent propose first and we response secondly
|
---|
| 297 | // update opponent model first
|
---|
| 298 | this.opponentBidHistory1.updateOpponentModel(
|
---|
| 299 | this.oppPreviousBid_Agent1, utilitySpace.getDomain(),
|
---|
| 300 | (AdditiveUtilitySpace) this.utilitySpace);
|
---|
| 301 | this.opponentBidHistory2.updateOpponentModel(
|
---|
| 302 | this.oppPreviousBid_Agent2, utilitySpace.getDomain(),
|
---|
| 303 | (AdditiveUtilitySpace) this.utilitySpace);
|
---|
| 304 | if (this.discountingFactor == 1) {
|
---|
| 305 | this.updateConcedeDegree_nonDiscountingFactor_Agent1();
|
---|
| 306 | this.updateConcedeDegree_nonDiscountingFactor_Agent2();
|
---|
| 307 | } else if (this.discountingFactor <= 0.5) {
|
---|
| 308 | this.updateConcedeDegree_smallDiscountingFactor();
|
---|
| 309 | } else {
|
---|
| 310 | this.updateConcedeDegree_largeDiscountingFactor_Agent1();
|
---|
| 311 | this.updateConcedeDegree_largeDiscountingFactor_Agent2();
|
---|
| 312 | }
|
---|
| 313 | // update the estimation
|
---|
| 314 | if (ownBidHistory.numOfBidsProposed() == 0) {
|
---|
| 315 | bid = this.bid_maximum_utility;
|
---|
| 316 | action = new Offer(getPartyId(), bid);
|
---|
| 317 | } else { // other conditions
|
---|
| 318 | if (estimateRoundLeft(true) > 10) {
|
---|
| 319 | // still have some rounds left to further negotiate (the
|
---|
| 320 | // major negotiation period)
|
---|
| 321 | bid = BidToOffer_original();
|
---|
| 322 | Boolean IsAccept = AcceptOpponentOffer(
|
---|
| 323 | this.oppPreviousBid_Agent2, bid);
|
---|
| 324 | IsAccept = OtherAcceptCondition(IsAccept);
|
---|
| 325 |
|
---|
| 326 | Boolean IsTerminate = TerminateCurrentNegotiation(bid);
|
---|
| 327 | if (IsAccept && !IsTerminate) {
|
---|
| 328 | action = new Accept(getPartyId(),
|
---|
| 329 | ((ActionWithBid) getLastReceivedAction())
|
---|
| 330 | .getBid());
|
---|
| 331 | System.out.println("accept the offer");
|
---|
| 332 | } else if (IsTerminate && !IsAccept) {
|
---|
| 333 | action = new EndNegotiation(getPartyId());
|
---|
| 334 | System.out.println(
|
---|
| 335 | "we determine to terminate the negotiation");
|
---|
| 336 | } else if (IsAccept && IsTerminate) {
|
---|
| 337 | if (this.utilitySpace.getUtility(
|
---|
| 338 | this.oppPreviousBid_Agent2) > this.reservationValue) {
|
---|
| 339 | action = new Accept(getPartyId(),
|
---|
| 340 | ((ActionWithBid) getLastReceivedAction())
|
---|
| 341 | .getBid());
|
---|
| 342 | System.out.println(
|
---|
| 343 | "we accept the offer RANDOMLY");
|
---|
| 344 | } else {
|
---|
| 345 | action = new EndNegotiation(getPartyId());
|
---|
| 346 | System.out.println(
|
---|
| 347 | "we determine to terminate the negotiation RANDOMLY");
|
---|
| 348 | }
|
---|
| 349 | } else {
|
---|
| 350 | // we expect that the negotiation is over once we
|
---|
| 351 | // select a bid from the opponent's history.
|
---|
| 352 | if (this.concedeToOpponent == true) {
|
---|
| 353 | // bid =
|
---|
| 354 | // opponentBidHistory.chooseBestFromHistory(this.utilitySpace);
|
---|
| 355 | Bid bid1 = opponentBidHistory1
|
---|
| 356 | .getBestBidInHistory();
|
---|
| 357 | Bid bid2 = opponentBidHistory2
|
---|
| 358 | .getBestBidInHistory();
|
---|
| 359 | if (this.utilitySpace
|
---|
| 360 | .getUtility(bid1) > this.utilitySpace
|
---|
| 361 | .getUtility(bid2)) {
|
---|
| 362 | bid = bid2;
|
---|
| 363 | } else if (this.utilitySpace
|
---|
| 364 | .getUtility(bid1) == this.utilitySpace
|
---|
| 365 | .getUtility(bid2)
|
---|
| 366 | && Math.random() < 0.5) {
|
---|
| 367 | bid = bid2;
|
---|
| 368 | } else {
|
---|
| 369 | bid = bid1;
|
---|
| 370 | }
|
---|
| 371 | action = new Offer(getPartyId(), bid);
|
---|
| 372 | // System.out.println("we offer the best bid in
|
---|
| 373 | // the history and the opponent should accept
|
---|
| 374 | // it");
|
---|
| 375 | this.toughAgent = true;
|
---|
| 376 | this.concedeToOpponent = false;
|
---|
| 377 | } else {
|
---|
| 378 | action = new Offer(getPartyId(), bid);
|
---|
| 379 | this.toughAgent = false;
|
---|
| 380 | // System.out.println("i propose " + debug +
|
---|
| 381 | // " bid at time " + timeline.getTime());
|
---|
| 382 | }
|
---|
| 383 | }
|
---|
| 384 | } else {// this is the last chance and we concede by
|
---|
| 385 | // providing the opponent the best offer he ever
|
---|
| 386 | // proposed to us
|
---|
| 387 | // in this case, it corresponds to an opponent whose
|
---|
| 388 | // decision time is short
|
---|
| 389 |
|
---|
| 390 | if (timeline.getTime() > 0.9985
|
---|
| 391 | && estimateRoundLeft(true) < 5) {
|
---|
| 392 | bid = BidToOffer_original();
|
---|
| 393 |
|
---|
| 394 | Boolean IsAccept = AcceptOpponentOffer(
|
---|
| 395 | this.oppPreviousBid_Agent2, bid);
|
---|
| 396 | IsAccept = OtherAcceptCondition(IsAccept);
|
---|
| 397 |
|
---|
| 398 | Boolean IsTerminate = TerminateCurrentNegotiation(
|
---|
| 399 | bid);
|
---|
| 400 | if (IsAccept && !IsTerminate) {
|
---|
| 401 | action = new Accept(getPartyId(),
|
---|
| 402 | ((ActionWithBid) getLastReceivedAction())
|
---|
| 403 | .getBid());
|
---|
| 404 | System.out.println("accept the offer");
|
---|
| 405 | } else if (IsTerminate && !IsAccept) {
|
---|
| 406 | action = new EndNegotiation(getPartyId());
|
---|
| 407 | System.out.println(
|
---|
| 408 | "we determine to terminate the negotiation");
|
---|
| 409 | } else if (IsTerminate && IsAccept) {
|
---|
| 410 | if (this.utilitySpace.getUtility(
|
---|
| 411 | this.oppPreviousBid_Agent2) > this.reservationValue) {
|
---|
| 412 | action = new Accept(getPartyId(),
|
---|
| 413 | ((ActionWithBid) getLastReceivedAction())
|
---|
| 414 | .getBid());
|
---|
| 415 | System.out.println(
|
---|
| 416 | "we accept the offer RANDOMLY");
|
---|
| 417 | } else {
|
---|
| 418 | action = new EndNegotiation(getPartyId());
|
---|
| 419 | System.out.println(
|
---|
| 420 | "we determine to terminate the negotiation RANDOMLY");
|
---|
| 421 | }
|
---|
| 422 | } else {
|
---|
| 423 | if (this.toughAgent == true) {
|
---|
| 424 | action = new Accept(getPartyId(),
|
---|
| 425 | ((ActionWithBid) getLastReceivedAction())
|
---|
| 426 | .getBid());
|
---|
| 427 | System.out.println(
|
---|
| 428 | "the opponent is tough and the deadline is approching thus we accept the offer");
|
---|
| 429 | } else {
|
---|
| 430 | action = new Offer(getPartyId(), bid);
|
---|
| 431 | // this.toughAgent = true;
|
---|
| 432 | System.out.println(
|
---|
| 433 | "this is really the last chance"
|
---|
| 434 | + bid.toString()
|
---|
| 435 | + " with utility of "
|
---|
| 436 | + utilitySpace
|
---|
| 437 | .getUtility(bid));
|
---|
| 438 | }
|
---|
| 439 | }
|
---|
| 440 | // in this case, it corresponds to the situation
|
---|
| 441 | // that we encounter an opponent who needs more
|
---|
| 442 | // computation to make decision each round
|
---|
| 443 | } else {// we still have some time to negotiate,
|
---|
| 444 | // and be tough by sticking with the lowest one
|
---|
| 445 | // in previous offer history.
|
---|
| 446 | // we also have to make the decisin fast to
|
---|
| 447 | // avoid reaching the deadline before the
|
---|
| 448 | // decision is made
|
---|
| 449 | // bid =
|
---|
| 450 | // ownBidHistory.GetMinBidInHistory();//reduce
|
---|
| 451 | // the computational cost
|
---|
| 452 | bid = BidToOffer_original();
|
---|
| 453 | // System.out.println("test----------------------------------------------------------"
|
---|
| 454 | // + timeline.getTime());
|
---|
| 455 | Boolean IsAccept = AcceptOpponentOffer(
|
---|
| 456 | this.oppPreviousBid_Agent2, bid);
|
---|
| 457 | IsAccept = OtherAcceptCondition(IsAccept);
|
---|
| 458 |
|
---|
| 459 | Boolean IsTerminate = TerminateCurrentNegotiation(
|
---|
| 460 | bid);
|
---|
| 461 | if (IsAccept && !IsTerminate) {
|
---|
| 462 | action = new Accept(getPartyId(),
|
---|
| 463 | ((ActionWithBid) getLastReceivedAction())
|
---|
| 464 | .getBid());
|
---|
| 465 | System.out.println("accept the offer");
|
---|
| 466 | } else if (IsTerminate && !IsAccept) {
|
---|
| 467 | action = new EndNegotiation(getPartyId());
|
---|
| 468 | System.out.println(
|
---|
| 469 | "we determine to terminate the negotiation");
|
---|
| 470 | } else if (IsAccept && IsTerminate) {
|
---|
| 471 | if (this.utilitySpace.getUtility(
|
---|
| 472 | this.oppPreviousBid_Agent2) > this.reservationValue) {
|
---|
| 473 | action = new Accept(getPartyId(),
|
---|
| 474 | ((ActionWithBid) getLastReceivedAction())
|
---|
| 475 | .getBid());
|
---|
| 476 | System.out.println(
|
---|
| 477 | "we accept the offer RANDOMLY");
|
---|
| 478 | } else {
|
---|
| 479 | action = new EndNegotiation(getPartyId());
|
---|
| 480 | System.out.println(
|
---|
| 481 | "we determine to terminate the negotiation RANDOMLY");
|
---|
| 482 | }
|
---|
| 483 | } else {
|
---|
| 484 | action = new Offer(getPartyId(), bid);
|
---|
| 485 | // System.out.println("we have to be tough now"
|
---|
| 486 | // + bid.toString() + " with utility of " +
|
---|
| 487 | // utilitySpace.getUtility(bid));
|
---|
| 488 | }
|
---|
| 489 | }
|
---|
| 490 | }
|
---|
| 491 | }
|
---|
| 492 | }
|
---|
| 493 | this.myLastBid = bid;
|
---|
| 494 | // System.out.println("i propose " + debug + " bid at time " +
|
---|
| 495 | // timeline.getTime());
|
---|
| 496 | this.ownBidHistory.addBid(bid, (AdditiveUtilitySpace) utilitySpace);
|
---|
| 497 | this.timeLeftAfter = timeline.getCurrentTime();
|
---|
| 498 | if (this.timeLeftAfter
|
---|
| 499 | - this.timeLeftBefore > this.maximumTimeOfOwn) {
|
---|
| 500 | this.maximumTimeOfOwn = this.timeLeftAfter
|
---|
| 501 | - this.timeLeftBefore;
|
---|
| 502 | } // update the estimation
|
---|
| 503 | // System.out.println(this.utilitythreshold + "-***-----" +
|
---|
| 504 | // this.timeline.getElapsedSeconds());
|
---|
| 505 | if (debug) {
|
---|
| 506 | try {
|
---|
| 507 | SysOut = System.out;
|
---|
| 508 | file = new PrintStream(
|
---|
| 509 | new FileOutputStream(fileName, true));
|
---|
| 510 | System.setOut(file);
|
---|
| 511 | } catch (FileNotFoundException ex) {
|
---|
| 512 |
|
---|
| 513 | }
|
---|
| 514 | System.out.println(Double.toString(this.timeline.getTime())
|
---|
| 515 | + "," + Double.toString(this.AvgUtilitythreshold) + ","
|
---|
| 516 | + Double.toString(this.minUtilityUhreshold));
|
---|
| 517 | System.setOut(SysOut);
|
---|
| 518 | }
|
---|
| 519 | } catch (Exception e) {
|
---|
| 520 | System.out.println("Exception in ChooseAction:" + e.getMessage());
|
---|
| 521 | System.out.println(estimateRoundLeft(false));
|
---|
| 522 | action = new EndNegotiation(getPartyId()); // terminate if anything
|
---|
| 523 | // goes wrong.
|
---|
| 524 | }
|
---|
| 525 | return action;
|
---|
| 526 | }
|
---|
| 527 |
|
---|
| 528 | @Override
|
---|
| 529 | public void receiveMessage(AgentID sender, Action opponentAction) {
|
---|
| 530 | super.receiveMessage(sender, opponentAction);
|
---|
| 531 | // sender.getClass().getName();
|
---|
| 532 | this.ActionOfOpponent = opponentAction;
|
---|
| 533 |
|
---|
| 534 | this.countOpp = this.countOpp + 1;
|
---|
| 535 | if (this.countOpp == this.EachRoundCount + 1)// Next Agent w.r.t. us
|
---|
| 536 | {
|
---|
| 537 | if ((this.ActionOfOpponent instanceof Offer)) {
|
---|
| 538 | if (this.oppFirstBid_Agent1 == null) {
|
---|
| 539 | oppFirstBid_Agent1 = ((Offer) this.ActionOfOpponent)
|
---|
| 540 | .getBid();
|
---|
| 541 | }
|
---|
| 542 | for (int i = 0; i < this.storingcapacity - 1; i++) {
|
---|
| 543 | this.OppBids1.set(i, this.OppBids1.get(i + 1));
|
---|
| 544 | }
|
---|
| 545 | this.oppPreviousBid_Agent1 = ((Offer) this.ActionOfOpponent)
|
---|
| 546 | .getBid();
|
---|
| 547 | this.OppBids1.set(this.storingcapacity - 1,
|
---|
| 548 | this.oppPreviousBid_Agent1);
|
---|
| 549 | } else if ((this.ActionOfOpponent instanceof Accept)) {
|
---|
| 550 | this.oppPreviousBid_Agent1 = this.myLastBid;
|
---|
| 551 | }
|
---|
| 552 | } else if (this.countOpp == this.EachRoundCount + 2)// Previous Agent
|
---|
| 553 | // w.r.t. us
|
---|
| 554 | {
|
---|
| 555 | if ((this.ActionOfOpponent instanceof Offer)) {
|
---|
| 556 | if (this.oppFirstBid_Agent2 == null) {
|
---|
| 557 | oppFirstBid_Agent2 = ((Offer) this.ActionOfOpponent)
|
---|
| 558 | .getBid();
|
---|
| 559 | }
|
---|
| 560 | for (int i = 0; i < this.storingcapacity - 1; i++) {
|
---|
| 561 | this.OppBids2.set(i, this.OppBids2.get(i + 1));
|
---|
| 562 | }
|
---|
| 563 | this.oppPreviousBid_Agent2 = ((Offer) this.ActionOfOpponent)
|
---|
| 564 | .getBid();
|
---|
| 565 | this.OppBids2.set(this.storingcapacity - 1,
|
---|
| 566 | this.oppPreviousBid_Agent2);
|
---|
| 567 | } else if ((this.ActionOfOpponent instanceof Accept)) {
|
---|
| 568 | this.oppPreviousBid_Agent2 = this.oppPreviousBid_Agent1;
|
---|
| 569 | }
|
---|
| 570 | }
|
---|
| 571 | }
|
---|
| 572 |
|
---|
| 573 | private double BidToOffer() {
|
---|
| 574 | try {
|
---|
| 575 |
|
---|
| 576 | double maximumOfBid = this.MaximumUtility;// utilitySpace.getUtility(utilitySpace.getMaxUtilityBid());
|
---|
| 577 | AvgConcedeTime = (this.concedeTime_Agent2 + this.concedeTime_Agent1)
|
---|
| 578 | / 2;
|
---|
| 579 |
|
---|
| 580 | if (timeline.getTime() <= AvgConcedeTime) {
|
---|
| 581 | if (this.discountingFactor <= 0.5) {
|
---|
| 582 | this.minThreshold_Agent1 = (maximumOfBid
|
---|
| 583 | * this.discountingFactor)
|
---|
| 584 | / Math.pow(this.discountingFactor,
|
---|
| 585 | this.concedeTime_Agent1);
|
---|
| 586 | this.minThreshold_Agent2 = (maximumOfBid
|
---|
| 587 | * this.discountingFactor)
|
---|
| 588 | / Math.pow(this.discountingFactor,
|
---|
| 589 | this.concedeTime_Agent2);
|
---|
| 590 | this.utilitythreshold_Agent1 = maximumOfBid
|
---|
| 591 | - (maximumOfBid - this.minThreshold_Agent1)
|
---|
| 592 | * Math.pow(
|
---|
| 593 | (timeline.getTime()
|
---|
| 594 | / this.concedeTime_Agent1),
|
---|
| 595 | alpha1);
|
---|
| 596 | this.utilitythreshold_Agent2 = maximumOfBid
|
---|
| 597 | - (maximumOfBid - this.minThreshold_Agent2)
|
---|
| 598 | * Math.pow(
|
---|
| 599 | (timeline.getTime()
|
---|
| 600 | / this.concedeTime_Agent2),
|
---|
| 601 | alpha1);
|
---|
| 602 | } else {
|
---|
| 603 | this.utilitythreshold_Agent1 = this.minThreshold_Agent1
|
---|
| 604 | + (maximumOfBid - this.minThreshold_Agent1) * (1
|
---|
| 605 | - Math.sin((Math.PI / 2) * (timeline
|
---|
| 606 | .getTime() / this.concedeTime_Agent1)));
|
---|
| 607 | this.utilitythreshold_Agent2 = this.minThreshold_Agent2
|
---|
| 608 | + (maximumOfBid - this.minThreshold_Agent2) * (1
|
---|
| 609 | - Math.sin((Math.PI / 2) * (timeline
|
---|
| 610 | .getTime() / this.concedeTime_Agent2)));
|
---|
| 611 | }
|
---|
| 612 | } else {
|
---|
| 613 | if (this.discountingFactor <= 0.5) {
|
---|
| 614 | this.utilitythreshold_Agent1 = (maximumOfBid
|
---|
| 615 | * this.discountingFactor)
|
---|
| 616 | / Math.pow(this.discountingFactor,
|
---|
| 617 | timeline.getTime());
|
---|
| 618 | this.utilitythreshold_Agent2 = (maximumOfBid
|
---|
| 619 | * this.discountingFactor)
|
---|
| 620 | / Math.pow(this.discountingFactor,
|
---|
| 621 | timeline.getTime());
|
---|
| 622 | } else {
|
---|
| 623 | this.utilitythreshold_Agent1 = this.minThreshold_Agent1
|
---|
| 624 | + (maximumOfBid - this.minThreshold_Agent1)
|
---|
| 625 | / (1 - concedeTime_Agent1)
|
---|
| 626 | * Math.pow(
|
---|
| 627 | (timeline.getTime()
|
---|
| 628 | - this.concedeTime_Agent1),
|
---|
| 629 | this.discountingFactor);
|
---|
| 630 | this.utilitythreshold_Agent2 = this.minThreshold_Agent2
|
---|
| 631 | + (maximumOfBid - this.minThreshold_Agent2)
|
---|
| 632 | / (1 - concedeTime_Agent2)
|
---|
| 633 | * Math.pow(
|
---|
| 634 | (timeline.getTime()
|
---|
| 635 | - this.concedeTime_Agent2),
|
---|
| 636 | this.discountingFactor);
|
---|
| 637 | }
|
---|
| 638 | }
|
---|
| 639 | this.AvgUtilitythreshold = (this.utilitythreshold_Agent2
|
---|
| 640 | + this.utilitythreshold_Agent1) / 2;
|
---|
| 641 |
|
---|
| 642 | if (this.AvgUtilitythreshold > MaximumUtility) {
|
---|
| 643 | this.AvgUtilitythreshold = MaximumUtility;
|
---|
| 644 | }
|
---|
| 645 |
|
---|
| 646 | boolean accept = false;
|
---|
| 647 | int count = 0;
|
---|
| 648 | while (!accept) {
|
---|
| 649 | // BidIterator myBidIterator = new
|
---|
| 650 | // BidIterator(this.utilitySpace.getDomain());
|
---|
| 651 | if (count < 2) {
|
---|
| 652 | for (double temputil = this.AvgUtilitythreshold; temputil <= this.MaximumUtility; temputil += 0.01) {
|
---|
| 653 | // Bid tempbid = myBidIterator.next();
|
---|
| 654 | // double temputil =
|
---|
| 655 | // this.utilitySpace.getUtility(tempbid);
|
---|
| 656 | double pchoose1 = (1 / this.relstdevUtility_Agent1
|
---|
| 657 | * (1 / Math.sqrt(2 * Math.PI)))
|
---|
| 658 | * Math.exp(-Math.pow(
|
---|
| 659 | temputil - this.relavgUtility_Agent1, 2)
|
---|
| 660 | / (2 * Math.pow(
|
---|
| 661 | this.relstdevUtility_Agent1,
|
---|
| 662 | 2)));
|
---|
| 663 | double pchoose2 = (1 / this.relstdevUtility_Agent2
|
---|
| 664 | * (1 / Math.sqrt(2 * Math.PI)))
|
---|
| 665 | * Math.exp(-Math.pow(
|
---|
| 666 | temputil - this.relavgUtility_Agent2, 2)
|
---|
| 667 | / (2 * Math.pow(
|
---|
| 668 | this.relstdevUtility_Agent2,
|
---|
| 669 | 2)));
|
---|
| 670 | double pchoose = (pchoose1 + pchoose2) / 2;
|
---|
| 671 | if (pchoose >= Math.random()/*
|
---|
| 672 | * && temputil >=
|
---|
| 673 | * this.utilitythreshold
|
---|
| 674 | */) {
|
---|
| 675 | return temputil;
|
---|
| 676 | }
|
---|
| 677 | }
|
---|
| 678 | } else {
|
---|
| 679 | return this.AvgUtilitythreshold;
|
---|
| 680 | }
|
---|
| 681 | count++;
|
---|
| 682 | }
|
---|
| 683 |
|
---|
| 684 | } catch (Exception e) {
|
---|
| 685 | System.out
|
---|
| 686 | .println(e.getMessage() + "exception in method BidToOffer");
|
---|
| 687 | this.except = 4;
|
---|
| 688 | }
|
---|
| 689 | // System.out.println("the current threshold is " +
|
---|
| 690 | // this.utilitythreshold + " with the value of alpha1 is " + alpha1);
|
---|
| 691 | return 1.0;
|
---|
| 692 | }
|
---|
| 693 |
|
---|
| 694 | /*
|
---|
| 695 | * decide whether to accept the current offer or not
|
---|
| 696 | */
|
---|
| 697 | private boolean AcceptOpponentOffer(Bid opponentBid, Bid ownBid) {
|
---|
| 698 | try {
|
---|
| 699 | double currentUtility = 0;
|
---|
| 700 | double nextRoundUtility = 0;
|
---|
| 701 | double maximumUtility = 0;
|
---|
| 702 | this.concedeToOpponent = false;
|
---|
| 703 | currentUtility = this.utilitySpace.getUtility(opponentBid);
|
---|
| 704 | maximumUtility = this.MaximumUtility;// utilitySpace.getUtility(utilitySpace.getMaxUtilityBid());
|
---|
| 705 | nextRoundUtility = this.utilitySpace.getUtility(ownBid);
|
---|
| 706 |
|
---|
| 707 | // System.out.println(this.utilitythreshold +"at time "+
|
---|
| 708 | // timeline.getTime());
|
---|
| 709 | if (currentUtility >= this.AvgUtilitythreshold
|
---|
| 710 | || currentUtility >= nextRoundUtility) {
|
---|
| 711 | return true;
|
---|
| 712 | } else {
|
---|
| 713 | // if the current utility with discount is larger than the
|
---|
| 714 | // predicted maximum utility with discount
|
---|
| 715 | // then accept it.
|
---|
| 716 | double predictMaximumUtility = maximumUtility
|
---|
| 717 | * this.discountingFactor;
|
---|
| 718 | // double currentMaximumUtility =
|
---|
| 719 | // this.utilitySpace.getUtilityWithDiscount(opponentBidHistory.chooseBestFromHistory(utilitySpace),
|
---|
| 720 | // timeline);
|
---|
| 721 | double currentMaximumUtility1 = this.utilitySpace
|
---|
| 722 | .getUtilityWithDiscount(
|
---|
| 723 | opponentBidHistory1.getBestBidInHistory(),
|
---|
| 724 | timeline);
|
---|
| 725 | double currentMaximumUtility2 = this.utilitySpace
|
---|
| 726 | .getUtilityWithDiscount(
|
---|
| 727 | opponentBidHistory2.getBestBidInHistory(),
|
---|
| 728 | timeline);
|
---|
| 729 | double currentMaximumUtility = Math.min(currentMaximumUtility1,
|
---|
| 730 | currentMaximumUtility2);
|
---|
| 731 | if (currentMaximumUtility > predictMaximumUtility
|
---|
| 732 | && timeline.getTime() > this.AvgConcedeTime) {
|
---|
| 733 | try {
|
---|
| 734 | // if the current offer is approximately as good as the
|
---|
| 735 | // best one in the history, then accept it.
|
---|
| 736 | if (utilitySpace.getUtilityWithDiscount(opponentBid,
|
---|
| 737 | timeline) >= currentMaximumUtility - 0.01) {
|
---|
| 738 | System.out.println("he offered me "
|
---|
| 739 | + currentMaximumUtility
|
---|
| 740 | + " we predict we can get at most "
|
---|
| 741 | + predictMaximumUtility
|
---|
| 742 | + "we concede now to avoid lower payoff due to conflict");
|
---|
| 743 | return true;
|
---|
| 744 | } else {
|
---|
| 745 | this.concedeToOpponent = true;
|
---|
| 746 | return false;
|
---|
| 747 | }
|
---|
| 748 | } catch (Exception e) {
|
---|
| 749 | System.out.println(
|
---|
| 750 | "exception in Method AcceptOpponentOffer");
|
---|
| 751 | this.except = 7;
|
---|
| 752 | return true;
|
---|
| 753 | }
|
---|
| 754 | // retrieve the opponent's biding history and utilize it
|
---|
| 755 | } else if (currentMaximumUtility > this.AvgUtilitythreshold
|
---|
| 756 | * Math.pow(this.discountingFactor,
|
---|
| 757 | timeline.getTime())) {
|
---|
| 758 | try {
|
---|
| 759 | // if the current offer is approximately as good as the
|
---|
| 760 | // best one in the history, then accept it.
|
---|
| 761 | if (utilitySpace.getUtilityWithDiscount(opponentBid,
|
---|
| 762 | timeline) >= currentMaximumUtility - 0.01) {
|
---|
| 763 | return true;
|
---|
| 764 | } else {
|
---|
| 765 | System.out.println("test"
|
---|
| 766 | + utilitySpace.getUtility(opponentBid)
|
---|
| 767 | + this.AvgUtilitythreshold);
|
---|
| 768 | this.concedeToOpponent = true;
|
---|
| 769 | return false;
|
---|
| 770 | }
|
---|
| 771 | } catch (Exception e) {
|
---|
| 772 | System.out.println(
|
---|
| 773 | "exception in Method AcceptOpponentOffer");
|
---|
| 774 | this.except = 8;
|
---|
| 775 | return true;
|
---|
| 776 | }
|
---|
| 777 | } else {
|
---|
| 778 | return false;
|
---|
| 779 | }
|
---|
| 780 | }
|
---|
| 781 | } catch (Exception e) {
|
---|
| 782 | System.out.println("exception in Method AcceptOpponentOffer");
|
---|
| 783 | return true;
|
---|
| 784 | }
|
---|
| 785 |
|
---|
| 786 | }
|
---|
| 787 |
|
---|
| 788 | /*
|
---|
| 789 | * decide whether or not to terminate now
|
---|
| 790 | */
|
---|
| 791 | private boolean TerminateCurrentNegotiation(Bid ownBid) {
|
---|
| 792 | double currentUtility = 0;
|
---|
| 793 | double nextRoundUtility = 0;
|
---|
| 794 | double maximumUtility = 0;
|
---|
| 795 | this.concedeToOpponent = false;
|
---|
| 796 | try {
|
---|
| 797 | currentUtility = this.reservationValue;
|
---|
| 798 | nextRoundUtility = this.utilitySpace.getUtility(ownBid);
|
---|
| 799 | maximumUtility = this.MaximumUtility;
|
---|
| 800 |
|
---|
| 801 | if (this.discountingFactor == 1 || this.reservationValue == 0) {
|
---|
| 802 | return false;
|
---|
| 803 | }
|
---|
| 804 |
|
---|
| 805 | if (currentUtility >= nextRoundUtility) {
|
---|
| 806 | return true;
|
---|
| 807 | } else {
|
---|
| 808 | // if the current reseravation utility with discount is larger
|
---|
| 809 | // than the predicted maximum utility with discount
|
---|
| 810 | // then terminate the negotiation.
|
---|
| 811 | double predictMaximumUtility = maximumUtility
|
---|
| 812 | * this.discountingFactor;
|
---|
| 813 | double currentMaximumUtility = this.utilitySpace
|
---|
| 814 | .getReservationValueWithDiscount(timeline);
|
---|
| 815 | // System.out.println("the current reserved value is "+
|
---|
| 816 | // this.reservationValue+" after discounting is
|
---|
| 817 | // "+currentMaximumUtility);
|
---|
| 818 | if (currentMaximumUtility > predictMaximumUtility
|
---|
| 819 | && timeline.getTime() > this.AvgConcedeTime) {
|
---|
| 820 | return true;
|
---|
| 821 | } else {
|
---|
| 822 | return false;
|
---|
| 823 | }
|
---|
| 824 | }
|
---|
| 825 | } catch (Exception e) {
|
---|
| 826 | System.out.println(e.getMessage()
|
---|
| 827 | + "Exception in method TerminateCurrentNegotiation");
|
---|
| 828 | this.except = 9;
|
---|
| 829 | return true;
|
---|
| 830 | }
|
---|
| 831 | }
|
---|
| 832 |
|
---|
| 833 | /*
|
---|
| 834 | * estimate the number of rounds left before reaching the deadline @param
|
---|
| 835 | * opponent @return
|
---|
| 836 | */
|
---|
| 837 | private int estimateRoundLeft(boolean opponent) {
|
---|
| 838 | double round;
|
---|
| 839 | try {
|
---|
| 840 | if (opponent == true) {
|
---|
| 841 | if (this.timeLeftBefore
|
---|
| 842 | - this.timeLeftAfter > this.maximumTimeOfOpponent) {
|
---|
| 843 | this.maximumTimeOfOpponent = this.timeLeftBefore
|
---|
| 844 | - this.timeLeftAfter;
|
---|
| 845 | }
|
---|
| 846 | } else {
|
---|
| 847 | if (this.timeLeftAfter
|
---|
| 848 | - this.timeLeftBefore > this.maximumTimeOfOwn) {
|
---|
| 849 | this.maximumTimeOfOwn = this.timeLeftAfter
|
---|
| 850 | - this.timeLeftBefore;
|
---|
| 851 | }
|
---|
| 852 | }
|
---|
| 853 | if (this.maximumTimeOfOpponent + this.maximumTimeOfOwn == 0) {
|
---|
| 854 | System.out.println("divided by zero exception");
|
---|
| 855 |
|
---|
| 856 | this.except = 10;
|
---|
| 857 | }
|
---|
| 858 | round = (this.totalTime - timeline.getCurrentTime())
|
---|
| 859 | / (this.maximumTimeOfOpponent + this.maximumTimeOfOwn);
|
---|
| 860 | // System.out.println("current time is " +
|
---|
| 861 | // timeline.getElapsedSeconds() + "---" + round + "----" +
|
---|
| 862 | // this.maximumTimeOfOpponent);
|
---|
| 863 | } catch (Exception e) {
|
---|
| 864 | System.out.println(e.getMessage()
|
---|
| 865 | + "Exception in method TerminateCurrentNegotiation");
|
---|
| 866 | this.except = 9;
|
---|
| 867 | return 20;
|
---|
| 868 | }
|
---|
| 869 | return ((int) (round));
|
---|
| 870 | }
|
---|
| 871 |
|
---|
| 872 | /*
|
---|
| 873 | * pre-processing to save the computational time each round
|
---|
| 874 | */
|
---|
| 875 | private void calculateBidsBetweenUtility() {
|
---|
| 876 | BidIterator myBidIterator = null;
|
---|
| 877 | myBidIterator = new BidIterator(this.utilitySpace.getDomain());
|
---|
| 878 | int counts[] = new int[this.NumberofDivisions];
|
---|
| 879 | try {
|
---|
| 880 | this.MinimumUtility = Math.min(this.MinimumUtility_Agent1,
|
---|
| 881 | this.MinimumUtility_Agent2);
|
---|
| 882 | this.SpacebetweenDivisions = (this.MaximumUtility
|
---|
| 883 | - this.MinimumUtility) / this.NumberofDivisions;
|
---|
| 884 | // initalization for each arraylist storing the bids between each
|
---|
| 885 | // range
|
---|
| 886 | for (int i = 0; i < this.NumberofDivisions; i++) {
|
---|
| 887 | ArrayList<Bid> BidList = null;
|
---|
| 888 | BidList = new ArrayList<Bid>();
|
---|
| 889 | // BidList.add(this.bid_maximum_utility);
|
---|
| 890 | this.bidsBetweenUtility.add(i, BidList);
|
---|
| 891 | }
|
---|
| 892 | this.bidsBetweenUtility.get(this.NumberofDivisions - 1).add(
|
---|
| 893 | counts[this.NumberofDivisions - 1],
|
---|
| 894 | this.bid_maximum_utility);
|
---|
| 895 | // note that here we may need to use some trick to reduce the
|
---|
| 896 | // computation cost (to be checked later);
|
---|
| 897 | // add those bids in each range into the corresponding arraylist
|
---|
| 898 | while (myBidIterator.hasNext()) {
|
---|
| 899 | Bid b = myBidIterator.next();
|
---|
| 900 | for (int i = 0; i < this.NumberofDivisions; i++) {
|
---|
| 901 | if (this.utilitySpace.getUtility(
|
---|
| 902 | b) <= (i + 1) * this.SpacebetweenDivisions
|
---|
| 903 | + this.MinimumUtility
|
---|
| 904 | && this.utilitySpace.getUtility(b) >= i
|
---|
| 905 | * this.SpacebetweenDivisions
|
---|
| 906 | + Math.min(this.MinimumUtility_Agent1,
|
---|
| 907 | this.MinimumUtility_Agent2)) {
|
---|
| 908 | this.bidsBetweenUtility.get(i).add(counts[i], b);
|
---|
| 909 | counts[i]++;
|
---|
| 910 | break;
|
---|
| 911 | }
|
---|
| 912 | }
|
---|
| 913 | }
|
---|
| 914 | } catch (Exception e) {
|
---|
| 915 | System.out.println("Exception in calculateBidsBetweenUtility()");
|
---|
| 916 | this.except = 11;
|
---|
| 917 | }
|
---|
| 918 | }
|
---|
| 919 |
|
---|
| 920 | private Bid RandomSearchBid() throws Exception {
|
---|
| 921 | HashMap<Integer, Value> values = new HashMap<Integer, Value>();
|
---|
| 922 | List<Issue> issues = utilitySpace.getDomain().getIssues();
|
---|
| 923 | Bid bid = null;
|
---|
| 924 |
|
---|
| 925 | for (Issue lIssue : issues) {
|
---|
| 926 | Random random = new Random();
|
---|
| 927 | switch (lIssue.getType()) {
|
---|
| 928 | case DISCRETE:
|
---|
| 929 | IssueDiscrete lIssueDiscrete = (IssueDiscrete) lIssue;
|
---|
| 930 | int optionIndex = random
|
---|
| 931 | .nextInt(lIssueDiscrete.getNumberOfValues());
|
---|
| 932 | values.put(lIssue.getNumber(),
|
---|
| 933 | lIssueDiscrete.getValue(optionIndex));
|
---|
| 934 | break;
|
---|
| 935 | case REAL:
|
---|
| 936 | IssueReal lIssueReal = (IssueReal) lIssue;
|
---|
| 937 | int optionInd = random.nextInt(
|
---|
| 938 | lIssueReal.getNumberOfDiscretizationSteps() - 1);
|
---|
| 939 | values.put(lIssueReal.getNumber(),
|
---|
| 940 | new ValueReal(lIssueReal.getLowerBound() + (lIssueReal
|
---|
| 941 | .getUpperBound() - lIssueReal.getLowerBound())
|
---|
| 942 | * (optionInd) / (lIssueReal
|
---|
| 943 | .getNumberOfDiscretizationSteps())));
|
---|
| 944 | break;
|
---|
| 945 | case INTEGER:
|
---|
| 946 | IssueInteger lIssueInteger = (IssueInteger) lIssue;
|
---|
| 947 | int optionIndex2 = lIssueInteger.getLowerBound()
|
---|
| 948 | + random.nextInt(lIssueInteger.getUpperBound()
|
---|
| 949 | - lIssueInteger.getLowerBound());
|
---|
| 950 | values.put(lIssueInteger.getNumber(),
|
---|
| 951 | new ValueInteger(optionIndex2));
|
---|
| 952 | break;
|
---|
| 953 | default:
|
---|
| 954 | this.except = 12;
|
---|
| 955 | throw new Exception(
|
---|
| 956 | "issue type " + lIssue.getType() + " not supported");
|
---|
| 957 | }
|
---|
| 958 | }
|
---|
| 959 | bid = new Bid(utilitySpace.getDomain(), values);
|
---|
| 960 | return bid;
|
---|
| 961 | }
|
---|
| 962 |
|
---|
| 963 | /*
|
---|
| 964 | * Get all the bids within a given utility range.
|
---|
| 965 | */
|
---|
| 966 | private List<Bid> getBidsBetweenUtility(double lowerBound,
|
---|
| 967 | double upperBound) {
|
---|
| 968 | List<Bid> bidsInRange = new ArrayList<Bid>();
|
---|
| 969 | try {
|
---|
| 970 | int range = (int) ((upperBound - this.minimumUtilityThreshold)
|
---|
| 971 | / 0.01);
|
---|
| 972 | int initial = (int) ((lowerBound - this.minimumUtilityThreshold)
|
---|
| 973 | / 0.01);
|
---|
| 974 | // System.out.println(range+"---"+initial);
|
---|
| 975 | for (int i = initial; i < range; i++) {
|
---|
| 976 | bidsInRange.addAll(i, this.bidsBetweenUtility.get(i));
|
---|
| 977 | }
|
---|
| 978 | if (bidsInRange.isEmpty()) {
|
---|
| 979 | bidsInRange.add(range - 1, this.bid_maximum_utility);
|
---|
| 980 | }
|
---|
| 981 | } catch (Exception e) {
|
---|
| 982 | System.out.println("Exception in getBidsBetweenUtility");
|
---|
| 983 | this.except = 13;
|
---|
| 984 | e.printStackTrace();
|
---|
| 985 | }
|
---|
| 986 | return bidsInRange;
|
---|
| 987 | }
|
---|
| 988 |
|
---|
| 989 | /*
|
---|
| 990 | * determine concede-to-time degree based on the discounting factor.
|
---|
| 991 | */
|
---|
| 992 | private void chooseConcedeToDiscountingDegree() {
|
---|
| 993 | try {
|
---|
| 994 | double alpha = 0;
|
---|
| 995 | double beta = 1.5;// 1.3;//this value controls the rate at which the
|
---|
| 996 | // agent concedes to the discouting factor.
|
---|
| 997 | // the larger beta is, the more the agent makes concesions.
|
---|
| 998 | // if (utilitySpace.getDomain().getNumberOfPossibleBids() > 100) {
|
---|
| 999 | /*
|
---|
| 1000 | * if (this.maximumOfBid > 100) { beta = 2;//1.3; } else { beta =
|
---|
| 1001 | * 1.5; }
|
---|
| 1002 | */
|
---|
| 1003 | // the vaule of beta depends on the discounting factor (trade-off
|
---|
| 1004 | // between concede-to-time degree and discouting factor)
|
---|
| 1005 | if (this.discountingFactor > 0.75) {
|
---|
| 1006 | beta = 1.8;
|
---|
| 1007 | } else if (this.discountingFactor > 0.5) {
|
---|
| 1008 | beta = 1.5;
|
---|
| 1009 | } else {
|
---|
| 1010 | beta = 1.2;
|
---|
| 1011 | }
|
---|
| 1012 | alpha = Math.pow(this.discountingFactor, beta);
|
---|
| 1013 | this.AvgConcedeTime = this.minConcedeTime
|
---|
| 1014 | + (1 - this.minConcedeTime) * alpha;
|
---|
| 1015 | this.concedeTime_original = this.AvgConcedeTime;
|
---|
| 1016 | // System.out.println("concedeToDiscountingFactor is " +
|
---|
| 1017 | // this.AvgConcedeTime + "current time is " + timeline.getTime());
|
---|
| 1018 | } catch (Exception e) {
|
---|
| 1019 | System.out.println(
|
---|
| 1020 | "Exception in method chooseConcedeToDiscountingDegree");
|
---|
| 1021 | }
|
---|
| 1022 | }
|
---|
| 1023 |
|
---|
| 1024 | /*
|
---|
| 1025 | * update the concede-to-time degree based on the predicted toughness degree
|
---|
| 1026 | * of the opponent
|
---|
| 1027 | */
|
---|
| 1028 |
|
---|
| 1029 | private Bid regeneratebid(double bidutil) {
|
---|
| 1030 | Bid ans = null;
|
---|
| 1031 | ArrayList<Bid> Bids = null;
|
---|
| 1032 | this.mindistance = 999;
|
---|
| 1033 | this.averagedistance = 999;
|
---|
| 1034 | int count = 0;
|
---|
| 1035 | try {
|
---|
| 1036 | int check = 0;
|
---|
| 1037 | if (this.OppBids1.get(this.storingcapacity - 1) == null
|
---|
| 1038 | || this.OppBids2.get(this.storingcapacity - 1) == null) {
|
---|
| 1039 | ans = this.bid_maximum_utility;
|
---|
| 1040 | } else {
|
---|
| 1041 | for (this.CurrentrangeNumber = 0; check == 0; this.CurrentrangeNumber++) {
|
---|
| 1042 | if (bidutil < ((this.CurrentrangeNumber + 1)
|
---|
| 1043 | * this.SpacebetweenDivisions
|
---|
| 1044 | + this.MinimumUtility)) {
|
---|
| 1045 | check = 1;
|
---|
| 1046 | break;
|
---|
| 1047 | }
|
---|
| 1048 | }
|
---|
| 1049 | Bids = this.bidsBetweenUtility.get(this.CurrentrangeNumber);
|
---|
| 1050 | while (Bids.size() <= 10) {
|
---|
| 1051 | if (this.CurrentrangeNumber <= this.NumberofDivisions - 2) {
|
---|
| 1052 | for (int i = 0; i < this.bidsBetweenUtility
|
---|
| 1053 | .get(this.CurrentrangeNumber + 1).size(); i++) {
|
---|
| 1054 | Bids.add(Bids.size(), this.bidsBetweenUtility
|
---|
| 1055 | .get(this.CurrentrangeNumber + 1).get(i));
|
---|
| 1056 | }
|
---|
| 1057 | } else {
|
---|
| 1058 | break;
|
---|
| 1059 | }
|
---|
| 1060 | this.CurrentrangeNumber++;
|
---|
| 1061 | }
|
---|
| 1062 | this.size = Bids.size();
|
---|
| 1063 | if (Bids == null) {
|
---|
| 1064 | ans = this.mylastBid;
|
---|
| 1065 | } else {
|
---|
| 1066 | if (Math.random() > 0.1) {
|
---|
| 1067 | for (Bid Bid1 : Bids) {
|
---|
| 1068 | if (this.utilitySpace.getUtility(
|
---|
| 1069 | Bid1) > this.AvgUtilitythreshold) {
|
---|
| 1070 | count = 0;
|
---|
| 1071 | for (int i = 0; i < this.storingcapacity; i++) {
|
---|
| 1072 | if (this.OppBids1.get(i) != null) {
|
---|
| 1073 | this.averagedistance += calculatedistance(
|
---|
| 1074 | Bid1, this.OppBids1.get(i));
|
---|
| 1075 | count++;
|
---|
| 1076 | }
|
---|
| 1077 | if (this.OppBids2.get(i) != null) {
|
---|
| 1078 | this.averagedistance += calculatedistance(
|
---|
| 1079 | Bid1, this.OppBids2.get(i));
|
---|
| 1080 | count++;
|
---|
| 1081 | }
|
---|
| 1082 | }
|
---|
| 1083 | this.averagedistance /= count;
|
---|
| 1084 | if (this.averagedistance < this.mindistance) {
|
---|
| 1085 | this.mindistance = this.averagedistance;
|
---|
| 1086 | ans = Bid1;
|
---|
| 1087 | } else if (this.averagedistance == this.mindistance
|
---|
| 1088 | && Math.random() <= 0.5) {
|
---|
| 1089 | this.mindistance = this.averagedistance;
|
---|
| 1090 | ans = Bid1;
|
---|
| 1091 | }
|
---|
| 1092 | }
|
---|
| 1093 | }
|
---|
| 1094 | } else {
|
---|
| 1095 | ans = Bids.get((int) (Math.random() * Bids.size()));
|
---|
| 1096 | }
|
---|
| 1097 | }
|
---|
| 1098 | }
|
---|
| 1099 | } catch (Exception e) {
|
---|
| 1100 | System.out.println("Exception in method regeneratebid");
|
---|
| 1101 | this.except = 17;
|
---|
| 1102 | ans = this.bid_maximum_utility;
|
---|
| 1103 | }
|
---|
| 1104 | return ans;
|
---|
| 1105 |
|
---|
| 1106 | }
|
---|
| 1107 |
|
---|
| 1108 | private HashMap<Issue, Value> getBidValues(Bid bid) {
|
---|
| 1109 | try {
|
---|
| 1110 | HashMap<Issue, Value> Values = new HashMap<Issue, Value>();
|
---|
| 1111 | for (Issue lIssue : this.Issues) {
|
---|
| 1112 | int issueNum = lIssue.getNumber();
|
---|
| 1113 | Value v = bid.getValue(issueNum);
|
---|
| 1114 | Values.put(lIssue, v);
|
---|
| 1115 | }
|
---|
| 1116 | return Values;
|
---|
| 1117 | } catch (Exception e) {
|
---|
| 1118 | System.out
|
---|
| 1119 | .println("Exception in getBidValues(): " + e.getMessage());
|
---|
| 1120 | this.except = 18;
|
---|
| 1121 | }
|
---|
| 1122 | return null;
|
---|
| 1123 | }
|
---|
| 1124 |
|
---|
| 1125 | private double calculatedistance(Bid Bid1, Bid Bid2) {
|
---|
| 1126 | try {
|
---|
| 1127 | double distance = 0.0D;
|
---|
| 1128 | HashMap<Issue, Value> Map1 = this.getBidValues(Bid1);
|
---|
| 1129 | HashMap<Issue, Value> Map2 = this.getBidValues(Bid2);
|
---|
| 1130 | for (Issue Issue1 : this.Issues) {
|
---|
| 1131 | switch (Issue1.getType()) {
|
---|
| 1132 | case DISCRETE:
|
---|
| 1133 | IssueDiscrete lIssueDiscrete = (IssueDiscrete) Issue1;
|
---|
| 1134 | ValueDiscrete value1 = (ValueDiscrete) Map1.get(Issue1);
|
---|
| 1135 | ValueDiscrete value2 = (ValueDiscrete) Map2.get(Issue1);
|
---|
| 1136 | int index1 = lIssueDiscrete.getValueIndex(value1);
|
---|
| 1137 | int index2 = lIssueDiscrete.getValueIndex(value2);
|
---|
| 1138 | distance += Math.abs(index1 - index2);
|
---|
| 1139 |
|
---|
| 1140 | break;
|
---|
| 1141 | case REAL:
|
---|
| 1142 | ValueReal valueReal1 = (ValueReal) Map1.get(Issue1);
|
---|
| 1143 | ValueReal valueReal2 = (ValueReal) Map2.get(Issue1);
|
---|
| 1144 | double indexReal1 = valueReal1.getValue();
|
---|
| 1145 | double indexReal2 = valueReal2.getValue();
|
---|
| 1146 | distance += Math.abs(indexReal1 - indexReal2);
|
---|
| 1147 | break;
|
---|
| 1148 | case INTEGER:
|
---|
| 1149 | ValueInteger valueInteger1 = (ValueInteger) Map1
|
---|
| 1150 | .get(Issue1);
|
---|
| 1151 | ValueInteger valueInteger2 = (ValueInteger) Map2
|
---|
| 1152 | .get(Issue1);
|
---|
| 1153 | double indexInteger1 = valueInteger1.getValue();
|
---|
| 1154 | double indexInteger2 = valueInteger2.getValue();
|
---|
| 1155 | distance += Math.abs(indexInteger1 - indexInteger2);
|
---|
| 1156 | break;
|
---|
| 1157 | }
|
---|
| 1158 | }
|
---|
| 1159 | return distance;
|
---|
| 1160 | } catch (Exception e) {
|
---|
| 1161 | System.out.println("Exception in method calculatedistance");
|
---|
| 1162 | this.except = 19;
|
---|
| 1163 | return 999;
|
---|
| 1164 | }
|
---|
| 1165 | }
|
---|
| 1166 |
|
---|
| 1167 | private void updateConcedeDegree_smallDiscountingFactor() {
|
---|
| 1168 | double gama = 10;
|
---|
| 1169 | double weight = 0.1;
|
---|
| 1170 | double opponnetToughnessDegree = this.opponentBidHistory2
|
---|
| 1171 | .getConcessionDegree();
|
---|
| 1172 | try {
|
---|
| 1173 | if (IsOppFirstBid_Agent1) {
|
---|
| 1174 | this.oppFirstBidUtility_Agent1 = utilitySpace
|
---|
| 1175 | .getUtility(this.oppFirstBid_Agent1);
|
---|
| 1176 | if (this.reservationValue <= this.oppFirstBidUtility_Agent1) {
|
---|
| 1177 | this.MinimumUtility_Agent1 = this.oppFirstBidUtility_Agent1;
|
---|
| 1178 | }
|
---|
| 1179 | IsOppFirstBid_Agent1 = false;
|
---|
| 1180 | }
|
---|
| 1181 |
|
---|
| 1182 | if (IsOppFirstBid_Agent2) {
|
---|
| 1183 | this.oppFirstBidUtility_Agent2 = utilitySpace
|
---|
| 1184 | .getUtility(this.oppFirstBid_Agent2);
|
---|
| 1185 | if (this.reservationValue <= this.oppFirstBidUtility_Agent2) {
|
---|
| 1186 | this.MinimumUtility_Agent2 = this.oppFirstBidUtility_Agent2;
|
---|
| 1187 | }
|
---|
| 1188 | IsOppFirstBid_Agent2 = false;
|
---|
| 1189 | }
|
---|
| 1190 |
|
---|
| 1191 | double temp = this.concedeTime_original
|
---|
| 1192 | + weight * (1 - this.concedeTime_original)
|
---|
| 1193 | * Math.pow(opponnetToughnessDegree, gama);
|
---|
| 1194 | this.concedeTime_Agent1 = temp;
|
---|
| 1195 | this.concedeTime_Agent2 = temp;
|
---|
| 1196 | if ((this.concedeTime_Agent1 >= 1)
|
---|
| 1197 | || (this.concedeTime_Agent2 >= 1)) {
|
---|
| 1198 | this.concedeTime_Agent1 = 1;
|
---|
| 1199 | this.concedeTime_Agent2 = 1;
|
---|
| 1200 | }
|
---|
| 1201 | } catch (Exception e) {
|
---|
| 1202 | System.out.println(
|
---|
| 1203 | "Exception in method updateConcedeDegree_smallDiscountingFactor");
|
---|
| 1204 | this.except = 20;
|
---|
| 1205 | }
|
---|
| 1206 | // System.out.println("concedeToDiscountingFactor is " +
|
---|
| 1207 | // this.concedeToDiscountingFactor + "current time is " +
|
---|
| 1208 | // timeline.getTime() + "original concedetodiscoutingfactor is " +
|
---|
| 1209 | // this.concedeToDiscountingFactor_original);
|
---|
| 1210 | }
|
---|
| 1211 |
|
---|
| 1212 | private void updateConcedeDegree_largeDiscountingFactor_Agent1() {
|
---|
| 1213 | try {
|
---|
| 1214 | double i = 0;
|
---|
| 1215 | if (IsOppFirstBid_Agent1) {
|
---|
| 1216 | this.CalculateMinThreshold_Agent1();
|
---|
| 1217 | IsOppFirstBid_Agent1 = false;
|
---|
| 1218 | }
|
---|
| 1219 |
|
---|
| 1220 | this.MeasureConcedePartOfOppBehaviour_Agent1();
|
---|
| 1221 |
|
---|
| 1222 | this.concedePartOfdiscountingFactor_Agent1 = this.discountingFactor
|
---|
| 1223 | - 1;
|
---|
| 1224 | this.concedePartOfOppBehaviour_Agent1 = (((((this.relcountLowerBoundMid2_Agent1
|
---|
| 1225 | / this.relcountUpperBoundMid2_Agent1)
|
---|
| 1226 | * this.slopeOfSlopeOfSessionMax2_Agent1)
|
---|
| 1227 | - ((this.relcountLowerBoundMid1_Agent1
|
---|
| 1228 | / this.relcountUpperBoundMid1_Agent1)
|
---|
| 1229 | * this.slopeOfSlopeOfSessionMax1_Agent1))
|
---|
| 1230 | / this.k) / this.relstdevUtility_Agent1) - this.N;
|
---|
| 1231 | if (this.startConcede_Agent1 == true) {
|
---|
| 1232 | i = this.concedePartOfdiscountingFactor_Agent1
|
---|
| 1233 | + this.concedePartOfOppBehaviour_Agent1;
|
---|
| 1234 | this.concedeTime_Agent1 = Math.exp(i);
|
---|
| 1235 | if (this.concedeTime_Agent1 > 1) {
|
---|
| 1236 | this.concedeTime_Agent1 = 1;
|
---|
| 1237 | }
|
---|
| 1238 | } else {
|
---|
| 1239 | this.concedeTime_Agent2 = 0.5;
|
---|
| 1240 | }
|
---|
| 1241 | } catch (Exception e) {
|
---|
| 1242 | this.except = 23;
|
---|
| 1243 | System.out.println(
|
---|
| 1244 | "updateConcedeDegree_largeDiscountingFactor_Agent1 exception");
|
---|
| 1245 | }
|
---|
| 1246 | }
|
---|
| 1247 |
|
---|
| 1248 | private void updateConcedeDegree_largeDiscountingFactor_Agent2() {
|
---|
| 1249 | try {
|
---|
| 1250 | double i = 0;
|
---|
| 1251 | if (IsOppFirstBid_Agent2) {
|
---|
| 1252 | this.CalculateMinThreshold_Agent2();
|
---|
| 1253 | IsOppFirstBid_Agent2 = false;
|
---|
| 1254 | }
|
---|
| 1255 |
|
---|
| 1256 | this.MeasureConcedePartOfOppBehaviour_Agent2();
|
---|
| 1257 |
|
---|
| 1258 | this.concedePartOfdiscountingFactor_Agent2 = this.discountingFactor
|
---|
| 1259 | - 1;
|
---|
| 1260 | this.concedePartOfOppBehaviour_Agent2 = (((((this.relcountLowerBoundMid2_Agent2
|
---|
| 1261 | / this.relcountUpperBoundMid2_Agent2)
|
---|
| 1262 | * this.slopeOfSlopeOfSessionMax2_Agent2)
|
---|
| 1263 | - ((this.relcountLowerBoundMid1_Agent2
|
---|
| 1264 | / this.relcountUpperBoundMid1_Agent2)
|
---|
| 1265 | * this.slopeOfSlopeOfSessionMax1_Agent2))
|
---|
| 1266 | / this.k) / this.relstdevUtility_Agent2) - this.N;
|
---|
| 1267 | if (this.startConcede_Agent2 == true) {
|
---|
| 1268 | i = this.concedePartOfdiscountingFactor_Agent2
|
---|
| 1269 | + this.concedePartOfOppBehaviour_Agent2;
|
---|
| 1270 | this.concedeTime_Agent2 = Math.exp(i);
|
---|
| 1271 | if (this.concedeTime_Agent2 > 1) {
|
---|
| 1272 | this.concedeTime_Agent2 = 1;
|
---|
| 1273 | }
|
---|
| 1274 | } else {
|
---|
| 1275 | this.concedeTime_Agent2 = 0.5;
|
---|
| 1276 | }
|
---|
| 1277 | } catch (Exception e) {
|
---|
| 1278 | this.except = 23;
|
---|
| 1279 | System.out.println(
|
---|
| 1280 | "updateConcedeDegree_largeDiscountingFactor_Agent2 exception");
|
---|
| 1281 | }
|
---|
| 1282 | }
|
---|
| 1283 |
|
---|
| 1284 | private void updateConcedeDegree_nonDiscountingFactor_Agent1() {
|
---|
| 1285 | try {
|
---|
| 1286 | if (IsOppFirstBid_Agent1) {
|
---|
| 1287 | this.CalculateMinThreshold_Agent1();
|
---|
| 1288 | IsOppFirstBid_Agent1 = false;
|
---|
| 1289 | }
|
---|
| 1290 |
|
---|
| 1291 | this.concedeTime_Agent1 = 1;
|
---|
| 1292 | } catch (Exception e) {
|
---|
| 1293 | this.except = 25;
|
---|
| 1294 | System.out.println(
|
---|
| 1295 | "updateConcedeDegree_nonDiscountingFactor_Agent1 exception");
|
---|
| 1296 | }
|
---|
| 1297 | }
|
---|
| 1298 |
|
---|
| 1299 | private void updateConcedeDegree_nonDiscountingFactor_Agent2() {
|
---|
| 1300 | try {
|
---|
| 1301 | if (IsOppFirstBid_Agent2) {
|
---|
| 1302 | this.CalculateMinThreshold_Agent2();
|
---|
| 1303 | IsOppFirstBid_Agent2 = false;
|
---|
| 1304 | }
|
---|
| 1305 |
|
---|
| 1306 | this.concedeTime_Agent2 = 1;
|
---|
| 1307 | } catch (Exception e) {
|
---|
| 1308 | this.except = 25;
|
---|
| 1309 | System.out.println(
|
---|
| 1310 | "updateConcedeDegree_nonDiscountingFactor_Agent2 exception");
|
---|
| 1311 | }
|
---|
| 1312 | }
|
---|
| 1313 |
|
---|
| 1314 | private void CalculateMinThreshold_Agent1() {
|
---|
| 1315 | try {
|
---|
| 1316 | ArrayList<Double> bidsUtil = new ArrayList();
|
---|
| 1317 | bidsUtil = this.CalculateSumAndCount_Agent1(bidsUtil);
|
---|
| 1318 |
|
---|
| 1319 | this.relavgUtility_Agent1 = this.relsumUtility_Agent1
|
---|
| 1320 | / this.relcountUtility_Agent1;
|
---|
| 1321 |
|
---|
| 1322 | for (Iterator f = bidsUtil.iterator(); f.hasNext();) {
|
---|
| 1323 | double bidUtil = (Double) f.next();
|
---|
| 1324 |
|
---|
| 1325 | if (bidUtil >= this.oppFirstBidUtility_Agent1) {
|
---|
| 1326 | this.relSqRootOfAvgUtility_Agent1 += (bidUtil
|
---|
| 1327 | - this.relavgUtility_Agent1)
|
---|
| 1328 | * (bidUtil - this.relavgUtility_Agent1);
|
---|
| 1329 | }
|
---|
| 1330 | }
|
---|
| 1331 | this.relstdevUtility_Agent1 = Math
|
---|
| 1332 | .sqrt(this.relSqRootOfAvgUtility_Agent1
|
---|
| 1333 | / this.relcountUtility_Agent1);
|
---|
| 1334 |
|
---|
| 1335 | if (this.relstdevUtility_Agent1 < 0.1) {
|
---|
| 1336 | this.relSqRootOfAvgUtility_Agent1 = 0;
|
---|
| 1337 | for (Iterator g = bidsUtil.iterator(); g.hasNext();) {
|
---|
| 1338 | double bidUtil = (Double) g.next();
|
---|
| 1339 |
|
---|
| 1340 | if (bidUtil >= this.oppFirstBidUtility_Agent1
|
---|
| 1341 | && (bidUtil < (this.relavgUtility_Agent1
|
---|
| 1342 | - this.relstdevUtility_Agent1)
|
---|
| 1343 | || bidUtil > (this.relavgUtility_Agent1
|
---|
| 1344 | + this.relstdevUtility_Agent1))) {
|
---|
| 1345 | this.relSqRootOfAvgUtility_Agent1 += (bidUtil
|
---|
| 1346 | - this.relavgUtility_Agent1)
|
---|
| 1347 | * (bidUtil - this.relavgUtility_Agent1);
|
---|
| 1348 | this.relcountUtilityInSmallSD_Agent1++;
|
---|
| 1349 | }
|
---|
| 1350 | }
|
---|
| 1351 | this.relstdevUtility_Agent1 = Math
|
---|
| 1352 | .sqrt(this.relSqRootOfAvgUtility_Agent1
|
---|
| 1353 | / this.relcountUtilityInSmallSD_Agent1);
|
---|
| 1354 | }
|
---|
| 1355 |
|
---|
| 1356 | this.minThreshold_Agent1 = this.relavgUtility_Agent1
|
---|
| 1357 | + this.discountingFactor * this.relstdevUtility_Agent1
|
---|
| 1358 | * this.reservationValue;
|
---|
| 1359 |
|
---|
| 1360 | if (this.relcountUtility_Agent1 < 20) {
|
---|
| 1361 | this.minThreshold_Agent1 = this.relavgUtility_Agent1;
|
---|
| 1362 | }
|
---|
| 1363 |
|
---|
| 1364 | this.Compare_MinThreshold_And_SecondMax_Agent1();
|
---|
| 1365 | } catch (Exception e) {
|
---|
| 1366 | System.out.println(e.getMessage()
|
---|
| 1367 | + "exception in method CalculateMinThreshold_Agent1");
|
---|
| 1368 | }
|
---|
| 1369 | }
|
---|
| 1370 |
|
---|
| 1371 | private void CalculateMinThreshold_Agent2() {
|
---|
| 1372 | try {
|
---|
| 1373 | ArrayList<Double> bidsUtil = new ArrayList();
|
---|
| 1374 | bidsUtil = this.CalculateSumAndCount_Agent2(bidsUtil);
|
---|
| 1375 |
|
---|
| 1376 | this.relavgUtility_Agent2 = this.relsumUtility_Agent2
|
---|
| 1377 | / this.relcountUtility_Agent2;
|
---|
| 1378 |
|
---|
| 1379 | for (Iterator f = bidsUtil.iterator(); f.hasNext();) {
|
---|
| 1380 | double bidUtil = (Double) f.next();
|
---|
| 1381 |
|
---|
| 1382 | if (bidUtil >= this.oppFirstBidUtility_Agent2) {
|
---|
| 1383 | this.relSqRootOfAvgUtility_Agent2 += (bidUtil
|
---|
| 1384 | - this.relavgUtility_Agent2)
|
---|
| 1385 | * (bidUtil - this.relavgUtility_Agent2);
|
---|
| 1386 | }
|
---|
| 1387 | }
|
---|
| 1388 | this.relstdevUtility_Agent2 = Math
|
---|
| 1389 | .sqrt(this.relSqRootOfAvgUtility_Agent2
|
---|
| 1390 | / this.relcountUtility_Agent2);
|
---|
| 1391 |
|
---|
| 1392 | if (this.relstdevUtility_Agent2 < 0.1) {
|
---|
| 1393 | this.relSqRootOfAvgUtility_Agent2 = 0;
|
---|
| 1394 | for (Iterator g = bidsUtil.iterator(); g.hasNext();) {
|
---|
| 1395 | double bidUtil = (Double) g.next();
|
---|
| 1396 |
|
---|
| 1397 | if (bidUtil >= this.oppFirstBidUtility_Agent2
|
---|
| 1398 | && (bidUtil < (this.relavgUtility_Agent2
|
---|
| 1399 | - this.relstdevUtility_Agent2)
|
---|
| 1400 | || bidUtil > (this.relavgUtility_Agent2
|
---|
| 1401 | + this.relstdevUtility_Agent2))) {
|
---|
| 1402 | this.relSqRootOfAvgUtility_Agent2 += (bidUtil
|
---|
| 1403 | - this.relavgUtility_Agent2)
|
---|
| 1404 | * (bidUtil - this.relavgUtility_Agent2);
|
---|
| 1405 | this.relcountUtilityInSmallSD_Agent2++;
|
---|
| 1406 | }
|
---|
| 1407 | }
|
---|
| 1408 | this.relstdevUtility_Agent2 = Math
|
---|
| 1409 | .sqrt(this.relSqRootOfAvgUtility_Agent2
|
---|
| 1410 | / this.relcountUtilityInSmallSD_Agent2);
|
---|
| 1411 | }
|
---|
| 1412 |
|
---|
| 1413 | this.minThreshold_Agent2 = this.relavgUtility_Agent2
|
---|
| 1414 | + this.discountingFactor * this.relstdevUtility_Agent2
|
---|
| 1415 | * this.reservationValue;
|
---|
| 1416 |
|
---|
| 1417 | if (this.relcountUtility_Agent2 < 20) {
|
---|
| 1418 | this.minThreshold_Agent2 = this.relavgUtility_Agent2;
|
---|
| 1419 | }
|
---|
| 1420 |
|
---|
| 1421 | this.Compare_MinThreshold_And_SecondMax_Agent2();
|
---|
| 1422 | } catch (Exception e) {
|
---|
| 1423 | System.out.println(e.getMessage()
|
---|
| 1424 | + "exception in method CalculateMinThreshold_Agent2");
|
---|
| 1425 | }
|
---|
| 1426 | }
|
---|
| 1427 |
|
---|
| 1428 | private void Compare_MinThreshold_And_SecondMax_Agent1() {
|
---|
| 1429 | if (this.minThreshold_Agent1 > utility_SecondMaximum_Agent1) {
|
---|
| 1430 | this.minThreshold_Agent1 = utility_SecondMaximum_Agent1 * 0.9;
|
---|
| 1431 | }
|
---|
| 1432 | }
|
---|
| 1433 |
|
---|
| 1434 | private void Compare_MinThreshold_And_SecondMax_Agent2() {
|
---|
| 1435 | if (this.minThreshold_Agent2 > utility_SecondMaximum_Agent2) {
|
---|
| 1436 | this.minThreshold_Agent2 = utility_SecondMaximum_Agent2 * 0.9;
|
---|
| 1437 | }
|
---|
| 1438 | }
|
---|
| 1439 |
|
---|
| 1440 | private ArrayList<Double> CalculateSumAndCount_Agent1(
|
---|
| 1441 | ArrayList<Double> bidsUtil) {
|
---|
| 1442 | try {
|
---|
| 1443 | this.oppFirstBidUtility_Agent1 = utilitySpace
|
---|
| 1444 | .getUtility(this.oppFirstBid_Agent1);
|
---|
| 1445 | if (this.reservationValue <= this.oppFirstBidUtility_Agent1) {
|
---|
| 1446 | this.MinimumUtility_Agent1 = this.oppFirstBidUtility_Agent1;
|
---|
| 1447 | }
|
---|
| 1448 |
|
---|
| 1449 | BidIterator myBidIterator = new BidIterator(
|
---|
| 1450 | this.utilitySpace.getDomain());
|
---|
| 1451 | for (; myBidIterator.hasNext();) {
|
---|
| 1452 | try {
|
---|
| 1453 | bidsUtil.add(
|
---|
| 1454 | this.utilitySpace.getUtility(myBidIterator.next()));
|
---|
| 1455 | } catch (Exception e) {
|
---|
| 1456 | System.out.println(e.getMessage()
|
---|
| 1457 | + "exception in method CalculateSumAndCount_Agent1");
|
---|
| 1458 | return null;
|
---|
| 1459 | }
|
---|
| 1460 | }
|
---|
| 1461 | this.relavgUtility_Agent1 = 0;
|
---|
| 1462 | this.relsumUtility_Agent1 = 0;
|
---|
| 1463 | this.relcountUtility_Agent1 = 0;
|
---|
| 1464 | this.relSqRootOfAvgUtility_Agent1 = 0;
|
---|
| 1465 | this.relstdevUtility_Agent1 = 0;
|
---|
| 1466 | this.minThreshold_Agent1 = 0;
|
---|
| 1467 |
|
---|
| 1468 | for (Iterator e = bidsUtil.iterator(); e.hasNext();) {
|
---|
| 1469 | double bidUtil = (Double) e.next();
|
---|
| 1470 | if (this.utility_FirstMaximum_Agent1 < bidUtil) {
|
---|
| 1471 | this.utility_FirstMaximum_Agent1 = bidUtil;
|
---|
| 1472 | } else if (utility_SecondMaximum_Agent1 < bidUtil) {
|
---|
| 1473 | this.utility_SecondMaximum_Agent1 = bidUtil;
|
---|
| 1474 | }
|
---|
| 1475 |
|
---|
| 1476 | if (bidUtil >= this.oppFirstBidUtility_Agent1) {
|
---|
| 1477 | this.relsumUtility_Agent1 += bidUtil;
|
---|
| 1478 | this.relcountUtility_Agent1 += 1;
|
---|
| 1479 | }
|
---|
| 1480 | }
|
---|
| 1481 |
|
---|
| 1482 | return bidsUtil;
|
---|
| 1483 | } catch (Exception e) {
|
---|
| 1484 | System.out.println(e.getMessage()
|
---|
| 1485 | + "exception in method CalculateSumAndCount_Agent1");
|
---|
| 1486 | }
|
---|
| 1487 |
|
---|
| 1488 | return null;
|
---|
| 1489 | }
|
---|
| 1490 |
|
---|
| 1491 | private ArrayList<Double> CalculateSumAndCount_Agent2(
|
---|
| 1492 | ArrayList<Double> bidsUtil) {
|
---|
| 1493 | try {
|
---|
| 1494 | this.oppFirstBidUtility_Agent2 = utilitySpace
|
---|
| 1495 | .getUtility(this.oppFirstBid_Agent2);
|
---|
| 1496 | if (this.reservationValue <= this.oppFirstBidUtility_Agent2) {
|
---|
| 1497 | this.MinimumUtility_Agent2 = this.oppFirstBidUtility_Agent2;
|
---|
| 1498 | }
|
---|
| 1499 |
|
---|
| 1500 | BidIterator myBidIterator = new BidIterator(
|
---|
| 1501 | this.utilitySpace.getDomain());
|
---|
| 1502 | for (; myBidIterator.hasNext();) {
|
---|
| 1503 | bidsUtil.add(
|
---|
| 1504 | this.utilitySpace.getUtility(myBidIterator.next()));
|
---|
| 1505 | }
|
---|
| 1506 | this.relavgUtility_Agent2 = 0;
|
---|
| 1507 | this.relsumUtility_Agent2 = 0;
|
---|
| 1508 | this.relcountUtility_Agent2 = 0;
|
---|
| 1509 | this.relSqRootOfAvgUtility_Agent2 = 0;
|
---|
| 1510 | this.relstdevUtility_Agent2 = 0;
|
---|
| 1511 | this.minThreshold_Agent2 = 0;
|
---|
| 1512 |
|
---|
| 1513 | for (Iterator e = bidsUtil.iterator(); e.hasNext();) {
|
---|
| 1514 | double bidUtil = (Double) e.next();
|
---|
| 1515 | if (this.utility_FirstMaximum_Agent2 < bidUtil) {
|
---|
| 1516 | this.utility_FirstMaximum_Agent2 = bidUtil;
|
---|
| 1517 | } else if (utility_SecondMaximum_Agent2 < bidUtil) {
|
---|
| 1518 | this.utility_SecondMaximum_Agent2 = bidUtil;
|
---|
| 1519 | }
|
---|
| 1520 |
|
---|
| 1521 | if (bidUtil >= this.oppFirstBidUtility_Agent2) {
|
---|
| 1522 | this.relsumUtility_Agent2 += bidUtil;
|
---|
| 1523 | this.relcountUtility_Agent2 += 1;
|
---|
| 1524 | }
|
---|
| 1525 | }
|
---|
| 1526 |
|
---|
| 1527 | return bidsUtil;
|
---|
| 1528 | } catch (Exception e) {
|
---|
| 1529 | System.out.println(e.getMessage()
|
---|
| 1530 | + "exception in method CalculateSumAndCount_Agent2");
|
---|
| 1531 | return null;
|
---|
| 1532 | }
|
---|
| 1533 | }
|
---|
| 1534 |
|
---|
| 1535 | private void MeasureConcedePartOfOppBehaviour_Agent1() {
|
---|
| 1536 | try {
|
---|
| 1537 | count_Agent1++;
|
---|
| 1538 |
|
---|
| 1539 | if (count_Agent1 < this.FirstTimeInterval) {
|
---|
| 1540 | if (utilitySpace.getUtility(
|
---|
| 1541 | this.oppPreviousBid_Agent1) > this.utility_maximum_from_opponent_Session1_Agent1) {
|
---|
| 1542 | this.utility_maximum_from_opponent_Session1_Agent1 = utilitySpace
|
---|
| 1543 | .getUtility(this.oppPreviousBid_Agent1);
|
---|
| 1544 | }
|
---|
| 1545 | } else if (count_Agent2 < this.SecondTimeInterval) {
|
---|
| 1546 | if (utilitySpace.getUtility(
|
---|
| 1547 | this.oppPreviousBid_Agent1) > this.utility_maximum_from_opponent_Session2_Agent1) {
|
---|
| 1548 | this.utility_maximum_from_opponent_Session2_Agent1 = utilitySpace
|
---|
| 1549 | .getUtility(this.oppPreviousBid_Agent1);
|
---|
| 1550 | }
|
---|
| 1551 | } else if (count_Agent2 < this.ThirdTimeInterval) {
|
---|
| 1552 | if (utilitySpace.getUtility(
|
---|
| 1553 | this.oppPreviousBid_Agent1) > this.utility_maximum_from_opponent_Session3_Agent1) {
|
---|
| 1554 | this.utility_maximum_from_opponent_Session3_Agent1 = utilitySpace
|
---|
| 1555 | .getUtility(this.oppPreviousBid_Agent1);
|
---|
| 1556 | }
|
---|
| 1557 | } else {
|
---|
| 1558 | this.relcountUpperBoundMid1_Agent1 = 0;
|
---|
| 1559 | this.relcountUpperBoundMid2_Agent1 = 0;
|
---|
| 1560 | this.relcountLowerBoundMid1_Agent1 = 0;
|
---|
| 1561 | this.relcountLowerBoundMid2_Agent1 = 0;
|
---|
| 1562 | this.midPointOfSlopeSessionMax1_Agent1 = (this.utility_maximum_from_opponent_Session2_Agent1
|
---|
| 1563 | + this.utility_maximum_from_opponent_Session1_Agent1)
|
---|
| 1564 | / 2;
|
---|
| 1565 | this.midPointOfSlopeSessionMax2_Agent1 = (this.utility_maximum_from_opponent_Session3_Agent1
|
---|
| 1566 | + this.utility_maximum_from_opponent_Session2_Agent1)
|
---|
| 1567 | / 2;
|
---|
| 1568 | this.slopeOfSlopeOfSessionMax1_Agent1 = this.utility_maximum_from_opponent_Session2_Agent1
|
---|
| 1569 | - this.utility_maximum_from_opponent_Session1_Agent1;
|
---|
| 1570 | this.slopeOfSlopeOfSessionMax2_Agent1 = this.utility_maximum_from_opponent_Session3_Agent1
|
---|
| 1571 | - this.utility_maximum_from_opponent_Session2_Agent1;
|
---|
| 1572 |
|
---|
| 1573 | ArrayList<Double> bidsUtil = new ArrayList();
|
---|
| 1574 | BidIterator myBidIterator = new BidIterator(
|
---|
| 1575 | this.utilitySpace.getDomain());
|
---|
| 1576 | for (; myBidIterator.hasNext();) {
|
---|
| 1577 | bidsUtil.add(
|
---|
| 1578 | this.utilitySpace.getUtility(myBidIterator.next()));
|
---|
| 1579 | }
|
---|
| 1580 | for (Iterator e = bidsUtil.iterator(); e.hasNext();) {
|
---|
| 1581 | double bidUtil = (Double) e.next();
|
---|
| 1582 | if (bidUtil >= this.midPointOfSlopeSessionMax1_Agent1) {
|
---|
| 1583 | this.relcountUpperBoundMid1_Agent1 += 1;
|
---|
| 1584 | } else {
|
---|
| 1585 | this.relcountLowerBoundMid1_Agent1 += 1;
|
---|
| 1586 | }
|
---|
| 1587 |
|
---|
| 1588 | if (bidUtil >= this.midPointOfSlopeSessionMax2_Agent1) {
|
---|
| 1589 | this.relcountUpperBoundMid2_Agent1 += 1;
|
---|
| 1590 | } else {
|
---|
| 1591 | this.relcountLowerBoundMid2_Agent1 += 1;
|
---|
| 1592 | }
|
---|
| 1593 | }
|
---|
| 1594 | this.utility_maximum_from_opponent_Session1_Agent1 = this.utility_maximum_from_opponent_Session2_Agent1;
|
---|
| 1595 | this.utility_maximum_from_opponent_Session2_Agent1 = this.utility_maximum_from_opponent_Session3_Agent1;
|
---|
| 1596 | this.utility_maximum_from_opponent_Session3_Agent1 = 0;
|
---|
| 1597 | this.count_Agent1 = this.SecondTimeInterval - 1;
|
---|
| 1598 | this.startConcede_Agent1 = true;
|
---|
| 1599 | }
|
---|
| 1600 | } catch (Exception e) {
|
---|
| 1601 | System.out.println(e.getMessage()
|
---|
| 1602 | + "exception in method MeasureConcedePartOfOppBehaviour_Agent1");
|
---|
| 1603 | }
|
---|
| 1604 | }
|
---|
| 1605 |
|
---|
| 1606 | private void MeasureConcedePartOfOppBehaviour_Agent2() {
|
---|
| 1607 | try {
|
---|
| 1608 | count_Agent2++;
|
---|
| 1609 |
|
---|
| 1610 | if (count_Agent2 < this.FirstTimeInterval) {
|
---|
| 1611 | if (utilitySpace.getUtility(
|
---|
| 1612 | this.oppPreviousBid_Agent2) > this.utility_maximum_from_opponent_Session1_Agent2) {
|
---|
| 1613 | this.utility_maximum_from_opponent_Session1_Agent2 = utilitySpace
|
---|
| 1614 | .getUtility(this.oppPreviousBid_Agent2);
|
---|
| 1615 | }
|
---|
| 1616 | } else if (count_Agent2 < this.SecondTimeInterval) {
|
---|
| 1617 | if (utilitySpace.getUtility(
|
---|
| 1618 | this.oppPreviousBid_Agent2) > this.utility_maximum_from_opponent_Session2_Agent2) {
|
---|
| 1619 | this.utility_maximum_from_opponent_Session2_Agent2 = utilitySpace
|
---|
| 1620 | .getUtility(this.oppPreviousBid_Agent2);
|
---|
| 1621 | }
|
---|
| 1622 | } else if (count_Agent2 < this.ThirdTimeInterval) {
|
---|
| 1623 | if (utilitySpace.getUtility(
|
---|
| 1624 | this.oppPreviousBid_Agent2) > this.utility_maximum_from_opponent_Session3_Agent2) {
|
---|
| 1625 | this.utility_maximum_from_opponent_Session3_Agent2 = utilitySpace
|
---|
| 1626 | .getUtility(this.oppPreviousBid_Agent2);
|
---|
| 1627 | }
|
---|
| 1628 | } else {
|
---|
| 1629 | this.relcountUpperBoundMid1_Agent2 = 0;
|
---|
| 1630 | this.relcountUpperBoundMid2_Agent2 = 0;
|
---|
| 1631 | this.relcountLowerBoundMid1_Agent2 = 0;
|
---|
| 1632 | this.relcountLowerBoundMid2_Agent2 = 0;
|
---|
| 1633 | this.midPointOfSlopeSessionMax1_Agent2 = (this.utility_maximum_from_opponent_Session2_Agent2
|
---|
| 1634 | + this.utility_maximum_from_opponent_Session1_Agent2)
|
---|
| 1635 | / 2;
|
---|
| 1636 | this.midPointOfSlopeSessionMax2_Agent2 = (this.utility_maximum_from_opponent_Session3_Agent2
|
---|
| 1637 | + this.utility_maximum_from_opponent_Session2_Agent2)
|
---|
| 1638 | / 2;
|
---|
| 1639 | this.slopeOfSlopeOfSessionMax1_Agent2 = this.utility_maximum_from_opponent_Session2_Agent2
|
---|
| 1640 | - this.utility_maximum_from_opponent_Session1_Agent2;
|
---|
| 1641 | this.slopeOfSlopeOfSessionMax2_Agent2 = this.utility_maximum_from_opponent_Session3_Agent2
|
---|
| 1642 | - this.utility_maximum_from_opponent_Session2_Agent2;
|
---|
| 1643 |
|
---|
| 1644 | ArrayList<Double> bidsUtil = new ArrayList();
|
---|
| 1645 | BidIterator myBidIterator = new BidIterator(
|
---|
| 1646 | this.utilitySpace.getDomain());
|
---|
| 1647 | for (; myBidIterator.hasNext();) {
|
---|
| 1648 | bidsUtil.add(
|
---|
| 1649 | this.utilitySpace.getUtility(myBidIterator.next()));
|
---|
| 1650 | }
|
---|
| 1651 | for (Iterator e = bidsUtil.iterator(); e.hasNext();) {
|
---|
| 1652 | double bidUtil = (Double) e.next();
|
---|
| 1653 | if (bidUtil >= this.midPointOfSlopeSessionMax1_Agent2) {
|
---|
| 1654 | this.relcountUpperBoundMid1_Agent2 += 1;
|
---|
| 1655 | } else {
|
---|
| 1656 | this.relcountLowerBoundMid1_Agent2 += 1;
|
---|
| 1657 | }
|
---|
| 1658 |
|
---|
| 1659 | if (bidUtil >= this.midPointOfSlopeSessionMax2_Agent2) {
|
---|
| 1660 | this.relcountUpperBoundMid2_Agent2 += 1;
|
---|
| 1661 | } else {
|
---|
| 1662 | this.relcountLowerBoundMid2_Agent2 += 1;
|
---|
| 1663 | }
|
---|
| 1664 | }
|
---|
| 1665 | this.utility_maximum_from_opponent_Session1_Agent2 = this.utility_maximum_from_opponent_Session2_Agent2;
|
---|
| 1666 | this.utility_maximum_from_opponent_Session2_Agent2 = this.utility_maximum_from_opponent_Session3_Agent2;
|
---|
| 1667 | this.utility_maximum_from_opponent_Session3_Agent2 = 0;
|
---|
| 1668 | this.count_Agent2 = SecondTimeInterval - 1;
|
---|
| 1669 | this.startConcede_Agent2 = true;
|
---|
| 1670 | }
|
---|
| 1671 | } catch (Exception e) {
|
---|
| 1672 | System.out.println(e.getMessage()
|
---|
| 1673 | + "exception in method MeasureConcedePartOfOppBehaviour_Agent2");
|
---|
| 1674 | }
|
---|
| 1675 | }
|
---|
| 1676 |
|
---|
| 1677 | private Bid BidToOffer_original() {
|
---|
| 1678 | Bid bidReturned = null;
|
---|
| 1679 | int test = 0;
|
---|
| 1680 |
|
---|
| 1681 | try {
|
---|
| 1682 | double maximumOfBid = this.MaximumUtility;// utilitySpace.getUtility(utilitySpace.getMaxUtilityBid());
|
---|
| 1683 | double minimumOfBid;
|
---|
| 1684 |
|
---|
| 1685 | if (timeline.getTime() <= ((this.concedeTime_Agent2
|
---|
| 1686 | + this.concedeTime_Agent1) / 2)) {
|
---|
| 1687 | if (this.discountingFactor <= 0.5) {
|
---|
| 1688 | this.minThreshold_Agent1 = (maximumOfBid
|
---|
| 1689 | * this.discountingFactor)
|
---|
| 1690 | / Math.pow(this.discountingFactor,
|
---|
| 1691 | this.concedeTime_Agent1);
|
---|
| 1692 | this.minThreshold_Agent2 = (maximumOfBid
|
---|
| 1693 | * this.discountingFactor)
|
---|
| 1694 | / Math.pow(this.discountingFactor,
|
---|
| 1695 | this.concedeTime_Agent2);
|
---|
| 1696 | this.utilitythreshold_Agent1 = maximumOfBid
|
---|
| 1697 | - (maximumOfBid - this.minThreshold_Agent1)
|
---|
| 1698 | * Math.pow(
|
---|
| 1699 | (timeline.getTime()
|
---|
| 1700 | / this.concedeTime_Agent1),
|
---|
| 1701 | alpha1);
|
---|
| 1702 | this.utilitythreshold_Agent2 = maximumOfBid
|
---|
| 1703 | - (maximumOfBid - this.minThreshold_Agent2)
|
---|
| 1704 | * Math.pow(
|
---|
| 1705 | (timeline.getTime()
|
---|
| 1706 | / this.concedeTime_Agent2),
|
---|
| 1707 | alpha1);
|
---|
| 1708 | } else {
|
---|
| 1709 | this.utilitythreshold_Agent1 = this.minThreshold_Agent1
|
---|
| 1710 | + (maximumOfBid - this.minThreshold_Agent1) * (1
|
---|
| 1711 | - Math.sin((Math.PI / 2) * (timeline
|
---|
| 1712 | .getTime() / this.concedeTime_Agent1)));
|
---|
| 1713 | this.utilitythreshold_Agent2 = this.minThreshold_Agent2
|
---|
| 1714 | + (maximumOfBid - this.minThreshold_Agent2) * (1
|
---|
| 1715 | - Math.sin((Math.PI / 2) * (timeline
|
---|
| 1716 | .getTime() / this.concedeTime_Agent2)));
|
---|
| 1717 | }
|
---|
| 1718 | } else {
|
---|
| 1719 | if (this.discountingFactor <= 0.5) {
|
---|
| 1720 | this.utilitythreshold_Agent1 = (maximumOfBid
|
---|
| 1721 | * this.discountingFactor)
|
---|
| 1722 | / Math.pow(this.discountingFactor,
|
---|
| 1723 | timeline.getTime());
|
---|
| 1724 | this.utilitythreshold_Agent2 = (maximumOfBid
|
---|
| 1725 | * this.discountingFactor)
|
---|
| 1726 | / Math.pow(this.discountingFactor,
|
---|
| 1727 | timeline.getTime());
|
---|
| 1728 | } else {
|
---|
| 1729 | this.utilitythreshold_Agent1 = this.minThreshold_Agent1
|
---|
| 1730 | + (maximumOfBid - this.minThreshold_Agent1)
|
---|
| 1731 | / (1 - concedeTime_Agent1)
|
---|
| 1732 | * Math.pow(
|
---|
| 1733 | (timeline.getTime()
|
---|
| 1734 | - this.concedeTime_Agent1),
|
---|
| 1735 | this.discountingFactor);
|
---|
| 1736 | this.utilitythreshold_Agent2 = this.minThreshold_Agent2
|
---|
| 1737 | + (maximumOfBid - this.minThreshold_Agent2)
|
---|
| 1738 | / (1 - concedeTime_Agent2)
|
---|
| 1739 | * Math.pow(
|
---|
| 1740 | (timeline.getTime()
|
---|
| 1741 | - this.concedeTime_Agent2),
|
---|
| 1742 | this.discountingFactor);
|
---|
| 1743 | }
|
---|
| 1744 | }
|
---|
| 1745 | this.AvgUtilitythreshold = (this.utilitythreshold_Agent2
|
---|
| 1746 | + this.utilitythreshold_Agent1) / 2;
|
---|
| 1747 | if (this.AvgUtilitythreshold > MaximumUtility) {
|
---|
| 1748 | this.AvgUtilitythreshold = MaximumUtility;
|
---|
| 1749 | }
|
---|
| 1750 |
|
---|
| 1751 | minimumOfBid = this.AvgUtilitythreshold;
|
---|
| 1752 |
|
---|
| 1753 | /*
|
---|
| 1754 | * if(minimumOfBid < 0.9 && this.guessOpponentType == false){
|
---|
| 1755 | * if(this.opponentBidHistory.getSize() <= 2){ this.opponentType =
|
---|
| 1756 | * 1;//tough opponent alpha1 = 2; } else{ this.opponentType = 0;
|
---|
| 1757 | * alpha1 = 4; } this.guessOpponentType = true;//we only guess the
|
---|
| 1758 | * opponent type once here System.out.println("we guess the opponent
|
---|
| 1759 | * type is "+this.opponentType); }
|
---|
| 1760 | */
|
---|
| 1761 |
|
---|
| 1762 | // choose from the opponent bid history first to reduce calculation
|
---|
| 1763 | // time
|
---|
| 1764 | Bid bestBidOfferedByOpponent1 = opponentBidHistory1
|
---|
| 1765 | .getBestBidInHistory();
|
---|
| 1766 | Bid bestBidOfferedByOpponent2 = opponentBidHistory2
|
---|
| 1767 | .getBestBidInHistory();
|
---|
| 1768 | Bid bestBidOfferedByOpponent = this
|
---|
| 1769 | .getUtility(bestBidOfferedByOpponent1) > this
|
---|
| 1770 | .getUtility(bestBidOfferedByOpponent2)
|
---|
| 1771 | ? bestBidOfferedByOpponent2
|
---|
| 1772 | : bestBidOfferedByOpponent1;
|
---|
| 1773 | if (utilitySpace.getUtility(
|
---|
| 1774 | bestBidOfferedByOpponent) >= this.AvgUtilitythreshold
|
---|
| 1775 | || utilitySpace.getUtility(
|
---|
| 1776 | bestBidOfferedByOpponent) >= minimumOfBid) {
|
---|
| 1777 | return bestBidOfferedByOpponent;
|
---|
| 1778 | }
|
---|
| 1779 | this.nextbidutil = this.BidToOffer();
|
---|
| 1780 | bidReturned = this.regeneratebid(this.nextbidutil);
|
---|
| 1781 | if (bidReturned == null) {
|
---|
| 1782 | System.out.println("no bid is searched warning");
|
---|
| 1783 | bidReturned = this.utilitySpace.getMaxUtilityBid();
|
---|
| 1784 | }
|
---|
| 1785 | MinAcceptCondition(bidReturned);
|
---|
| 1786 | } catch (Exception e) {
|
---|
| 1787 | System.out.println(
|
---|
| 1788 | e.getMessage() + "exception in method BidToOffer_original");
|
---|
| 1789 | this.except = 26;
|
---|
| 1790 | return this.bid_maximum_utility;
|
---|
| 1791 | }
|
---|
| 1792 | // System.out.println("the current threshold is " +
|
---|
| 1793 | // this.utilitythreshold + " with the value of alpha1 is " + alpha1);
|
---|
| 1794 | return bidReturned;
|
---|
| 1795 | }
|
---|
| 1796 |
|
---|
| 1797 | private boolean OtherAcceptCondition(boolean IsAccept) {
|
---|
| 1798 | try {
|
---|
| 1799 | if ((timeline.getTime() >= ((this.concedeTime_Agent2
|
---|
| 1800 | + this.concedeTime_Agent1) / 2))
|
---|
| 1801 | && (this.utilitySpace.getUtility(
|
---|
| 1802 | this.oppPreviousBid_Agent2) >= this.minUtilityUhreshold)) {
|
---|
| 1803 | IsAccept = true;
|
---|
| 1804 | }
|
---|
| 1805 | } catch (Exception e) {
|
---|
| 1806 | this.except = 27;
|
---|
| 1807 | System.out.println(e.getMessage()
|
---|
| 1808 | + "exception in method OtherAcceptCondition");
|
---|
| 1809 | return true;
|
---|
| 1810 | }
|
---|
| 1811 | return IsAccept;
|
---|
| 1812 | }
|
---|
| 1813 |
|
---|
| 1814 | private void MinAcceptCondition(Bid bidReturned) {
|
---|
| 1815 | try {
|
---|
| 1816 | if (this.minUtilityUhreshold > this.utilitySpace
|
---|
| 1817 | .getUtility(bidReturned)) {
|
---|
| 1818 | this.minUtilityUhreshold = this.utilitySpace
|
---|
| 1819 | .getUtility(bidReturned);
|
---|
| 1820 | }
|
---|
| 1821 | } catch (Exception e) {
|
---|
| 1822 | this.except = 28;
|
---|
| 1823 | System.out.println(
|
---|
| 1824 | e.getMessage() + "exception in method MinAcceptCondition");
|
---|
| 1825 | }
|
---|
| 1826 | }
|
---|
| 1827 |
|
---|
| 1828 | @Override
|
---|
| 1829 | public String getDescription() {
|
---|
| 1830 | return "ANAC2015";
|
---|
| 1831 | }
|
---|
| 1832 | }
|
---|