1 | /**
|
---|
2 | *
|
---|
3 | */
|
---|
4 | package bargainingchips.analysis;
|
---|
5 |
|
---|
6 | import java.io.Serializable;
|
---|
7 | import java.util.ArrayList;
|
---|
8 | import java.util.Collections;
|
---|
9 | import java.util.Comparator;
|
---|
10 | import java.util.List;
|
---|
11 |
|
---|
12 | import bargainingchips.analysis.BundleUtilityPoint;
|
---|
13 |
|
---|
14 | /**
|
---|
15 | *
|
---|
16 | * This class is for storing Pareto-frontier by adding bundles at analysis time.
|
---|
17 | * It adapts {@link genius.core.analysis.ParetoFrontier}.
|
---|
18 | *
|
---|
19 | *
|
---|
20 | * @author Faria Nassiri-Mofakham
|
---|
21 | *
|
---|
22 | */
|
---|
23 |
|
---|
24 | public class ParetoFrontier implements Serializable {
|
---|
25 |
|
---|
26 | /**
|
---|
27 | *
|
---|
28 | */
|
---|
29 | private static final long serialVersionUID = 1L;
|
---|
30 | /** List holding the Pareto-frontier bids. */
|
---|
31 | private List<BundleUtilityPoint> frontier;
|
---|
32 |
|
---|
33 | /**
|
---|
34 | * Create an empty list to store the Pareto-frontier.
|
---|
35 | */
|
---|
36 | public ParetoFrontier() {
|
---|
37 | frontier = new ArrayList<BundleUtilityPoint>();
|
---|
38 | }
|
---|
39 |
|
---|
40 | /**
|
---|
41 | * Determines if a bid should be added to the Pareto-frontier. A bid is
|
---|
42 | * added when it strictly dominates a bid in the Pareto-frontier OR when it
|
---|
43 | * is equal to a bid in the Pareto-frontier.
|
---|
44 | *
|
---|
45 | * @param bidpoint
|
---|
46 | * bid to be added to the Pareto-frontier.
|
---|
47 | */
|
---|
48 | public void mergeIntoFrontier(BundleUtilityPoint bundleutilitypoint) {
|
---|
49 | for (BundleUtilityPoint f : frontier) {
|
---|
50 | if (bundleutilitypoint.isStrictlyDominatedBy(f)) {
|
---|
51 | // the bundleutilitypoint is dominated, and therefore not added
|
---|
52 | return;
|
---|
53 | }
|
---|
54 | if (f.isStrictlyDominatedBy(bundleutilitypoint)) {
|
---|
55 | // the bundleutilitypoint dominates a Pareto-bid, which is therefore
|
---|
56 | // replaced
|
---|
57 | merge(bundleutilitypoint, f);
|
---|
58 | return;
|
---|
59 | }
|
---|
60 | }
|
---|
61 | // the bid must be equal to an existing bid, therefore add it
|
---|
62 | frontier.add(bundleutilitypoint);
|
---|
63 | }
|
---|
64 |
|
---|
65 | /**
|
---|
66 | * Adds a bid to the Pareto frontier
|
---|
67 | *
|
---|
68 | * @param newParetoBid
|
---|
69 | * new Pareto bid.
|
---|
70 | * @param dominatedParetoBid
|
---|
71 | * old Pareto bid which must now be removed.
|
---|
72 | */
|
---|
73 | private void merge(BundleUtilityPoint newParetoBid, BundleUtilityPoint dominatedParetoBid) {
|
---|
74 | // remove dominated bid.
|
---|
75 | frontier.remove(dominatedParetoBid);
|
---|
76 | // there might still be more bids which should be removed.
|
---|
77 | ArrayList<BundleUtilityPoint> toBeRemoved = new ArrayList<BundleUtilityPoint>();
|
---|
78 | for (BundleUtilityPoint f : frontier) {
|
---|
79 | if (f.isStrictlyDominatedBy(newParetoBid)) // delete dominated
|
---|
80 | // frontier points
|
---|
81 | toBeRemoved.add(f);
|
---|
82 | }
|
---|
83 | frontier.removeAll(toBeRemoved);
|
---|
84 | frontier.add(newParetoBid);
|
---|
85 | }
|
---|
86 |
|
---|
87 | /**
|
---|
88 | * Returns true if the given BundleUtilityPoint is not part of the Pareto-frontier.
|
---|
89 | *
|
---|
90 | * @param bid
|
---|
91 | * to be checked if it is Pareto-optimal.
|
---|
92 | * @return true if NOT pareto-optimal bid.
|
---|
93 | */
|
---|
94 | public boolean isBelowFrontier(BundleUtilityPoint bid) {
|
---|
95 | for (BundleUtilityPoint f : this.getFrontier())
|
---|
96 | if (bid.isStrictlyDominatedBy(f))
|
---|
97 | return true;
|
---|
98 | return false;
|
---|
99 | }
|
---|
100 |
|
---|
101 | /**
|
---|
102 | * Order the bids based on the utility for agent A.
|
---|
103 | */
|
---|
104 | public void sort() {
|
---|
105 | Collections.sort(frontier, new Comparator<BundleUtilityPoint>() {
|
---|
106 | @Override
|
---|
107 | public int compare(BundleUtilityPoint x, BundleUtilityPoint y) {
|
---|
108 | if (x.getUtilityA() < y.getUtilityA())
|
---|
109 | return -1;
|
---|
110 | else if (x.getUtilityA() > y.getUtilityA())
|
---|
111 | return 1;
|
---|
112 | else
|
---|
113 | return 0;
|
---|
114 | }
|
---|
115 | });
|
---|
116 | }
|
---|
117 |
|
---|
118 | /**
|
---|
119 | * Returns the Pareto-optimal frontier.
|
---|
120 | *
|
---|
121 | * @return Pareto-optimal frontier.
|
---|
122 | */
|
---|
123 | public List<BundleUtilityPoint> getFrontier() {
|
---|
124 | return frontier;
|
---|
125 | }
|
---|
126 | } |
---|