1 | package geniusweb.bidspace.pareto;
|
---|
2 |
|
---|
3 | import static org.junit.Assert.assertEquals;
|
---|
4 |
|
---|
5 | import java.io.IOException;
|
---|
6 | import java.nio.file.Files;
|
---|
7 | import java.nio.file.Path;
|
---|
8 | import java.nio.file.Paths;
|
---|
9 | import java.util.Arrays;
|
---|
10 | import java.util.Collection;
|
---|
11 | import java.util.LinkedList;
|
---|
12 | import java.util.List;
|
---|
13 |
|
---|
14 | import org.junit.Test;
|
---|
15 | import org.junit.runner.RunWith;
|
---|
16 | import org.junit.runners.Parameterized;
|
---|
17 | import org.junit.runners.Parameterized.Parameters;
|
---|
18 |
|
---|
19 | import com.fasterxml.jackson.databind.ObjectMapper;
|
---|
20 |
|
---|
21 | import geniusweb.profile.Profile;
|
---|
22 | import geniusweb.profile.utilityspace.LinearAdditive;
|
---|
23 | import geniusweb.profile.utilityspace.LinearAdditiveUtilitySpace;
|
---|
24 |
|
---|
25 | /**
|
---|
26 | * Test pareto functionality with some real profiles in an e2e test
|
---|
27 | */
|
---|
28 | @RunWith(Parameterized.class)
|
---|
29 | public class ParetoE2Etest {
|
---|
30 | private final static ObjectMapper jackson = new ObjectMapper();
|
---|
31 |
|
---|
32 | @Parameters
|
---|
33 | public static Collection<Object[]> data() {
|
---|
34 | return Arrays.asList(new Object[][] {
|
---|
35 | { "src/test/resources/jobs/jobs1.json",
|
---|
36 | "src/test/resources/jobs/jobs2.json", 18 },
|
---|
37 | { "src/test/resources/7issues/7issues1.json",
|
---|
38 | "src/test/resources/7issues/7issues2.json", 557 } });
|
---|
39 | }
|
---|
40 |
|
---|
41 | private Path path1;
|
---|
42 | private Path path2;
|
---|
43 | private int expectedNrPoints;
|
---|
44 |
|
---|
45 | public ParetoE2Etest(String profile1file, String profile2file,
|
---|
46 | int expectedNr) {
|
---|
47 | this.path1 = Paths.get(profile1file);
|
---|
48 | this.path2 = Paths.get(profile2file);
|
---|
49 | this.expectedNrPoints = expectedNr;
|
---|
50 | }
|
---|
51 |
|
---|
52 | @Test
|
---|
53 | public void checkGenerciPareto() throws IOException {
|
---|
54 | String file1 = new String(Files.readAllBytes(path1));
|
---|
55 | LinearAdditiveUtilitySpace profile1 = (LinearAdditiveUtilitySpace) jackson
|
---|
56 | .readValue(file1, Profile.class);
|
---|
57 | String file2 = new String(Files.readAllBytes(path2));
|
---|
58 | LinearAdditiveUtilitySpace profile2 = (LinearAdditiveUtilitySpace) jackson
|
---|
59 | .readValue(file2, Profile.class);
|
---|
60 |
|
---|
61 | List<LinearAdditive> profiles = new LinkedList<>();
|
---|
62 | profiles.add(profile1);
|
---|
63 | profiles.add(profile2);
|
---|
64 | ParetoFrontier linaddpareto = new ParetoLinearAdditive(profiles);
|
---|
65 | System.out.println("linaddpareto result" + linaddpareto);
|
---|
66 | assertEquals(expectedNrPoints, linaddpareto.getPoints().size());
|
---|
67 |
|
---|
68 | if (expectedNrPoints < 40) {
|
---|
69 | ParetoFrontier generalpareto = new GenericPareto(profiles);
|
---|
70 | assertEquals(generalpareto.getPoints(), linaddpareto.getPoints());
|
---|
71 | System.out.println("generalpareto result" + generalpareto);
|
---|
72 | } else {
|
---|
73 | System.out.println("Skippedn generalpareto - expected too slow");
|
---|
74 | }
|
---|
75 | }
|
---|
76 |
|
---|
77 | }
|
---|