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

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

#278 more @NonNull annotations

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 /**
53 * Merges the issues from both bids and adds the utilities. This only works
54 * correctly if the issues in other point are completely disjoint from our
55 * bid issues.
56 *
57 * @param otherpoint with the utils summed and the issue values merged
58 */
59 public @NonNull ParetoPoint merge(@NonNull ParetoPoint otherpoint) {
60 final @NonNull List<@NonNull BigDecimal> summedutils = new LinkedList<>();
61 for (int n = 0; n < utilities.size(); n = n + 1) {
62 summedutils.add(utilities.get(n).add(otherpoint.utilities.get(n)));
63 }
64
65 return new ParetoPoint(summedutils, bid.merge(otherpoint.getBid()));
66 }
67
68 /**
69 *
70 * @param other
71 * @return true if this ParetoPoint is dominated by the other. That means
72 * other has better or equal utilities in ALL dimensions.
73 */
74 public boolean isDominatedBy(@NonNull ParetoPoint other) {
75 final @NonNull List<@NonNull BigDecimal> otherutils = other
76 .getUtilities();
77 for (int i = 0; i < utilities.size(); i = i + 1) {
78 if (otherutils.get(i).compareTo(utilities.get(i)) < 0) {
79 return false;
80 }
81 }
82 return true;
83 }
84
85 protected @NonNull List<@NonNull BigDecimal> getUtilities() {
86 return utilities;
87 }
88
89 public @NonNull Bid getBid() {
90 return bid;
91 }
92
93}
Note: See TracBrowser for help on using the repository browser.