1 | package negotiator.boaframework.opponentmodel;
|
---|
2 |
|
---|
3 | import java.util.ArrayList;
|
---|
4 | import java.util.Map;
|
---|
5 |
|
---|
6 | import genius.core.Bid;
|
---|
7 | import genius.core.boaframework.NegotiationSession;
|
---|
8 | import genius.core.boaframework.OpponentModel;
|
---|
9 | import genius.core.issue.Issue;
|
---|
10 | import genius.core.issue.IssueDiscrete;
|
---|
11 | import genius.core.issue.Value;
|
---|
12 | import genius.core.issue.ValueDiscrete;
|
---|
13 | import genius.core.utility.AdditiveUtilitySpace;
|
---|
14 | import negotiator.boaframework.opponentmodel.agentx.DiscreteIssueProcessor;
|
---|
15 | import negotiator.boaframework.opponentmodel.agentx.DiscreteValueProcessor;
|
---|
16 | import negotiator.boaframework.opponentmodel.tools.UtilitySpaceAdapter;
|
---|
17 |
|
---|
18 | /**
|
---|
19 | * Class for building an opponent model in discrete space. Contains value- and
|
---|
20 | * issue-processors to deal with opponent bids.
|
---|
21 | *
|
---|
22 | * Adapted by Mark Hendrikx to be compatible with the BOA framework.
|
---|
23 | *
|
---|
24 | * Tim Baarslag, Koen Hindriks, Mark Hendrikx, Alex Dirkzwager and Catholijn M.
|
---|
25 | * Jonker. Decoupling Negotiating Agents to Explore the Space of Negotiation
|
---|
26 | * Strategies
|
---|
27 | *
|
---|
28 | * @author E. Jacobs, Mark Hendrikx
|
---|
29 | */
|
---|
30 | public class AgentXFrequencyModel extends OpponentModel {
|
---|
31 |
|
---|
32 | private DiscreteIssueProcessor issueProcessor;
|
---|
33 | private ArrayList<IssueDiscrete> discreteIssueList = new ArrayList<IssueDiscrete>();
|
---|
34 | private ArrayList<DiscreteValueProcessor> valueProcessList = new ArrayList<DiscreteValueProcessor>();
|
---|
35 | private int startingBidIssue = 0;
|
---|
36 |
|
---|
37 | /**
|
---|
38 | * Creates an opponent model for the given utility space
|
---|
39 | *
|
---|
40 | * @param u
|
---|
41 | * The utility space
|
---|
42 | */
|
---|
43 | @Override
|
---|
44 | public void init(NegotiationSession negotiationSession, Map<String, Double> parameters) {
|
---|
45 | this.negotiationSession = negotiationSession;
|
---|
46 | issueProcessor = new DiscreteIssueProcessor(negotiationSession.getUtilitySpace().getDomain());
|
---|
47 | discreteIssueList = issueProcessor.getIssueList();
|
---|
48 | createValueProcessors();
|
---|
49 | while (!testIndexOfFirstIssue(negotiationSession.getUtilitySpace().getDomain().getRandomBid(null),
|
---|
50 | startingBidIssue)) {
|
---|
51 | startingBidIssue++;
|
---|
52 | }
|
---|
53 | }
|
---|
54 |
|
---|
55 | /**
|
---|
56 | * Just an auxiliar funtion to calculate the index where issues start on a
|
---|
57 | * bid because we found out that it depends on the domain.
|
---|
58 | *
|
---|
59 | * @return true when the received index is the proper index
|
---|
60 | */
|
---|
61 | private boolean testIndexOfFirstIssue(Bid bid, int i) {
|
---|
62 | try {
|
---|
63 | @SuppressWarnings("unused")
|
---|
64 | ValueDiscrete valueOfIssue = (ValueDiscrete) bid.getValue(i);
|
---|
65 | } catch (Exception e) {
|
---|
66 | return false;
|
---|
67 | }
|
---|
68 | return true;
|
---|
69 | }
|
---|
70 |
|
---|
71 | /**
|
---|
72 | * Creates discreteValueProcessors for all issues
|
---|
73 | */
|
---|
74 | private void createValueProcessors() {
|
---|
75 |
|
---|
76 | for (IssueDiscrete i : discreteIssueList) {
|
---|
77 | valueProcessList.add(new DiscreteValueProcessor(i.getValues()));
|
---|
78 | }
|
---|
79 | }
|
---|
80 |
|
---|
81 | /**
|
---|
82 | * Returns a DiscreteValueProcessor, allowing the use of several methods
|
---|
83 | *
|
---|
84 | * @param i
|
---|
85 | * The issue for which a ValueProcessor is needed
|
---|
86 | * @return a DiscreteValueProcessor for the issue
|
---|
87 | */
|
---|
88 | public DiscreteValueProcessor getValueProcessor(IssueDiscrete i) {
|
---|
89 |
|
---|
90 | int index = discreteIssueList.indexOf(i);
|
---|
91 |
|
---|
92 | if (index != -1)
|
---|
93 | return valueProcessList.get(index);
|
---|
94 |
|
---|
95 | return null;
|
---|
96 |
|
---|
97 | }
|
---|
98 |
|
---|
99 | /**
|
---|
100 | * Gives the discreteIssueProcessor for this opponent model
|
---|
101 | *
|
---|
102 | * @return The discreteIssueProcessor
|
---|
103 | */
|
---|
104 | public DiscreteIssueProcessor getIssueProcessor() {
|
---|
105 | return issueProcessor;
|
---|
106 | }
|
---|
107 |
|
---|
108 | /**
|
---|
109 | * Processes a bid, possibly changing value ranks for the internal opponent
|
---|
110 | * model. Currently, values on which more bids are made are ranked higher.
|
---|
111 | *
|
---|
112 | * @param b
|
---|
113 | * The bid done by the opponent
|
---|
114 | * @param time
|
---|
115 | * Time at which the bid was done
|
---|
116 | */
|
---|
117 | public void updateModel(Bid b, double time) {
|
---|
118 |
|
---|
119 | issueProcessor.adaptWeightsByBid(b, time);
|
---|
120 | for (IssueDiscrete i : discreteIssueList) {
|
---|
121 | Value v = null;
|
---|
122 |
|
---|
123 | try {
|
---|
124 | v = b.getValue(i.getNumber());
|
---|
125 | } catch (Exception e) {
|
---|
126 | }
|
---|
127 |
|
---|
128 | if (v != null) {
|
---|
129 | ValueDiscrete vDisc = (ValueDiscrete) v;
|
---|
130 | getValueProcessor(i).addBidForValue(vDisc);
|
---|
131 | }
|
---|
132 | }
|
---|
133 | }
|
---|
134 |
|
---|
135 | /**
|
---|
136 | * Gives the normalized value rank of some value within a certain Issue
|
---|
137 | *
|
---|
138 | * @param issueIndex
|
---|
139 | * The index of the issue. Same index as in the ArrayList
|
---|
140 | * provided by utilitySpace.getDomain().getIssues()
|
---|
141 | * @param valueOfIssue
|
---|
142 | * The value from that issue for which the normalized rank is
|
---|
143 | * required
|
---|
144 | * @return The normalized valueRank for the value of the issue given
|
---|
145 | */
|
---|
146 | public double getEvaluationOfValue(int issueIndex, ValueDiscrete valueOfIssue) {
|
---|
147 | return valueProcessList.get(issueIndex).getNormalizedValueRank(valueOfIssue);
|
---|
148 | }
|
---|
149 |
|
---|
150 | /**
|
---|
151 | * Calculates the utility to our opponent of the bid received as a parameter
|
---|
152 | * using the current knowledge given by our opponent model
|
---|
153 | *
|
---|
154 | * @param bid
|
---|
155 | * @return utility value for our opponent
|
---|
156 | */
|
---|
157 | public double getBidEvaluation(Bid bid) {
|
---|
158 |
|
---|
159 | double utility = 0;
|
---|
160 |
|
---|
161 | // Taking into account that Opponent Issue list is in the same our of
|
---|
162 | // the domain
|
---|
163 | int nrIssues = negotiationSession.getUtilitySpace().getDomain().getIssues().size();
|
---|
164 |
|
---|
165 | for (int i = 0; i < nrIssues; i++) {
|
---|
166 | try {
|
---|
167 | // It was needed to use an auxiliar variable startingBidIssue,
|
---|
168 | // because we found out it varies from domain to domain
|
---|
169 | ValueDiscrete valueOfIssue = (ValueDiscrete) bid.getValue(i + startingBidIssue);
|
---|
170 | double w = getIssueProcessor().getWeightByIssue(
|
---|
171 | (IssueDiscrete) negotiationSession.getUtilitySpace().getDomain().getIssues().get(i));
|
---|
172 | double eval = getEvaluationOfValue(i, valueOfIssue);
|
---|
173 |
|
---|
174 | utility += w * eval;
|
---|
175 |
|
---|
176 | } catch (Exception e) {
|
---|
177 | // e.printStackTrace();
|
---|
178 | }
|
---|
179 | }
|
---|
180 |
|
---|
181 | return utility;
|
---|
182 | }
|
---|
183 |
|
---|
184 | /**
|
---|
185 | * @return the weight of the issue.
|
---|
186 | */
|
---|
187 | public double getWeight(Issue issue) {
|
---|
188 | return getIssueProcessor().getWeightByIssue((IssueDiscrete) issue);
|
---|
189 | }
|
---|
190 |
|
---|
191 | /**
|
---|
192 | * @return utilityspace created by using the opponent model adapter.
|
---|
193 | */
|
---|
194 | public AdditiveUtilitySpace getOpponentUtilitySpace() {
|
---|
195 | return new UtilitySpaceAdapter(this, negotiationSession.getUtilitySpace().getDomain());
|
---|
196 | }
|
---|
197 |
|
---|
198 | public String getName() {
|
---|
199 | return "AgentX Frequency Model";
|
---|
200 | }
|
---|
201 | } |
---|