1 | package agents.anac.y2018.yeela;
|
---|
2 |
|
---|
3 | import java.util.List;
|
---|
4 |
|
---|
5 | import java.util.Vector;
|
---|
6 |
|
---|
7 | import genius.core.AgentID;
|
---|
8 | import genius.core.Bid;
|
---|
9 | import genius.core.actions.Accept;
|
---|
10 | import genius.core.actions.Action;
|
---|
11 | import genius.core.actions.Offer;
|
---|
12 | import genius.core.parties.AbstractNegotiationParty;
|
---|
13 | import genius.core.parties.NegotiationInfo;
|
---|
14 |
|
---|
15 | /**
|
---|
16 | * group1.Agent1 returns the bid that maximizes its own utility for half of the negotiation session.
|
---|
17 | * In the second half, it offers a random bid. It only accepts the bid on the table in this phase,
|
---|
18 | * if the utility of the bid is higher than Example Agent's last bid.
|
---|
19 | */
|
---|
20 | public class Yeela extends AbstractNegotiationParty {
|
---|
21 | /**
|
---|
22 | *
|
---|
23 | */
|
---|
24 | private static final long serialVersionUID = -2676016971703971492L;
|
---|
25 |
|
---|
26 | private final String description = "yeela Agent";
|
---|
27 |
|
---|
28 | private Bid lastReceivedOffer; // offer on the table
|
---|
29 | private Bid bestReceivedOffer; // best offer seen
|
---|
30 | private Learner curLearner;
|
---|
31 | private boolean firstGameAct;
|
---|
32 | private double timeToGiveUp = 0.75;
|
---|
33 | private List<Bid> bids;
|
---|
34 | private NegotiationInfo m_info;
|
---|
35 | @Override
|
---|
36 | public void init(NegotiationInfo info) {
|
---|
37 | super.init(info);
|
---|
38 |
|
---|
39 | System.out.println("Discount Factor is " + info.getUtilitySpace().getDiscountFactor());
|
---|
40 | System.out.println("Reservation Value is " + info.getUtilitySpace().getReservationValueUndiscounted());
|
---|
41 |
|
---|
42 | firstGameAct = true;
|
---|
43 | m_info = info;
|
---|
44 | bids = new Vector<Bid>();
|
---|
45 |
|
---|
46 | curLearner = new Learner(getMaxUtilityBid(), info);
|
---|
47 | }
|
---|
48 |
|
---|
49 | /**
|
---|
50 | * When this function is called, it is expected that the Party chooses one of the actions from the possible
|
---|
51 | * action list and returns an instance of the chosen action.
|
---|
52 | *
|
---|
53 | * @param list
|
---|
54 | * @return
|
---|
55 | */
|
---|
56 | public Action chooseAction(List<Class<? extends Action>> list) {
|
---|
57 | // According to Stacked Alternating Offers Protocol list includes
|
---|
58 | // Accept, Offer and EndNegotiation actions only.
|
---|
59 | double time = getTimeLine().getTime(); // Gets the time, running from t = 0 (start) to t = 1 (deadline).
|
---|
60 | // The time is normalized, so agents need not be
|
---|
61 | // concerned with the actual internal clock.
|
---|
62 |
|
---|
63 | System.out.println(time);
|
---|
64 |
|
---|
65 | // if we are first
|
---|
66 | if (firstGameAct)
|
---|
67 | {
|
---|
68 | firstGameAct = false;
|
---|
69 | bids.add(this.getMaxUtilityBid());
|
---|
70 | return new Offer(this.getPartyId(), this.getMaxUtilityBid());
|
---|
71 | }
|
---|
72 |
|
---|
73 | try
|
---|
74 | {
|
---|
75 | if (timeToGiveUp < time)
|
---|
76 | {
|
---|
77 | return new Accept(this.getPartyId(), lastReceivedOffer);
|
---|
78 | }
|
---|
79 |
|
---|
80 | // create new offer
|
---|
81 | bids.add(curLearner.run(lastReceivedOffer));
|
---|
82 |
|
---|
83 | // decide whether to accept counter offer
|
---|
84 | for (Bid bid : bids)
|
---|
85 | {
|
---|
86 | if (m_info.getUtilitySpace().getUtility(lastReceivedOffer) == m_info.getUtilitySpace().getUtility(bid))
|
---|
87 | {
|
---|
88 | return new Accept(this.getPartyId(), lastReceivedOffer);
|
---|
89 | }
|
---|
90 | }
|
---|
91 |
|
---|
92 | // decide whether to offer previous counter offer since its better than newly suggested offer
|
---|
93 | if (m_info.getUtilitySpace().getUtility(bestReceivedOffer) > m_info.getUtilitySpace().getUtility(bids.get(bids.size() - 1)))
|
---|
94 | {
|
---|
95 | return new Offer(this.getPartyId(), bestReceivedOffer);
|
---|
96 | }
|
---|
97 |
|
---|
98 | // suggest our new offer
|
---|
99 | return new Offer(this.getPartyId(), bids.get(bids.size() - 1));
|
---|
100 | }
|
---|
101 | catch (Exception e)
|
---|
102 | {
|
---|
103 | e.printStackTrace();
|
---|
104 | return new Accept(this.getPartyId(), lastReceivedOffer);
|
---|
105 | }
|
---|
106 | }
|
---|
107 |
|
---|
108 | /**
|
---|
109 | * This method is called to inform the party that another NegotiationParty chose an Action.
|
---|
110 | * @param sender
|
---|
111 | * @param act
|
---|
112 | */
|
---|
113 | @Override
|
---|
114 | public void receiveMessage(AgentID sender, Action act) {
|
---|
115 | super.receiveMessage(sender, act);
|
---|
116 |
|
---|
117 | if (act instanceof Offer) { // sender is making an offer
|
---|
118 | Offer offer = (Offer) act;
|
---|
119 |
|
---|
120 | // storing last received offer
|
---|
121 | lastReceivedOffer = offer.getBid();
|
---|
122 |
|
---|
123 | if ((null == bestReceivedOffer) || (m_info.getUtilitySpace().getUtility(bestReceivedOffer) < m_info.getUtilitySpace().getUtility(lastReceivedOffer)))
|
---|
124 | {
|
---|
125 | bestReceivedOffer = lastReceivedOffer;
|
---|
126 | }
|
---|
127 | firstGameAct = false;
|
---|
128 | }
|
---|
129 | }
|
---|
130 |
|
---|
131 | /**
|
---|
132 | * A human-readable description for this party.
|
---|
133 | * @return
|
---|
134 | */
|
---|
135 |
|
---|
136 | public String getDescription() {
|
---|
137 | return description;
|
---|
138 | }
|
---|
139 |
|
---|
140 | private Bid getMaxUtilityBid() {
|
---|
141 | try
|
---|
142 | {
|
---|
143 | return this.utilitySpace.getMaxUtilityBid();
|
---|
144 | } catch (Exception e) {
|
---|
145 | e.printStackTrace();
|
---|
146 | }
|
---|
147 | return null;
|
---|
148 | }
|
---|
149 | }
|
---|