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