source: src/main/java/agents/ai2014/group3/Group3.java@ 127

Last change on this file since 127 was 127, checked in by Wouter Pasman, 6 years ago

#41 ROLL BACK of rev.126 . So this version is equal to rev. 125

File size: 6.5 KB
Line 
1package agents.ai2014.group3;
2
3import java.util.ArrayList;
4import java.util.List;
5
6import genius.core.AgentID;
7import genius.core.Bid;
8import genius.core.BidHistory;
9import genius.core.DeadlineType;
10import genius.core.actions.Accept;
11import genius.core.actions.Action;
12import genius.core.actions.DefaultAction;
13import genius.core.actions.Offer;
14import genius.core.bidding.BidDetails;
15import genius.core.parties.AbstractNegotiationParty;
16import genius.core.parties.NegotiationInfo;
17import genius.core.utility.AdditiveUtilitySpace;
18
19/**
20 * This is your negotiation party.
21 */
22public class Group3 extends AbstractNegotiationParty {
23
24 private int roundN = 0; // Number of the round we are in
25 private Bid lastbid; // LastBid we received from someone
26 private List<BidHistory> bidhistorylist; // List of the lists of Bids
27 // received, one list for every
28 // agent
29 private List<AgentID> partylist; // List of Agents
30 private ArrayList<Bid> possibleBids; // List of all possible Bids in this
31 // utility Space
32 private ArrayList<Bid> alreadyProposed; // List of all Bids, we received and
33 // then reproposed
34 private ArrayList<AgentUtils> agentUtilsList;
35
36 // List of AgentUtils that are objects that model the opponents utility
37 // function and give their utility to a specific Bid
38
39 @Override
40 public void init(NegotiationInfo info) {
41 super.init(info);
42
43 // Initialize the lists
44 bidhistorylist = new ArrayList<BidHistory>();
45 partylist = new ArrayList<AgentID>();
46 alreadyProposed = new ArrayList<Bid>();
47 possibleBids = BidGenerator.BidList(((AdditiveUtilitySpace) utilitySpace));
48 agentUtilsList = new ArrayList<AgentUtils>();
49
50 }
51
52 /**
53 * Each round this method gets called and ask you to accept or offer. The
54 * first party in the first round is a bit different, it can only propose an
55 * offer.
56 *
57 * @param validActions
58 * Either a list containing both accept and offer or only offer.
59 * @return The chosen action.
60 */
61 @Override
62 public Action chooseAction(List<Class<? extends Action>> validActions) {
63 roundN++; // Update the round number
64 // System.out.println("Round N� "+ roundN);
65 // System.out.println("I am " + this.getPartyId().toString());
66 if (!validActions.contains(Accept.class)) {
67 // No Offer on the table yet
68
69 // Generate all possible bids for this utility space
70 double[] utils = BidGenerator.utilitylist(possibleBids, this);
71 // for(int i=0;i<possibleBids.size();i++) {
72 // System.out.println("Bid N� "+ i+" utility: " + utils[i] ) ;
73 // }
74
75 // System.out.println("Deadline"+ deadlines.toString());
76 // System.out.println("Deadline "+ this.roundDeadline());
77
78 // Offer Maximum Utility
79 try {
80 // System.out.println("Offering maximum");
81 return new Offer(getPartyId(), utilitySpace.getMaxUtilityBid());
82 } catch (Exception e) {
83 e.printStackTrace();
84 return new Offer(getPartyId(), generateRandomBid());
85 }
86 }
87
88 // If accepting conditions are met, accept
89 if (Strategy.acceptingConditions(this)) {
90 // System.out.println("Accepting");
91 return new Accept(getPartyId(), lastbid);
92 }
93
94 // System.out.println("My Next Bid Utility"+
95 // Strategy.nextBidUtility(this));
96
97 // Check if we should offer an offer we received already, we will only
98 // resend an offer one time
99 if (Strategy.offerPreviousOffer(this)) {
100 Bid toOffer = Strategy.bestPreviousBid(this);
101
102 // Add this offer to list so we don't send it again
103 alreadyProposed.add(toOffer);
104 // System.out.println("Offering previous bid, of Utility "+
105 // getUtility(toOffer));
106 return new Offer(getPartyId(), toOffer);
107 }
108
109 // Generate new offer with that desired utility
110 Bid toOffer = Strategy.calculateMyBid(this);
111 // System.out.println("Generating a new Bid, of Utility "+
112 // getUtility(toOffer));
113 return new Offer(getPartyId(), toOffer);
114 }
115
116 /**
117 * All offers proposed by the other parties will be received as a message.
118 * You can use this information to your advantage, for example to predict
119 * their utility.
120 *
121 * @param sender
122 * The party that did the action.
123 * @param action
124 * The action that party did.
125 */
126 @Override
127 public void receiveMessage(AgentID sender, Action action) {
128 // Here you can listen to other parties' messages
129
130 if (action instanceof Offer) {
131 if (!partylist.contains(/* action.getAgent() */(AgentID) sender)) {
132 // We have never seen this agent
133 // System.out.println("New Agent: " +
134 // action.getAgent().toString());
135 partylist.add((AgentID) sender); // add
136 // it
137 // to
138 // our
139 // list
140 BidHistory newAgentBidHistory = new BidHistory(); // create a
141 // new agent
142 // list and
143 // add it.
144 bidhistorylist.add(newAgentBidHistory);
145 // create a new agentUtils and add it
146 AgentUtils newAgentUtils = new AgentUtils(((AgentID) sender), newAgentBidHistory,
147 ((AdditiveUtilitySpace) utilitySpace).getNrOfEvaluators());
148 agentUtilsList.add(newAgentUtils);
149 }
150 lastbid = DefaultAction.getBidFromAction(action);
151 // add the bid to the bidhistory
152 bidhistorylist.get(partylist.indexOf(((AgentID) sender))).add(new BidDetails(lastbid, getUtility(lastbid)));
153 // Loop through our agent List to find the one that sent the message
154 // and update his AgentUtils
155 for (int i = 0; i < agentUtilsList.size(); i++) {
156 if (agentUtilsList.get(i).agent == ((AgentID) sender)) {
157 agentUtilsList.get(i).recalculateUtilFunction();
158 break;
159 }
160 }
161 // System.out.println(this.getPartyId().toString() +
162 // " Received bid of utility:" + getUtility(lastbid));
163 }
164
165 }
166
167 // Extra methods
168
169 public ArrayList<AgentUtils> getAgentUtilsList() {
170 return agentUtilsList;
171 }
172
173 public int roundDeadline() {
174 return getDeadlines().getType() == DeadlineType.ROUND ? getDeadlines().getValue() : 0;
175 }
176
177 public int getRoundN() {
178 return roundN;
179 }
180
181 public List<AgentID> getPartylist() {
182 return partylist;
183 }
184
185 public Bid getLastbid() {
186 return lastbid;
187 }
188
189 public BidHistory getBidhistory(AgentID Agent) {
190 return bidhistorylist.get(partylist.indexOf(Agent));
191 }
192
193 public ArrayList<Bid> getAlreadyProposed() {
194 return alreadyProposed;
195 }
196
197 public ArrayList<Bid> getPossibleBids() {
198 return possibleBids;
199 }
200
201 protected AgentID partyId = new AgentID("Group 3");
202
203 @Override
204 public String getDescription() {
205 return "ai2014 group3";
206 }
207
208}
Note: See TracBrowser for help on using the repository browser.