source: src/main/java/agents/anac/y2015/pnegotiator/PNegotiator.java

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

Initial import : Genius 9.0.0

File size: 6.4 KB
Line 
1package agents.anac.y2015.pnegotiator;
2
3import java.util.ArrayList;
4import java.util.List;
5
6import genius.core.AgentID;
7import genius.core.Bid;
8import genius.core.actions.Accept;
9import genius.core.actions.Action;
10import genius.core.actions.DefaultAction;
11import genius.core.actions.Offer;
12import genius.core.issue.Objective;
13import genius.core.parties.AbstractNegotiationParty;
14import genius.core.parties.NegotiationInfo;
15import genius.core.utility.AdditiveUtilitySpace;
16
17/**
18 * This is your negotiation party.
19 */
20public class PNegotiator extends AbstractNegotiationParty {
21
22 // State of the agent (am I being a hardliner or am I conceding?)
23 public enum AgentState {
24 HARDLINER, CONCEDER
25 };
26
27 public AgentState agentState;
28
29 // Parameters of the negotiation
30 // private UtilitySpace utilitySpace;
31 // private Timeline timeline;
32 private List<Objective> objectives;
33
34 // Other private fields
35 private Bid currentBid = null;
36 private Bid nextBid = null;
37 // private double concessionFactor = 1;
38 // private int totalBids = 1;
39
40 private BestBids bestBids;
41 private BayesLogic bayesLogic;
42
43 private double lRng = 0.9, rRng = 1.0;
44
45 @Override
46 public void init(NegotiationInfo info) {
47 super.init(info);
48 // Set agent's game parameters
49 // this.utilitySpace = utilitySpace;
50 // this.timeline = timeline;
51 this.objectives = utilitySpace.getDomain().getObjectives();
52
53 try {
54 this.bestBids = new BestBids(
55 (AdditiveUtilitySpace) this.utilitySpace);
56 } catch (Exception e) {
57 e.printStackTrace();
58 }
59
60 agentState = AgentState.HARDLINER;
61
62 // Print stuff for the benefit of our understanding
63 // System.out.println("Discount factor: " +
64 // utilitySpace.getDiscountFactor());
65 // for(int i = 1; i < objectives.size(); ++i)
66 // {
67 // System.out.println("(Name, Type, Weight): (" +
68 // objectives.get(i).getName() + ", " + objectives.get(i).getType() +
69 // ", "+ utilitySpace.getWeight(i) + ")");
70 // }
71 //
72 // System.out.println("Disagreement point (Discounted): " +
73 // utilitySpace.getReservationValueWithDiscount(timeline));
74 // System.out.println("Disagreement point (Undiscounted): " +
75 // utilitySpace.getReservationValueUndiscounted());
76 // System.out.println("Discount factor: " +
77 // utilitySpace.getDiscountFactor());
78 // System.out.println("Number of possible bids: " +
79 // domain.getNumberOfPossibleBids());
80 }
81
82 /**
83 * Each round this method gets called and ask you to accept or offer. The
84 * first party in the first round is a bit different, it can only propose an
85 * offer.
86 *
87 * @param validActions
88 * Either a list containing both accept and offer or only offer.
89 * @return The chosen action.
90 */
91 @Override
92 public Action chooseAction(List<Class<? extends Action>> validActions) {
93 // ++totalBids;
94 try {
95 setState();
96 updateBayes();
97 System.out.println(currentBid);
98 if (currentBid == null) {
99 nextBid = utilitySpace.getMaxUtilityBid();
100 } else {
101 // setState();
102 lRng = getConcessionUtility();
103 Bid bestBid = bestBids.getRandomBid(generateRandomBid(), rand,
104 lRng, rRng);
105 double CU = utilitySpace.getUtility(currentBid);
106 System.out.format("%6.4f < %6.4f < %6.4f\n", lRng,
107 utilitySpace.getUtility(bestBid), rRng);
108 switch (agentState) {
109 case HARDLINER:
110 // System.out.println("HARDLINER");
111 nextBid = bestBid;
112 break;
113 default:
114 // System.out.println("CONCEDER");
115 Bid bayes;
116 double U1;
117 do {
118 bayes = bayesLogic
119 .bayesBid(utilitySpace.getMaxUtilityBid());
120 U1 = utilitySpace.getUtility(bayes);
121 // System.out.format("V: %3d U: %6.4f\n", bayesLogic.V,
122 // U1);
123 bayesLogic.V++;
124 } while (U1 < lRng);
125 bayesLogic.V = 1;
126 // bayes = bayesLogic.bayesBid2(rand);
127 // U1 = utilitySpace.getUtility(bayes);
128 // System.out.format("Bayes: %6.4f | Proposed: %6.4f\n",
129 // U1,CU);
130 nextBid = bayes;
131 }
132 // bayesLogic.updateOpponentFrequency(bestBid, 0);
133 if (utilitySpace.getUtility(currentBid) >= lRng)
134 return new Accept(getPartyId(), currentBid);
135 }
136 } catch (Exception e) {
137 e.printStackTrace();
138 }
139 // Print the total utility of the bid we are making and submit it
140 System.out.println("Proposing bid with utility: "
141 + utilitySpace.getUtilityWithDiscount(nextBid, timeline));
142 return new Offer(getPartyId(), nextBid);
143 }
144
145 private void updateBayes() throws Exception {
146 if (bayesLogic == null) {
147 this.bayesLogic = new BayesLogic(
148 (AdditiveUtilitySpace) this.utilitySpace,
149 this.getNumberOfParties());
150 }
151 bayesLogic.T = (int) (getTimeLine().getTime() * 100);
152 System.out.format("T: %d\n", bayesLogic.T);
153 }
154
155 /**
156 * All offers proposed by the other parties will be received as a message.
157 * You can use this information to your advantage, for example to predict
158 * their utility.
159 *
160 * @param sender
161 * The party that did the action.
162 * @param action
163 * The action that party did.
164 */
165 @Override
166 public void receiveMessage(AgentID sender, Action action) {
167 super.receiveMessage(sender, action);
168 if (!players.contains(sender)) {
169 players.add(sender);
170 }
171 int P = players.indexOf(sender);
172 if (DefaultAction.getBidFromAction(action) != null)
173 currentBid = DefaultAction.getBidFromAction(action);
174 try {
175 if (currentBid != null) {
176 updateBayes();
177 bayesLogic.updateOpponentFrequency(currentBid, P);
178 }
179 } catch (Exception e) {
180 e.printStackTrace();
181 }
182 }
183
184 ArrayList<Object> players = new ArrayList<Object>();
185
186 // A dumb function that just sets a scalar concession factor based on the
187 // current time
188 private double getConcessionUtility() throws Exception {
189 double Bj = utilitySpace.getUtility(utilitySpace.getMaxUtilityBid());
190 double Cj = Bj * timeline.getTime() * timeline.getTime();
191 double Uj = Bj - (Cj / objectives.size());
192 // System.out.println("Max : "+Bj+"Cj "+Cj+" time:
193 // "+timeline.getTime()+"Bound:"+Uj);
194 return Uj * Uj;
195 }
196
197 // Logic to decide the next bid
198 // private void decideNextBid() throws Exception {
199 // switch(agentState) {
200 // case HARDLINER:
201 // System.out.println("MaxRand");
202 // nextBid = bestBids.getRandomBid(generateRandomBid(), rand, 0.8, 1.);
203 // break;
204 // case CONCEDER:
205 // System.out.println("Bayes");
206 // nextBid = bayesLogic.bayesBid(utilitySpace.getMaxUtilityBid());
207 // }
208 // }
209
210 private void setState() {
211 if (timeline.getTime() >= .2) {
212 agentState = AgentState.CONCEDER;
213 }
214 }
215
216 @Override
217 public String getDescription() {
218 return "ANAC2015";
219 }
220}
Note: See TracBrowser for help on using the repository browser.