1 | package geniusweb.ip;
|
---|
2 |
|
---|
3 | import static org.junit.Assert.assertArrayEquals;
|
---|
4 | import static org.junit.Assert.assertEquals;
|
---|
5 |
|
---|
6 | import org.junit.Test;
|
---|
7 |
|
---|
8 | import geniusweb.ip.inputOutput.Input;
|
---|
9 | import geniusweb.ip.inputOutput.Output;
|
---|
10 | import geniusweb.ip.ipSolver.IPSolver;
|
---|
11 | import geniusweb.ip.mainSolver.Result;
|
---|
12 |
|
---|
13 | public class IpSolverTest {
|
---|
14 |
|
---|
15 | @Test
|
---|
16 | public void textBookTest() {
|
---|
17 | System.out.println("textbook test");
|
---|
18 | int numOfAgents = 4;
|
---|
19 | double[] coalitionValues = new double[] { 0d, 30d, 40d, 50d, 25d, 60d,
|
---|
20 | 55d, 90d, 45d, 80d, 70d, 120d, 80d, 100d, 115d, 140d };
|
---|
21 | double acceptableRatio = 100;
|
---|
22 | Input input = new Input(numOfAgents, coalitionValues, acceptableRatio);
|
---|
23 | Result result = new Result(input);
|
---|
24 | Output output = new Output(input);
|
---|
25 |
|
---|
26 | IPSolver ipSolver = new IPSolver();
|
---|
27 | ipSolver.solve(input, output, result);
|
---|
28 |
|
---|
29 | System.out.println(result);
|
---|
30 |
|
---|
31 | assertArrayEquals(new int[][] { { 3, 4 }, { 1 }, { 2 } },
|
---|
32 | result.get_ipBestCSFound());
|
---|
33 | assertEquals(150d, result.get_ipValueOfBestCSFound(), 0.00001);
|
---|
34 | }
|
---|
35 |
|
---|
36 | @Test
|
---|
37 | public void anotherTest() {
|
---|
38 | // 4 agents; agent2 can be in coalition1 and coalition2;
|
---|
39 | // but there is a minimum coalition size of 2.
|
---|
40 | System.out.println("another test");
|
---|
41 | int numOfAgents = 4;
|
---|
42 | double[] coalitionValues = new double[] { 0d, 0d, 0d, 2d, 0d, 0d, 2d,
|
---|
43 | 0d, 0d, 0d, 0d, 0d, 2d, 0d, 0d, 0d };
|
---|
44 | double acceptableRatio = 100;
|
---|
45 | Input input = new Input(numOfAgents, coalitionValues, acceptableRatio);
|
---|
46 | Result result = new Result(input);
|
---|
47 | Output output = new Output(input);
|
---|
48 |
|
---|
49 | IPSolver ipSolver = new IPSolver();
|
---|
50 | ipSolver.solve(input, output, result);
|
---|
51 |
|
---|
52 | System.out.println(result);
|
---|
53 | assertArrayEquals(new int[][] { { 3, 4 }, { 1, 2 } },
|
---|
54 | result.get_ipBestCSFound());
|
---|
55 | assertEquals(4d, result.get_ipValueOfBestCSFound(), 0.00001);
|
---|
56 |
|
---|
57 | }
|
---|
58 |
|
---|
59 | } |
---|