source: src/main/java/negotiator/boaframework/opponentmodel/agentsmithv2/SmithModelV2.java

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

Initial import : Genius 9.0.0

File size: 2.8 KB
Line 
1package negotiator.boaframework.opponentmodel.agentsmithv2;
2
3import java.util.HashMap;
4import java.util.List;
5
6import agents.bayesianopponentmodel.OpponentModel;
7import genius.core.Bid;
8import genius.core.issue.Issue;
9import genius.core.utility.AbstractUtilitySpace;
10
11/**
12 * Highly optimized version of the Smith Frequency Model. The value weights are
13 * estimated based on frequency. The issue weights are calculated based on the
14 * distribution of the value weights.
15 *
16 * @author Mark Hendrikx
17 */
18public class SmithModelV2 extends OpponentModel {
19
20 /**
21 * Object for each issue which keeps track how many times each value was
22 * offered
23 */
24 private HashMap<Issue, IssueModel> fIssueModels;
25 /** All issues in the domain. Cached for performance reasons */
26 private List<Issue> lIssues;
27 /**
28 * Issue weights in the current iteration of the model. Cached for
29 * performance
30 */
31 private HashMap<Issue, Double> weights;
32
33 /**
34 * Creates a highly optimized version of the SmithFrequencyModel.
35 */
36 public SmithModelV2(AbstractUtilitySpace space) {
37 fIssueModels = new HashMap<Issue, IssueModel>();
38 fDomain = space.getDomain();
39 lIssues = space.getDomain().getIssues();
40 initIssueModels();
41 }
42
43 /**
44 * For each of the issues it initializes a model which stores the opponents'
45 * preferences
46 */
47 private void initIssueModels() {
48 for (Issue lIssue : lIssues) {
49 IssueModel lModel;
50 lModel = new IssueModel(lIssue);
51 fIssueModels.put(lIssue, lModel);
52 }
53 }
54
55 /**
56 * Adds the values of each issue of a bid to the preferenceprofilemanager
57 */
58 public void addBid(Bid pBid) {
59 for (Issue lIssue : lIssues) {
60 fIssueModels.get(lIssue).addValue(pBid);
61 }
62 weights = getWeights();
63 }
64
65 /**
66 * Returns a hashmap with the weights for each of the issues
67 */
68 private HashMap<Issue, Double> getWeights() {
69 HashMap<Issue, Double> lWeights = new HashMap<Issue, Double>();
70
71 for (Issue lIssue : lIssues) {
72 double weight = fIssueModels.get(lIssue).getWeight();
73 lWeights.put(lIssue, weight);
74 }
75
76 double lTotal = 0;
77 for (Issue lIssue : lIssues)
78 lTotal += lWeights.get(lIssue);
79
80 for (Issue lIssue : lIssues) {
81 lWeights.put(lIssue, lWeights.get(lIssue) / lTotal);
82 }
83 return lWeights;
84 }
85
86 public double getWeight(int issueNr) {
87 Issue foundIssue = null;
88 for (Issue issue : lIssues) {
89 if (issue.getNumber() == issueNr) {
90 foundIssue = issue;
91 break;
92 }
93 }
94 return weights.get(foundIssue);
95 }
96
97 /**
98 * Returns the utility of a bid, but instead of the normal utility it is
99 * based on the weights of each issues
100 */
101 public double getNormalizedUtility(Bid pBid) {
102 double lUtility = 0;
103
104 for (Issue lIssue : lIssues) {
105 double lWeight = weights.get(lIssue);
106
107 double lLocalUtility = fIssueModels.get(lIssue).getUtility(pBid);
108 lUtility += lWeight * lLocalUtility;
109 }
110 return lUtility;
111 }
112}
Note: See TracBrowser for help on using the repository browser.