1 | package agents.anac.y2019.agentgg;
|
---|
2 |
|
---|
3 | import genius.core.Bid;
|
---|
4 | import genius.core.issue.Issue;
|
---|
5 | import genius.core.issue.IssueDiscrete;
|
---|
6 | import genius.core.issue.Value;
|
---|
7 | import genius.core.uncertainty.UserModel;
|
---|
8 |
|
---|
9 | import java.util.ArrayList;
|
---|
10 | import java.util.HashMap;
|
---|
11 | import java.util.List;
|
---|
12 | import java.util.Map;
|
---|
13 |
|
---|
14 | public class ImpMap extends HashMap<Issue, List<impUnit>> {
|
---|
15 | //importance map
|
---|
16 | public ImpMap(UserModel userModel) {
|
---|
17 | super();
|
---|
18 | //遍历userModel中的issue,创建空importance表格
|
---|
19 | for (Issue issue : userModel.getDomain().getIssues()) {
|
---|
20 | IssueDiscrete temp = (IssueDiscrete) issue;
|
---|
21 | List<impUnit> issueImpUnit = new ArrayList<>();
|
---|
22 | int numberInIssue = temp.getNumberOfValues();
|
---|
23 | for (int i = 0; i < numberInIssue; i++) {
|
---|
24 | issueImpUnit.add(new impUnit(temp.getValue(i)));
|
---|
25 | }
|
---|
26 | this.put(issue, issueImpUnit);
|
---|
27 | }
|
---|
28 | }
|
---|
29 |
|
---|
30 | // 更新对手map
|
---|
31 | public void opponent_update(Bid receivedOfferBid) {
|
---|
32 | for (Issue issue : receivedOfferBid.getIssues()) {
|
---|
33 | int no = issue.getNumber();
|
---|
34 | List<impUnit> currentIssueList = this.get(issue);
|
---|
35 | for (impUnit currentUnit : currentIssueList) {
|
---|
36 | if (currentUnit.valueOfIssue.toString().equals(receivedOfferBid.getValue(no).toString())) {
|
---|
37 | currentUnit.meanWeightSum += 1;
|
---|
38 | break;
|
---|
39 | }
|
---|
40 | }
|
---|
41 | }
|
---|
42 | for (List<impUnit> impUnitList : this.values()) {
|
---|
43 | impUnitList.sort(new impUnit.meanWeightSumComparator());
|
---|
44 | }
|
---|
45 | }
|
---|
46 |
|
---|
47 | // 更新自己的importance map
|
---|
48 | public void self_update(UserModel userModel) {
|
---|
49 | //遍历已知bidOrder,更新importance表格中的“权和”、“次数”
|
---|
50 | int currentWeight = 0;
|
---|
51 | for (Bid bid : userModel.getBidRanking().getBidOrder()) {
|
---|
52 | currentWeight += 1;
|
---|
53 | List<Issue> issueList = bid.getIssues();
|
---|
54 | for (Issue issue : issueList) {
|
---|
55 | int no = issue.getNumber();
|
---|
56 | List<impUnit> currentIssueList = this.get(issue);
|
---|
57 | for (impUnit currentUnit : currentIssueList) {
|
---|
58 | if (currentUnit.valueOfIssue.toString().equals(bid.getValue(no).toString())) {
|
---|
59 | currentUnit.weightSum += currentWeight;
|
---|
60 | currentUnit.count += 1;
|
---|
61 | break;
|
---|
62 | }
|
---|
63 | }
|
---|
64 | }
|
---|
65 | }
|
---|
66 | // 计算权重
|
---|
67 | for (List<impUnit> impUnitList : this.values()) {
|
---|
68 | for (impUnit currentUnit : impUnitList) {
|
---|
69 | if (currentUnit.count == 0) {
|
---|
70 | currentUnit.meanWeightSum = 0.0;
|
---|
71 | } else {
|
---|
72 | currentUnit.meanWeightSum = (double) currentUnit.weightSum / (double) currentUnit.count;
|
---|
73 | }
|
---|
74 | }
|
---|
75 | }
|
---|
76 | // 排序
|
---|
77 | for (List<impUnit> impUnitList : this.values()) {
|
---|
78 | impUnitList.sort(new impUnit.meanWeightSumComparator());
|
---|
79 | }
|
---|
80 | // 找到最小值
|
---|
81 | double minMeanWeightSum = Double.POSITIVE_INFINITY;
|
---|
82 | for (Map.Entry<Issue, List<impUnit>> entry : this.entrySet()) {
|
---|
83 | double tempMeanWeightSum = entry.getValue().get(entry.getValue().size() - 1).meanWeightSum;
|
---|
84 | if (tempMeanWeightSum < minMeanWeightSum) {
|
---|
85 | minMeanWeightSum = tempMeanWeightSum;
|
---|
86 | }
|
---|
87 | }
|
---|
88 | // 所有值都减去最小值
|
---|
89 | for (List<impUnit> impUnitList : this.values()) {
|
---|
90 | for (impUnit currentUnit : impUnitList) {
|
---|
91 | currentUnit.meanWeightSum -= minMeanWeightSum;
|
---|
92 | }
|
---|
93 | }
|
---|
94 | }
|
---|
95 |
|
---|
96 | //计算某个bid对应的importance值
|
---|
97 | public double getImportance(Bid bid) {
|
---|
98 | double bidImportance = 0.0;
|
---|
99 | for (Issue issue : bid.getIssues()) {
|
---|
100 | Value value = bid.getValue(issue.getNumber());
|
---|
101 | double valueImportance = 0.0;
|
---|
102 | for (impUnit i : this.get(issue)) {
|
---|
103 | if (i.valueOfIssue.equals(value)) {
|
---|
104 | valueImportance = i.meanWeightSum;
|
---|
105 | break;
|
---|
106 | }
|
---|
107 | }
|
---|
108 | bidImportance += valueImportance;
|
---|
109 | }
|
---|
110 | return bidImportance;
|
---|
111 | }
|
---|
112 | }
|
---|
113 |
|
---|