diff options
Diffstat (limited to 'Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.reasoner/src/hu/bme/mit/inf/dslreasoner/viatrasolver/reasoner/dse/BestFirstStrategyForModelGeneration.java')
-rw-r--r-- | Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.reasoner/src/hu/bme/mit/inf/dslreasoner/viatrasolver/reasoner/dse/BestFirstStrategyForModelGeneration.java | 70 |
1 files changed, 23 insertions, 47 deletions
diff --git a/Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.reasoner/src/hu/bme/mit/inf/dslreasoner/viatrasolver/reasoner/dse/BestFirstStrategyForModelGeneration.java b/Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.reasoner/src/hu/bme/mit/inf/dslreasoner/viatrasolver/reasoner/dse/BestFirstStrategyForModelGeneration.java index 60f46033..6ff867d7 100644 --- a/Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.reasoner/src/hu/bme/mit/inf/dslreasoner/viatrasolver/reasoner/dse/BestFirstStrategyForModelGeneration.java +++ b/Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.reasoner/src/hu/bme/mit/inf/dslreasoner/viatrasolver/reasoner/dse/BestFirstStrategyForModelGeneration.java | |||
@@ -75,8 +75,6 @@ public class BestFirstStrategyForModelGeneration implements IStrategy { | |||
75 | // Running | 75 | // Running |
76 | private PriorityQueue<TrajectoryWithFitness> trajectoiresToExplore; | 76 | private PriorityQueue<TrajectoryWithFitness> trajectoiresToExplore; |
77 | private SolutionStore solutionStore; | 77 | private SolutionStore solutionStore; |
78 | private SolutionStoreWithCopy solutionStoreWithCopy; | ||
79 | private SolutionStoreWithDiversityDescriptor solutionStoreWithDiversityDescriptor; | ||
80 | private volatile boolean isInterrupted = false; | 78 | private volatile boolean isInterrupted = false; |
81 | private ModelResult modelResultByInternalSolver = null; | 79 | private ModelResult modelResultByInternalSolver = null; |
82 | private Random random = new Random(); | 80 | private Random random = new Random(); |
@@ -97,12 +95,6 @@ public class BestFirstStrategyForModelGeneration implements IStrategy { | |||
97 | this.method = method; | 95 | this.method = method; |
98 | } | 96 | } |
99 | 97 | ||
100 | public SolutionStoreWithCopy getSolutionStoreWithCopy() { | ||
101 | return solutionStoreWithCopy; | ||
102 | } | ||
103 | public SolutionStoreWithDiversityDescriptor getSolutionStoreWithDiversityDescriptor() { | ||
104 | return solutionStoreWithDiversityDescriptor; | ||
105 | } | ||
106 | public int getNumberOfStatecoderFail() { | 98 | public int getNumberOfStatecoderFail() { |
107 | return numberOfStatecoderFail; | 99 | return numberOfStatecoderFail; |
108 | } | 100 | } |
@@ -121,9 +113,6 @@ public class BestFirstStrategyForModelGeneration implements IStrategy { | |||
121 | matchers.add(matcher); | 113 | matchers.add(matcher); |
122 | } | 114 | } |
123 | 115 | ||
124 | this.solutionStoreWithCopy = new SolutionStoreWithCopy(); | ||
125 | this.solutionStoreWithDiversityDescriptor = new SolutionStoreWithDiversityDescriptor(configuration.diversityRequirement); | ||
126 | |||
127 | final ObjectiveComparatorHelper objectiveComparatorHelper = context.getObjectiveComparatorHelper(); | 116 | final ObjectiveComparatorHelper objectiveComparatorHelper = context.getObjectiveComparatorHelper(); |
128 | this.comparator = new Comparator<TrajectoryWithFitness>() { | 117 | this.comparator = new Comparator<TrajectoryWithFitness>() { |
129 | @Override | 118 | @Override |
@@ -146,13 +135,13 @@ public class BestFirstStrategyForModelGeneration implements IStrategy { | |||
146 | return; | 135 | return; |
147 | } | 136 | } |
148 | 137 | ||
149 | final Fitness firstFittness = context.calculateFitness(); | 138 | final Fitness firstfitness = context.calculateFitness(); |
150 | checkForSolution(firstFittness); | 139 | solutionStore.newSolution(context); |
151 | 140 | ||
152 | final ObjectiveComparatorHelper objectiveComparatorHelper = context.getObjectiveComparatorHelper(); | 141 | final ObjectiveComparatorHelper objectiveComparatorHelper = context.getObjectiveComparatorHelper(); |
153 | final Object[] firstTrajectory = context.getTrajectory().toArray(new Object[0]); | 142 | final Object[] firstTrajectory = context.getTrajectory().toArray(new Object[0]); |
154 | TrajectoryWithFitness currentTrajectoryWithFittness = new TrajectoryWithFitness(firstTrajectory, firstFittness); | 143 | TrajectoryWithFitness currentTrajectoryWithfitness = new TrajectoryWithFitness(firstTrajectory, firstfitness); |
155 | trajectoiresToExplore.add(currentTrajectoryWithFittness); | 144 | trajectoiresToExplore.add(currentTrajectoryWithfitness); |
156 | 145 | ||
157 | //if(configuration) | 146 | //if(configuration) |
158 | visualiseCurrentState(); | 147 | visualiseCurrentState(); |
@@ -167,22 +156,22 @@ public class BestFirstStrategyForModelGeneration implements IStrategy { | |||
167 | 156 | ||
168 | mainLoop: while (!isInterrupted && !configuration.progressMonitor.isCancelled()) { | 157 | mainLoop: while (!isInterrupted && !configuration.progressMonitor.isCancelled()) { |
169 | 158 | ||
170 | if (currentTrajectoryWithFittness == null) { | 159 | if (currentTrajectoryWithfitness == null) { |
171 | if (trajectoiresToExplore.isEmpty()) { | 160 | if (trajectoiresToExplore.isEmpty()) { |
172 | logger.debug("State space is fully traversed."); | 161 | logger.debug("State space is fully traversed."); |
173 | return; | 162 | return; |
174 | } else { | 163 | } else { |
175 | currentTrajectoryWithFittness = selectState(); | 164 | currentTrajectoryWithfitness = selectState(); |
176 | if (logger.isDebugEnabled()) { | 165 | if (logger.isDebugEnabled()) { |
177 | logger.debug("Current trajectory: " + Arrays.toString(context.getTrajectory().toArray())); | 166 | logger.debug("Current trajectory: " + Arrays.toString(context.getTrajectory().toArray())); |
178 | logger.debug("New trajectory is chosen: " + currentTrajectoryWithFittness); | 167 | logger.debug("New trajectory is chosen: " + currentTrajectoryWithfitness); |
179 | } | 168 | } |
180 | context.getDesignSpaceManager().executeTrajectoryWithMinimalBacktrackWithoutStateCoding(currentTrajectoryWithFittness.trajectory); | 169 | context.getDesignSpaceManager().executeTrajectoryWithMinimalBacktrackWithoutStateCoding(currentTrajectoryWithfitness.trajectory); |
181 | } | 170 | } |
182 | } | 171 | } |
183 | 172 | ||
184 | // visualiseCurrentState(); | 173 | // visualiseCurrentState(); |
185 | // boolean consistencyCheckResult = checkConsistency(currentTrajectoryWithFittness); | 174 | // boolean consistencyCheckResult = checkConsistency(currentTrajectoryWithfitness); |
186 | // if(consistencyCheckResult == true) { | 175 | // if(consistencyCheckResult == true) { |
187 | // continue mainLoop; | 176 | // continue mainLoop; |
188 | // } | 177 | // } |
@@ -194,7 +183,7 @@ public class BestFirstStrategyForModelGeneration implements IStrategy { | |||
194 | final Object nextActivation = iterator.next(); | 183 | final Object nextActivation = iterator.next(); |
195 | // if (!iterator.hasNext()) { | 184 | // if (!iterator.hasNext()) { |
196 | // logger.debug("Last untraversed activation of the state."); | 185 | // logger.debug("Last untraversed activation of the state."); |
197 | // trajectoiresToExplore.remove(currentTrajectoryWithFittness); | 186 | // trajectoiresToExplore.remove(currentTrajectoryWithfitness); |
198 | // } | 187 | // } |
199 | logger.debug("Executing new activation: " + nextActivation); | 188 | logger.debug("Executing new activation: " + nextActivation); |
200 | context.executeAcitvationId(nextActivation); | 189 | context.executeAcitvationId(nextActivation); |
@@ -209,7 +198,7 @@ public class BestFirstStrategyForModelGeneration implements IStrategy { | |||
209 | // System.out.println("---------"); | 198 | // System.out.println("---------"); |
210 | // } | 199 | // } |
211 | 200 | ||
212 | boolean consistencyCheckResult = checkConsistency(currentTrajectoryWithFittness); | 201 | boolean consistencyCheckResult = checkConsistency(currentTrajectoryWithfitness); |
213 | if(consistencyCheckResult == true) { continue mainLoop; } | 202 | if(consistencyCheckResult == true) { continue mainLoop; } |
214 | 203 | ||
215 | if (context.isCurrentStateAlreadyTraversed()) { | 204 | if (context.isCurrentStateAlreadyTraversed()) { |
@@ -220,38 +209,38 @@ public class BestFirstStrategyForModelGeneration implements IStrategy { | |||
220 | context.backtrack(); | 209 | context.backtrack(); |
221 | } else { | 210 | } else { |
222 | final Fitness nextFitness = context.calculateFitness(); | 211 | final Fitness nextFitness = context.calculateFitness(); |
223 | checkForSolution(nextFitness); | 212 | solutionStore.newSolution(context); |
224 | if (context.getDepth() > configuration.searchSpaceConstraints.maxDepth) { | 213 | if (context.getDepth() > configuration.searchSpaceConstraints.maxDepth) { |
225 | logger.debug("Reached max depth."); | 214 | logger.debug("Reached max depth."); |
226 | context.backtrack(); | 215 | context.backtrack(); |
227 | continue; | 216 | continue; |
228 | } | 217 | } |
229 | 218 | ||
230 | TrajectoryWithFitness nextTrajectoryWithFittness = new TrajectoryWithFitness( | 219 | TrajectoryWithFitness nextTrajectoryWithfitness = new TrajectoryWithFitness( |
231 | context.getTrajectory().toArray(), nextFitness); | 220 | context.getTrajectory().toArray(), nextFitness); |
232 | trajectoiresToExplore.add(nextTrajectoryWithFittness); | 221 | trajectoiresToExplore.add(nextTrajectoryWithfitness); |
233 | 222 | ||
234 | int compare = objectiveComparatorHelper.compare(currentTrajectoryWithFittness.fitness, | 223 | int compare = objectiveComparatorHelper.compare(currentTrajectoryWithfitness.fitness, |
235 | nextTrajectoryWithFittness.fitness); | 224 | nextTrajectoryWithfitness.fitness); |
236 | if (compare < 0) { | 225 | if (compare < 0) { |
237 | logger.debug("Better fitness, moving on: " + nextFitness); | 226 | logger.debug("Better fitness, moving on: " + nextFitness); |
238 | currentTrajectoryWithFittness = nextTrajectoryWithFittness; | 227 | currentTrajectoryWithfitness = nextTrajectoryWithfitness; |
239 | continue mainLoop; | 228 | continue mainLoop; |
240 | } else if (compare == 0) { | 229 | } else if (compare == 0) { |
241 | logger.debug("Equally good fitness, moving on: " + nextFitness); | 230 | logger.debug("Equally good fitness, moving on: " + nextFitness); |
242 | currentTrajectoryWithFittness = nextTrajectoryWithFittness; | 231 | currentTrajectoryWithfitness = nextTrajectoryWithfitness; |
243 | continue mainLoop; | 232 | continue mainLoop; |
244 | } else { | 233 | } else { |
245 | logger.debug("Worse fitness."); | 234 | logger.debug("Worse fitness."); |
246 | currentTrajectoryWithFittness = null; | 235 | currentTrajectoryWithfitness = null; |
247 | continue mainLoop; | 236 | continue mainLoop; |
248 | } | 237 | } |
249 | } | 238 | } |
250 | } | 239 | } |
251 | 240 | ||
252 | logger.debug("State is fully traversed."); | 241 | logger.debug("State is fully traversed."); |
253 | trajectoiresToExplore.remove(currentTrajectoryWithFittness); | 242 | trajectoiresToExplore.remove(currentTrajectoryWithfitness); |
254 | currentTrajectoryWithFittness = null; | 243 | currentTrajectoryWithfitness = null; |
255 | 244 | ||
256 | } | 245 | } |
257 | logger.info("Interrupted."); | 246 | logger.info("Interrupted."); |
@@ -269,19 +258,6 @@ public class BestFirstStrategyForModelGeneration implements IStrategy { | |||
269 | return activationIds; | 258 | return activationIds; |
270 | } | 259 | } |
271 | 260 | ||
272 | private void checkForSolution(final Fitness fittness) { | ||
273 | if (fittness.isSatisifiesHardObjectives()) { | ||
274 | if (solutionStoreWithDiversityDescriptor.isDifferent(context)) { | ||
275 | solutionStoreWithCopy.newSolution(context); | ||
276 | solutionStoreWithDiversityDescriptor.newSolution(context); | ||
277 | solutionStore.newSolution(context); | ||
278 | configuration.progressMonitor.workedModelFound(configuration.solutionScope.numberOfRequiredSolution); | ||
279 | |||
280 | logger.debug("Found a solution."); | ||
281 | } | ||
282 | } | ||
283 | } | ||
284 | |||
285 | @Override | 261 | @Override |
286 | public void interruptStrategy() { | 262 | public void interruptStrategy() { |
287 | isInterrupted = true; | 263 | isInterrupted = true; |
@@ -311,11 +287,11 @@ public class BestFirstStrategyForModelGeneration implements IStrategy { | |||
311 | } | 287 | } |
312 | 288 | ||
313 | public void visualiseCurrentState() { | 289 | public void visualiseCurrentState() { |
314 | PartialInterpretationVisualiser partialInterpretatioVisualiser = configuration.debugCongiguration.partialInterpretatioVisualiser; | 290 | PartialInterpretationVisualiser partialInterpretatioVisualiser = configuration.debugConfiguration.partialInterpretatioVisualiser; |
315 | if(partialInterpretatioVisualiser != null && this.configuration.documentationLevel == DocumentationLevel.FULL && workspace != null) { | 291 | if(partialInterpretatioVisualiser != null && this.configuration.documentationLevel == DocumentationLevel.FULL && workspace != null) { |
316 | PartialInterpretation p = (PartialInterpretation) (context.getModel()); | 292 | PartialInterpretation p = (PartialInterpretation) (context.getModel()); |
317 | int id = ++numberOfPrintedModel; | 293 | int id = ++numberOfPrintedModel; |
318 | if (id % configuration.debugCongiguration.partalInterpretationVisualisationFrequency == 0) { | 294 | if (id % configuration.debugConfiguration.partalInterpretationVisualisationFrequency == 0) { |
319 | PartialInterpretationVisualisation visualisation = partialInterpretatioVisualiser.visualiseConcretization(p); | 295 | PartialInterpretationVisualisation visualisation = partialInterpretatioVisualiser.visualiseConcretization(p); |
320 | visualisation.writeToFile(workspace, String.format("state%09d.png", id)); | 296 | visualisation.writeToFile(workspace, String.format("state%09d.png", id)); |
321 | } | 297 | } |