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

Last change on this file since 605 was 582, checked in by wouter, 18 months ago

#169 geniusweb translator now works for 3 big modules: bidspace, profile, issuevalue!

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.LinearAdditive;
13
14/**
15 * pareto frontier implementation for {@link LinearAdditive}. This is a highly
16 * optimized pareto method for {@link LinearAdditive} spaces
17 */
18public 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 //#PY return { point.getBid() for point in partial.getPoints() }
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.