aboutsummaryrefslogtreecommitdiffstats
path: root/Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.reasoner/src/hu/bme/mit/inf/dslreasoner/viatrasolver/reasoner/dse/BestFirstStrategyForModelGeneration.java
diff options
context:
space:
mode:
authorLibravatar Kristóf Marussy <marussy@mit.bme.hu>2020-06-23 15:16:27 +0200
committerLibravatar Kristóf Marussy <marussy@mit.bme.hu>2020-06-23 15:16:27 +0200
commitf9c646d97400741b1fb2863668ea68de0c4f18b7 (patch)
tree783983f3217f006d9acde59b1cf007059a73f9d4 /Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.reasoner/src/hu/bme/mit/inf/dslreasoner/viatrasolver/reasoner/dse/BestFirstStrategyForModelGeneration.java
parentFix numeric-solver-at-end (diff)
downloadVIATRA-Generator-f9c646d97400741b1fb2863668ea68de0c4f18b7.tar.gz
VIATRA-Generator-f9c646d97400741b1fb2863668ea68de0c4f18b7.tar.zst
VIATRA-Generator-f9c646d97400741b1fb2863668ea68de0c4f18b7.zip
Measurements framework fixes
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.java43
1 files changed, 35 insertions, 8 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 e0f838a6..e3603af3 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
@@ -32,6 +32,7 @@ import org.eclipse.viatra.dse.base.ThreadContext;
32import org.eclipse.viatra.dse.objectives.Fitness; 32import org.eclipse.viatra.dse.objectives.Fitness;
33import org.eclipse.viatra.dse.objectives.ObjectiveComparatorHelper; 33import org.eclipse.viatra.dse.objectives.ObjectiveComparatorHelper;
34import org.eclipse.viatra.dse.solutionstore.SolutionStore; 34import org.eclipse.viatra.dse.solutionstore.SolutionStore;
35import org.eclipse.viatra.query.runtime.api.AdvancedViatraQueryEngine;
35import org.eclipse.viatra.query.runtime.api.IPatternMatch; 36import org.eclipse.viatra.query.runtime.api.IPatternMatch;
36import org.eclipse.viatra.query.runtime.api.IQuerySpecification; 37import org.eclipse.viatra.query.runtime.api.IQuerySpecification;
37import org.eclipse.viatra.query.runtime.api.ViatraQueryEngine; 38import org.eclipse.viatra.query.runtime.api.ViatraQueryEngine;
@@ -94,6 +95,8 @@ public class BestFirstStrategyForModelGeneration implements IStrategy {
94 private int numberOfStatecoderFail = 0; 95 private int numberOfStatecoderFail = 0;
95 private int numberOfPrintedModel = 0; 96 private int numberOfPrintedModel = 0;
96 private int numberOfSolverCalls = 0; 97 private int numberOfSolverCalls = 0;
98 public long globalConstraintEvaluationTime = 0;
99 public long fitnessCalculationTime = 0;
97 100
98 public long explorationStarted = 0; 101 public long explorationStarted = 0;
99 102
@@ -116,6 +119,12 @@ public class BestFirstStrategyForModelGeneration implements IStrategy {
116 public int getNumberOfStatecoderFail() { 119 public int getNumberOfStatecoderFail() {
117 return numberOfStatecoderFail; 120 return numberOfStatecoderFail;
118 } 121 }
122 public long getForwardTime() {
123 return context.getDesignSpaceManager().getForwardTime();
124 }
125 public long getBacktrackingTime() {
126 return context.getDesignSpaceManager().getBacktrackingTime();
127 }
119 //LinkedList<ViatraQueryMatcher<? extends IPatternMatch>> matchers; 128 //LinkedList<ViatraQueryMatcher<? extends IPatternMatch>> matchers;
120 @Override 129 @Override
121 public void initStrategy(ThreadContext context) { 130 public void initStrategy(ThreadContext context) {
@@ -130,10 +139,8 @@ public class BestFirstStrategyForModelGeneration implements IStrategy {
130// ViatraQueryMatcher<? extends IPatternMatch> matcher = p.getMatcher(engine); 139// ViatraQueryMatcher<? extends IPatternMatch> matcher = p.getMatcher(engine);
131// matchers.add(matcher); 140// matchers.add(matcher);
132// } 141// }
133
134 this.solutionStoreWithCopy = new SolutionStoreWithCopy(); 142 this.solutionStoreWithCopy = new SolutionStoreWithCopy();
135 this.solutionStoreWithDiversityDescriptor = new SolutionStoreWithDiversityDescriptor(configuration.diversityRequirement); 143 this.solutionStoreWithDiversityDescriptor = new SolutionStoreWithDiversityDescriptor(configuration.diversityRequirement);
136
137 final ObjectiveComparatorHelper objectiveComparatorHelper = context.getObjectiveComparatorHelper(); 144 final ObjectiveComparatorHelper objectiveComparatorHelper = context.getObjectiveComparatorHelper();
138 this.comparator = new Comparator<TrajectoryWithFitness>() { 145 this.comparator = new Comparator<TrajectoryWithFitness>() {
139 @Override 146 @Override
@@ -155,9 +162,9 @@ public class BestFirstStrategyForModelGeneration implements IStrategy {
155// } catch (IOException e) { 162// } catch (IOException e) {
156// // TODO Auto-generated catch block 163// // TODO Auto-generated catch block
157// e.printStackTrace(); 164// e.printStackTrace();
158// } 165// }
159 this.explorationStarted=System.nanoTime(); 166 this.explorationStarted=System.nanoTime();
160 if (!context.checkGlobalConstraints()) { 167 if (!checkGlobalConstraints()) {
161 logger.info("Global contraint is not satisifed in the first state. Terminate."); 168 logger.info("Global contraint is not satisifed in the first state. Terminate.");
162 return; 169 return;
163 } else if(!numericSolver.maySatisfiable()) { 170 } else if(!numericSolver.maySatisfiable()) {
@@ -169,7 +176,7 @@ public class BestFirstStrategyForModelGeneration implements IStrategy {
169 return; 176 return;
170 } 177 }
171 178
172 final Fitness firstFittness = context.calculateFitness(); 179 final Fitness firstFittness = calculateFitness();
173 checkForSolution(firstFittness); 180 checkForSolution(firstFittness);
174 181
175 final ObjectiveComparatorHelper objectiveComparatorHelper = context.getObjectiveComparatorHelper(); 182 final ObjectiveComparatorHelper objectiveComparatorHelper = context.getObjectiveComparatorHelper();
@@ -237,14 +244,14 @@ public class BestFirstStrategyForModelGeneration implements IStrategy {
237 if (context.isCurrentStateAlreadyTraversed()) { 244 if (context.isCurrentStateAlreadyTraversed()) {
238 logger.info("The new state is already visited."); 245 logger.info("The new state is already visited.");
239 context.backtrack(); 246 context.backtrack();
240 } else if (!context.checkGlobalConstraints()) { 247 } else if (!checkGlobalConstraints()) {
241 logger.debug("Global contraint is not satisifed."); 248 logger.debug("Global contraint is not satisifed.");
242 context.backtrack(); 249 context.backtrack();
243 } else if (!numericSolver.maySatisfiable()) { 250 } else if (!numericSolver.maySatisfiable()) {
244 logger.debug("Numeric constraints are not satisifed."); 251 logger.debug("Numeric constraints are not satisifed.");
245 context.backtrack(); 252 context.backtrack();
246 } else { 253 } else {
247 final Fitness nextFitness = context.calculateFitness(); 254 final Fitness nextFitness = calculateFitness();
248 checkForSolution(nextFitness); 255 checkForSolution(nextFitness);
249 if (context.getDepth() > configuration.searchSpaceConstraints.maxDepth) { 256 if (context.getDepth() > configuration.searchSpaceConstraints.maxDepth) {
250 logger.debug("Reached max depth."); 257 logger.debug("Reached max depth.");
@@ -282,6 +289,20 @@ public class BestFirstStrategyForModelGeneration implements IStrategy {
282 logger.info("Interrupted."); 289 logger.info("Interrupted.");
283 } 290 }
284 291
292 private boolean checkGlobalConstraints() {
293 long start = System.nanoTime();
294 boolean result = context.checkGlobalConstraints();
295 globalConstraintEvaluationTime += System.nanoTime() - start;
296 return result;
297 }
298
299 private Fitness calculateFitness() {
300 long start = System.nanoTime();
301 Fitness fitness = context.calculateFitness();
302 fitnessCalculationTime += System.nanoTime() - start;
303 return fitness;
304 }
305
285 private List<Object> selectActivation() { 306 private List<Object> selectActivation() {
286 List<Object> activationIds; 307 List<Object> activationIds;
287 try { 308 try {
@@ -311,6 +332,8 @@ public class BestFirstStrategyForModelGeneration implements IStrategy {
311 public List<String> times = new LinkedList<String>(); 332 public List<String> times = new LinkedList<String>();
312 private void saveTimes() { 333 private void saveTimes() {
313 long statecoderTime = ((NeighbourhoodBasedPartialInterpretationStateCoder)this.context.getStateCoder()).getStatecoderRuntime()/1000000; 334 long statecoderTime = ((NeighbourhoodBasedPartialInterpretationStateCoder)this.context.getStateCoder()).getStatecoderRuntime()/1000000;
335 long forwardTime = context.getDesignSpaceManager().getForwardTime()/1000000;
336 long backtrackingTime = context.getDesignSpaceManager().getBacktrackingTime()/1000000;
314 long solutionCopy = solutionStoreWithCopy.getSumRuntime()/1000000; 337 long solutionCopy = solutionStoreWithCopy.getSumRuntime()/1000000;
315 long activationSelection = this.activationSelector.getRuntime()/1000000; 338 long activationSelection = this.activationSelector.getRuntime()/1000000;
316 long numericalSolverSumTime = this.numericSolver.getRuntime()/1000000; 339 long numericalSolverSumTime = this.numericSolver.getRuntime()/1000000;
@@ -320,6 +343,10 @@ public class BestFirstStrategyForModelGeneration implements IStrategy {
320 this.times.add( 343 this.times.add(
321 "(TransformationExecutionTime"+method.getStatistics().transformationExecutionTime/1000000+ 344 "(TransformationExecutionTime"+method.getStatistics().transformationExecutionTime/1000000+
322 "|StateCoderTime:"+statecoderTime+ 345 "|StateCoderTime:"+statecoderTime+
346 "|ForwardTime:"+forwardTime+
347 "|Backtrackingtime:"+backtrackingTime+
348 "|GlobalConstraintEvaluationTime:"+(globalConstraintEvaluationTime/1000000)+
349 "|FitnessCalculationTime:"+(fitnessCalculationTime/1000000)+
323 "|SolutionCopyTime:"+solutionCopy+ 350 "|SolutionCopyTime:"+solutionCopy+
324 "|ActivationSelectionTime:"+activationSelection+ 351 "|ActivationSelectionTime:"+activationSelection+
325 "|NumericalSolverSumTime:"+numericalSolverSumTime+ 352 "|NumericalSolverSumTime:"+numericalSolverSumTime+
@@ -355,7 +382,7 @@ public class BestFirstStrategyForModelGeneration implements IStrategy {
355 } else { 382 } else {
356 return trajectoiresToExplore.element(); 383 return trajectoiresToExplore.element();
357 } 384 }
358 } 385 }
359 386
360 public void visualiseCurrentState() { 387 public void visualiseCurrentState() {
361 PartialInterpretationVisualiser partialInterpretatioVisualiser = configuration.debugCongiguration.partialInterpretatioVisualiser; 388 PartialInterpretationVisualiser partialInterpretatioVisualiser = configuration.debugCongiguration.partialInterpretatioVisualiser;