source: src/main/java/genius/core/boaframework/OpponentModel.java

Last change on this file 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: 4.3 KB
Line 
1package genius.core.boaframework;
2
3import java.io.Serializable;
4import java.util.List;
5import java.util.Map;
6
7import genius.core.Bid;
8import genius.core.issue.Issue;
9import genius.core.protocol.BilateralAtomicNegotiationSession;
10import genius.core.utility.AbstractUtilitySpace;
11import genius.core.utility.AdditiveUtilitySpace;
12
13/**
14 * Describes an opponent model of an agent of the BOA framework. This model
15 * assumes issue weights hence only supports {@link AdditiveUtilitySpace}. Also
16 * notice that most implementations are assuming bi-lateral negotiation (2
17 * parties).
18 *
19 * paper: https://ii.tudelft.nl/sites/default/files/boa.pdf
20 *
21 */
22public abstract class OpponentModel extends BOA {
23
24 /** Reference to the estimated opponent's utility state */
25 protected AdditiveUtilitySpace opponentUtilitySpace;
26 /** Boolean to indicate that the model has been cleared to free resources */
27 private boolean cleared;
28
29 /**
30 * Initializes the model. The init method should always be called after
31 * creating an opponent model.
32 *
33 * @param negotiationSession
34 * reference to the state of the negotiation
35 * @param parameters
36 * @throws Exception
37 */
38 @Override
39 public void init(NegotiationSession negotiationSession,
40 Map<String, Double> parameters) {
41 super.init(negotiationSession, parameters);
42 opponentUtilitySpace = (AdditiveUtilitySpace) negotiationSession
43 .getUtilitySpace().copy();
44 cleared = false;
45 }
46
47 /**
48 * Called to inform about a new {@link Bid} done by the opponent.
49 *
50 * @param opponentBid
51 * the bid received from the opponent
52 */
53 public void updateModel(Bid opponentBid) {
54 updateModel(opponentBid, negotiationSession.getTime());
55 }
56
57 /**
58 * As {@link #updateModel(Bid)} but with the current time added.
59 */
60 protected abstract void updateModel(Bid bid, double time);
61
62 /**
63 * Support function. Determines the utility of a bid according to the
64 * preference profile.
65 *
66 * @param bid
67 * of which the utility is calculated.
68 * @return Utility of the bid
69 */
70 public double getBidEvaluation(Bid bid) {
71 try {
72 return opponentUtilitySpace.getUtility(bid);
73 } catch (Exception e) {
74 e.printStackTrace();
75 }
76 return -1;
77 }
78
79 /**
80 * @return the estimated utility space of the opponent
81 */
82 public AbstractUtilitySpace getOpponentUtilitySpace() {
83 return opponentUtilitySpace;
84 }
85
86 /**
87 * Method which may be overwritten by an opponent model to get access to the
88 * opponent's utilityspace.
89 *
90 * @param fNegotiation
91 */
92 public void setOpponentUtilitySpace(
93 BilateralAtomicNegotiationSession fNegotiation) {
94 }
95
96 /**
97 * Method which may be overwritten by an opponent model to get access to the
98 * opponent's utilityspace.
99 *
100 * @param opponentUtilitySpace
101 */
102 public void setOpponentUtilitySpace(
103 AdditiveUtilitySpace opponentUtilitySpace) {
104 }
105
106 /**
107 * Returns the weight of a particular issue in the domain. Only works with
108 * {@link AdditiveUtilitySpace}.
109 *
110 * @param issue
111 * from which the weight should be returned
112 * @return weight of the given issue
113 */
114 public double getWeight(Issue issue) {
115 return opponentUtilitySpace.getWeight(issue.getNumber());
116 }
117
118 /**
119 * @return set of all estimated issue weights.
120 */
121 public double[] getIssueWeights() {
122 List<Issue> issues = negotiationSession.getUtilitySpace().getDomain()
123 .getIssues();
124 double estimatedIssueWeights[] = new double[issues.size()];
125 int i = 0;
126 for (Issue issue : issues) {
127 estimatedIssueWeights[i] = getWeight(issue);
128 i++;
129 }
130 return estimatedIssueWeights;
131 }
132
133 /**
134 * Removes references to the objects used by the opponent model.
135 */
136 public void cleanUp() {
137 negotiationSession = null;
138 cleared = true;
139 }
140
141 /**
142 * @return if the opponent model is in a usable state.
143 */
144 public boolean isCleared() {
145 return cleared;
146 }
147
148 /**
149 * @return name of the opponent model.
150 */
151 @Override
152 public String getName() {
153 return "Default";
154 }
155
156 @Override
157 public final void storeData(Serializable object) {
158 negotiationSession.setData(BoaType.OPPONENTMODEL, object);
159 }
160
161 @Override
162 public final Serializable loadData() {
163 return negotiationSession.getData(BoaType.OPPONENTMODEL);
164 }
165
166}
Note: See TracBrowser for help on using the repository browser.