1 | package negotiator.boaframework.opponentmodel;
|
---|
2 |
|
---|
3 | import java.util.HashSet;
|
---|
4 | import java.util.Map;
|
---|
5 | import java.util.Set;
|
---|
6 |
|
---|
7 | import agents.bayesianopponentmodel.BayesianOpponentModel;
|
---|
8 | import agents.bayesianopponentmodel.OpponentModelUtilSpace;
|
---|
9 | import genius.core.Bid;
|
---|
10 | import genius.core.boaframework.BOAparameter;
|
---|
11 | import genius.core.boaframework.NegotiationSession;
|
---|
12 | import genius.core.boaframework.OpponentModel;
|
---|
13 | import genius.core.issue.Issue;
|
---|
14 | import genius.core.issue.ValueDiscrete;
|
---|
15 | import genius.core.utility.AdditiveUtilitySpace;
|
---|
16 |
|
---|
17 | /**
|
---|
18 | * Adapter for BayesianModel. Note that this model only works on small domains.
|
---|
19 | *
|
---|
20 | * Adapted by Mark Hendrikx to be compatible with the BOA framework.
|
---|
21 | *
|
---|
22 | * Tim Baarslag, Koen Hindriks, Mark Hendrikx, Alex Dirkzwager and Catholijn M.
|
---|
23 | * Jonker. Decoupling Negotiating Agents to Explore the Space of Negotiation
|
---|
24 | * Strategies
|
---|
25 | *
|
---|
26 | * @author Mark Hendrikx
|
---|
27 | */
|
---|
28 | public class BayesianModel extends OpponentModel {
|
---|
29 |
|
---|
30 | /** Reference to the normal Bayesian Opponent Model */
|
---|
31 | private BayesianOpponentModel model;
|
---|
32 | /** Index of the first issue weight */
|
---|
33 | private int startingBidIssue = 0;
|
---|
34 |
|
---|
35 | /**
|
---|
36 | * Initializes the opponent model. If the parameter m is set to a value
|
---|
37 | * greater than zero, only the best hypothesis about the opponent's utility
|
---|
38 | * space is used.
|
---|
39 | */
|
---|
40 | @Override
|
---|
41 | public void init(NegotiationSession negotiationSession, Map<String, Double> parameters) {
|
---|
42 | this.negotiationSession = negotiationSession;
|
---|
43 | model = new BayesianOpponentModel((AdditiveUtilitySpace) negotiationSession.getUtilitySpace());
|
---|
44 | if (parameters.get("m") != null) {
|
---|
45 | model.setMostProbableUSHypsOnly(parameters.get("m") > 0);
|
---|
46 | } else {
|
---|
47 | model.setMostProbableUSHypsOnly(false);
|
---|
48 | System.out.println("Constant \"m\" was not set. Assumed default value.");
|
---|
49 | }
|
---|
50 | while (!testIndexOfFirstIssue(negotiationSession.getUtilitySpace().getDomain().getRandomBid(null),
|
---|
51 | startingBidIssue)) {
|
---|
52 | startingBidIssue++;
|
---|
53 | }
|
---|
54 | }
|
---|
55 |
|
---|
56 | /**
|
---|
57 | * Just an auxiliar funtion to calculate the index where issues start on a
|
---|
58 | * bid because we found out that it depends on the domain.
|
---|
59 | *
|
---|
60 | * @return true when the received index is the proper index
|
---|
61 | */
|
---|
62 | private boolean testIndexOfFirstIssue(Bid bid, int i) {
|
---|
63 | try {
|
---|
64 | @SuppressWarnings("unused")
|
---|
65 | ValueDiscrete valueOfIssue = (ValueDiscrete) bid.getValue(i);
|
---|
66 | } catch (Exception e) {
|
---|
67 | return false;
|
---|
68 | }
|
---|
69 | return true;
|
---|
70 | }
|
---|
71 |
|
---|
72 | /**
|
---|
73 | * Update the opponent model by updating all hypotheses about the opponent's
|
---|
74 | * preference profile.
|
---|
75 | *
|
---|
76 | * @param opponentBid
|
---|
77 | * @param time
|
---|
78 | * of offering
|
---|
79 | */
|
---|
80 | @Override
|
---|
81 | public void updateModel(Bid opponentBid, double time) {
|
---|
82 | try {
|
---|
83 | model.updateBeliefs(opponentBid);
|
---|
84 | } catch (Exception e) {
|
---|
85 | e.printStackTrace();
|
---|
86 | }
|
---|
87 | }
|
---|
88 |
|
---|
89 | @Override
|
---|
90 | public double getBidEvaluation(Bid bid) {
|
---|
91 | try {
|
---|
92 | return model.getNormalizedUtility(bid);
|
---|
93 | } catch (Exception e) {
|
---|
94 | e.printStackTrace();
|
---|
95 | }
|
---|
96 | return 0;
|
---|
97 | }
|
---|
98 |
|
---|
99 | /**
|
---|
100 | * @return estimated issue weight of the given issue.
|
---|
101 | */
|
---|
102 | public double getWeight(Issue issue) {
|
---|
103 | return model.getNormalizedWeight(issue, startingBidIssue);
|
---|
104 | }
|
---|
105 |
|
---|
106 | /**
|
---|
107 | * @return utilityspace created by using the opponent model adapter.
|
---|
108 | */
|
---|
109 | @Override
|
---|
110 | public AdditiveUtilitySpace getOpponentUtilitySpace() {
|
---|
111 | return new OpponentModelUtilSpace(model);
|
---|
112 | }
|
---|
113 |
|
---|
114 | public void cleanUp() {
|
---|
115 | super.cleanUp();
|
---|
116 | }
|
---|
117 |
|
---|
118 | @Override
|
---|
119 | public String getName() {
|
---|
120 | return "Bayesian Model";
|
---|
121 | }
|
---|
122 |
|
---|
123 | @Override
|
---|
124 | public Set<BOAparameter> getParameterSpec() {
|
---|
125 | Set<BOAparameter> set = new HashSet<BOAparameter>();
|
---|
126 | set.add(new BOAparameter("m", 0.0, "If higher than 0 the most probable hypothesis is only used"));
|
---|
127 | return set;
|
---|
128 | }
|
---|
129 | } |
---|