[127] | 1 | package agents.anac.y2015.TUDMixedStrategyAgent;
|
---|
| 2 |
|
---|
| 3 | import java.util.ArrayList;
|
---|
| 4 | import java.util.List;
|
---|
| 5 |
|
---|
| 6 | import genius.core.AgentID;
|
---|
| 7 | import genius.core.Bid;
|
---|
| 8 | import genius.core.BidHistory;
|
---|
| 9 | import genius.core.DeadlineType;
|
---|
| 10 | import genius.core.actions.Accept;
|
---|
| 11 | import genius.core.actions.Action;
|
---|
| 12 | import genius.core.actions.DefaultAction;
|
---|
| 13 | import genius.core.actions.Offer;
|
---|
| 14 | import genius.core.bidding.BidDetails;
|
---|
| 15 | import genius.core.parties.AbstractNegotiationParty;
|
---|
| 16 | import genius.core.parties.NegotiationInfo;
|
---|
| 17 | import genius.core.utility.AdditiveUtilitySpace;
|
---|
| 18 |
|
---|
| 19 | /**
|
---|
| 20 | * This is your negotiation party.
|
---|
| 21 | */
|
---|
| 22 | public class TUDMixedStrategyAgent extends AbstractNegotiationParty {
|
---|
| 23 |
|
---|
| 24 | private int roundN = 0; // Number of the round we are in
|
---|
| 25 | private Bid lastbid; // LastBid we received from someone
|
---|
| 26 | private List<BidHistory> bidhistorylist; // List of the lists of Bids
|
---|
| 27 | // received, one list for every
|
---|
| 28 | // agent
|
---|
| 29 | private List<AgentID> partylist; // List of Agents
|
---|
| 30 | private ArrayList<Bid> possibleBids; // List of all possible Bids in this
|
---|
| 31 | // utility Space
|
---|
| 32 | private ArrayList<Bid> alreadyProposed; // List of all Bids, we received and
|
---|
| 33 | // then reproposed
|
---|
| 34 | private ArrayList<AgentUtils> agentUtilsList;
|
---|
| 35 |
|
---|
| 36 | // List of AgentUtils that are objects that model the opponents utility
|
---|
| 37 | // function and give their utility to a specific Bid
|
---|
| 38 |
|
---|
| 39 | /**
|
---|
| 40 | * Please keep this constructor. This is called by genius.
|
---|
| 41 | *
|
---|
| 42 | * @param utilitySpace
|
---|
| 43 | * Your utility space.
|
---|
| 44 | * @param deadlines
|
---|
| 45 | * The deadlines set for this negotiation.
|
---|
| 46 | * @param timeline
|
---|
| 47 | * Value counting from 0 (start) to 1 (end).
|
---|
| 48 | * @param randomSeed
|
---|
| 49 | * If you use any randomization, use this seed for it.
|
---|
| 50 | */
|
---|
| 51 | @Override
|
---|
| 52 | public void init(NegotiationInfo info) {
|
---|
| 53 | // Make sure that this constructor calls it's parent.
|
---|
| 54 | super.init(info);
|
---|
| 55 |
|
---|
| 56 | // Initialize the lists
|
---|
| 57 | bidhistorylist = new ArrayList<BidHistory>();
|
---|
| 58 | partylist = new ArrayList<AgentID>();
|
---|
| 59 | alreadyProposed = new ArrayList<Bid>();
|
---|
| 60 | possibleBids = BidGenerator
|
---|
| 61 | .BidList(((AdditiveUtilitySpace) utilitySpace));
|
---|
| 62 | agentUtilsList = new ArrayList<AgentUtils>();
|
---|
| 63 |
|
---|
| 64 | }
|
---|
| 65 |
|
---|
| 66 | /**
|
---|
| 67 | * Each round this method gets called and ask you to accept or offer. The
|
---|
| 68 | * first party in the first round is a bit different, it can only propose an
|
---|
| 69 | * offer.
|
---|
| 70 | *
|
---|
| 71 | * @param validActions
|
---|
| 72 | * Either a list containing both accept and offer or only offer.
|
---|
| 73 | * @return The chosen action.
|
---|
| 74 | */
|
---|
| 75 | @Override
|
---|
| 76 | public Action chooseAction(List<Class<? extends Action>> validActions) {
|
---|
| 77 | roundN++; // Update the round number
|
---|
| 78 | // System.out.println("Round N� "+ roundN);
|
---|
| 79 | // System.out.println("I am " + this.getPartyId().toString());
|
---|
| 80 | if (!validActions.contains(Accept.class)) {
|
---|
| 81 | // No Offer on the table yet
|
---|
| 82 |
|
---|
| 83 | // Generate all possible bids for this utility space
|
---|
| 84 | double[] utils = BidGenerator.utilitylist(possibleBids, this);
|
---|
| 85 | // for(int i=0;i<possibleBids.size();i++) {
|
---|
| 86 | // System.out.println("Bid N� "+ i+" utility: " + utils[i] ) ;
|
---|
| 87 | // }
|
---|
| 88 |
|
---|
| 89 | // System.out.println("Deadline"+ deadlines.toString());
|
---|
| 90 | // System.out.println("Deadline "+ this.roundDeadline());
|
---|
| 91 |
|
---|
| 92 | // Offer Maximum Utility
|
---|
| 93 | try {
|
---|
| 94 | // System.out.println("Offering maximum");
|
---|
| 95 | return new Offer(getPartyId(), utilitySpace.getMaxUtilityBid());
|
---|
| 96 | } catch (Exception e) {
|
---|
| 97 | e.printStackTrace();
|
---|
| 98 | return new Offer(getPartyId(), generateRandomBid());
|
---|
| 99 | }
|
---|
| 100 | }
|
---|
| 101 |
|
---|
| 102 | // If accepting conditions are met, accept
|
---|
| 103 | if (Strategy.acceptingConditions(this)) {
|
---|
| 104 | // System.out.println("Accepting");
|
---|
| 105 | return new Accept(getPartyId(), lastbid);
|
---|
| 106 | }
|
---|
| 107 |
|
---|
| 108 | // System.out.println("My Next Bid Utility"+
|
---|
| 109 | // Strategy.nextBidUtility(this));
|
---|
| 110 |
|
---|
| 111 | // Check if we should offer an offer we received already, we will only
|
---|
| 112 | // resend an offer one time
|
---|
| 113 | if (Strategy.offerPreviousOffer(this)) {
|
---|
| 114 | Bid toOffer = Strategy.bestPreviousBid(this);
|
---|
| 115 |
|
---|
| 116 | // Add this offer to list so we don't send it again
|
---|
| 117 | alreadyProposed.add(toOffer);
|
---|
| 118 | // System.out.println("Offering previous bid, of Utility "+
|
---|
| 119 | // getUtility(toOffer));
|
---|
| 120 | return new Offer(getPartyId(), toOffer);
|
---|
| 121 | }
|
---|
| 122 |
|
---|
| 123 | // Generate new offer with that desired utility
|
---|
| 124 | Bid toOffer = Strategy.calculateMyBid(this);
|
---|
| 125 | // System.out.println("Generating a new Bid, of Utility "+
|
---|
| 126 | // getUtility(toOffer));
|
---|
| 127 | return new Offer(getPartyId(), toOffer);
|
---|
| 128 | }
|
---|
| 129 |
|
---|
| 130 | /**
|
---|
| 131 | * All offers proposed by the other parties will be received as a message.
|
---|
| 132 | * You can use this information to your advantage, for example to predict
|
---|
| 133 | * their utility.
|
---|
| 134 | *
|
---|
| 135 | * @param sender
|
---|
| 136 | * The party that did the action.
|
---|
| 137 | * @param action
|
---|
| 138 | * The action that party did.
|
---|
| 139 | */
|
---|
| 140 | @Override
|
---|
| 141 | public void receiveMessage(AgentID sender, Action action) {
|
---|
| 142 | // Here you can listen to other parties' messages
|
---|
| 143 |
|
---|
| 144 | if (action instanceof Offer) {
|
---|
| 145 | if (!partylist.contains(/* action.getAgent() */(sender))) {
|
---|
| 146 | // We have never seen this agent
|
---|
| 147 | // System.out.println("New Agent: " +
|
---|
| 148 | // action.getAgent().toString());
|
---|
| 149 | partylist.add((sender)); // add
|
---|
| 150 | // it
|
---|
| 151 | // to
|
---|
| 152 | // our
|
---|
| 153 | // list
|
---|
| 154 | BidHistory newAgentBidHistory = new BidHistory(); // create a
|
---|
| 155 | // new agent
|
---|
| 156 | // list and
|
---|
| 157 | // add it.
|
---|
| 158 | bidhistorylist.add(newAgentBidHistory);
|
---|
| 159 | // create a new agentUtils and add it
|
---|
| 160 | AgentUtils newAgentUtils = new AgentUtils((sender),
|
---|
| 161 | newAgentBidHistory,
|
---|
| 162 | ((AdditiveUtilitySpace) utilitySpace)
|
---|
| 163 | .getNrOfEvaluators());
|
---|
| 164 | agentUtilsList.add(newAgentUtils);
|
---|
| 165 | }
|
---|
| 166 | lastbid = DefaultAction.getBidFromAction(action);
|
---|
| 167 | // add the bid to the bidhistory
|
---|
| 168 | bidhistorylist.get(partylist.indexOf((sender)))
|
---|
| 169 | .add(new BidDetails(lastbid, getUtility(lastbid)));
|
---|
| 170 | // Loop through our agent List to find the one that sent the message
|
---|
| 171 | // and update his AgentUtils
|
---|
| 172 | for (int i = 0; i < agentUtilsList.size(); i++) {
|
---|
| 173 | if (agentUtilsList.get(i).agent == (sender)) {
|
---|
| 174 | agentUtilsList.get(i).recalculateUtilFunction();
|
---|
| 175 | break;
|
---|
| 176 | }
|
---|
| 177 | }
|
---|
| 178 | // System.out.println(this.getPartyId().toString() +
|
---|
| 179 | // " Received bid of utility:" + getUtility(lastbid));
|
---|
| 180 | }
|
---|
| 181 |
|
---|
| 182 | }
|
---|
| 183 |
|
---|
| 184 | // Extra methods
|
---|
| 185 |
|
---|
| 186 | public ArrayList<AgentUtils> getAgentUtilsList() {
|
---|
| 187 | return agentUtilsList;
|
---|
| 188 | }
|
---|
| 189 |
|
---|
| 190 | public int roundDeadline() {
|
---|
| 191 | return getDeadlines().getType() == DeadlineType.ROUND
|
---|
| 192 | ? getDeadlines().getValue() : 0;
|
---|
| 193 | }
|
---|
| 194 |
|
---|
| 195 | public int getRoundN() {
|
---|
| 196 | return roundN;
|
---|
| 197 | }
|
---|
| 198 |
|
---|
| 199 | public List<AgentID> getPartylist() {
|
---|
| 200 | return partylist;
|
---|
| 201 | }
|
---|
| 202 |
|
---|
| 203 | public Bid getLastbid() {
|
---|
| 204 | return lastbid;
|
---|
| 205 | }
|
---|
| 206 |
|
---|
| 207 | public BidHistory getBidhistory(AgentID Agent) {
|
---|
| 208 | return bidhistorylist.get(partylist.indexOf(Agent));
|
---|
| 209 | }
|
---|
| 210 |
|
---|
| 211 | public ArrayList<Bid> getAlreadyProposed() {
|
---|
| 212 | return alreadyProposed;
|
---|
| 213 | }
|
---|
| 214 |
|
---|
| 215 | public ArrayList<Bid> getPossibleBids() {
|
---|
| 216 | return possibleBids;
|
---|
| 217 | }
|
---|
| 218 |
|
---|
| 219 | @Override
|
---|
| 220 | public String getDescription() {
|
---|
| 221 | return "ANAC2015";
|
---|
| 222 | }
|
---|
| 223 |
|
---|
| 224 | }
|
---|