source: ip/src/test/java/geniusweb/ip/IpSolverTest.java@ 52

Last change on this file since 52 was 52, checked in by ruud, 14 months ago

Fixed small issues in domaineditor.

File size: 1.7 KB
Line 
1package geniusweb.ip;
2
3import static org.junit.Assert.assertArrayEquals;
4import static org.junit.Assert.assertEquals;
5
6import org.junit.Test;
7
8import geniusweb.ip.inputOutput.Input;
9import geniusweb.ip.inputOutput.Output;
10import geniusweb.ip.ipSolver.IPSolver;
11import geniusweb.ip.mainSolver.Result;
12
13public 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}
Note: See TracBrowser for help on using the repository browser.