source: src/main/java/agents/anac/y2014/BraveCat/necessaryClasses/BOAagent.java@ 1

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

Initial import : Genius 9.0.0

File size: 5.2 KB
Line 
1package agents.anac.y2014.BraveCat.necessaryClasses;
2
3import java.io.Serializable;
4import java.util.ArrayList;
5
6import agents.anac.y2014.BraveCat.AcceptanceStrategies.AcceptanceStrategy;
7import agents.anac.y2014.BraveCat.OfferingStrategies.OfferingStrategy;
8import agents.anac.y2014.BraveCat.OpponentModelStrategies.OMStrategy;
9import agents.anac.y2014.BraveCat.OpponentModels.NoModel;
10import agents.anac.y2014.BraveCat.OpponentModels.OpponentModel;
11import genius.core.Agent;
12import genius.core.Bid;
13import genius.core.NegotiationResult;
14import genius.core.actions.Accept;
15import genius.core.actions.Action;
16import genius.core.actions.EndNegotiation;
17import genius.core.actions.Offer;
18import genius.core.bidding.BidDetails;
19import genius.core.boaframework.Actions;
20import genius.core.boaframework.OutcomeSpace;
21import genius.core.boaframework.SessionData;
22import genius.core.misc.Pair;
23
24public abstract class BOAagent extends Agent {
25 // Added variables.
26 public int numberOfReceivedBids = 0;
27 public int numberOfEvaluatedBids = 0;
28
29 protected AcceptanceStrategy acceptConditions;
30 protected OfferingStrategy offeringStrategy;
31 protected OpponentModel opponentModel;
32 public NegotiationSession negotiationSession;
33 protected OMStrategy omStrategy;
34 public ArrayList<Pair<Bid, String>> savedOutcomes;
35 protected OutcomeSpace outcomeSpace;
36 private Bid oppBid;
37
38 @Override
39 public void init() {
40 super.init();
41 Serializable storedData = loadSessionData();
42 SessionData sessionData;
43 if (storedData == null)
44 sessionData = new SessionData();
45 else {
46 sessionData = (SessionData) storedData;
47 }
48 this.negotiationSession = new NegotiationSession(sessionData,
49 this.utilitySpace, this.timeline);
50 agentSetup();
51 }
52
53 public abstract void agentSetup();
54
55 public void setDecoupledComponents(AcceptanceStrategy ac,
56 OfferingStrategy os, OpponentModel om, OMStrategy oms) {
57 this.acceptConditions = ac;
58 this.offeringStrategy = os;
59 this.opponentModel = om;
60 this.omStrategy = oms;
61 }
62
63 @Override
64 public abstract String getName();
65
66 @Override
67 public void ReceiveMessage(Action opponentAction) {
68 if ((opponentAction instanceof Offer)) {
69 numberOfReceivedBids++;
70 oppBid = ((Offer) opponentAction).getBid();
71 try {
72 BidDetails opponentBid = new BidDetails(oppBid,
73 this.negotiationSession.getUtilitySpace().getUtility(
74 oppBid), this.negotiationSession.getTime());
75 this.negotiationSession.getOpponentBidHistory()
76 .add(opponentBid);
77 } catch (Exception e) {
78 }
79
80 if ((this.opponentModel != null)
81 && (!(this.opponentModel instanceof NoModel)))
82 if (this.omStrategy.canUpdateOM()) {
83 this.opponentModel.updateModel(oppBid);
84 } else if (!this.opponentModel.isCleared())
85 this.opponentModel.cleanUp();
86 }
87 }
88
89 @Override
90 public Action chooseAction() {
91 BidDetails bid = null;
92 if (this.negotiationSession.getOwnBidHistory().getHistory().isEmpty()) {
93 bid = this.offeringStrategy.determineOpeningBid();
94 } else {
95 try {
96 bid = this.offeringStrategy.determineNextBid();
97 } catch (Exception ex) {
98 System.out
99 .println("Exception occured while determining the next bid in the chooseAction function!");
100 }
101 if (this.offeringStrategy.isEndNegotiation()) {
102 return new EndNegotiation(getAgentID());
103 }
104
105 }
106
107 if (bid == null) {
108 System.out.println("Error in code, null bid was given");
109 return new Accept(getAgentID(), oppBid);
110 }
111 this.offeringStrategy.setNextBid(bid);
112
113 Actions decision = Actions.Reject;
114 if (!this.negotiationSession.getOpponentBidHistory().getHistory()
115 .isEmpty()) {
116 decision = this.acceptConditions.determineAcceptability();
117 }
118
119 if (decision.equals(Actions.Break)) {
120 System.out.println("send EndNegotiation");
121 return new EndNegotiation(getAgentID());
122 }
123
124 if (decision.equals(Actions.Reject)) {
125 try {
126 this.negotiationSession.getOwnBidHistory().add(
127 new BidDetails(bid.getBid(), this.negotiationSession
128 .getUtilitySpace().getUtility(bid.getBid()),
129 this.negotiationSession.getTime()));
130 } catch (Exception ex) {
131 }
132 return new Offer(getAgentID(), bid.getBid());
133 }
134 return new Accept(getAgentID(), oppBid);
135 }
136
137 public OfferingStrategy getOfferingStrategy() {
138 return this.offeringStrategy;
139 }
140
141 public OpponentModel getOpponentModel() {
142 return this.opponentModel;
143 }
144
145 public AcceptanceStrategy getAcceptanceStrategy() {
146 return this.acceptConditions;
147 }
148
149 @Override
150 public void endSession(NegotiationResult result) {
151 this.offeringStrategy.endSession(result);
152 this.acceptConditions.endSession(result);
153 this.opponentModel.endSession(result);
154 SessionData savedData = this.negotiationSession.getSessionData();
155 if ((!savedData.isEmpty()) && (savedData.isChanged())) {
156 savedData.changesCommitted();
157 saveSessionData(savedData);
158 }
159 }
160
161 public void cleanUp() {
162 this.offeringStrategy = null;
163 this.acceptConditions = null;
164 this.omStrategy = null;
165 this.opponentModel = null;
166 this.outcomeSpace = null;
167 this.negotiationSession = null;
168 }
169
170 public NegotiationSession ReturnnegotiationSession() {
171 return this.negotiationSession;
172 }
173}
Note: See TracBrowser for help on using the repository browser.