source: bidspace/src/main/java/geniusweb/bidspace/pareto/ParetoPoint.java@ 52

Last change on this file since 52 was 52, checked in by ruud, 14 months ago

Fixed small issues in domaineditor.

File size: 2.1 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 geniusweb.issuevalue.Bid;
9import 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 */
16class 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}
Note: See TracBrowser for help on using the repository browser.