[1] | 1 | /**
|
---|
| 2 | * OptimalBidderU: using the optimal stopping rule (cutoffs) for bidding
|
---|
| 3 | * @author rafik
|
---|
| 4 | **/
|
---|
| 5 |
|
---|
| 6 | package agents;
|
---|
| 7 |
|
---|
| 8 | import java.util.ArrayList;
|
---|
| 9 | import java.util.HashMap;
|
---|
| 10 | import java.util.TreeMap;
|
---|
| 11 |
|
---|
| 12 | import genius.core.Agent;
|
---|
| 13 | import genius.core.Bid;
|
---|
| 14 | import genius.core.actions.Action;
|
---|
| 15 | import genius.core.actions.Offer;
|
---|
| 16 | import genius.core.issue.Issue;
|
---|
| 17 | import genius.core.issue.Value;
|
---|
| 18 | import genius.core.timeline.DiscreteTimeline;
|
---|
| 19 |
|
---|
| 20 | public abstract class OptimalBidderU extends Agent {
|
---|
| 21 | private static double rv = -1.0;
|
---|
| 22 | protected static int partitions;
|
---|
| 23 | private static int ownTotalSessions;
|
---|
| 24 | protected static HashMap<Integer, Value> values;
|
---|
| 25 | private static ArrayList<Double> bids, utilities;
|
---|
| 26 | protected static Issue pie;
|
---|
| 27 | private Action actionOfPartner = null;
|
---|
| 28 |
|
---|
| 29 | /**
|
---|
| 30 | * computation of the bid for round j
|
---|
| 31 | *
|
---|
| 32 | * @param round
|
---|
| 33 | * j
|
---|
| 34 | * @return bid value
|
---|
| 35 | **/
|
---|
| 36 | public abstract double bid(int j);
|
---|
| 37 |
|
---|
| 38 | public abstract double utility(int j);
|
---|
| 39 |
|
---|
| 40 | /**
|
---|
| 41 | * depending on the agent's utility space, the reservation value will have
|
---|
| 42 | * to be acquired in a specific manner
|
---|
| 43 | *
|
---|
| 44 | * @param double arg
|
---|
| 45 | * @return double rv
|
---|
| 46 | * @throws Exception
|
---|
| 47 | **/
|
---|
| 48 | public abstract double getReservationValue(double arg) throws Exception;
|
---|
| 49 |
|
---|
| 50 | /**
|
---|
| 51 | * Init is called when a next session starts with the same opponent.
|
---|
| 52 | **/
|
---|
| 53 | public void init() {
|
---|
| 54 | try {
|
---|
| 55 | ownTotalSessions = (getTotalRounds() - 1) / 2;
|
---|
| 56 | pie = utilitySpace.getDomain().getIssues().get(0); // unique issue
|
---|
| 57 |
|
---|
| 58 | print("=====================================================================");
|
---|
| 59 | print(" OwntotalSessions = " + ownTotalSessions);
|
---|
| 60 | print(" issue name = " + pie);
|
---|
| 61 | print(" issue type = " + pie.getType());
|
---|
| 62 |
|
---|
| 63 | rv = getReservationValue(rv); // sets rvB
|
---|
| 64 |
|
---|
| 65 | bids = new ArrayList<Double>(ownTotalSessions);
|
---|
| 66 | utilities = new ArrayList<Double>(ownTotalSessions);
|
---|
| 67 |
|
---|
| 68 | for (int i = 0; i < ownTotalSessions; i++) {
|
---|
| 69 | bids.add(bid(i + 1));
|
---|
| 70 | utilities.add(utility(i + 1));
|
---|
| 71 | }
|
---|
| 72 | print(" OwntotalSessions = " + ownTotalSessions);
|
---|
| 73 |
|
---|
| 74 | for (int i = 0; i < ownTotalSessions; i++)
|
---|
| 75 | print(" \t B[" + i + "] = " + bids.get(i) + " \t U[" + i
|
---|
| 76 | + "] = " + utilities.get(i));
|
---|
| 77 |
|
---|
| 78 | print("\n=====================================================================");
|
---|
| 79 | } catch (Exception e) {
|
---|
| 80 | e.printStackTrace();
|
---|
| 81 | }
|
---|
| 82 | }
|
---|
| 83 |
|
---|
| 84 | @Override
|
---|
| 85 | public String getVersion() {
|
---|
| 86 | return "2.0 (Genius 4.2)";
|
---|
| 87 | }
|
---|
| 88 |
|
---|
| 89 | @Override
|
---|
| 90 | public String getName() {
|
---|
| 91 | return "OptimalBidderU";
|
---|
| 92 | }
|
---|
| 93 |
|
---|
| 94 | public void ReceiveMessage(Action opponentAction) {
|
---|
| 95 | actionOfPartner = opponentAction;
|
---|
| 96 | }
|
---|
| 97 |
|
---|
| 98 | public Action chooseAction() {
|
---|
| 99 | Action action = null;
|
---|
| 100 | try {
|
---|
| 101 | if (actionOfPartner == null) {
|
---|
| 102 | action = chooseOptimalBidAction();
|
---|
| 103 | }
|
---|
| 104 | if (actionOfPartner instanceof Offer) {
|
---|
| 105 | action = chooseOptimalBidAction();
|
---|
| 106 | }
|
---|
| 107 | } catch (Exception e) {
|
---|
| 108 | print("Exception in ChooseAction:" + e.getMessage());
|
---|
| 109 | }
|
---|
| 110 | return action;
|
---|
| 111 | }
|
---|
| 112 |
|
---|
| 113 | /**
|
---|
| 114 | * Wrapper for getOptimalBid, for convenience
|
---|
| 115 | *
|
---|
| 116 | * @return new Bid()
|
---|
| 117 | **/
|
---|
| 118 | private Action chooseOptimalBidAction() {
|
---|
| 119 | Bid nextBid = null;
|
---|
| 120 | try {
|
---|
| 121 | nextBid = getOptimalBid();
|
---|
| 122 | } catch (Exception e) {
|
---|
| 123 | print("Problem with received bid:" + e.getMessage()
|
---|
| 124 | + ". cancelling bidding");
|
---|
| 125 | }
|
---|
| 126 | return (new Offer(getAgentID(), nextBid));
|
---|
| 127 | }
|
---|
| 128 |
|
---|
| 129 | // discrete rounds' methods
|
---|
| 130 | public int getRound() {
|
---|
| 131 | return ((DiscreteTimeline) timeline).getRound();
|
---|
| 132 | }
|
---|
| 133 |
|
---|
| 134 | public int getRoundsLeft() {
|
---|
| 135 | return ((DiscreteTimeline) timeline).getRoundsLeft();
|
---|
| 136 | }
|
---|
| 137 |
|
---|
| 138 | public int getOwnRoundsLeft() {
|
---|
| 139 | return ((DiscreteTimeline) timeline).getOwnRoundsLeft();
|
---|
| 140 | }
|
---|
| 141 |
|
---|
| 142 | public int getTotalRounds() {
|
---|
| 143 | return ((DiscreteTimeline) timeline).getTotalRounds();
|
---|
| 144 | }
|
---|
| 145 |
|
---|
| 146 | public double getTotalTime() {
|
---|
| 147 | return ((DiscreteTimeline) timeline).getTotalTime();
|
---|
| 148 | }
|
---|
| 149 |
|
---|
| 150 | // trace
|
---|
| 151 | void print(String s) {
|
---|
| 152 | System.out.println("############ " + s);
|
---|
| 153 | }
|
---|
| 154 |
|
---|
| 155 | /**
|
---|
| 156 | *
|
---|
| 157 | *
|
---|
| 158 | */
|
---|
| 159 | private Bid getOptimalBid() throws Exception {
|
---|
| 160 | print("############ B's ####################################");
|
---|
| 161 | print(" Round = " + getRound());
|
---|
| 162 | print(" RoundsLeft = " + getRoundsLeft());
|
---|
| 163 | print(" OwnRoundsLeft = " + getOwnRoundsLeft());
|
---|
| 164 | print(" TotalRounds = " + getTotalRounds());
|
---|
| 165 | print(" TotalTime = " + getTotalTime());
|
---|
| 166 |
|
---|
| 167 | double min = 1.0;
|
---|
| 168 | Value optValue = null;
|
---|
| 169 |
|
---|
| 170 | Double targetUtility = utilities.get(getOwnRoundsLeft()); // cutoff
|
---|
| 171 | // utility :
|
---|
| 172 | // U[roundsleft]
|
---|
| 173 | double targetBid = targetUtility + rv; // Finding the x for which u_B(x)
|
---|
| 174 | // = targetUtility
|
---|
| 175 | print(" targetBidToBid = " + targetBid);
|
---|
| 176 |
|
---|
| 177 | for (Integer key : new TreeMap<Integer, Value>(values).keySet()) {
|
---|
| 178 | // find the closest bid to targetBidToBid
|
---|
| 179 | double piePartition = (double) key / partitions;
|
---|
| 180 | if (Math.abs(targetBid - piePartition) < min) {
|
---|
| 181 | min = Math.abs(targetBid - piePartition);
|
---|
| 182 | optValue = values.get(key);
|
---|
| 183 | }
|
---|
| 184 | }
|
---|
| 185 |
|
---|
| 186 | HashMap<Integer, Value> optVals = new HashMap<Integer, Value>();
|
---|
| 187 | optVals.put(pie.getNumber(), optValue);
|
---|
| 188 | return new Bid(utilitySpace.getDomain(), optVals); // optimal bid
|
---|
| 189 |
|
---|
| 190 | }
|
---|
| 191 | }
|
---|
| 192 |
|
---|
| 193 | // End |
---|