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

Last change on this file since 29 was 29, checked in by bart, 3 years ago

some minor fixes

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