1 | package agents.anac.y2013.MetaAgent.portfolio.AgentLG;
|
---|
2 |
|
---|
3 | import genius.core.Agent;
|
---|
4 | import genius.core.Bid;
|
---|
5 | import genius.core.actions.Accept;
|
---|
6 | import genius.core.actions.Action;
|
---|
7 | import genius.core.actions.Offer;
|
---|
8 | import genius.core.utility.AdditiveUtilitySpace;
|
---|
9 |
|
---|
10 | /**
|
---|
11 | * The Agent is most of the time stubborn but in the end it starts to
|
---|
12 | * compromise. In the beginning it votes in the beginning its best votes. when
|
---|
13 | * the time is 0-0.6 : it votes incrementally from its best utility to a minimum
|
---|
14 | * of 0.75* utility and learns opponent utility. when the time is 0.6-0.9: it
|
---|
15 | * starts to compromise and chooses better bid for the opponents that still good
|
---|
16 | * for it only if the opponent is also comprising (the rate of compromise
|
---|
17 | * depends on the opponent and on the discount factor). when the time over 0.9:
|
---|
18 | * the agents starts to "panic" and compromise more frequently. when the time is
|
---|
19 | * over(more then 0.9995 ) it chooses opponents max utility bid for it. The
|
---|
20 | * Agent accept an offer only if it offered before by the agent or the time is
|
---|
21 | * almost over and the bid is close enough to its worst offer.
|
---|
22 | *
|
---|
23 | * @author Luba Golosman
|
---|
24 | */
|
---|
25 | public class AgentLG extends Agent {
|
---|
26 |
|
---|
27 | private Bid myLastBid = null;
|
---|
28 | private Bid oponnetLastBid = null;
|
---|
29 |
|
---|
30 | private BidChooser bidChooser = null;
|
---|
31 | private OpponentBids oppenentsBid;
|
---|
32 | private boolean bidLast = false;
|
---|
33 |
|
---|
34 | @Override
|
---|
35 | public Action chooseAction() {
|
---|
36 |
|
---|
37 | Action currentAction = null;
|
---|
38 | try {
|
---|
39 | double time = timeline.getTime();
|
---|
40 |
|
---|
41 | // first bid -> vote the optimal bid
|
---|
42 | if (myLastBid == null || oponnetLastBid == null) {
|
---|
43 | myLastBid = this.utilitySpace.getMaxUtilityBid();
|
---|
44 | currentAction = new Offer(getAgentID(), myLastBid);
|
---|
45 | } else {
|
---|
46 | double opponentUtility = this.utilitySpace
|
---|
47 | .getUtilityWithDiscount(oponnetLastBid, time);
|
---|
48 | double myUtility = this.utilitySpace.getUtilityWithDiscount(
|
---|
49 | myLastBid, time);
|
---|
50 |
|
---|
51 | // accept if opponent offer is good enough or there is no time
|
---|
52 | // and the offer is 'good'
|
---|
53 | if (opponentUtility >= myUtility * 0.99
|
---|
54 | || (time > 0.999 && opponentUtility >= myUtility * 0.9)
|
---|
55 | || bidChooser.getMyBidsMinUtility(time) <= opponentUtility) {
|
---|
56 | currentAction = new Accept(getAgentID(), oponnetLastBid);
|
---|
57 | } else if (bidLast) {
|
---|
58 | currentAction = new Offer(getAgentID(), myLastBid);
|
---|
59 | }
|
---|
60 | // there is lot of time ->learn the opponent and bid the 1/4
|
---|
61 | // most optimal bids
|
---|
62 | else if (time < 0.6) {
|
---|
63 | currentAction = bidChooser.getNextOptimicalBid(time);
|
---|
64 | } else {
|
---|
65 | // the time is over -> bid the opponents max utility bid for
|
---|
66 | // me
|
---|
67 | if (time >= 0.9995) {
|
---|
68 | myLastBid = oppenentsBid.getMaxUtilityBidForMe();
|
---|
69 | if (utilitySpace
|
---|
70 | .getUtilityWithDiscount(myLastBid, time) < utilitySpace
|
---|
71 | .getReservationValueWithDiscount(time))
|
---|
72 | myLastBid = bidChooser.getMyminBidfromBids();
|
---|
73 | currentAction = new Offer(getAgentID(), myLastBid);
|
---|
74 | } else {
|
---|
75 | // Comprise and chose better bid for the opponents that
|
---|
76 | // still good for me
|
---|
77 | currentAction = bidChooser.getNextBid(time);
|
---|
78 | }
|
---|
79 | }
|
---|
80 | }
|
---|
81 | if (currentAction instanceof Offer) {
|
---|
82 | myLastBid = ((Offer) currentAction).getBid();
|
---|
83 | if (oppenentsBid.getOpponentsBids().contains(myLastBid))
|
---|
84 | bidLast = true;
|
---|
85 | }
|
---|
86 |
|
---|
87 | } catch (Exception e) {
|
---|
88 | // System.out.println("Error: " + e);
|
---|
89 | currentAction = new Accept(getAgentID(), oponnetLastBid);
|
---|
90 | }
|
---|
91 |
|
---|
92 | return currentAction;
|
---|
93 | }
|
---|
94 |
|
---|
95 | @Override
|
---|
96 | public String getName() {
|
---|
97 | return "AgentLG";
|
---|
98 | }
|
---|
99 |
|
---|
100 | public void init() {
|
---|
101 | oppenentsBid = new OpponentBids(utilitySpace);
|
---|
102 | bidChooser = new BidChooser((AdditiveUtilitySpace) this.utilitySpace,
|
---|
103 | getAgentID(), oppenentsBid);
|
---|
104 | }
|
---|
105 |
|
---|
106 | public void ReceiveMessage(Action opponentAction) {
|
---|
107 | if (opponentAction instanceof Offer) {
|
---|
108 | oponnetLastBid = ((Offer) opponentAction).getBid();
|
---|
109 |
|
---|
110 | try {
|
---|
111 | oppenentsBid.addBid(((Offer) opponentAction).getBid());
|
---|
112 | oppenentsBid.getOpponentBidUtility(
|
---|
113 | this.utilitySpace.getDomain(), oponnetLastBid);
|
---|
114 | } catch (Exception e) {
|
---|
115 | e.printStackTrace();
|
---|
116 | }
|
---|
117 | }
|
---|
118 |
|
---|
119 | }
|
---|
120 |
|
---|
121 | @Override
|
---|
122 | public String getVersion() {
|
---|
123 | return "1.1";
|
---|
124 | }
|
---|
125 |
|
---|
126 | }
|
---|