package geniusweb.exampleparties.simpleshaop; import java.math.BigDecimal; import geniusweb.issuevalue.Bid; public class NegotiationStrategy { private CompRegress compRegress; private NegotiationInfo negotiationInfo; private BigDecimal reserveValue; private BigDecimal A11 = BigDecimal.ZERO; // utility - A: hardliner, B: hardliner private BigDecimal A12 = BigDecimal.ZERO; // utility - A: hardliner, B: conceder private BigDecimal A21 = BigDecimal.ZERO; // utility - A: conceder, B; hardliner private BigDecimal A22 = BigDecimal.ZERO; // utility - A: conceder, B: conceder //static private BigDecimal timeFinal = BigDecimal.ONE; static private BigDecimal probFinal = BigDecimal.valueOf(0.5); // probability of own agent compromising first on last round when both agents concede public NegotiationStrategy(CompRegress compRegress, NegotiationInfo negotiationInfo, Bid reserveBid) { this.compRegress = compRegress; this.negotiationInfo = negotiationInfo; this.reserveValue = compRegress.getUtil(reserveBid); } //////////////////////////////////////////////////////////////////////////////// // select methods for accept and end negotiation //////////////////////////////////////////////////////////////////////////////// /** * selectAccept - decide whether to perform Action: Accept * * @param offeredBid - Bid; the bid offered by opponent * @param time - double; time of negotiation * * @return boolean - true if our agent should accept the offered bid */ public boolean selectAccept(Bid offeredBid, BigDecimal time) { try { BigDecimal offeredBidUtil = compRegress.getUtil(offeredBid); return offeredBidUtil.compareTo(getThreshold(time)) >= 0; } catch (Exception e) { System.out.println("selectAccept failed"); e.printStackTrace(); return false; } } /** * selectEndNegotiation - decide whether to end negotiation */ public boolean selectEndNegotiation(BigDecimal time) { return reserveValue.compareTo(getThreshold(time)) >= 0; } //////////////////////////////////////////////////////////////////////////////// // method getThreshold and its helper methods //////////////////////////////////////////////////////////////////////////////// /** * getThreshold - returns threshold */ public BigDecimal getThreshold(BigDecimal time) { BigDecimal threshold = BigDecimal.ONE; updateGameMatrix(); BigDecimal target = getExpectedUtilInFinal(); threshold = target.add((BigDecimal.ONE.subtract(target)).multiply(BigDecimal.ONE.subtract(time))); return threshold; } /** * updateGameMatrix - used in getThreshold */ private void updateGameMatrix() { BigDecimal utilConcede = negotiationInfo.getBestOfferedUtil(); A11 = reserveValue; A12 = BigDecimal.ONE; if (utilConcede.compareTo(reserveValue) >= 0) A21 = utilConcede; else A21 = reserveValue; A22 = (probFinal.multiply(A21)).add((BigDecimal.ONE.subtract(probFinal)).multiply(A12)); } /** * getExpectedUtilInFinal - used in getThreshold */ private BigDecimal getExpectedUtilInFinal() { BigDecimal q = getOpponentProbHardliner(); return (q.multiply(A21)).add((BigDecimal.ONE.subtract(q)).multiply(A22)); } /** * getOpponentProbHardliner - used in getExpectedUtilInFinal, calculate opponent's probability of choosing hardliner strategy in final round */ private BigDecimal getOpponentProbHardliner() { double q = 1.0; double A11d = A11.doubleValue(); double A12d = A12.doubleValue(); double A21d = A21.doubleValue(); double A22d = A22.doubleValue(); if ((A12d - A22d != 0) && (1.0 - (A11d - A21d) / (A12d - A22d) != 0)) { q = 1.0 / (1.0 - (A11d - A21d) / (A12d -A22d)); } if (q < 0.0 || q > 1.0) { q = 1.0; } return BigDecimal.valueOf(q); } }