source: java2python/geniuswebtranslator/geniuswebsrc/geniusweb/bidspace/pareto/ParetoLinearAdditive.java@ 874

Last change on this file since 874 was 867, checked in by wouter, 7 months ago

added few 'final' annotations

File size: 2.3 KB
Line 
1package geniusweb.bidspace.pareto;
2
3import java.util.Collections;
4import java.util.LinkedList;
5import java.util.List;
6import java.util.Set;
7import java.util.stream.Collectors;
8
9import org.eclipse.jdt.annotation.NonNull;
10
11import geniusweb.issuevalue.Bid;
12import geniusweb.issuevalue.Domain;
13import geniusweb.profile.Profile;
14import geniusweb.profile.utilityspace.LinearAdditive;
15
16/**
17 * pareto frontier implementation for {@link LinearAdditive}. This is a highly
18 * optimized pareto method for {@link LinearAdditive} spaces
19 */
20public class ParetoLinearAdditive implements ParetoFrontier {
21
22 private final @NonNull List<@NonNull LinearAdditive> utilSpaces;
23 private Set<@NonNull Bid> points = null;
24 // all issues in a deterministic order
25
26 /**
27 *
28 * @param utilSpaces. Must contain at least two {@link LinearAdditive}s and
29 * all must be defined on the same donain.
30 */
31 public ParetoLinearAdditive(
32 final @NonNull List<@NonNull LinearAdditive> utilSpaces) {
33 if (utilSpaces == null || utilSpaces.size() < 2
34 || utilSpaces.contains(null)) {
35 throw new IllegalArgumentException(
36 "utilSpaces must contain at least 2 spaces");
37 }
38 final @NonNull Domain domain = utilSpaces.get(0).getDomain();
39 for (final @NonNull LinearAdditive space : utilSpaces) {
40 if (!space.getDomain().equals(domain)) {
41 throw new IllegalArgumentException(
42 "Expected all spaces using domain " + domain.getName()
43 + " but found " + space.getDomain().getName());
44 }
45 }
46 this.utilSpaces = utilSpaces;
47 }
48
49 @Override
50 public @NonNull List<@NonNull Profile> getProfiles() {
51 return Collections.unmodifiableList(utilSpaces);
52 }
53
54 @Override
55 public @NonNull Set<@NonNull Bid> getPoints() {
56 if (points == null) {
57 points = computePareto();
58 }
59 return points;
60 }
61
62 @Override
63 public @NonNull String toString() {
64 return "Pareto " + getPoints();
65 }
66
67 private @NonNull Set<@NonNull Bid> computePareto() {
68 final @NonNull List<@NonNull String> issues = new LinkedList<>(
69 utilSpaces.get(0).getDomain().getIssuesValues().keySet());
70 final @NonNull PartialPareto partial = PartialPareto.create(utilSpaces,
71 issues);
72 //#PY return { point.getBid() for point in partial.getPoints() }
73 return partial.getPoints().stream().map(point -> point.getBid())
74 .collect(Collectors.toSet());
75 }
76
77}
Note: See TracBrowser for help on using the repository browser.