1 | package geniusweb.bidspace.pareto;
|
---|
2 |
|
---|
3 | import java.util.Collections;
|
---|
4 | import java.util.LinkedList;
|
---|
5 | import java.util.List;
|
---|
6 | import java.util.Set;
|
---|
7 | import java.util.stream.Collectors;
|
---|
8 |
|
---|
9 | import org.eclipse.jdt.annotation.NonNull;
|
---|
10 |
|
---|
11 | import geniusweb.issuevalue.Bid;
|
---|
12 | import geniusweb.issuevalue.Domain;
|
---|
13 | import geniusweb.profile.Profile;
|
---|
14 | import 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 | */
|
---|
20 | public 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());
|
---|
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 | }
|
---|