1 | package negotiator.ahbuneagent.impmap;
|
---|
2 |
|
---|
3 | import geniusweb.issuevalue.Bid;
|
---|
4 | import geniusweb.issuevalue.Domain;
|
---|
5 | import geniusweb.issuevalue.Value;
|
---|
6 | import geniusweb.issuevalue.ValueSet;
|
---|
7 | import geniusweb.profile.Profile;
|
---|
8 | import negotiator.ahbuneagent.linearorder.OppSimpleLinearOrdering;
|
---|
9 | import java.util.*;
|
---|
10 |
|
---|
11 | public class OppSimilarityMap {
|
---|
12 |
|
---|
13 | private Domain domain;
|
---|
14 | private HashMap<String, List<OppIssueValueUnit>> oppIssueValueImpMap;
|
---|
15 | private OppSimpleLinearOrdering oppEstimatedProfile;
|
---|
16 | private Bid maxImpBid;
|
---|
17 | private HashMap<String, List<Value>> availableValues;
|
---|
18 | private List<String> issueList = new ArrayList<>();
|
---|
19 |
|
---|
20 | public OppSimilarityMap(Profile profile) {
|
---|
21 | this.domain = profile.getDomain();
|
---|
22 | for (String issue : domain.getIssues()) {
|
---|
23 | issueList.add(issue);
|
---|
24 | }
|
---|
25 | renewMaps();
|
---|
26 | }
|
---|
27 |
|
---|
28 | private void createConditionLists(int numFirstBids){
|
---|
29 | renewLists();
|
---|
30 | List<Bid> sortedBids = oppEstimatedProfile.getBids();
|
---|
31 | int firstStartIndex = (sortedBids.size()-1) - numFirstBids;
|
---|
32 | if(firstStartIndex <= 0){
|
---|
33 | firstStartIndex = 0;
|
---|
34 | }
|
---|
35 | for(int bidIndex = firstStartIndex; bidIndex < sortedBids.size(); bidIndex++){
|
---|
36 | Bid currentBid = sortedBids.get(bidIndex);
|
---|
37 | for (String issue : currentBid.getIssues()) {
|
---|
38 | List<OppIssueValueUnit> currentIssueList = oppIssueValueImpMap.get(issue);
|
---|
39 | for (OppIssueValueUnit currentUnit : currentIssueList) {
|
---|
40 | if (currentUnit.valueOfIssue.equals(currentBid.getValue(issue))) {
|
---|
41 | if(!availableValues.get(issue).contains(currentBid.getValue(issue))){
|
---|
42 | availableValues.get(issue).add(currentBid.getValue(issue));
|
---|
43 | }
|
---|
44 | break;
|
---|
45 | }
|
---|
46 | }
|
---|
47 | }
|
---|
48 | }
|
---|
49 | }
|
---|
50 |
|
---|
51 | public boolean isCompromised(Bid bid, int numFirstBids, double minUtility){
|
---|
52 | createConditionLists(numFirstBids);
|
---|
53 | double issueChangeLoss = 1.0 / domain.getIssues().size();
|
---|
54 | int changeRest = (int)((1 - minUtility) / issueChangeLoss) + 1;
|
---|
55 | if(changeRest > issueList.size()){
|
---|
56 | changeRest = issueList.size();
|
---|
57 | }
|
---|
58 | int changedIssue= 0;
|
---|
59 | for (int i = 0; i < issueList.size(); i++) {
|
---|
60 | String issue = issueList.get(i);
|
---|
61 | List<Value> availableIssueValueList = availableValues.get(issue);
|
---|
62 | if(!maxImpBid.getValue(issue).equals(bid.getValue(issue))){
|
---|
63 | if(!availableIssueValueList.contains(bid.getValue(issue))){
|
---|
64 | changedIssue += 2;
|
---|
65 | }
|
---|
66 | else{
|
---|
67 | changedIssue++;
|
---|
68 | }
|
---|
69 | }
|
---|
70 | }
|
---|
71 | if(changedIssue <= changeRest){
|
---|
72 | return false;
|
---|
73 | }
|
---|
74 | return true;
|
---|
75 | }
|
---|
76 |
|
---|
77 | public void update(OppSimpleLinearOrdering estimatedProfile) {
|
---|
78 | renewMaps();
|
---|
79 | this.oppEstimatedProfile = estimatedProfile;
|
---|
80 | List<Bid> sortedBids = estimatedProfile.getBids();
|
---|
81 | this.maxImpBid = estimatedProfile.getMaxBid();
|
---|
82 | for(int bidIndex = 0; bidIndex < sortedBids.size(); bidIndex++){
|
---|
83 | Bid currentBid = sortedBids.get(bidIndex);
|
---|
84 | double bidImportance = estimatedProfile.getUtility(currentBid).doubleValue();
|
---|
85 | for (String issue : currentBid.getIssues()) {
|
---|
86 | List<OppIssueValueUnit> currentIssueList = oppIssueValueImpMap.get(issue);
|
---|
87 | for (OppIssueValueUnit currentUnit : currentIssueList) {
|
---|
88 | if (currentUnit.valueOfIssue.equals(currentBid.getValue(issue))) {
|
---|
89 | currentUnit.importanceList.add(bidImportance);
|
---|
90 | break;
|
---|
91 | }
|
---|
92 | }
|
---|
93 | }
|
---|
94 | }
|
---|
95 | }
|
---|
96 |
|
---|
97 | private void renewMaps(){
|
---|
98 | oppIssueValueImpMap = new HashMap<>();
|
---|
99 | for (String issue : domain.getIssues()) {
|
---|
100 | ValueSet values = domain.getValues(issue);
|
---|
101 | List<OppIssueValueUnit> issueIssueValueUnit = new ArrayList<>();
|
---|
102 | for (Value value : values) {
|
---|
103 | issueIssueValueUnit.add(new OppIssueValueUnit(value));
|
---|
104 | }
|
---|
105 | oppIssueValueImpMap.put(issue, issueIssueValueUnit);
|
---|
106 | }
|
---|
107 | }
|
---|
108 |
|
---|
109 | private void renewLists(){
|
---|
110 | availableValues = new HashMap<>();
|
---|
111 | for (String issue : domain.getIssues()) {
|
---|
112 | availableValues.put(issue, new ArrayList<>());
|
---|
113 | }
|
---|
114 | }
|
---|
115 |
|
---|
116 | public LinkedHashMap<Bid,Integer> mostCompromisedBids(){
|
---|
117 | List<Bid> orderedBids = oppEstimatedProfile.getBids();
|
---|
118 | Bid maxUtilBid = orderedBids.get(orderedBids.size() - 1);
|
---|
119 | HashMap<Bid,Integer> listOfOpponentCompremesid = new HashMap<>();
|
---|
120 | for(int i = 0; i < orderedBids.size(); i++){
|
---|
121 | Bid testBid = orderedBids.get(i);
|
---|
122 | int compromiseCount = 0;
|
---|
123 | for(String issue : domain.getIssues()){
|
---|
124 | if(!maxUtilBid.getValue(issue).equals(testBid.getValue(issue))){
|
---|
125 | compromiseCount ++;
|
---|
126 | }
|
---|
127 | }
|
---|
128 | listOfOpponentCompremesid.put(testBid,compromiseCount);
|
---|
129 | }
|
---|
130 | LinkedHashMap<Bid,Integer> sorted = sortByValueBid(listOfOpponentCompremesid);
|
---|
131 | return sorted;
|
---|
132 | }
|
---|
133 |
|
---|
134 | private LinkedHashMap<Bid, Integer> sortByValueBid(HashMap<Bid, Integer> hm)
|
---|
135 | {
|
---|
136 | List<Map.Entry<Bid, Integer>> list = new LinkedList<>(hm.entrySet());
|
---|
137 | Collections.sort(list, Comparator.comparing(Map.Entry::getValue));
|
---|
138 | LinkedHashMap<Bid, Integer> temp = new LinkedHashMap<>();
|
---|
139 | for (Map.Entry<Bid, Integer> aa : list) {
|
---|
140 | temp.put(aa.getKey(), aa.getValue());
|
---|
141 | }
|
---|
142 | return temp;
|
---|
143 | }
|
---|
144 | }
|
---|