[1] | 1 | package agents.anac.y2010.AgentSmith;
|
---|
| 2 |
|
---|
| 3 | import genius.core.Agent;
|
---|
| 4 | import genius.core.Bid;
|
---|
| 5 | import genius.core.SupportedNegotiationSetting;
|
---|
| 6 | import genius.core.actions.Accept;
|
---|
| 7 | import genius.core.actions.Action;
|
---|
| 8 | import genius.core.actions.Offer;
|
---|
| 9 | import genius.core.utility.AdditiveUtilitySpace;
|
---|
| 10 |
|
---|
| 11 | /**
|
---|
| 12 | * ANAC2010 competitor Agent Smith.
|
---|
| 13 | */
|
---|
| 14 | public class AgentSmith extends Agent {
|
---|
| 15 | private PreferenceProfileManager fPreferenceProfile;
|
---|
| 16 | private ABidStrategy fBidStrategy;
|
---|
| 17 | private BidHistory fBidHistory;
|
---|
| 18 |
|
---|
| 19 | // Some possible requirements for the bayes agent
|
---|
| 20 |
|
---|
| 21 | // private ArrayList<Bid> ourPreviousBids;
|
---|
| 22 |
|
---|
| 23 | private boolean firstRound = true;
|
---|
| 24 | private double sMargin = 0.9;
|
---|
| 25 |
|
---|
| 26 | /**
|
---|
| 27 | * The version of this agent
|
---|
| 28 | *
|
---|
| 29 | * @return
|
---|
| 30 | */
|
---|
| 31 | @Override
|
---|
| 32 | public String getVersion() {
|
---|
| 33 | return "3"; //
|
---|
| 34 | }
|
---|
| 35 |
|
---|
| 36 | @Override
|
---|
| 37 | public String getName() {
|
---|
| 38 | return "Agent Smith";
|
---|
| 39 | }
|
---|
| 40 |
|
---|
| 41 | /**
|
---|
| 42 | * The agent will be initialized here.
|
---|
| 43 | */
|
---|
| 44 | @Override
|
---|
| 45 | public void init() {
|
---|
| 46 |
|
---|
| 47 | fBidHistory = new BidHistory();
|
---|
| 48 | fPreferenceProfile = new PreferenceProfileManager(fBidHistory,
|
---|
| 49 | (AdditiveUtilitySpace) this.utilitySpace);
|
---|
| 50 | fBidStrategy = new SmithBidStrategy(fBidHistory,
|
---|
| 51 | (AdditiveUtilitySpace) this.utilitySpace, fPreferenceProfile,
|
---|
| 52 | getAgentID());
|
---|
| 53 | }
|
---|
| 54 |
|
---|
| 55 | /**
|
---|
| 56 | * This is called when a action was done, by the other agent.
|
---|
| 57 | */
|
---|
| 58 | @Override
|
---|
| 59 | public void ReceiveMessage(Action pAction) {
|
---|
| 60 | /*
|
---|
| 61 | * Leaving it for now, to prevent it from breaking but it can be
|
---|
| 62 | * replaced with:
|
---|
| 63 | */
|
---|
| 64 |
|
---|
| 65 | if (pAction == null)
|
---|
| 66 | return;
|
---|
| 67 |
|
---|
| 68 | if (pAction instanceof Offer) {
|
---|
| 69 | Bid lBid = ((Offer) pAction).getBid();
|
---|
| 70 |
|
---|
| 71 | fBidHistory.addOpponentBid(lBid);
|
---|
| 72 | fPreferenceProfile.addBid(lBid);
|
---|
| 73 | }
|
---|
| 74 |
|
---|
| 75 | }
|
---|
| 76 |
|
---|
| 77 | /**
|
---|
| 78 | * When we take turn, this function is invoked.
|
---|
| 79 | */
|
---|
| 80 | @Override
|
---|
| 81 | public Action chooseAction() {
|
---|
| 82 | Bid currentBid = null;
|
---|
| 83 | Action currentAction = null;
|
---|
| 84 | try {
|
---|
| 85 | if (fBidHistory.getOpponentLastBid() != null && utilitySpace
|
---|
| 86 | .getUtility(fBidHistory.getOpponentLastBid()) > sMargin) {
|
---|
| 87 | // bid higher then margin
|
---|
| 88 | currentAction = new Accept(getAgentID(),
|
---|
| 89 | fBidHistory.getOpponentLastBid());
|
---|
| 90 | } else {
|
---|
| 91 | // start with the highest bid
|
---|
| 92 | if (firstRound && (fBidHistory.getMyLastBid() == null)) {
|
---|
| 93 | firstRound = !firstRound;
|
---|
| 94 | currentBid = getInitialBid();
|
---|
| 95 | currentAction = new Offer(getAgentID(), currentBid);
|
---|
| 96 | Bid lBid = ((Offer) currentAction).getBid();
|
---|
| 97 | fBidHistory.addMyBid(lBid);
|
---|
| 98 |
|
---|
| 99 | } else {
|
---|
| 100 |
|
---|
| 101 | // the utility of the opponents' bid is higher then ours ->
|
---|
| 102 | // accept!
|
---|
| 103 | double utilOpponent = this.utilitySpace
|
---|
| 104 | .getUtility(fBidHistory.getOpponentLastBid());
|
---|
| 105 | double utilOur = this.utilitySpace
|
---|
| 106 | .getUtility(fBidHistory.getMyLastBid());
|
---|
| 107 | if (utilOpponent >= utilOur) {
|
---|
| 108 | currentAction = new Accept(getAgentID(),
|
---|
| 109 | fBidHistory.getOpponentLastBid());
|
---|
| 110 | } else {
|
---|
| 111 | // should be rewritten into something else...
|
---|
| 112 | currentAction = fBidStrategy
|
---|
| 113 | .getNextAction(timeline.getTime());
|
---|
| 114 | if (currentAction instanceof Offer) {
|
---|
| 115 | Bid lBid = ((Offer) currentAction).getBid();
|
---|
| 116 | fBidHistory.addMyBid(lBid);
|
---|
| 117 | }
|
---|
| 118 | }
|
---|
| 119 | }
|
---|
| 120 | }
|
---|
| 121 | } catch (Exception e) {
|
---|
| 122 | e.printStackTrace();
|
---|
| 123 | }
|
---|
| 124 |
|
---|
| 125 | return currentAction;
|
---|
| 126 | }
|
---|
| 127 |
|
---|
| 128 | /*
|
---|
| 129 | * Get the initial bid, with the highest utility
|
---|
| 130 | */
|
---|
| 131 | private Bid getInitialBid() throws Exception {
|
---|
| 132 | return this.utilitySpace.getMaxUtilityBid();
|
---|
| 133 | }
|
---|
| 134 |
|
---|
| 135 | @Override
|
---|
| 136 | public SupportedNegotiationSetting getSupportedNegotiationSetting() {
|
---|
| 137 | return SupportedNegotiationSetting.getLinearUtilitySpaceInstance();
|
---|
| 138 | }
|
---|
| 139 |
|
---|
| 140 | @Override
|
---|
| 141 | public String getDescription() {
|
---|
| 142 | return "ANAC2010";
|
---|
| 143 | }
|
---|
| 144 |
|
---|
| 145 | }
|
---|