1 | /** |
2 | * |
3 | */ |
4 | package de.uka.ipd.sdq.tcfmoop.tests; |
5 | |
6 | import static org.junit.Assert.*; |
7 | |
8 | import java.util.HashSet; |
9 | |
10 | import org.junit.Before; |
11 | import org.junit.Test; |
12 | import org.opt4j.common.archive.DefaultArchive; |
13 | import org.opt4j.core.Archive; |
14 | import org.opt4j.core.Individual; |
15 | import org.opt4j.core.IndividualStateListener; |
16 | import org.opt4j.core.Objective; |
17 | import org.opt4j.core.Objectives; |
18 | import org.opt4j.core.Objective.Sign; |
19 | import org.opt4j.core.domination.ParetoDomination; |
20 | |
21 | import de.uka.ipd.sdq.tcfmoop.config.NoNewParetoOptimalCandidatesFoundConfig; |
22 | import de.uka.ipd.sdq.tcfmoop.terminationcriteria.NoNewParetoOptimalCandidatesFoundCriterion; |
23 | |
24 | /** |
25 | * @author Atanas Dimitrov |
26 | * |
27 | */ |
28 | public class NoNewParetoOptimalCandidatesCriterionTest { |
29 | NoNewParetoOptimalCandidatesFoundConfig nnpocconf; |
30 | NoNewParetoOptimalCandidatesFoundCriterion nnpoccrit; |
31 | |
32 | Archive archive = new DefaultArchive(); |
33 | |
34 | Objectives o1 = new Objectives(new ParetoDomination()); |
35 | Objectives o2 = new Objectives(new ParetoDomination()); |
36 | Objectives o3 = new Objectives(new ParetoDomination()); |
37 | Objectives o4 = new Objectives(new ParetoDomination()); |
38 | Objectives o5 = new Objectives(new ParetoDomination()); |
39 | |
40 | MyIndividual i1 = new MyIndividual(); |
41 | MyIndividual i2 = new MyIndividual(); |
42 | MyIndividual i3 = new MyIndividual(); |
43 | MyIndividual i4 = new MyIndividual(); |
44 | MyIndividual i5 = new MyIndividual(); |
45 | |
46 | Objective X = new Objective("X", Sign.MIN); |
47 | Objective Y = new Objective("Y", Sign.MIN); |
48 | |
49 | /** |
50 | * @throws java.lang.Exception |
51 | */ |
52 | @Before |
53 | public void setUp() throws Exception { |
54 | |
55 | nnpocconf = new NoNewParetoOptimalCandidatesFoundConfig(); |
56 | |
57 | o1.add(X, 2); |
58 | o1.add(Y, 6); |
59 | |
60 | o2.add(X, 4); |
61 | o2.add(Y, 3); |
62 | |
63 | o3.add(X, 6); |
64 | o3.add(Y, 1); |
65 | |
66 | o4.add(X, 8); |
67 | o4.add(Y, 0.5); |
68 | |
69 | o5.add(X, 9); |
70 | o5.add(Y, 1.5); |
71 | |
72 | i1.setObjectives(o1); |
73 | i2.setObjectives(o2); |
74 | i3.setObjectives(o3); |
75 | i4.setObjectives(o4); |
76 | i5.setObjectives(o5); |
77 | |
78 | archive.add(i1); |
79 | archive.add(i2); |
80 | archive.add(i3); |
81 | archive.add(i4); |
82 | |
83 | nnpocconf.setIterationsWithoutNewCandidates(3); |
84 | if(!nnpocconf.validateConfiguration()){ |
85 | throw new Exception(); |
86 | } |
87 | |
88 | } |
89 | |
90 | /** |
91 | * Test method for {@link de.uka.ipd.sdq.tcfmoop.terminationcriteria.AbstractTerminationCriterion#getEvaluationResult()}. |
92 | */ |
93 | @Test |
94 | public void testNoNewCandidates() { |
95 | |
96 | nnpoccrit = new NoNewParetoOptimalCandidatesFoundCriterion(nnpocconf, null, archive); |
97 | |
98 | nnpoccrit.evaluate(0, 0); |
99 | assertFalse(nnpoccrit.getEvaluationResult()); |
100 | nnpoccrit.evaluate(0, 0); |
101 | assertFalse(nnpoccrit.getEvaluationResult()); |
102 | nnpoccrit.evaluate(0, 0); |
103 | assertFalse(nnpoccrit.getEvaluationResult()); |
104 | nnpoccrit.evaluate(0, 0); |
105 | assertTrue(nnpoccrit.getEvaluationResult()); |
106 | |
107 | } |
108 | |
109 | /** |
110 | * Test method for {@link de.uka.ipd.sdq.tcfmoop.terminationcriteria.AbstractTerminationCriterion#getEvaluationResult()}. |
111 | */ |
112 | @Test |
113 | public void testOneNewCandidate() { |
114 | |
115 | nnpoccrit = new NoNewParetoOptimalCandidatesFoundCriterion(nnpocconf, null, archive); |
116 | |
117 | nnpoccrit.evaluate(0, 0); |
118 | assertFalse(nnpoccrit.getEvaluationResult()); |
119 | nnpoccrit.evaluate(0, 0); |
120 | assertFalse(nnpoccrit.getEvaluationResult()); |
121 | archive.add(i5); |
122 | nnpoccrit.evaluate(0, 0); |
123 | assertFalse(nnpoccrit.getEvaluationResult()); |
124 | nnpoccrit.evaluate(0, 0); |
125 | assertFalse(nnpoccrit.getEvaluationResult()); |
126 | nnpoccrit.evaluate(0, 0); |
127 | assertFalse(nnpoccrit.getEvaluationResult()); |
128 | nnpoccrit.evaluate(0, 0); |
129 | assertTrue(nnpoccrit.getEvaluationResult()); |
130 | |
131 | } |
132 | |
133 | /** |
134 | * Test method for {@link de.uka.ipd.sdq.tcfmoop.terminationcriteria.AbstractTerminationCriterion#getEvaluationResult()}. |
135 | */ |
136 | @Test |
137 | public void testEmptyArchive() { |
138 | |
139 | nnpoccrit = new NoNewParetoOptimalCandidatesFoundCriterion(nnpocconf, null, archive); |
140 | archive.clear(); |
141 | nnpoccrit.evaluate(0, 0); |
142 | assertFalse(nnpoccrit.getEvaluationResult()); |
143 | nnpoccrit.evaluate(0, 0); |
144 | assertFalse(nnpoccrit.getEvaluationResult()); |
145 | nnpoccrit.evaluate(0, 0); |
146 | assertTrue(nnpoccrit.getEvaluationResult()); |
147 | |
148 | } |
149 | |
150 | public class MyIndividual extends Individual{ |
151 | public MyIndividual(){ |
152 | this.setIndividualStatusListeners(new HashSet<IndividualStateListener>()); |
153 | } |
154 | } |
155 | |
156 | } |