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

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

#264 more fixes

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 @NonNull
39 Domain domain = utilSpaces.get(0).getDomain();
40 for (@NonNull
41 LinearAdditive space : utilSpaces) {
42 if (!space.getDomain().equals(domain)) {
43 throw new IllegalArgumentException(
44 "Expected all spaces using domain " + domain.getName()
45 + " but found " + space.getDomain().getName());
46 }
47 }
48 this.utilSpaces = utilSpaces;
49 }
50
51 @Override
52 public @NonNull List<@NonNull Profile> getProfiles() {
53 return Collections.unmodifiableList(utilSpaces);
54 }
55
56 @Override
57 public @NonNull Set<@NonNull Bid> getPoints() {
58 if (points == null) {
59 points = computePareto();
60 }
61 return points;
62 }
63
64 @Override
65 public @NonNull String toString() {
66 return "Pareto " + getPoints();
67 }
68
69 private @NonNull Set<@NonNull Bid> computePareto() {
70 @NonNull
71 List<@NonNull String> issues = new LinkedList<>(
72 utilSpaces.get(0).getDomain().getIssuesValues().keySet());
73 @NonNull
74 PartialPareto partial = PartialPareto.create(utilSpaces, issues);
75 //#PY return { point.getBid() for point in partial.getPoints() }
76 return partial.getPoints().stream().map(point -> point.getBid())
77 .collect(Collectors.toSet());
78 }
79
80}
Note: See TracBrowser for help on using the repository browser.