diff options
author | Kristóf Marussy <marussy@mit.bme.hu> | 2020-06-25 19:55:10 +0200 |
---|---|---|
committer | Kristóf Marussy <marussy@mit.bme.hu> | 2020-06-25 19:55:10 +0200 |
commit | c3a6d4b9cf3657070d180aa65ddbf0459e880329 (patch) | |
tree | 780c4fc61578dcb309af53fb0c164c7627e51676 /Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.reasoner/src/hu/bme/mit/inf/dslreasoner/viatrasolver/reasoner/dse/BestFirstStrategyForModelGeneration.java | |
parent | New configuration language parser WIP (diff) | |
parent | Scope unsat benchmarks (diff) | |
download | VIATRA-Generator-c3a6d4b9cf3657070d180aa65ddbf0459e880329.tar.gz VIATRA-Generator-c3a6d4b9cf3657070d180aa65ddbf0459e880329.tar.zst VIATRA-Generator-c3a6d4b9cf3657070d180aa65ddbf0459e880329.zip |
Merge branch 'kris'
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 | 131 |
1 files changed, 61 insertions, 70 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 e3603af3..e529892c 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 | |||
@@ -9,34 +9,25 @@ | |||
9 | *******************************************************************************/ | 9 | *******************************************************************************/ |
10 | package hu.bme.mit.inf.dslreasoner.viatrasolver.reasoner.dse; | 10 | package hu.bme.mit.inf.dslreasoner.viatrasolver.reasoner.dse; |
11 | 11 | ||
12 | import java.io.BufferedReader; | ||
13 | import java.io.IOException; | ||
14 | import java.io.InputStreamReader; | ||
15 | import java.util.ArrayList; | ||
16 | import java.util.Arrays; | 12 | import java.util.Arrays; |
17 | import java.util.Collection; | ||
18 | import java.util.Collections; | 13 | import java.util.Collections; |
19 | import java.util.Comparator; | 14 | import java.util.Comparator; |
20 | import java.util.Iterator; | 15 | import java.util.Iterator; |
21 | import java.util.LinkedList; | 16 | import java.util.LinkedList; |
22 | import java.util.List; | 17 | import java.util.List; |
23 | import java.util.Map; | ||
24 | import java.util.PriorityQueue; | 18 | import java.util.PriorityQueue; |
25 | import java.util.Random; | 19 | import java.util.Random; |
26 | 20 | ||
27 | import org.apache.log4j.Logger; | 21 | import org.apache.log4j.Logger; |
28 | import org.eclipse.emf.ecore.EObject; | 22 | import org.eclipse.emf.ecore.EObject; |
29 | import org.eclipse.emf.ecore.util.EcoreUtil; | 23 | import org.eclipse.emf.ecore.util.EcoreUtil; |
24 | import org.eclipse.viatra.dse.api.SolutionTrajectory; | ||
30 | import org.eclipse.viatra.dse.api.strategy.interfaces.IStrategy; | 25 | import org.eclipse.viatra.dse.api.strategy.interfaces.IStrategy; |
31 | import org.eclipse.viatra.dse.base.ThreadContext; | 26 | import org.eclipse.viatra.dse.base.ThreadContext; |
32 | import org.eclipse.viatra.dse.objectives.Fitness; | 27 | import org.eclipse.viatra.dse.objectives.Fitness; |
33 | import org.eclipse.viatra.dse.objectives.ObjectiveComparatorHelper; | 28 | import org.eclipse.viatra.dse.objectives.ObjectiveComparatorHelper; |
29 | import org.eclipse.viatra.dse.solutionstore.ISolutionFoundHandler; | ||
34 | import org.eclipse.viatra.dse.solutionstore.SolutionStore; | 30 | import org.eclipse.viatra.dse.solutionstore.SolutionStore; |
35 | import org.eclipse.viatra.query.runtime.api.AdvancedViatraQueryEngine; | ||
36 | import org.eclipse.viatra.query.runtime.api.IPatternMatch; | ||
37 | import org.eclipse.viatra.query.runtime.api.IQuerySpecification; | ||
38 | import org.eclipse.viatra.query.runtime.api.ViatraQueryEngine; | ||
39 | import org.eclipse.viatra.query.runtime.api.ViatraQueryMatcher; | ||
40 | 31 | ||
41 | import hu.bme.mit.inf.dslreasoner.logic.model.builder.DocumentationLevel; | 32 | import hu.bme.mit.inf.dslreasoner.logic.model.builder.DocumentationLevel; |
42 | import hu.bme.mit.inf.dslreasoner.logic.model.builder.LogicReasoner; | 33 | import hu.bme.mit.inf.dslreasoner.logic.model.builder.LogicReasoner; |
@@ -44,7 +35,6 @@ import hu.bme.mit.inf.dslreasoner.logic.model.logicproblem.LogicProblem; | |||
44 | import hu.bme.mit.inf.dslreasoner.logic.model.logicresult.InconsistencyResult; | 35 | import hu.bme.mit.inf.dslreasoner.logic.model.logicresult.InconsistencyResult; |
45 | import hu.bme.mit.inf.dslreasoner.logic.model.logicresult.LogicResult; | 36 | import hu.bme.mit.inf.dslreasoner.logic.model.logicresult.LogicResult; |
46 | import hu.bme.mit.inf.dslreasoner.logic.model.logicresult.ModelResult; | 37 | import hu.bme.mit.inf.dslreasoner.logic.model.logicresult.ModelResult; |
47 | import hu.bme.mit.inf.dslreasoner.viatra2logic.NumericProblemSolver; | ||
48 | import hu.bme.mit.inf.dslreasoner.viatrasolver.logic2viatra.ModelGenerationMethod; | 38 | import hu.bme.mit.inf.dslreasoner.viatrasolver.logic2viatra.ModelGenerationMethod; |
49 | import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretation2logic.PartialInterpretation2Logic; | 39 | import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretation2logic.PartialInterpretation2Logic; |
50 | import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage.partialinterpretation.PartialInterpretation; | 40 | import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage.partialinterpretation.PartialInterpretation; |
@@ -83,14 +73,13 @@ public class BestFirstStrategyForModelGeneration implements IStrategy { | |||
83 | // Running | 73 | // Running |
84 | private PriorityQueue<TrajectoryWithFitness> trajectoiresToExplore; | 74 | private PriorityQueue<TrajectoryWithFitness> trajectoiresToExplore; |
85 | private SolutionStore solutionStore; | 75 | private SolutionStore solutionStore; |
86 | private SolutionStoreWithCopy solutionStoreWithCopy; | ||
87 | private SolutionStoreWithDiversityDescriptor solutionStoreWithDiversityDescriptor; | ||
88 | private volatile boolean isInterrupted = false; | 76 | private volatile boolean isInterrupted = false; |
89 | private ModelResult modelResultByInternalSolver = null; | 77 | private ModelResult modelResultByInternalSolver = null; |
90 | private Random random = new Random(); | 78 | private Random random = new Random(); |
91 | //private Collection<ViatraQueryMatcher<? extends IPatternMatch>> matchers; | 79 | //private Collection<ViatraQueryMatcher<? extends IPatternMatch>> matchers; |
92 | public ActivationSelector activationSelector = new EvenActivationSelector(random); | 80 | public ActivationSelector activationSelector = new EvenActivationSelector(random); |
93 | public NumericSolver numericSolver = null; | 81 | public ViatraReasonerSolutionSaver solutionSaver; |
82 | public NumericSolver numericSolver; | ||
94 | // Statistics | 83 | // Statistics |
95 | private int numberOfStatecoderFail = 0; | 84 | private int numberOfStatecoderFail = 0; |
96 | private int numberOfPrintedModel = 0; | 85 | private int numberOfPrintedModel = 0; |
@@ -103,19 +92,17 @@ public class BestFirstStrategyForModelGeneration implements IStrategy { | |||
103 | public BestFirstStrategyForModelGeneration( | 92 | public BestFirstStrategyForModelGeneration( |
104 | ReasonerWorkspace workspace, | 93 | ReasonerWorkspace workspace, |
105 | ViatraReasonerConfiguration configuration, | 94 | ViatraReasonerConfiguration configuration, |
106 | ModelGenerationMethod method) | 95 | ModelGenerationMethod method, |
107 | { | 96 | ViatraReasonerSolutionSaver solutionSaver, |
97 | NumericSolver numericSolver) { | ||
108 | this.workspace = workspace; | 98 | this.workspace = workspace; |
109 | this.configuration = configuration; | 99 | this.configuration = configuration; |
110 | this.method = method; | 100 | this.method = method; |
101 | this.solutionSaver = solutionSaver; | ||
102 | this.numericSolver = numericSolver; | ||
103 | //logger.setLevel(Level.DEBUG); | ||
111 | } | 104 | } |
112 | 105 | ||
113 | public SolutionStoreWithCopy getSolutionStoreWithCopy() { | ||
114 | return solutionStoreWithCopy; | ||
115 | } | ||
116 | public SolutionStoreWithDiversityDescriptor getSolutionStoreWithDiversityDescriptor() { | ||
117 | return solutionStoreWithDiversityDescriptor; | ||
118 | } | ||
119 | public int getNumberOfStatecoderFail() { | 106 | public int getNumberOfStatecoderFail() { |
120 | return numberOfStatecoderFail; | 107 | return numberOfStatecoderFail; |
121 | } | 108 | } |
@@ -125,22 +112,35 @@ public class BestFirstStrategyForModelGeneration implements IStrategy { | |||
125 | public long getBacktrackingTime() { | 112 | public long getBacktrackingTime() { |
126 | return context.getDesignSpaceManager().getBacktrackingTime(); | 113 | return context.getDesignSpaceManager().getBacktrackingTime(); |
127 | } | 114 | } |
128 | //LinkedList<ViatraQueryMatcher<? extends IPatternMatch>> matchers; | 115 | |
129 | @Override | 116 | @Override |
130 | public void initStrategy(ThreadContext context) { | 117 | public void initStrategy(ThreadContext context) { |
131 | this.context = context; | 118 | this.context = context; |
132 | this.solutionStore = context.getGlobalContext().getSolutionStore(); | 119 | this.solutionStore = context.getGlobalContext().getSolutionStore(); |
120 | solutionStore.registerSolutionFoundHandler(new ISolutionFoundHandler() { | ||
121 | |||
122 | @Override | ||
123 | public void solutionTriedToSave(ThreadContext context, SolutionTrajectory trajectory) { | ||
124 | // Ignore. | ||
125 | } | ||
126 | |||
127 | @Override | ||
128 | public void solutionFound(ThreadContext context, SolutionTrajectory trajectory) { | ||
129 | configuration.progressMonitor.workedModelFound(configuration.solutionScope.numberOfRequiredSolutions); | ||
130 | saveTimes(); | ||
131 | logger.debug("Found a solution."); | ||
132 | } | ||
133 | }); | ||
134 | numericSolver.init(context); | ||
133 | 135 | ||
134 | // ViatraQueryEngine engine = context.getQueryEngine(); | 136 | // ViatraQueryEngine engine = context.getQueryEngine(); |
135 | // // TODO: visualisation | ||
136 | // matchers = new LinkedList<ViatraQueryMatcher<? extends IPatternMatch>>(); | 137 | // matchers = new LinkedList<ViatraQueryMatcher<? extends IPatternMatch>>(); |
137 | // for(IQuerySpecification<? extends ViatraQueryMatcher<? extends IPatternMatch>> p : this.method.getAllPatterns()) { | 138 | // for(IQuerySpecification<? extends ViatraQueryMatcher<? extends IPatternMatch>> p : this.method.getAllPatterns()) { |
138 | // //System.out.println(p.getSimpleName()); | 139 | // //System.out.println(p.getSimpleName()); |
139 | // ViatraQueryMatcher<? extends IPatternMatch> matcher = p.getMatcher(engine); | 140 | // ViatraQueryMatcher<? extends IPatternMatch> matcher = p.getMatcher(engine); |
140 | // matchers.add(matcher); | 141 | // matchers.add(matcher); |
141 | // } | 142 | // } |
142 | this.solutionStoreWithCopy = new SolutionStoreWithCopy(); | 143 | |
143 | this.solutionStoreWithDiversityDescriptor = new SolutionStoreWithDiversityDescriptor(configuration.diversityRequirement); | ||
144 | final ObjectiveComparatorHelper objectiveComparatorHelper = context.getObjectiveComparatorHelper(); | 144 | final ObjectiveComparatorHelper objectiveComparatorHelper = context.getObjectiveComparatorHelper(); |
145 | this.comparator = new Comparator<TrajectoryWithFitness>() { | 145 | this.comparator = new Comparator<TrajectoryWithFitness>() { |
146 | @Override | 146 | @Override |
@@ -148,8 +148,6 @@ public class BestFirstStrategyForModelGeneration implements IStrategy { | |||
148 | return objectiveComparatorHelper.compare(o2.fitness, o1.fitness); | 148 | return objectiveComparatorHelper.compare(o2.fitness, o1.fitness); |
149 | } | 149 | } |
150 | }; | 150 | }; |
151 | |||
152 | this.numericSolver = new NumericSolver(context, method, this.configuration.runIntermediateNumericalConsistencyChecks, false); | ||
153 | 151 | ||
154 | trajectoiresToExplore = new PriorityQueue<TrajectoryWithFitness>(11, comparator); | 152 | trajectoiresToExplore = new PriorityQueue<TrajectoryWithFitness>(11, comparator); |
155 | } | 153 | } |
@@ -176,14 +174,13 @@ public class BestFirstStrategyForModelGeneration implements IStrategy { | |||
176 | return; | 174 | return; |
177 | } | 175 | } |
178 | 176 | ||
179 | final Fitness firstFittness = calculateFitness(); | 177 | final Fitness firstFitness = calculateFitness(); |
180 | checkForSolution(firstFittness); | 178 | checkForSolution(firstFitness); |
181 | 179 | ||
182 | final ObjectiveComparatorHelper objectiveComparatorHelper = context.getObjectiveComparatorHelper(); | 180 | final ObjectiveComparatorHelper objectiveComparatorHelper = context.getObjectiveComparatorHelper(); |
183 | final Object[] firstTrajectory = context.getTrajectory().toArray(new Object[0]); | 181 | final Object[] firstTrajectory = context.getTrajectory().toArray(new Object[0]); |
184 | TrajectoryWithFitness currentTrajectoryWithFittness = new TrajectoryWithFitness(firstTrajectory, firstFittness); | 182 | TrajectoryWithFitness currentTrajectoryWithFitness = new TrajectoryWithFitness(firstTrajectory, firstFitness); |
185 | trajectoiresToExplore.add(currentTrajectoryWithFittness); | 183 | trajectoiresToExplore.add(currentTrajectoryWithFitness); |
186 | |||
187 | //if(configuration) | 184 | //if(configuration) |
188 | visualiseCurrentState(); | 185 | visualiseCurrentState(); |
189 | // for(ViatraQueryMatcher<? extends IPatternMatch> matcher : matchers) { | 186 | // for(ViatraQueryMatcher<? extends IPatternMatch> matcher : matchers) { |
@@ -197,22 +194,22 @@ public class BestFirstStrategyForModelGeneration implements IStrategy { | |||
197 | 194 | ||
198 | mainLoop: while (!isInterrupted && !configuration.progressMonitor.isCancelled()) { | 195 | mainLoop: while (!isInterrupted && !configuration.progressMonitor.isCancelled()) { |
199 | 196 | ||
200 | if (currentTrajectoryWithFittness == null) { | 197 | if (currentTrajectoryWithFitness == null) { |
201 | if (trajectoiresToExplore.isEmpty()) { | 198 | if (trajectoiresToExplore.isEmpty()) { |
202 | logger.debug("State space is fully traversed."); | 199 | logger.debug("State space is fully traversed."); |
203 | return; | 200 | return; |
204 | } else { | 201 | } else { |
205 | currentTrajectoryWithFittness = selectState(); | 202 | currentTrajectoryWithFitness = selectState(); |
206 | if (logger.isDebugEnabled()) { | 203 | if (logger.isDebugEnabled()) { |
207 | logger.debug("Current trajectory: " + Arrays.toString(context.getTrajectory().toArray())); | 204 | logger.debug("Current trajectory: " + Arrays.toString(context.getTrajectory().toArray())); |
208 | logger.debug("New trajectory is chosen: " + currentTrajectoryWithFittness); | 205 | logger.debug("New trajectory is chosen: " + currentTrajectoryWithFitness); |
209 | } | 206 | } |
210 | context.getDesignSpaceManager().executeTrajectoryWithMinimalBacktrackWithoutStateCoding(currentTrajectoryWithFittness.trajectory); | 207 | context.getDesignSpaceManager().executeTrajectoryWithMinimalBacktrackWithoutStateCoding(currentTrajectoryWithFitness.trajectory); |
211 | } | 208 | } |
212 | } | 209 | } |
213 | 210 | ||
214 | // visualiseCurrentState(); | 211 | // visualiseCurrentState(); |
215 | // boolean consistencyCheckResult = checkConsistency(currentTrajectoryWithFittness); | 212 | // boolean consistencyCheckResult = checkConsistency(currentTrajectoryWithfitness); |
216 | // if(consistencyCheckResult == true) { | 213 | // if(consistencyCheckResult == true) { |
217 | // continue mainLoop; | 214 | // continue mainLoop; |
218 | // } | 215 | // } |
@@ -224,10 +221,11 @@ public class BestFirstStrategyForModelGeneration implements IStrategy { | |||
224 | final Object nextActivation = iterator.next(); | 221 | final Object nextActivation = iterator.next(); |
225 | // if (!iterator.hasNext()) { | 222 | // if (!iterator.hasNext()) { |
226 | // logger.debug("Last untraversed activation of the state."); | 223 | // logger.debug("Last untraversed activation of the state."); |
227 | // trajectoiresToExplore.remove(currentTrajectoryWithFittness); | 224 | // trajectoiresToExplore.remove(currentTrajectoryWithfitness); |
228 | // } | 225 | // } |
229 | logger.debug("Executing new activation: " + nextActivation); | 226 | logger.debug("Executing new activation: " + nextActivation); |
230 | context.executeAcitvationId(nextActivation); | 227 | context.executeAcitvationId(nextActivation); |
228 | method.getStatistics().incrementDecisionCount(); | ||
231 | 229 | ||
232 | visualiseCurrentState(); | 230 | visualiseCurrentState(); |
233 | // for(ViatraQueryMatcher<? extends IPatternMatch> matcher : matchers) { | 231 | // for(ViatraQueryMatcher<? extends IPatternMatch> matcher : matchers) { |
@@ -238,7 +236,7 @@ public class BestFirstStrategyForModelGeneration implements IStrategy { | |||
238 | // | 236 | // |
239 | // } | 237 | // } |
240 | 238 | ||
241 | boolean consistencyCheckResult = checkConsistency(currentTrajectoryWithFittness); | 239 | boolean consistencyCheckResult = checkConsistency(currentTrajectoryWithFitness); |
242 | if(consistencyCheckResult == true) { continue mainLoop; } | 240 | if(consistencyCheckResult == true) { continue mainLoop; } |
243 | 241 | ||
244 | if (context.isCurrentStateAlreadyTraversed()) { | 242 | if (context.isCurrentStateAlreadyTraversed()) { |
@@ -251,7 +249,7 @@ public class BestFirstStrategyForModelGeneration implements IStrategy { | |||
251 | logger.debug("Numeric constraints are not satisifed."); | 249 | logger.debug("Numeric constraints are not satisifed."); |
252 | context.backtrack(); | 250 | context.backtrack(); |
253 | } else { | 251 | } else { |
254 | final Fitness nextFitness = calculateFitness(); | 252 | final Fitness nextFitness = context.calculateFitness(); |
255 | checkForSolution(nextFitness); | 253 | checkForSolution(nextFitness); |
256 | if (context.getDepth() > configuration.searchSpaceConstraints.maxDepth) { | 254 | if (context.getDepth() > configuration.searchSpaceConstraints.maxDepth) { |
257 | logger.debug("Reached max depth."); | 255 | logger.debug("Reached max depth."); |
@@ -259,31 +257,31 @@ public class BestFirstStrategyForModelGeneration implements IStrategy { | |||
259 | continue; | 257 | continue; |
260 | } | 258 | } |
261 | 259 | ||
262 | TrajectoryWithFitness nextTrajectoryWithFittness = new TrajectoryWithFitness( | 260 | TrajectoryWithFitness nextTrajectoryWithfitness = new TrajectoryWithFitness( |
263 | context.getTrajectory().toArray(), nextFitness); | 261 | context.getTrajectory().toArray(), nextFitness); |
264 | trajectoiresToExplore.add(nextTrajectoryWithFittness); | 262 | trajectoiresToExplore.add(nextTrajectoryWithfitness); |
265 | 263 | ||
266 | int compare = objectiveComparatorHelper.compare(currentTrajectoryWithFittness.fitness, | 264 | int compare = objectiveComparatorHelper.compare(currentTrajectoryWithFitness.fitness, |
267 | nextTrajectoryWithFittness.fitness); | 265 | nextTrajectoryWithfitness.fitness); |
268 | if (compare < 0) { | 266 | if (compare < 0) { |
269 | logger.debug("Better fitness, moving on: " + nextFitness); | 267 | logger.debug("Better fitness, moving on: " + nextFitness); |
270 | currentTrajectoryWithFittness = nextTrajectoryWithFittness; | 268 | currentTrajectoryWithFitness = nextTrajectoryWithfitness; |
271 | continue mainLoop; | 269 | continue mainLoop; |
272 | } else if (compare == 0) { | 270 | } else if (compare == 0) { |
273 | logger.debug("Equally good fitness, moving on: " + nextFitness); | 271 | logger.debug("Equally good fitness, moving on: " + nextFitness); |
274 | currentTrajectoryWithFittness = nextTrajectoryWithFittness; | 272 | currentTrajectoryWithFitness = nextTrajectoryWithfitness; |
275 | continue mainLoop; | 273 | continue mainLoop; |
276 | } else { | 274 | } else { |
277 | logger.debug("Worse fitness."); | 275 | logger.debug("Worse fitness."); |
278 | currentTrajectoryWithFittness = null; | 276 | currentTrajectoryWithFitness = null; |
279 | continue mainLoop; | 277 | continue mainLoop; |
280 | } | 278 | } |
281 | } | 279 | } |
282 | } | 280 | } |
283 | 281 | ||
284 | logger.debug("State is fully traversed."); | 282 | logger.debug("State is fully traversed."); |
285 | trajectoiresToExplore.remove(currentTrajectoryWithFittness); | 283 | trajectoiresToExplore.remove(currentTrajectoryWithFitness); |
286 | currentTrajectoryWithFittness = null; | 284 | currentTrajectoryWithFitness = null; |
287 | 285 | ||
288 | } | 286 | } |
289 | logger.info("Interrupted."); | 287 | logger.info("Interrupted."); |
@@ -308,6 +306,7 @@ public class BestFirstStrategyForModelGeneration implements IStrategy { | |||
308 | try { | 306 | try { |
309 | activationIds = this.activationSelector.randomizeActivationIDs(context.getUntraversedActivationIds()); | 307 | activationIds = this.activationSelector.randomizeActivationIDs(context.getUntraversedActivationIds()); |
310 | } catch (NullPointerException e) { | 308 | } catch (NullPointerException e) { |
309 | // logger.warn("Unexpected state code: " + context.getDesignSpaceManager().getCurrentState()); | ||
311 | numberOfStatecoderFail++; | 310 | numberOfStatecoderFail++; |
312 | activationIds = Collections.emptyList(); | 311 | activationIds = Collections.emptyList(); |
313 | } | 312 | } |
@@ -315,27 +314,16 @@ public class BestFirstStrategyForModelGeneration implements IStrategy { | |||
315 | } | 314 | } |
316 | 315 | ||
317 | private void checkForSolution(final Fitness fittness) { | 316 | private void checkForSolution(final Fitness fittness) { |
318 | if (fittness.isSatisifiesHardObjectives()) { | 317 | solutionStore.newSolution(context); |
319 | if (solutionStoreWithDiversityDescriptor.isDifferent(context)) { | ||
320 | if(numericSolver.currentSatisfiable()) { | ||
321 | Map<EObject, EObject> trace = solutionStoreWithCopy.newSolution(context); | ||
322 | numericSolver.fillSolutionCopy(trace); | ||
323 | solutionStoreWithDiversityDescriptor.newSolution(context); | ||
324 | solutionStore.newSolution(context); | ||
325 | configuration.progressMonitor.workedModelFound(configuration.solutionScope.numberOfRequiredSolution); | ||
326 | saveTimes(); | ||
327 | logger.debug("Found a solution."); | ||
328 | } | ||
329 | } | ||
330 | } | ||
331 | } | 318 | } |
319 | |||
332 | public List<String> times = new LinkedList<String>(); | 320 | public List<String> times = new LinkedList<String>(); |
333 | private void saveTimes() { | 321 | private void saveTimes() { |
334 | long statecoderTime = ((NeighbourhoodBasedPartialInterpretationStateCoder)this.context.getStateCoder()).getStatecoderRuntime()/1000000; | 322 | long statecoderTime = ((NeighbourhoodBasedPartialInterpretationStateCoder<?, ?>)this.context.getStateCoder()).getStatecoderRuntime()/1000000; |
335 | long forwardTime = context.getDesignSpaceManager().getForwardTime()/1000000; | 323 | long forwardTime = context.getDesignSpaceManager().getForwardTime()/1000000; |
336 | long backtrackingTime = context.getDesignSpaceManager().getBacktrackingTime()/1000000; | 324 | long backtrackingTime = context.getDesignSpaceManager().getBacktrackingTime()/1000000; |
337 | long solutionCopy = solutionStoreWithCopy.getSumRuntime()/1000000; | ||
338 | long activationSelection = this.activationSelector.getRuntime()/1000000; | 325 | long activationSelection = this.activationSelector.getRuntime()/1000000; |
326 | long solutionCopierTime = this.solutionSaver.getTotalCopierRuntime()/1000000; | ||
339 | long numericalSolverSumTime = this.numericSolver.getRuntime()/1000000; | 327 | long numericalSolverSumTime = this.numericSolver.getRuntime()/1000000; |
340 | long numericalSolverProblemForming = this.numericSolver.getSolverSolvingProblem()/1000000; | 328 | long numericalSolverProblemForming = this.numericSolver.getSolverSolvingProblem()/1000000; |
341 | long numericalSolverSolving = this.numericSolver.getSolverSolvingProblem()/1000000; | 329 | long numericalSolverSolving = this.numericSolver.getSolverSolvingProblem()/1000000; |
@@ -347,8 +335,8 @@ public class BestFirstStrategyForModelGeneration implements IStrategy { | |||
347 | "|Backtrackingtime:"+backtrackingTime+ | 335 | "|Backtrackingtime:"+backtrackingTime+ |
348 | "|GlobalConstraintEvaluationTime:"+(globalConstraintEvaluationTime/1000000)+ | 336 | "|GlobalConstraintEvaluationTime:"+(globalConstraintEvaluationTime/1000000)+ |
349 | "|FitnessCalculationTime:"+(fitnessCalculationTime/1000000)+ | 337 | "|FitnessCalculationTime:"+(fitnessCalculationTime/1000000)+ |
350 | "|SolutionCopyTime:"+solutionCopy+ | ||
351 | "|ActivationSelectionTime:"+activationSelection+ | 338 | "|ActivationSelectionTime:"+activationSelection+ |
339 | "|SolutionCopyTime:"+solutionCopierTime+ | ||
352 | "|NumericalSolverSumTime:"+numericalSolverSumTime+ | 340 | "|NumericalSolverSumTime:"+numericalSolverSumTime+ |
353 | "|NumericalSolverProblemFormingTime:"+numericalSolverProblemForming+ | 341 | "|NumericalSolverProblemFormingTime:"+numericalSolverProblemForming+ |
354 | "|NumericalSolverSolvingTime:"+numericalSolverSolving+ | 342 | "|NumericalSolverSolvingTime:"+numericalSolverSolving+ |
@@ -385,13 +373,16 @@ public class BestFirstStrategyForModelGeneration implements IStrategy { | |||
385 | } | 373 | } |
386 | 374 | ||
387 | public void visualiseCurrentState() { | 375 | public void visualiseCurrentState() { |
388 | PartialInterpretationVisualiser partialInterpretatioVisualiser = configuration.debugCongiguration.partialInterpretatioVisualiser; | 376 | PartialInterpretationVisualiser partialInterpretatioVisualiser = configuration.debugConfiguration.partialInterpretatioVisualiser; |
389 | if(partialInterpretatioVisualiser != null && this.configuration.documentationLevel == DocumentationLevel.FULL && workspace != null) { | 377 | if(partialInterpretatioVisualiser != null && this.configuration.documentationLevel == DocumentationLevel.FULL && workspace != null) { |
390 | PartialInterpretation p = (PartialInterpretation) (context.getModel()); | 378 | PartialInterpretation p = (PartialInterpretation) (context.getModel()); |
391 | int id = ++numberOfPrintedModel; | 379 | int id = ++numberOfPrintedModel; |
392 | if (id % configuration.debugCongiguration.partalInterpretationVisualisationFrequency == 0) { | 380 | if (id % configuration.debugConfiguration.partalInterpretationVisualisationFrequency == 0) { |
393 | PartialInterpretationVisualisation visualisation = partialInterpretatioVisualiser.visualiseConcretization(p); | 381 | PartialInterpretationVisualisation visualisation = partialInterpretatioVisualiser.visualiseConcretization(p); |
394 | visualisation.writeToFile(workspace, String.format("state%09d.png", id)); | 382 | logger.debug("Visualizing state: " + id + " (" + context.getDesignSpaceManager().getCurrentState() + ")"); |
383 | String name = String.format("state%09d", id); | ||
384 | visualisation.writeToFile(workspace, name + ".png"); | ||
385 | workspace.writeModel((EObject) context.getModel(), name + ".xmi"); | ||
395 | } | 386 | } |
396 | } | 387 | } |
397 | } | 388 | } |