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 geniusweb.issuevalue.Bid;
|
---|
10 | import geniusweb.issuevalue.Domain;
|
---|
11 | import geniusweb.profile.Profile;
|
---|
12 | import geniusweb.profile.utilityspace.LinearAdditive;
|
---|
13 |
|
---|
14 | /**
|
---|
15 | * pareto frontier implementation for {@link LinearAdditive}. Simplistic
|
---|
16 | * implementation that iterates over all bids.
|
---|
17 | */
|
---|
18 | public class ParetoLinearAdditive implements ParetoFrontier {
|
---|
19 |
|
---|
20 | private final List<LinearAdditive> utilSpaces;
|
---|
21 | private Set<Bid> points = null;
|
---|
22 | // all issues in a deterministic order
|
---|
23 |
|
---|
24 | /**
|
---|
25 | *
|
---|
26 | * @param utilSpaces. Must contain at least two {@link LinearAdditive}s and
|
---|
27 | * all must be defined on the same donain.
|
---|
28 | */
|
---|
29 | public ParetoLinearAdditive(List<LinearAdditive> utilSpaces) {
|
---|
30 | if (utilSpaces == null || utilSpaces.size() < 2) {
|
---|
31 | throw new IllegalArgumentException(
|
---|
32 | "utilSpaces must contain at least 2 spaces");
|
---|
33 | }
|
---|
34 | Domain domain = utilSpaces.get(0).getDomain();
|
---|
35 | for (LinearAdditive space : utilSpaces) {
|
---|
36 | if (!space.getDomain().equals(domain)) {
|
---|
37 | throw new IllegalArgumentException(
|
---|
38 | "Expected all spaces using domain " + domain.getName()
|
---|
39 | + " but found " + space.getDomain().getName());
|
---|
40 | }
|
---|
41 | }
|
---|
42 | this.utilSpaces = utilSpaces;
|
---|
43 | }
|
---|
44 |
|
---|
45 | @Override
|
---|
46 | public List<Profile> getProfiles() {
|
---|
47 | return Collections.unmodifiableList(utilSpaces);
|
---|
48 | }
|
---|
49 |
|
---|
50 | @Override
|
---|
51 | public Set<Bid> getPoints() {
|
---|
52 | if (points == null) {
|
---|
53 | points = computePareto();
|
---|
54 | }
|
---|
55 | return points;
|
---|
56 | }
|
---|
57 |
|
---|
58 | @Override
|
---|
59 | public String toString() {
|
---|
60 | return "Pareto " + getPoints();
|
---|
61 | }
|
---|
62 |
|
---|
63 | private Set<Bid> computePareto() {
|
---|
64 | LinkedList<String> issues = new LinkedList<>(
|
---|
65 | utilSpaces.get(0).getDomain().getIssues());
|
---|
66 | PartialPareto partial = PartialPareto.create(utilSpaces, issues);
|
---|
67 | return partial.getPoints().stream().map(point -> point.getBid())
|
---|
68 | .collect(Collectors.toSet());
|
---|
69 | }
|
---|
70 |
|
---|
71 | }
|
---|