source: bidspace/src/main/java/geniusweb/bidspace/pareto/ParetoLinearAdditive.java@ 1

Last change on this file since 1 was 1, checked in by bart, 5 years ago

Initial Release

File size: 2.0 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 geniusweb.issuevalue.Bid;
10import geniusweb.issuevalue.Domain;
11import geniusweb.profile.Profile;
12import geniusweb.profile.utilityspace.LinearAdditiveUtilitySpace;
13
14/**
15 * pareto frontier implementation for {@link LinearAdditiveUtilitySpace}.
16 * Simplistic implementation that iterates over all bids.
17 */
18public 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}
Note: See TracBrowser for help on using the repository browser.