1 | package agents.anac.y2015.JonnyBlack;
|
---|
2 |
|
---|
3 | import java.util.Collections;
|
---|
4 | import java.util.List;
|
---|
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.DefaultAction;
|
---|
12 | import genius.core.actions.Offer;
|
---|
13 | import genius.core.issue.Issue;
|
---|
14 | import genius.core.issue.IssueDiscrete;
|
---|
15 | import genius.core.issue.ValueDiscrete;
|
---|
16 | import genius.core.parties.AbstractNegotiationParty;
|
---|
17 | import genius.core.parties.NegotiationInfo;
|
---|
18 | import genius.core.utility.AdditiveUtilitySpace;
|
---|
19 |
|
---|
20 | /**
|
---|
21 | * This is your negotiation party.
|
---|
22 | */
|
---|
23 | public class JonnyBlack extends AbstractNegotiationParty {
|
---|
24 |
|
---|
25 | /**
|
---|
26 | * Please keep this constructor. This is called by genius.
|
---|
27 | *
|
---|
28 | * @param utilitySpace
|
---|
29 | * Your utility space.
|
---|
30 | * @param deadlines
|
---|
31 | * The deadlines set for this negotiation.
|
---|
32 | * @param timeline
|
---|
33 | * Value counting from 0 (start) to 1 (end).
|
---|
34 | * @param randomSeed
|
---|
35 | * If you use any randomization, use this seed for it.
|
---|
36 | */
|
---|
37 | double agreeVal = 1;
|
---|
38 | Bid lastBid;
|
---|
39 | int[] issueOrder;
|
---|
40 | int[][] issueValOrder;
|
---|
41 | public double finalStopVal = 0.6;
|
---|
42 | Vector<BidHolder> acceptableBids;
|
---|
43 | Vector<Party> parties = new Vector<Party>();
|
---|
44 | int agentToFavor = 0;
|
---|
45 | double care = 0.4;
|
---|
46 | int lastorder = 0;
|
---|
47 | int topNofOpp = 100;
|
---|
48 | int round = 0;
|
---|
49 | double unwillingness = 1.1;
|
---|
50 |
|
---|
51 | @Override
|
---|
52 | public void init(NegotiationInfo info) {
|
---|
53 | super.init(info);
|
---|
54 | initializeCounts((AdditiveUtilitySpace) utilitySpace);
|
---|
55 | }
|
---|
56 |
|
---|
57 | /**
|
---|
58 | * Each round this method gets called and ask you to accept or offer. The
|
---|
59 | * first party in the first round is a bit different, it can only propose an
|
---|
60 | * offer.
|
---|
61 | *
|
---|
62 | * @param validActions
|
---|
63 | * Either a list containing both accept and offer or only offer.
|
---|
64 | * @return The chosen action.
|
---|
65 | */
|
---|
66 | @Override
|
---|
67 | public Action chooseAction(List<Class<? extends Action>> validActions) {
|
---|
68 |
|
---|
69 | // with 50% chance, counter offer
|
---|
70 | // if we are the first party, also offer.
|
---|
71 | round++;
|
---|
72 | if (round % 10 == 0) {
|
---|
73 | this.agreeVal = Functions.calcStopVal(parties, topNofOpp,
|
---|
74 | (AdditiveUtilitySpace) utilitySpace);
|
---|
75 | System.out.println(getPartyId());
|
---|
76 | unwillingness *= .995;
|
---|
77 | System.out.println(unwillingness);
|
---|
78 | agreeVal *= this.unwillingness;
|
---|
79 | if (agreeVal >= 1)
|
---|
80 | agreeVal = 0.99;
|
---|
81 | System.out.println("AGREE VAL = " + this.agreeVal);
|
---|
82 | if (topNofOpp > 10) {
|
---|
83 | topNofOpp -= 5;
|
---|
84 | }
|
---|
85 | System.out.println(topNofOpp);
|
---|
86 | }
|
---|
87 | double d = 0;
|
---|
88 | if (lastBid != null)
|
---|
89 | d = Functions.getBidValue((AdditiveUtilitySpace) utilitySpace,
|
---|
90 | lastBid);
|
---|
91 | // System.out.println(d);
|
---|
92 | if (d >= this.stopValue())
|
---|
93 | return new Accept(getPartyId(), lastBid);
|
---|
94 | care *= 1.004;
|
---|
95 | Bid b = createBid();
|
---|
96 | if (parties.size() > 0) {
|
---|
97 | agentToFavor++;
|
---|
98 | agentToFavor = agentToFavor % parties.size();
|
---|
99 | }
|
---|
100 | return new Offer(getPartyId(), b);
|
---|
101 |
|
---|
102 | }
|
---|
103 |
|
---|
104 | /**
|
---|
105 | * All offers proposed by the other parties will be received as a message.
|
---|
106 | * You can use this information to your advantage, for example to predict
|
---|
107 | * their utility.
|
---|
108 | *
|
---|
109 | * @param sender
|
---|
110 | * The party that did the action.
|
---|
111 | * @param action
|
---|
112 | * The action that party did.
|
---|
113 | */
|
---|
114 | @Override
|
---|
115 | public void receiveMessage(AgentID sender, Action action) {
|
---|
116 | super.receiveMessage(sender, action);
|
---|
117 | if (action instanceof Accept) {
|
---|
118 | // if(sender instanceof AbstractNegotiationParty)
|
---|
119 | // {
|
---|
120 | // String accepter=((AbstractNegotiationParty)
|
---|
121 | // sender).getPartyId().toString();
|
---|
122 | // Party p=new Party(accepter, null);
|
---|
123 | // p = parties.get(parties.indexOf(p));
|
---|
124 | // ArrayList<Issue> issues = lastBid.getIssues();
|
---|
125 | // for(int i =0;i<issues.size();i++)
|
---|
126 | // {
|
---|
127 | // IssueDiscrete id = (IssueDiscrete)utilitySpace.getIssue(i);
|
---|
128 | // int choice =
|
---|
129 | // id.getValueIndex((ValueDiscrete)lastBid.getValue(i+1));
|
---|
130 | // p.counts[i][choice]++;
|
---|
131 | // }
|
---|
132 | // p.calcWeights();
|
---|
133 | // }
|
---|
134 | } else {
|
---|
135 | Bid b = DefaultAction.getBidFromAction(action);
|
---|
136 | lastBid = b;
|
---|
137 | }
|
---|
138 |
|
---|
139 | if (sender != null) {
|
---|
140 | Party p = new Party(sender.toString(), issueValOrder);
|
---|
141 | if (!parties.contains(p)) {
|
---|
142 | parties.add(p);
|
---|
143 | p.setOrderedBids(this.acceptableBids,
|
---|
144 | (AdditiveUtilitySpace) utilitySpace);
|
---|
145 | } else {
|
---|
146 | p = parties.get(parties.indexOf(p));
|
---|
147 | }
|
---|
148 | if (lastBid != null
|
---|
149 | && !action.equals(new Accept(getPartyId(), lastBid))) {
|
---|
150 | List<Issue> issues = lastBid.getIssues();
|
---|
151 | try {
|
---|
152 | for (int i = 0; i < issues.size(); i++) {
|
---|
153 | IssueDiscrete id = (IssueDiscrete) ((AdditiveUtilitySpace) utilitySpace)
|
---|
154 | .getIssue(i);
|
---|
155 | int choice = id.getValueIndex(
|
---|
156 | (ValueDiscrete) lastBid.getValue(i + 1));
|
---|
157 | p.counts[i][choice]++;
|
---|
158 | }
|
---|
159 | p.calcWeights();
|
---|
160 | } catch (Exception e) {
|
---|
161 | e.printStackTrace();
|
---|
162 | }
|
---|
163 | }
|
---|
164 | }
|
---|
165 | // Here you can listen to other parties' messages
|
---|
166 | }
|
---|
167 |
|
---|
168 | public void initializeCounts(AdditiveUtilitySpace us) {
|
---|
169 | this.issueOrder = Functions.calcOrderOfIssues(us);
|
---|
170 | this.issueValOrder = Functions.calcOrderOfIssueVals(us);
|
---|
171 | this.acceptableBids = getFeasibleBids();
|
---|
172 | Collections.sort(acceptableBids);
|
---|
173 | parties = new Vector<Party>();
|
---|
174 | }
|
---|
175 |
|
---|
176 | double stopValue() {
|
---|
177 | return agreeVal;
|
---|
178 | }
|
---|
179 |
|
---|
180 | public Bid createBid() {
|
---|
181 | // for(Party p :parties)
|
---|
182 | // {
|
---|
183 | // p.show();
|
---|
184 | // }
|
---|
185 |
|
---|
186 | if (parties.size() > 0)
|
---|
187 | for (int i = lastorder + 1; i < acceptableBids.size(); i++) {
|
---|
188 | BidHolder bh = acceptableBids.get(i);
|
---|
189 | if (bh.v > stopValue()
|
---|
190 | && parties.get(agentToFavor).getPredictedUtility(bh.b,
|
---|
191 | (AdditiveUtilitySpace) utilitySpace) > care) {
|
---|
192 | lastorder = i;
|
---|
193 | return bh.b;
|
---|
194 | }
|
---|
195 | if (bh.v < stopValue())
|
---|
196 | break;
|
---|
197 | }
|
---|
198 |
|
---|
199 | lastorder = 0;
|
---|
200 | return acceptableBids.get(0).b;
|
---|
201 | }
|
---|
202 |
|
---|
203 | public Vector<BidHolder> getFeasibleBids() {
|
---|
204 | Vector<BidHolder> bids = new Vector<BidHolder>();
|
---|
205 | Bid b = Functions.getCopyOfBestBid((AdditiveUtilitySpace) utilitySpace);
|
---|
206 | bids = recurseBids(b, bids, 0);
|
---|
207 | System.out.println("Vector Size:" + bids.size());
|
---|
208 | return bids;
|
---|
209 | }
|
---|
210 |
|
---|
211 | public Vector<BidHolder> recurseBids(Bid b, Vector<BidHolder> v, int is) {
|
---|
212 | Vector<BidHolder> v1 = new Vector<BidHolder>();
|
---|
213 | if (is == issueOrder.length) {
|
---|
214 | BidHolder bh = new BidHolder();
|
---|
215 | bh.b = b;
|
---|
216 | bh.v = Functions.getBidValue((AdditiveUtilitySpace) utilitySpace,
|
---|
217 | b);
|
---|
218 | v1.addElement(bh);
|
---|
219 |
|
---|
220 | return v1;
|
---|
221 | }
|
---|
222 | for (int i = 0; i < issueValOrder[issueOrder[is]].length; i++) {
|
---|
223 | Bid b1 = new Bid(b);
|
---|
224 | int issueID = issueOrder[is];
|
---|
225 | int item = issueValOrder[issueID][i] - 1;
|
---|
226 | ValueDiscrete val = Functions
|
---|
227 | .getVal((AdditiveUtilitySpace) utilitySpace, issueID, item);
|
---|
228 | b1 = b1.putValue(issueID + 1, val);
|
---|
229 | if (Functions.getBidValue((AdditiveUtilitySpace) utilitySpace,
|
---|
230 | b1) > this.finalStopVal) {
|
---|
231 | v1.addAll(recurseBids(b1, v1, is + 1));
|
---|
232 | }
|
---|
233 | }
|
---|
234 | return v1;
|
---|
235 | }
|
---|
236 |
|
---|
237 | @Override
|
---|
238 | public String getDescription() {
|
---|
239 | return "ANAC2015";
|
---|
240 | }
|
---|
241 | }
|
---|