1 | package agents.ai2014.group7;
|
---|
2 |
|
---|
3 | import java.util.List;
|
---|
4 |
|
---|
5 | import genius.core.AgentID;
|
---|
6 | import genius.core.Bid;
|
---|
7 | import genius.core.actions.Accept;
|
---|
8 | import genius.core.actions.Action;
|
---|
9 | import genius.core.actions.DefaultAction;
|
---|
10 | import genius.core.actions.Offer;
|
---|
11 | import genius.core.parties.AbstractNegotiationParty;
|
---|
12 | import genius.core.parties.NegotiationInfo;
|
---|
13 |
|
---|
14 | /**
|
---|
15 | * This is your negotiation party.
|
---|
16 | */
|
---|
17 | public class Group7 extends AbstractNegotiationParty {
|
---|
18 |
|
---|
19 | private Bid activeBid = null;
|
---|
20 | private Bid maxUtilityBid = null;
|
---|
21 | private double declineStart = 0.8;
|
---|
22 | private double startUtility = 0.95;
|
---|
23 | private double endUtility;
|
---|
24 |
|
---|
25 | @Override
|
---|
26 | public void init(NegotiationInfo info) {
|
---|
27 | super.init(info);
|
---|
28 |
|
---|
29 | endUtility = utilitySpace.getReservationValueUndiscounted();
|
---|
30 | try {
|
---|
31 | maxUtilityBid = utilitySpace.getMaxUtilityBid();
|
---|
32 | } catch (Exception e) {
|
---|
33 | e.printStackTrace();
|
---|
34 | }
|
---|
35 | }
|
---|
36 |
|
---|
37 | /**
|
---|
38 | * Each round this method gets called and ask you to accept or offer. The
|
---|
39 | * first party in the first round is a bit different, it can only propose an
|
---|
40 | * offer.
|
---|
41 | *
|
---|
42 | * @param validActions
|
---|
43 | * Either a list containing both accept and offer or only offer.
|
---|
44 | * @return The chosen action.
|
---|
45 | */
|
---|
46 | @Override
|
---|
47 | public Action chooseAction(List<Class<? extends Action>> validActions) {
|
---|
48 | System.out.println(cosDiscount(scale(timeline.getTime(), declineStart, 1f, 0f, 1f), startUtility, endUtility));
|
---|
49 | try {
|
---|
50 | Bid candidateBid = generateBid();
|
---|
51 | if (validActions.contains(Accept.class) && acceptable(activeBid))
|
---|
52 | return new Accept(getPartyId(), activeBid);
|
---|
53 | return new Offer(getPartyId(), candidateBid);
|
---|
54 | } catch (Exception e) {
|
---|
55 | e.printStackTrace();
|
---|
56 | }
|
---|
57 | return null;
|
---|
58 | }
|
---|
59 |
|
---|
60 | /**
|
---|
61 | * All offers proposed by the other parties will be received as a message.
|
---|
62 | * You can use this information to your advantage, for example to predict
|
---|
63 | * their utility.
|
---|
64 | *
|
---|
65 | * @param sender
|
---|
66 | * The party that did the action.
|
---|
67 | * @param action
|
---|
68 | * The action that party did.
|
---|
69 | */
|
---|
70 | @Override
|
---|
71 | public void receiveMessage(AgentID sender, Action action) {
|
---|
72 | Bid bid = DefaultAction.getBidFromAction(action);
|
---|
73 | if (bid != null)
|
---|
74 | activeBid = bid;
|
---|
75 | }
|
---|
76 |
|
---|
77 | /**
|
---|
78 | * Generate a random bid that this agent would currently find acceptable.
|
---|
79 | *
|
---|
80 | * @return An acceptable bid.
|
---|
81 | * @throws Exception
|
---|
82 | */
|
---|
83 | private Bid generateBid() throws Exception {
|
---|
84 | for (int i = 0; i < 1000; i++) {
|
---|
85 | Bid bid = generateRandomBid();
|
---|
86 | if (acceptable(bid))
|
---|
87 | return bid;
|
---|
88 | }
|
---|
89 | return new Bid(maxUtilityBid);
|
---|
90 | }
|
---|
91 |
|
---|
92 | /**
|
---|
93 | * Determine if a bid is currently acceptable. This depends on the
|
---|
94 | * negotiation progress. Bids with a lower utility become acceptable when
|
---|
95 | * nearing the deadline.
|
---|
96 | *
|
---|
97 | * @param bid
|
---|
98 | * @return
|
---|
99 | */
|
---|
100 | private boolean acceptable(Bid bid) {
|
---|
101 | double progress = timeline.getTime();
|
---|
102 | return progress < declineStart ? getUtility(bid) > startUtility
|
---|
103 | : getUtility(bid) > cosDiscount(scale(progress, declineStart, 1f, 0f, 1f), startUtility, endUtility);
|
---|
104 | }
|
---|
105 |
|
---|
106 | /**
|
---|
107 | * Calculate a discount based on the cosine function. Interpolates using
|
---|
108 | * first quarter of the cosine.
|
---|
109 | *
|
---|
110 | * @param progress
|
---|
111 | * Value between 0.0 to 1.0.
|
---|
112 | * @param high
|
---|
113 | * Return value when progress equals 0.0.
|
---|
114 | * @param low
|
---|
115 | * Return value when progress equals 1.0.
|
---|
116 | * @return Interpolated value between to and from.
|
---|
117 | */
|
---|
118 | private double cosDiscount(double progress, double high, double low) {
|
---|
119 | return scale(Math.cos(progress * Math.PI / 2), 0, 1f, low, high);
|
---|
120 | }
|
---|
121 |
|
---|
122 | private double scale(double value, double fromLow, double fromHigh, double toLow, double toHigh) {
|
---|
123 | return toLow + (value - fromLow) / (fromHigh - fromLow) * (toHigh - toLow);
|
---|
124 | }
|
---|
125 |
|
---|
126 | protected AgentID partyId = new AgentID("Group 7");
|
---|
127 |
|
---|
128 | @Override
|
---|
129 | public String getDescription() {
|
---|
130 | return "ai2014 group7";
|
---|
131 | }
|
---|
132 |
|
---|
133 | }
|
---|