1 | package geniusweb.bidspace.pareto;
|
---|
2 |
|
---|
3 | import java.math.BigDecimal;
|
---|
4 | import java.util.ArrayList;
|
---|
5 | import java.util.LinkedList;
|
---|
6 | import java.util.List;
|
---|
7 |
|
---|
8 | import geniusweb.issuevalue.Bid;
|
---|
9 | import geniusweb.profile.utilityspace.LinearAdditive;
|
---|
10 |
|
---|
11 | /**
|
---|
12 | * A Paretopoint is a Bid together with an N-dimensional utility vector. This is
|
---|
13 | * also a caching mechanism to avoid repeated utility computation of good bids.
|
---|
14 | * This is a internal utility class to streamline pareto computations.
|
---|
15 | */
|
---|
16 | class ParetoPoint {
|
---|
17 |
|
---|
18 | private final Bid bid;
|
---|
19 | // ArrayList is faster in indexing which is main reason for this class
|
---|
20 | private final ArrayList<BigDecimal> utilities;
|
---|
21 |
|
---|
22 | /**
|
---|
23 | *
|
---|
24 | * @param bid a (possibly partial) {@link Bid}
|
---|
25 | * @param spaces the {@link LinearAdditive}s to consider
|
---|
26 | */
|
---|
27 | public ParetoPoint(Bid bid, List<LinearAdditive> spaces) {
|
---|
28 | this.bid = bid;
|
---|
29 | utilities = new ArrayList<>();
|
---|
30 | for (LinearAdditive space : spaces) {
|
---|
31 | utilities.add(space.getUtility(bid));
|
---|
32 | }
|
---|
33 | }
|
---|
34 |
|
---|
35 | private ParetoPoint(List<BigDecimal> utils, Bid bid) {
|
---|
36 | this.bid = bid;
|
---|
37 | this.utilities = new ArrayList<>(utils);
|
---|
38 | }
|
---|
39 |
|
---|
40 | /**
|
---|
41 | * Merges the issues from both bids and adds the utilities. This only works
|
---|
42 | * correctly if the issues in other point are completely disjoint from our
|
---|
43 | * bid issues.
|
---|
44 | *
|
---|
45 | * @param otherpoint with the utils summed and the issue values merged
|
---|
46 | */
|
---|
47 | public ParetoPoint merge(ParetoPoint otherpoint) {
|
---|
48 | List<BigDecimal> summedutils = new LinkedList<>();
|
---|
49 | for (int n = 0; n < utilities.size(); n++) {
|
---|
50 | summedutils.add(utilities.get(n).add(otherpoint.utilities.get(n)));
|
---|
51 | }
|
---|
52 |
|
---|
53 | return new ParetoPoint(summedutils, bid.merge(otherpoint.getBid()));
|
---|
54 | }
|
---|
55 |
|
---|
56 | /**
|
---|
57 | *
|
---|
58 | * @param other
|
---|
59 | * @return true if this ParetoPoint is dominated by the other. That means
|
---|
60 | * other has better or equal utilities in ALL dimensions.
|
---|
61 | */
|
---|
62 | public boolean isDominatedBy(ParetoPoint other) {
|
---|
63 | ArrayList<BigDecimal> otherutils = other.getUtilities();
|
---|
64 | for (int i = 0; i < utilities.size(); i++) {
|
---|
65 | if (otherutils.get(i).compareTo(utilities.get(i)) < 0) {
|
---|
66 | return false;
|
---|
67 | }
|
---|
68 | }
|
---|
69 | return true;
|
---|
70 | }
|
---|
71 |
|
---|
72 | protected ArrayList<BigDecimal> getUtilities() {
|
---|
73 | return utilities;
|
---|
74 | }
|
---|
75 |
|
---|
76 | public Bid getBid() {
|
---|
77 | return bid;
|
---|
78 | }
|
---|
79 |
|
---|
80 | } |
---|