[1] | 1 | package agents.anac.y2013.GAgent;
|
---|
| 2 |
|
---|
| 3 | import java.util.List;
|
---|
| 4 | import java.util.Random;
|
---|
| 5 |
|
---|
| 6 | import genius.core.Agent;
|
---|
| 7 | import genius.core.Bid;
|
---|
| 8 | import genius.core.BidHistory;
|
---|
| 9 | import genius.core.SupportedNegotiationSetting;
|
---|
| 10 | import genius.core.actions.Accept;
|
---|
| 11 | import genius.core.actions.Action;
|
---|
| 12 | import genius.core.actions.ActionWithBid;
|
---|
| 13 | import genius.core.actions.Offer;
|
---|
| 14 | import genius.core.bidding.BidDetails;
|
---|
| 15 | import genius.core.boaframework.SortedOutcomeSpace;
|
---|
| 16 | import genius.core.misc.Range;
|
---|
| 17 |
|
---|
| 18 | public class AgentI extends Agent {
|
---|
| 19 |
|
---|
| 20 | private Action actionOfPartner = null;
|
---|
| 21 | private Range range = new Range(0D, 1D);
|
---|
| 22 | private double time = 0;
|
---|
| 23 | private BidHistory myBidHistory = new BidHistory();
|
---|
| 24 | private SortedOutcomeSpace outcomeSpace;
|
---|
| 25 | private BidHistory opponetBidHistory = new BidHistory();
|
---|
| 26 | private static double MINIMUM_BID_UTILITY = 1D;
|
---|
| 27 | private Random randomnr = new Random();
|
---|
| 28 | private boolean isDiscount = false;
|
---|
| 29 | private boolean isResavationValue = false;
|
---|
| 30 | private double widthUtil = 0D;
|
---|
| 31 | private boolean isFirst = true;
|
---|
| 32 | private Probability prob;
|
---|
| 33 | private double preOppponetUtil;
|
---|
| 34 | private double var;
|
---|
| 35 | private static double A = 0.9;
|
---|
| 36 |
|
---|
| 37 | private double sigmoidGain = 9;
|
---|
| 38 | private double lowerLimit = 0.6;
|
---|
| 39 | private double startTime = 0.7;
|
---|
| 40 | private double tim = 0.0;
|
---|
| 41 |
|
---|
| 42 | @Override
|
---|
| 43 | public void init() {
|
---|
| 44 |
|
---|
| 45 | if (utilitySpace.getDiscountFactor() != 0D) {
|
---|
| 46 | isDiscount = true;
|
---|
| 47 | }
|
---|
| 48 |
|
---|
| 49 | if (utilitySpace.getReservationValue() != 0D) {
|
---|
| 50 | isResavationValue = true;
|
---|
| 51 | }
|
---|
| 52 |
|
---|
| 53 | sigmoidGain = 2D;
|
---|
| 54 | lowerLimit = 0.9;
|
---|
| 55 |
|
---|
| 56 | MINIMUM_BID_UTILITY = 1D;
|
---|
| 57 | range.setLowerbound(changeThreshold(0));
|
---|
| 58 | time = timeline.getTime();
|
---|
| 59 | outcomeSpace = new SortedOutcomeSpace(utilitySpace);
|
---|
| 60 | }
|
---|
| 61 |
|
---|
| 62 | public double changeThreshold(double time) {
|
---|
| 63 | return (1 - lowerLimit + tim) / (1 + Math.exp(sigmoidGain * time))
|
---|
| 64 | + lowerLimit;
|
---|
| 65 | }
|
---|
| 66 |
|
---|
| 67 | @Override
|
---|
| 68 | public String getVersion() {
|
---|
| 69 | return "3.1";
|
---|
| 70 | }
|
---|
| 71 |
|
---|
| 72 | @Override
|
---|
| 73 | public String getName() {
|
---|
| 74 | return "GAgent";
|
---|
| 75 | }
|
---|
| 76 |
|
---|
| 77 | @Override
|
---|
| 78 | public void ReceiveMessage(Action opponentAction) {
|
---|
| 79 | actionOfPartner = opponentAction;
|
---|
| 80 | }
|
---|
| 81 |
|
---|
| 82 | @Override
|
---|
| 83 | public Action chooseAction() {
|
---|
| 84 | Action action = null;
|
---|
| 85 |
|
---|
| 86 | try {
|
---|
| 87 | if (actionOfPartner == null) {
|
---|
| 88 | action = new Offer(getAgentID(),
|
---|
| 89 | utilitySpace.getMaxUtilityBid());
|
---|
| 90 | }
|
---|
| 91 |
|
---|
| 92 | if (actionOfPartner instanceof Offer) {
|
---|
| 93 |
|
---|
| 94 | Bid partnerBid = ((Offer) actionOfPartner).getBid();
|
---|
| 95 | BidDetails opponetBid = new BidDetails(partnerBid, 1);
|
---|
| 96 | opponetBidHistory.add(opponetBid);
|
---|
| 97 |
|
---|
| 98 | // get my utility form opponet's bid
|
---|
| 99 | double offeredUtilFromOpponent = getUtility(partnerBid);
|
---|
| 100 | double offerundiscoutFromOpponent = utilitySpace
|
---|
| 101 | .getUtility(partnerBid);
|
---|
| 102 |
|
---|
| 103 | if (isFirst) {
|
---|
| 104 | widthUtil = 1 - offeredUtilFromOpponent;
|
---|
| 105 | prob = new Probability(widthUtil);
|
---|
| 106 |
|
---|
| 107 | lowerLimit = 1 - widthUtil / 3;
|
---|
| 108 | isFirst = false;
|
---|
| 109 | } else {
|
---|
| 110 | double diff = offerundiscoutFromOpponent - preOppponetUtil;
|
---|
| 111 | var = prob.getVar(diff);
|
---|
| 112 | }
|
---|
| 113 |
|
---|
| 114 | A = changeThreshold(time);
|
---|
| 115 |
|
---|
| 116 | preOppponetUtil = offerundiscoutFromOpponent;
|
---|
| 117 |
|
---|
| 118 | // get current time
|
---|
| 119 | time = timeline.getTime();
|
---|
| 120 |
|
---|
| 121 | double a = 1 - var * widthUtil;
|
---|
| 122 |
|
---|
| 123 | if (a > A) {
|
---|
| 124 | MINIMUM_BID_UTILITY = A;
|
---|
| 125 | } else {
|
---|
| 126 | if (var * widthUtil > (widthUtil / 2)) {
|
---|
| 127 | MINIMUM_BID_UTILITY = 1 - widthUtil / 2;
|
---|
| 128 | } else {
|
---|
| 129 | MINIMUM_BID_UTILITY = a;
|
---|
| 130 | }
|
---|
| 131 | }
|
---|
| 132 |
|
---|
| 133 | range.setLowerbound(MINIMUM_BID_UTILITY);
|
---|
| 134 |
|
---|
| 135 | action = chooseRandomBidAction(time);
|
---|
| 136 |
|
---|
| 137 | Bid myBid = ((Offer) action).getBid();
|
---|
| 138 | double myOfferedUtil = getUtility(myBid);
|
---|
| 139 |
|
---|
| 140 | if (isAcceptable(offerundiscoutFromOpponent, myOfferedUtil,
|
---|
| 141 | time, partnerBid)) {
|
---|
| 142 | action = new Accept(getAgentID(), partnerBid);
|
---|
| 143 | }
|
---|
| 144 | }
|
---|
| 145 | } catch (Exception e) {
|
---|
| 146 | e.printStackTrace();
|
---|
| 147 | // best guess if things go wrong.
|
---|
| 148 | action = new Accept(getAgentID(),
|
---|
| 149 | ((ActionWithBid) action).getBid());
|
---|
| 150 | }
|
---|
| 151 | return action;
|
---|
| 152 | }
|
---|
| 153 |
|
---|
| 154 | private boolean isAcceptable(double offeredUtilFromOpponent,
|
---|
| 155 | double myOfferedUtil, double time, Bid parBid) throws Exception {
|
---|
| 156 |
|
---|
| 157 | BidDetails bd = new BidDetails(parBid, 1);
|
---|
| 158 |
|
---|
| 159 | if (myBidHistory.getHistory().contains(bd)) {
|
---|
| 160 | return true;
|
---|
| 161 | }
|
---|
| 162 |
|
---|
| 163 | if (offeredUtilFromOpponent > MINIMUM_BID_UTILITY) {
|
---|
| 164 | return true;
|
---|
| 165 | }
|
---|
| 166 |
|
---|
| 167 | if (isResavationValue) {
|
---|
| 168 | if (getUtility(parBid) < lowerLimit) {
|
---|
| 169 | return false;
|
---|
| 170 | }
|
---|
| 171 | }
|
---|
| 172 |
|
---|
| 173 | if (time > 0.9988) {
|
---|
| 174 | Bid nextBid;
|
---|
| 175 | List<BidDetails> bdd = opponetBidHistory.getNBestBids(5);
|
---|
| 176 | nextBid = bdd.get(4).getBid();
|
---|
| 177 | double utility = getUtility(nextBid);
|
---|
| 178 |
|
---|
| 179 | if (offeredUtilFromOpponent > utility) {
|
---|
| 180 | return true;
|
---|
| 181 | }
|
---|
| 182 | }
|
---|
| 183 |
|
---|
| 184 | // double P = Paccept(offeredUtilFromOpponent,time);
|
---|
| 185 |
|
---|
| 186 | // if (P > 0.95)
|
---|
| 187 | // return true;
|
---|
| 188 |
|
---|
| 189 | return false;
|
---|
| 190 |
|
---|
| 191 | }
|
---|
| 192 |
|
---|
| 193 | private Action chooseRandomBidAction(double time) {
|
---|
| 194 | Bid nextBid = null;
|
---|
| 195 | try {
|
---|
| 196 | if (time > 0.9988) {
|
---|
| 197 | List<BidDetails> bdd = opponetBidHistory.getNBestBids(3);
|
---|
| 198 | int opt = randomnr.nextInt(3);
|
---|
| 199 | nextBid = bdd.get(opt).getBid();
|
---|
| 200 |
|
---|
| 201 | if (isResavationValue) {
|
---|
| 202 | if (getUtility(nextBid) < lowerLimit) {
|
---|
| 203 | nextBid = getRandomBid();
|
---|
| 204 | }
|
---|
| 205 | }
|
---|
| 206 |
|
---|
| 207 | } else {
|
---|
| 208 | nextBid = getRandomBid();
|
---|
| 209 | }
|
---|
| 210 | } catch (Exception e) {
|
---|
| 211 | e.printStackTrace();
|
---|
| 212 | }
|
---|
| 213 | if (nextBid == null)
|
---|
| 214 | return new Accept(getAgentID(),
|
---|
| 215 | ((ActionWithBid) actionOfPartner).getBid());
|
---|
| 216 | return (new Offer(getAgentID(), nextBid));
|
---|
| 217 | }
|
---|
| 218 |
|
---|
| 219 | private Bid getRandomBid() throws Exception {
|
---|
| 220 | List<BidDetails> rangeBid = outcomeSpace.getBidsinRange(range);
|
---|
| 221 | int rangeBidSize = rangeBid.size();
|
---|
| 222 | Bid offerbid;
|
---|
| 223 | BidDetails offerBidDetail;
|
---|
| 224 |
|
---|
| 225 | if (rangeBidSize == 1) {
|
---|
| 226 | offerbid = rangeBid.get(0).getBid();
|
---|
| 227 | offerBidDetail = new BidDetails(offerbid, 1);
|
---|
| 228 | } else {
|
---|
| 229 | int bitCount = 0;
|
---|
| 230 | offerBidDetail = rangeBid.get(bitCount);
|
---|
| 231 | while (myBidHistory.getHistory().contains(offerBidDetail)) {
|
---|
| 232 | int ran = randomnr.nextInt(rangeBidSize - 1);
|
---|
| 233 | offerBidDetail = rangeBid.get(ran);
|
---|
| 234 | bitCount++;
|
---|
| 235 | if (bitCount > 60) {
|
---|
| 236 | break;
|
---|
| 237 | }
|
---|
| 238 |
|
---|
| 239 | }
|
---|
| 240 | }
|
---|
| 241 | myBidHistory.add(offerBidDetail);
|
---|
| 242 | offerbid = offerBidDetail.getBid();
|
---|
| 243 | return offerbid;
|
---|
| 244 |
|
---|
| 245 | }
|
---|
| 246 |
|
---|
| 247 | double Paccept(double u, double t1) throws Exception {
|
---|
| 248 | double t = t1 * t1 * t1; // steeper increase when deadline approaches.
|
---|
| 249 | if (u < 0 || u > 1.05)
|
---|
| 250 | throw new Exception("utility " + u + " outside [0,1]");
|
---|
| 251 | // normalization may be slightly off, therefore we have a broad boundary
|
---|
| 252 | // up to 1.05
|
---|
| 253 | if (t < 0 || t > 1)
|
---|
| 254 | throw new Exception("time " + t + " outside [0,1]");
|
---|
| 255 | if (u > 1.)
|
---|
| 256 | u = 1;
|
---|
| 257 | if (t == 0.5)
|
---|
| 258 | return u;
|
---|
| 259 | return (u - 2. * u * t
|
---|
| 260 | + 2. * (-1. + t + Math.sqrt(sq(-1. + t) + u * (-1. + 2 * t))))
|
---|
| 261 | / (-1. + 2 * t);
|
---|
| 262 | }
|
---|
| 263 |
|
---|
| 264 | double sq(double x) {
|
---|
| 265 | return x * x;
|
---|
| 266 | }
|
---|
| 267 |
|
---|
| 268 | @Override
|
---|
| 269 | public SupportedNegotiationSetting getSupportedNegotiationSetting() {
|
---|
| 270 | return SupportedNegotiationSetting.getLinearUtilitySpaceInstance();
|
---|
| 271 | }
|
---|
| 272 |
|
---|
| 273 | @Override
|
---|
| 274 | public String getDescription() {
|
---|
| 275 | return "ANAC2013";
|
---|
| 276 | }
|
---|
| 277 | }
|
---|