source: src/main/java/negotiator/boaframework/opponentmodel/BayesianModel.java@ 346

Last change on this file since 346 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: 3.7 KB
Line 
1package negotiator.boaframework.opponentmodel;
2
3import java.util.HashSet;
4import java.util.Map;
5import java.util.Set;
6
7import agents.bayesianopponentmodel.BayesianOpponentModel;
8import agents.bayesianopponentmodel.OpponentModelUtilSpace;
9import genius.core.Bid;
10import genius.core.boaframework.BOAparameter;
11import genius.core.boaframework.NegotiationSession;
12import genius.core.boaframework.OpponentModel;
13import genius.core.issue.Issue;
14import genius.core.issue.ValueDiscrete;
15import 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 */
28public 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}
Note: See TracBrowser for help on using the repository browser.