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