1 | package agents.anac.y2015.group2;
|
---|
2 |
|
---|
3 | import java.util.ArrayList;
|
---|
4 | import java.util.LinkedList;
|
---|
5 | import java.util.Map.Entry;
|
---|
6 | import java.util.Set;
|
---|
7 |
|
---|
8 | class G2ParetoFinder
|
---|
9 | {
|
---|
10 | ArrayList<G2IssueSubSet> issueSubSets;
|
---|
11 | G2ParetoFinder(G2UtilitySpace ourUtilitySpace, ArrayList<G2UtilitySpace> OtherUtilitySpaces)
|
---|
12 | {
|
---|
13 | issueSubSets = new ArrayList<G2IssueSubSet>();
|
---|
14 | Set<Entry<String, G2Issue>> issues = ourUtilitySpace.getIssues();
|
---|
15 | for(Entry<String, G2Issue> issueInfo: issues)
|
---|
16 | {
|
---|
17 | String IssueName = issueInfo.getKey();
|
---|
18 | G2Issue issue = issueInfo.getValue();
|
---|
19 | LinkedList<G2SubBid> subBids = new LinkedList<G2SubBid>();
|
---|
20 |
|
---|
21 | Set<String> optionNames = issue.getOptionNames();
|
---|
22 | for(String optionName: optionNames)
|
---|
23 | {
|
---|
24 | ArrayList<Double> OtherUtilities = new ArrayList<Double>(OtherUtilitySpaces.size());
|
---|
25 | for(G2UtilitySpace utilitySpace: OtherUtilitySpaces)
|
---|
26 | {
|
---|
27 | OtherUtilities.add(utilitySpace.calculateOptionUtility(IssueName, optionName));
|
---|
28 | }
|
---|
29 | double ourUtility = ourUtilitySpace.calculateOptionUtility(IssueName, optionName);
|
---|
30 | subBids.add(new G2SubBid(optionName, ourUtility, OtherUtilities));
|
---|
31 | }
|
---|
32 | issueSubSets.add(new G2IssueSubSet(IssueName, subBids));
|
---|
33 | }
|
---|
34 | }
|
---|
35 |
|
---|
36 | private void trimMerge() {
|
---|
37 | for(G2IssueSubSet subSet: issueSubSets)
|
---|
38 | {
|
---|
39 | subSet.trimSubBids();
|
---|
40 | }
|
---|
41 |
|
---|
42 | ArrayList<G2IssueSubSet> newIssueSubSets = new ArrayList<G2IssueSubSet>();
|
---|
43 | int i=1;
|
---|
44 | while(i<issueSubSets.size())
|
---|
45 | {
|
---|
46 | newIssueSubSets.add(new G2IssueSubSet(issueSubSets.get(i-1), issueSubSets.get(i)));
|
---|
47 | i+=2;
|
---|
48 | }
|
---|
49 | if(i==issueSubSets.size())
|
---|
50 | {
|
---|
51 | newIssueSubSets.add(issueSubSets.get(i-1));
|
---|
52 | }
|
---|
53 | issueSubSets = newIssueSubSets;
|
---|
54 | }
|
---|
55 |
|
---|
56 | ArrayList<G2Bid> findParetoOptimalBids() {
|
---|
57 | while (issueSubSets.size()>1) {
|
---|
58 | trimMerge();
|
---|
59 | }
|
---|
60 | issueSubSets.get(0).trimSubBids();
|
---|
61 |
|
---|
62 | return issueSubSets.get(0).generateBids();
|
---|
63 | }
|
---|
64 | } |
---|