diff options
Diffstat (limited to 'Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.reasoner/src/hu/bme/mit/inf/dslreasoner/viatrasolver/reasoner/dse')
-rw-r--r-- | Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.reasoner/src/hu/bme/mit/inf/dslreasoner/viatrasolver/reasoner/dse/BestFirstStrategyForModelGeneration.java | 46 |
1 files changed, 39 insertions, 7 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..81b551fb 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 | |||
@@ -14,9 +14,11 @@ import java.util.Arrays; | |||
14 | import java.util.Collection; | 14 | import java.util.Collection; |
15 | import java.util.Collections; | 15 | import java.util.Collections; |
16 | import java.util.Comparator; | 16 | import java.util.Comparator; |
17 | import java.util.HashMap; | ||
17 | import java.util.Iterator; | 18 | import java.util.Iterator; |
18 | import java.util.LinkedList; | 19 | import java.util.LinkedList; |
19 | import java.util.List; | 20 | import java.util.List; |
21 | import java.util.Map; | ||
20 | import java.util.PriorityQueue; | 22 | import java.util.PriorityQueue; |
21 | import java.util.Random; | 23 | import java.util.Random; |
22 | 24 | ||
@@ -32,6 +34,8 @@ import org.eclipse.viatra.query.runtime.api.IQuerySpecification; | |||
32 | import org.eclipse.viatra.query.runtime.api.ViatraQueryEngine; | 34 | import org.eclipse.viatra.query.runtime.api.ViatraQueryEngine; |
33 | import org.eclipse.viatra.query.runtime.api.ViatraQueryMatcher; | 35 | import org.eclipse.viatra.query.runtime.api.ViatraQueryMatcher; |
34 | 36 | ||
37 | import ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator.app.MetricDistanceGroup; | ||
38 | import ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator.app.PartialInterpretationMetric; | ||
35 | import hu.bme.mit.inf.dslreasoner.logic.model.builder.DocumentationLevel; | 39 | import hu.bme.mit.inf.dslreasoner.logic.model.builder.DocumentationLevel; |
36 | import hu.bme.mit.inf.dslreasoner.logic.model.builder.LogicReasoner; | 40 | import hu.bme.mit.inf.dslreasoner.logic.model.builder.LogicReasoner; |
37 | import hu.bme.mit.inf.dslreasoner.logic.model.logicproblem.LogicProblem; | 41 | import hu.bme.mit.inf.dslreasoner.logic.model.logicproblem.LogicProblem; |
@@ -188,8 +192,25 @@ public class BestFirstStrategyForModelGeneration implements IStrategy { | |||
188 | // } | 192 | // } |
189 | 193 | ||
190 | List<Object> activationIds = selectActivation(); | 194 | List<Object> activationIds = selectActivation(); |
195 | PartialInterpretation model = (PartialInterpretation) context.getModel(); | ||
196 | System.out.println(model.getNewElements().size() ); | ||
197 | PartialInterpretationMetric.initPaths(); | ||
198 | if(model.getNewElements().size() >= 10) { | ||
199 | Map<Object, Double> valueMap = new HashMap<Object, Double>(); | ||
200 | System.out.println(PartialInterpretationMetric.calculateMetricDistance(model).getMPCDistance()); | ||
201 | for(Object id : activationIds) { | ||
202 | context.executeAcitvationId(id); | ||
203 | model = (PartialInterpretation) context.getModel(); | ||
204 | MetricDistanceGroup g = PartialInterpretationMetric.calculateMetricDistance(model); | ||
205 | valueMap.put(id, g.getMPCDistance()); | ||
206 | context.backtrack(); | ||
207 | } | ||
208 | Collections.sort(activationIds, Comparator.comparing(li -> valueMap.get(li))); | ||
209 | } | ||
210 | |||
211 | |||
191 | Iterator<Object> iterator = activationIds.iterator(); | 212 | Iterator<Object> iterator = activationIds.iterator(); |
192 | 213 | ||
193 | while (!isInterrupted && !configuration.progressMonitor.isCancelled() && iterator.hasNext()) { | 214 | while (!isInterrupted && !configuration.progressMonitor.isCancelled() && iterator.hasNext()) { |
194 | final Object nextActivation = iterator.next(); | 215 | final Object nextActivation = iterator.next(); |
195 | // if (!iterator.hasNext()) { | 216 | // if (!iterator.hasNext()) { |
@@ -198,7 +219,7 @@ public class BestFirstStrategyForModelGeneration implements IStrategy { | |||
198 | // } | 219 | // } |
199 | logger.debug("Executing new activation: " + nextActivation); | 220 | logger.debug("Executing new activation: " + nextActivation); |
200 | context.executeAcitvationId(nextActivation); | 221 | context.executeAcitvationId(nextActivation); |
201 | 222 | ||
202 | visualiseCurrentState(); | 223 | visualiseCurrentState(); |
203 | // for(ViatraQueryMatcher<? extends IPatternMatch> matcher : matchers) { | 224 | // for(ViatraQueryMatcher<? extends IPatternMatch> matcher : matchers) { |
204 | // System.out.println(matcher.getPatternName()); | 225 | // System.out.println(matcher.getPatternName()); |
@@ -209,13 +230,16 @@ public class BestFirstStrategyForModelGeneration implements IStrategy { | |||
209 | // System.out.println("---------"); | 230 | // System.out.println("---------"); |
210 | // } | 231 | // } |
211 | 232 | ||
233 | //calculate the metrics for each state | ||
234 | // logCurrentStateMetric(); | ||
235 | |||
212 | boolean consistencyCheckResult = checkConsistency(currentTrajectoryWithFittness); | 236 | boolean consistencyCheckResult = checkConsistency(currentTrajectoryWithFittness); |
213 | if(consistencyCheckResult == true) { continue mainLoop; } | 237 | if(consistencyCheckResult == true) { continue mainLoop; } |
214 | 238 | ||
215 | if (context.isCurrentStateAlreadyTraversed()) { | 239 | /* if (context.isCurrentStateAlreadyTraversed()) { |
216 | logger.info("The new state is already visited."); | 240 | // logger.info("The new state is already visited."); |
217 | context.backtrack(); | 241 | // context.backtrack(); |
218 | } else if (!context.checkGlobalConstraints()) { | 242 | // } else*/ if (!context.checkGlobalConstraints()) { |
219 | logger.debug("Global contraint is not satisifed."); | 243 | logger.debug("Global contraint is not satisifed."); |
220 | context.backtrack(); | 244 | context.backtrack(); |
221 | } else { | 245 | } else { |
@@ -248,7 +272,6 @@ public class BestFirstStrategyForModelGeneration implements IStrategy { | |||
248 | } | 272 | } |
249 | } | 273 | } |
250 | } | 274 | } |
251 | |||
252 | logger.debug("State is fully traversed."); | 275 | logger.debug("State is fully traversed."); |
253 | trajectoiresToExplore.remove(currentTrajectoryWithFittness); | 276 | trajectoiresToExplore.remove(currentTrajectoryWithFittness); |
254 | currentTrajectoryWithFittness = null; | 277 | currentTrajectoryWithFittness = null; |
@@ -309,6 +332,15 @@ public class BestFirstStrategyForModelGeneration implements IStrategy { | |||
309 | return trajectoiresToExplore.element(); | 332 | return trajectoiresToExplore.element(); |
310 | } | 333 | } |
311 | } | 334 | } |
335 | |||
336 | // private void logCurrentStateMetric() { | ||
337 | // if(this.configuration.documentationLevel != DocumentationLevel.NONE || workspace == null) { | ||
338 | // return; | ||
339 | // } | ||
340 | // | ||
341 | // PartialInterpretation interpretation = (PartialInterpretation)context.getModel(); //pattern.get("interpretation"); | ||
342 | // PartialInterpretationMetric.calculateMetric(interpretation, "debug/metric/" + context.getModel().hashCode(), context.getCurrentStateId().toString()); | ||
343 | // } | ||
312 | 344 | ||
313 | public void visualiseCurrentState() { | 345 | public void visualiseCurrentState() { |
314 | PartialInterpretationVisualiser partialInterpretatioVisualiser = configuration.debugCongiguration.partialInterpretatioVisualiser; | 346 | PartialInterpretationVisualiser partialInterpretatioVisualiser = configuration.debugCongiguration.partialInterpretatioVisualiser; |