source: java2python/geniuswebtranslator/geniuswebsrc/geniusweb/bidspace/pareto/ParetoPoint.java@ 825

Last change on this file since 825 was 825, checked in by wouter, 6 months ago

#291 move annotation to above the javadoc

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