source: src/main/java/agents/BayesianAgentForAuctionMultiPhase.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.1 KB
Line 
1package agents;
2
3import genius.core.AgentParam;
4import genius.core.Bid;
5import genius.core.actions.Accept;
6import genius.core.actions.Action;
7import genius.core.actions.EndNegotiation;
8import genius.core.actions.Offer;
9import genius.core.tournament.VariablesAndValues.AgentParameterVariable;
10
11public class BayesianAgentForAuctionMultiPhase extends BayesianAgentForAuction {
12 protected Bid myProviderLastBid;
13 protected double centerMaxOffer = 0;
14
15 @Override
16 protected Action proposeInitialBid() throws Exception {
17 Bid lBid = null;
18 switch (fRole) {
19 case CENTER:
20 switch (fPhase) {
21 case FIRST_PHASE:
22 CONCESSIONFACTOR = 0.07;
23 lBid = getMaxUtilityBid();
24 break;
25 case SECOND_PHASE:
26 CONCESSIONFACTOR = 0.0;
27 if (fOpponentPreviousBid == null) {
28 // double lSecondBest = getParameterValues().get(new
29 // AgentParameterVariable(new
30 // AgentParam(BayesianAgentForAuction.class.getName(),"starting_utility",0.,1.))).getValue();
31 lBid = getMaxUtilityBid();
32 } else
33 return new Accept(getAgentID(), fOpponentPreviousBid);
34 }
35 break;
36 case PROVIDER:
37 switch (fPhase) {
38 case FIRST_PHASE:
39 lBid = getMaxUtilityBid();
40 break;
41 case SECOND_PHASE:
42 // lBid = getMaxUtilityBid();
43 double lSecondBest = getParameterValues().get(
44 new AgentParameterVariable(new AgentParam(
45 BayesianAgentForAuction.class.getName(),
46 "starting_utility", 0., 1.))).getValue();
47 lBid = getTradeOff(lSecondBest);
48 myProviderLastBid = lBid;
49 if (lBid == null)
50 return new EndNegotiation(getAgentID());
51 break;
52 }
53 break;
54 }
55 // Return (one of the) possible bid(s) with maximal utility.
56 fSmartSteps = NUMBER_OF_SMART_STEPS;
57 myLastBid = lBid;
58 return new Offer(getAgentID(), lBid);
59 }
60
61 @Override
62 public Action chooseAction() {
63 // if((fOpponentPreviousBid!=null)&&(fRole == ROLE.CENTER)&&(fPhase ==
64 // PHASE.SECOND_PHASE)) return new Accept(this);
65 Action lAction = null;
66 ACTIONTYPE lActionType;
67 Bid lOppntBid = null;
68
69 try {
70 lActionType = getActionType(messageOpponent);
71 switch (lActionType) {
72 case OFFER: // Offer received from opponent
73 lOppntBid = ((Offer) messageOpponent).getBid();
74 // if (fOpponentModel.haveSeenBefore(lOppntBid)) {
75 // lAction=myLastAction; break; }
76 // double lDistance = calculateEuclideanDistanceUtilitySpace();
77 // if(myLastAction==null) dumpDistancesToLog(0);
78 System.out.print("Updating beliefs ...");
79 if (myPreviousBids.size() < 8)
80 fOpponentModel.updateBeliefs(lOppntBid);
81 // dumpDistancesToLog(fRound++);
82 System.out.println("Done!");
83 if (fRole == ROLE.CENTER) {
84 if (utilitySpace.getUtility(lOppntBid) > centerMaxOffer) {
85 centerMaxOffer = utilitySpace.getUtility(lOppntBid);
86 if (fPhase == PHASE.SECOND_PHASE)
87 return new Accept(getAgentID(), lOppntBid);
88 }
89 }
90 if (myLastAction == null)
91 // Other agent started, lets propose my initial bid.
92 lAction = proposeInitialBid();
93 else {
94 // log("time="+time+" offeredutil="+offeredutil+" accept probability P="+P);
95 if (utilitySpace.getUtility(lOppntBid) * 1.05 >= utilitySpace
96 .getUtility(myLastBid)
97 /* || .05*P>Math.random() */) {
98 // Opponent bids equally, or outbids my previous bid, so
99 // lets accept
100 lAction = new Accept(getAgentID(), lOppntBid);
101 // log("randomly accepted");
102 } else {
103 Bid lnextBid = proposeNextBid(lOppntBid);
104 if (lnextBid == null) {
105 lAction = new EndNegotiation(getAgentID());
106 } else {
107
108 lAction = new Offer(getAgentID(), lnextBid);
109
110 myProviderLastBid = lnextBid;
111 // Propose counteroffer. Get next bid.
112 // Check if utility of the new bid is lower than
113 // utility of the opponent's last bid
114 // if yes then accept last bid of the opponent.
115 if (utilitySpace.getUtility(lOppntBid) * 1.05 >= utilitySpace
116 .getUtility(lnextBid)) {
117 // Opponent bids equally, or outbids my previous
118 // bid, so lets accept
119 lAction = new Accept(getAgentID(), lOppntBid);
120 // log("opponent's bid higher than util of my last bid! accepted");
121 }
122 }
123
124 }
125 // remember current bid of the opponent as its previous bid
126 fOpponentPreviousBid = lOppntBid;
127 }
128 break;
129 case ACCEPT:
130 case BREAKOFF:
131 // nothing left to do. Negotiation ended, which should be
132 // checked by
133 // Negotiator...
134 break;
135 default:
136 // I am starting, but not sure whether Negotiator checks this,
137 // so
138 // lets check also myLastAction...
139 if (myLastAction == null) {
140 // dumpDistancesToLog(fRound++);
141 lAction = proposeInitialBid();
142 } else
143 // simply repeat last action
144 lAction = myLastAction;
145 break;
146 }
147 } catch (Exception e) {
148 // log("Exception in chooseAction:"+e.getMessage());
149 e.printStackTrace();
150 lAction = new Offer(getAgentID(), myLastBid);
151 }
152 myLastAction = lAction;
153 if (myLastAction instanceof Offer) {
154 myPreviousBids.add(((Offer) myLastAction).getBid());
155 myLastBid = ((Offer) myLastAction).getBid();
156 }
157 return lAction;
158
159 }
160
161 @Override
162 protected Bid getNextBidAuction(Bid pOppntBid) throws Exception {
163 if (pOppntBid == null)
164 throw new NullPointerException("pOpptBid=null");
165 if (myLastBid == null)
166 throw new Exception("myLastBid==null");
167 // log("Get next bid ...");
168 Bid lBid = null;
169
170 switch (fRole) {
171 case CENTER:
172 switch (fPhase) {
173 case FIRST_PHASE:
174 lBid = getNextBidSmart(pOppntBid);
175 break;
176 case SECOND_PHASE:
177 // double lSecondBest = getParameterValues().get(new
178 // AgentParameterVariable(new
179 // AgentParam(BayesianAgentForAuction.class.getName(),"reservation",0.,1.))).getValue();
180 // lBid = getTradeOff(lSecondBest);
181 // return new Accept(this);
182 lBid = getNextBidSmart(pOppntBid);
183 break;
184 }
185 break;
186 case PROVIDER:
187 switch (fPhase) {
188 case FIRST_PHASE:
189 lBid = getNextBidSmart(pOppntBid);
190 break;
191 case SECOND_PHASE:
192 lBid = getNextBidSmart(pOppntBid);
193 break;
194 }
195 break;
196 }
197 return lBid;
198 }
199
200}
Note: See TracBrowser for help on using the repository browser.