diff options
Diffstat (limited to 'Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.reasoner/src/hu/bme/mit/inf/dslreasoner/viatrasolver')
4 files changed, 108 insertions, 50 deletions
diff --git a/Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.reasoner/src/hu/bme/mit/inf/dslreasoner/viatrasolver/reasoner/ViatraReasoner.xtend b/Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.reasoner/src/hu/bme/mit/inf/dslreasoner/viatrasolver/reasoner/ViatraReasoner.xtend index 2ffff58a..482fcc1c 100644 --- a/Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.reasoner/src/hu/bme/mit/inf/dslreasoner/viatrasolver/reasoner/ViatraReasoner.xtend +++ b/Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.reasoner/src/hu/bme/mit/inf/dslreasoner/viatrasolver/reasoner/ViatraReasoner.xtend | |||
@@ -84,7 +84,8 @@ class ViatraReasoner extends LogicReasoner{ | |||
84 | dse.addObjective(new ModelGenerationCompositeObjective( | 84 | dse.addObjective(new ModelGenerationCompositeObjective( |
85 | new ScopeObjective, | 85 | new ScopeObjective, |
86 | method.unfinishedMultiplicities.map[new UnfinishedMultiplicityObjective(it)], | 86 | method.unfinishedMultiplicities.map[new UnfinishedMultiplicityObjective(it)], |
87 | new UnfinishedWFObjective(method.unfinishedWF) | 87 | new UnfinishedWFObjective(method.unfinishedWF), |
88 | viatraConfig.isWFOptional | ||
88 | )) | 89 | )) |
89 | 90 | ||
90 | dse.addGlobalConstraint(wf2ObjectiveConverter.createInvalidationObjective(method.invalidWF)) | 91 | dse.addGlobalConstraint(wf2ObjectiveConverter.createInvalidationObjective(method.invalidWF)) |
@@ -113,7 +114,7 @@ class ViatraReasoner extends LogicReasoner{ | |||
113 | dse.addTransformationRule(rule) | 114 | dse.addTransformationRule(rule) |
114 | } | 115 | } |
115 | 116 | ||
116 | val strategy = new BestFirstStrategyForModelGeneration(workspace,viatraConfig,method) | 117 | val strategy = new HillClimbingOnRealisticMetricStrategyForModelGeneration(workspace,viatraConfig,method) |
117 | viatraConfig.progressMonitor.workedForwardTransformation | 118 | viatraConfig.progressMonitor.workedForwardTransformation |
118 | 119 | ||
119 | val transformationTime = System.nanoTime - transformationStartTime | 120 | val transformationTime = System.nanoTime - transformationStartTime |
diff --git a/Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.reasoner/src/hu/bme/mit/inf/dslreasoner/viatrasolver/reasoner/ViatraReasonerConfiguration.xtend b/Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.reasoner/src/hu/bme/mit/inf/dslreasoner/viatrasolver/reasoner/ViatraReasonerConfiguration.xtend index c4d7e231..10734859 100644 --- a/Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.reasoner/src/hu/bme/mit/inf/dslreasoner/viatrasolver/reasoner/ViatraReasonerConfiguration.xtend +++ b/Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.reasoner/src/hu/bme/mit/inf/dslreasoner/viatrasolver/reasoner/ViatraReasonerConfiguration.xtend | |||
@@ -1,5 +1,6 @@ | |||
1 | package hu.bme.mit.inf.dslreasoner.viatrasolver.reasoner | 1 | package hu.bme.mit.inf.dslreasoner.viatrasolver.reasoner |
2 | 2 | ||
3 | import ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator.app.Domain | ||
3 | import hu.bme.mit.inf.dslreasoner.logic.model.builder.LogicReasoner | 4 | import hu.bme.mit.inf.dslreasoner.logic.model.builder.LogicReasoner |
4 | import hu.bme.mit.inf.dslreasoner.logic.model.builder.LogicSolverConfiguration | 5 | import hu.bme.mit.inf.dslreasoner.logic.model.builder.LogicSolverConfiguration |
5 | import hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.RelationDeclaration | 6 | import hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.RelationDeclaration |
@@ -45,6 +46,14 @@ class ViatraReasonerConfiguration extends LogicSolverConfiguration{ | |||
45 | * Configuration for cutting search space. | 46 | * Configuration for cutting search space. |
46 | */ | 47 | */ |
47 | public var SearchSpaceConstraint searchSpaceConstraints = new SearchSpaceConstraint | 48 | public var SearchSpaceConstraint searchSpaceConstraints = new SearchSpaceConstraint |
49 | |||
50 | public var RealisticGuidance realisticGuidance = RealisticGuidance.Composite; | ||
51 | |||
52 | public var isWFOptional = false; | ||
53 | |||
54 | public var allowMustViolations = false; | ||
55 | |||
56 | public var String domain = ''; | ||
48 | } | 57 | } |
49 | 58 | ||
50 | public class DiversityDescriptor { | 59 | public class DiversityDescriptor { |
@@ -57,6 +66,16 @@ public class DiversityDescriptor { | |||
57 | public var Set<RelationDeclaration> relevantRelations = null | 66 | public var Set<RelationDeclaration> relevantRelations = null |
58 | } | 67 | } |
59 | 68 | ||
69 | public enum RealisticGuidance{ | ||
70 | MPC, | ||
71 | NodeActivity, | ||
72 | OutDegree, | ||
73 | NodeType, | ||
74 | Composite, | ||
75 | Composite_Without_Violations, | ||
76 | Violations | ||
77 | } | ||
78 | |||
60 | public class DebugConfiguration { | 79 | public class DebugConfiguration { |
61 | public var logging = false | 80 | public var logging = false |
62 | public var PartialInterpretationVisualiser partialInterpretatioVisualiser = null; | 81 | public var PartialInterpretationVisualiser partialInterpretatioVisualiser = null; |
diff --git a/Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.reasoner/src/hu/bme/mit/inf/dslreasoner/viatrasolver/reasoner/dse/HillClimbingOnRealisticMetricStrategyForModelGeneration.java b/Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.reasoner/src/hu/bme/mit/inf/dslreasoner/viatrasolver/reasoner/dse/HillClimbingOnRealisticMetricStrategyForModelGeneration.java index 9409ac48..4dff00cd 100644 --- a/Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.reasoner/src/hu/bme/mit/inf/dslreasoner/viatrasolver/reasoner/dse/HillClimbingOnRealisticMetricStrategyForModelGeneration.java +++ b/Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.reasoner/src/hu/bme/mit/inf/dslreasoner/viatrasolver/reasoner/dse/HillClimbingOnRealisticMetricStrategyForModelGeneration.java | |||
@@ -24,6 +24,7 @@ import org.eclipse.viatra.query.runtime.api.IPatternMatch; | |||
24 | import org.eclipse.viatra.query.runtime.api.ViatraQueryEngine; | 24 | import org.eclipse.viatra.query.runtime.api.ViatraQueryEngine; |
25 | import org.eclipse.viatra.query.runtime.api.ViatraQueryMatcher; | 25 | import org.eclipse.viatra.query.runtime.api.ViatraQueryMatcher; |
26 | 26 | ||
27 | import ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator.app.Domain; | ||
27 | import ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator.app.MetricDistanceGroup; | 28 | import ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator.app.MetricDistanceGroup; |
28 | import ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator.app.PartialInterpretationMetricDistance; | 29 | import ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator.app.PartialInterpretationMetricDistance; |
29 | import hu.bme.mit.inf.dslreasoner.logic.model.builder.DocumentationLevel; | 30 | import hu.bme.mit.inf.dslreasoner.logic.model.builder.DocumentationLevel; |
@@ -37,6 +38,7 @@ import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretation2logic.Parti | |||
37 | import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage.partialinterpretation.PartialInterpretation; | 38 | import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage.partialinterpretation.PartialInterpretation; |
38 | import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage.visualisation.PartialInterpretationVisualisation; | 39 | import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage.visualisation.PartialInterpretationVisualisation; |
39 | import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage.visualisation.PartialInterpretationVisualiser; | 40 | import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage.visualisation.PartialInterpretationVisualiser; |
41 | import hu.bme.mit.inf.dslreasoner.viatrasolver.reasoner.RealisticGuidance; | ||
40 | import hu.bme.mit.inf.dslreasoner.viatrasolver.reasoner.ViatraReasonerConfiguration; | 42 | import hu.bme.mit.inf.dslreasoner.viatrasolver.reasoner.ViatraReasonerConfiguration; |
41 | import hu.bme.mit.inf.dslreasoner.workspace.ReasonerWorkspace; | 43 | import hu.bme.mit.inf.dslreasoner.workspace.ReasonerWorkspace; |
42 | 44 | ||
@@ -66,12 +68,16 @@ public class HillClimbingOnRealisticMetricStrategyForModelGeneration implements | |||
66 | private Map<Object, List<Object>> stateAndActivations; | 68 | private Map<Object, List<Object>> stateAndActivations; |
67 | private Map<TrajectoryWithFitness, Double> trajectoryFit; | 69 | private Map<TrajectoryWithFitness, Double> trajectoryFit; |
68 | 70 | ||
71 | private boolean allowMustViolation; | ||
72 | private Domain domain; | ||
73 | |||
69 | // Statistics | 74 | // Statistics |
70 | private int numberOfStatecoderFail = 0; | 75 | private int numberOfStatecoderFail = 0; |
71 | private int numberOfPrintedModel = 0; | 76 | private int numberOfPrintedModel = 0; |
72 | private int numberOfSolverCalls = 0; | 77 | private int numberOfSolverCalls = 0; |
73 | private PartialInterpretationMetricDistance metricDistance; | 78 | private PartialInterpretationMetricDistance metricDistance; |
74 | 79 | ||
80 | |||
75 | public HillClimbingOnRealisticMetricStrategyForModelGeneration( | 81 | public HillClimbingOnRealisticMetricStrategyForModelGeneration( |
76 | ReasonerWorkspace workspace, | 82 | ReasonerWorkspace workspace, |
77 | ViatraReasonerConfiguration configuration, | 83 | ViatraReasonerConfiguration configuration, |
@@ -126,7 +132,12 @@ public class HillClimbingOnRealisticMetricStrategyForModelGeneration implements | |||
126 | 132 | ||
127 | trajectoiresToExplore = new PriorityQueue<TrajectoryWithFitness>(11, comparator); | 133 | trajectoiresToExplore = new PriorityQueue<TrajectoryWithFitness>(11, comparator); |
128 | stateAndActivations = new HashMap<Object, List<Object>>(); | 134 | stateAndActivations = new HashMap<Object, List<Object>>(); |
129 | metricDistance = new PartialInterpretationMetricDistance(); | 135 | |
136 | domain = Domain.valueOf(configuration.domain); | ||
137 | metricDistance = new PartialInterpretationMetricDistance(domain); | ||
138 | |||
139 | //set whether allows must violations during the realistic generation | ||
140 | allowMustViolation = configuration.allowMustViolations; | ||
130 | } | 141 | } |
131 | 142 | ||
132 | @Override | 143 | @Override |
@@ -142,7 +153,7 @@ public class HillClimbingOnRealisticMetricStrategyForModelGeneration implements | |||
142 | 153 | ||
143 | final Fitness firstFittness = context.calculateFitness(); | 154 | final Fitness firstFittness = context.calculateFitness(); |
144 | 155 | ||
145 | final ObjectiveComparatorHelper objectiveComparatorHelper = context.getObjectiveComparatorHelper(); | 156 | //final ObjectiveComparatorHelper objectiveComparatorHelper = context.getObjectiveComparatorHelper(); |
146 | final Object[] firstTrajectory = context.getTrajectory().toArray(new Object[0]); | 157 | final Object[] firstTrajectory = context.getTrajectory().toArray(new Object[0]); |
147 | TrajectoryWithFitness currentTrajectoryWithFittness = new TrajectoryWithFitness(firstTrajectory, firstFittness); | 158 | TrajectoryWithFitness currentTrajectoryWithFittness = new TrajectoryWithFitness(firstTrajectory, firstFittness); |
148 | trajectoryFit.put(currentTrajectoryWithFittness, Double.MAX_VALUE); | 159 | trajectoryFit.put(currentTrajectoryWithFittness, Double.MAX_VALUE); |
@@ -151,7 +162,6 @@ public class HillClimbingOnRealisticMetricStrategyForModelGeneration implements | |||
151 | 162 | ||
152 | //if(configuration) | 163 | //if(configuration) |
153 | visualiseCurrentState(); | 164 | visualiseCurrentState(); |
154 | |||
155 | // the two is the True and False node generated at the beginning of the generation | 165 | // the two is the True and False node generated at the beginning of the generation |
156 | int targetSize = configuration.typeScopes.maxNewElements + 2; | 166 | int targetSize = configuration.typeScopes.maxNewElements + 2; |
157 | int count = 0; | 167 | int count = 0; |
@@ -193,26 +203,19 @@ public class HillClimbingOnRealisticMetricStrategyForModelGeneration implements | |||
193 | double draw = Math.random(); | 203 | double draw = Math.random(); |
194 | count++; | 204 | count++; |
195 | 205 | ||
196 | // output statistics | ||
197 | //System.out.println("KS"); | ||
198 | System.out.println("NA distance: " + heuristics.getNADistance()); | 206 | System.out.println("NA distance: " + heuristics.getNADistance()); |
199 | System.out.println("MPC distance: " + heuristics.getMPCDistance()); | 207 | System.out.println("MPC distance: " + heuristics.getMPCDistance()); |
200 | System.out.println("Out degree distance:" + heuristics.getOutDegreeDistance()); | 208 | System.out.println("Out degree distance:" + heuristics.getOutDegreeDistance()); |
201 | System.out.println("NodeType :" + heuristics.getNodeTypeDistance()); | 209 | System.out.println("NodeType :" + heuristics.getNodeTypeDistance()); |
202 | System.out.println("Transition :" + heuristics.getNodeTypePercentage("Transition")); | 210 | System.out.println("Edge :" + heuristics.edgeTypeDistance); |
203 | System.out.println("FinalState :" + heuristics.getNodeTypePercentage("FinalState")); | 211 | |
212 | // System.out.println("FinalState :" + heuristics.getNodeTypePercentage("FinalState")); | ||
204 | 213 | ||
205 | // MetricDistanceGroup lsHeuristic = metricDistance.calculateMetricDistance(model); | ||
206 | // System.out.println("LS"); | ||
207 | // System.out.println("NA distance: " + lsHeuristic.getNADistance()); | ||
208 | // System.out.println("MPC distance: " + lsHeuristic.getMPCDistance()); | ||
209 | // System.out.println("Out degree distance:" + lsHeuristic.getOutDegreeDistance()); | ||
210 | |||
211 | //TODO: the number of activations to be checked should be configurasble | 214 | //TODO: the number of activations to be checked should be configurasble |
212 | if(activationIds.size() > 50) { | 215 | if(activationIds.size() > 50) { |
213 | activationIds = activationIds.subList(0, 50); | 216 | activationIds = activationIds.subList(0, 50); |
214 | } | 217 | } |
215 | 218 | ||
216 | valueMap = sortWithWeight(activationIds, model.getNewElements().size()); | 219 | valueMap = sortWithWeight(activationIds, model.getNewElements().size()); |
217 | lastState = context.getCurrentStateId(); | 220 | lastState = context.getCurrentStateId(); |
218 | while (!isInterrupted && !configuration.progressMonitor.isCancelled() && activationIds.size() > 0) { | 221 | while (!isInterrupted && !configuration.progressMonitor.isCancelled() && activationIds.size() > 0) { |
@@ -222,26 +225,19 @@ public class HillClimbingOnRealisticMetricStrategyForModelGeneration implements | |||
222 | logger.debug("Executing new activation: " + nextActivation); | 225 | logger.debug("Executing new activation: " + nextActivation); |
223 | context.executeAcitvationId(nextActivation); | 226 | context.executeAcitvationId(nextActivation); |
224 | visualiseCurrentState(); | 227 | visualiseCurrentState(); |
225 | |||
226 | boolean consistencyCheckResult = checkConsistency(currentTrajectoryWithFittness); | 228 | boolean consistencyCheckResult = checkConsistency(currentTrajectoryWithFittness); |
227 | if(consistencyCheckResult == true) { continue mainLoop; } | 229 | if(consistencyCheckResult == true) { continue mainLoop; } |
228 | 230 | ||
229 | int currentSize = model.getNewElements().size(); | 231 | int currentSize = model.getNewElements().size(); |
230 | int targetDiff = targetSize - currentSize; | 232 | int targetDiff = targetSize - currentSize; |
231 | boolean shouldFinish = targetDiff <= 0; | ||
232 | 233 | ||
233 | // does not allow must violations | 234 | // does not allow must violations |
234 | // if((getNumberOfViolations(mustMatchers) > 0|| getNumberOfViolations(mayMatchers) > targetDiff) && !shouldFinish) { | 235 | if((getNumberOfViolations(mustMatchers) > 0|| getNumberOfViolations(mayMatchers) > targetDiff) && !allowMustViolation) { |
235 | // context.backtrack(); | 236 | context.backtrack(); |
236 | // }else { | 237 | }else { |
237 | final Fitness nextFitness = context.calculateFitness(); | 238 | final Fitness nextFitness = context.calculateFitness(); |
238 | 239 | ||
239 | // the only hard objectives are the size | 240 | // the only hard objectives are configured in the config file |
240 | if(shouldFinish) { | ||
241 | System.out.println("Solution Found!!"); | ||
242 | System.out.println("# violations: " + (getNumberOfViolations(mustMatchers))); | ||
243 | nextFitness.setSatisifiesHardObjectives(true); | ||
244 | } | ||
245 | checkForSolution(nextFitness); | 241 | checkForSolution(nextFitness); |
246 | 242 | ||
247 | if (context.getDepth() > configuration.searchSpaceConstraints.maxDepth) { | 243 | if (context.getDepth() > configuration.searchSpaceConstraints.maxDepth) { |
@@ -261,20 +257,23 @@ public class HillClimbingOnRealisticMetricStrategyForModelGeneration implements | |||
261 | trajectoiresToExplore.add(nextTrajectoryWithFittness); | 257 | trajectoiresToExplore.add(nextTrajectoryWithFittness); |
262 | 258 | ||
263 | //Currently, just go to the next state without considering the value of trajectory | 259 | //Currently, just go to the next state without considering the value of trajectory |
264 | int compare = objectiveComparatorHelper.compare(currentTrajectoryWithFittness.fitness, | 260 | currentTrajectoryWithFittness = nextTrajectoryWithFittness; |
265 | nextTrajectoryWithFittness.fitness); | 261 | continue mainLoop; |
266 | if (compare < 0) { | 262 | |
267 | logger.debug("Better fitness, moving on: " + nextFitness); | 263 | // int compare = objectiveComparatorHelper.compare(currentTrajectoryWithFittness.fitness, |
268 | currentTrajectoryWithFittness = nextTrajectoryWithFittness; | 264 | // nextTrajectoryWithFittness.fitness); |
269 | continue mainLoop; | 265 | // if (compare < 0) { |
270 | } else if (compare == 0) { | 266 | // logger.debug("Better fitness, moving on: " + nextFitness); |
271 | logger.debug("Equally good fitness, moving on: " + nextFitness); | 267 | // currentTrajectoryWithFittness = nextTrajectoryWithFittness; |
272 | currentTrajectoryWithFittness = nextTrajectoryWithFittness; | 268 | // continue mainLoop; |
273 | continue mainLoop; | 269 | // } else if (compare == 0) { |
274 | } else { | 270 | // logger.debug("Equally good fitness, moving on: " + nextFitness); |
275 | logger.debug("Worse fitness."); | 271 | // currentTrajectoryWithFittness = nextTrajectoryWithFittness; |
276 | currentTrajectoryWithFittness = nextTrajectoryWithFittness; | 272 | // continue mainLoop; |
277 | continue mainLoop; | 273 | // } else { |
274 | // logger.debug("Worse fitness."); | ||
275 | // currentTrajectoryWithFittness = nextTrajectoryWithFittness; | ||
276 | // continue mainLoop; | ||
278 | } | 277 | } |
279 | } | 278 | } |
280 | } | 279 | } |
@@ -282,7 +281,7 @@ public class HillClimbingOnRealisticMetricStrategyForModelGeneration implements | |||
282 | trajectoiresToExplore.remove(currentTrajectoryWithFittness); | 281 | trajectoiresToExplore.remove(currentTrajectoryWithFittness); |
283 | currentTrajectoryWithFittness = null; | 282 | currentTrajectoryWithFittness = null; |
284 | context.backtrack(); | 283 | context.backtrack(); |
285 | //} | 284 | // } |
286 | 285 | ||
287 | logger.info("Interrupted."); | 286 | logger.info("Interrupted."); |
288 | } | 287 | } |
@@ -327,10 +326,33 @@ public class HillClimbingOnRealisticMetricStrategyForModelGeneration implements | |||
327 | private double calculateCurrentStateValue(int factor, int violation) { | 326 | private double calculateCurrentStateValue(int factor, int violation) { |
328 | PartialInterpretation model = (PartialInterpretation) context.getModel(); | 327 | PartialInterpretation model = (PartialInterpretation) context.getModel(); |
329 | MetricDistanceGroup g = metricDistance.calculateMetricDistanceKS(model); | 328 | MetricDistanceGroup g = metricDistance.calculateMetricDistanceKS(model); |
330 | |||
331 | double consistenceWeights = 5 * factor / (configuration.typeScopes.maxNewElements + 2) * (1- 1.0/(1+violation)); | ||
332 | 329 | ||
333 | return(100.0 *(g.getNodeTypeDistance()) + 5*(g.getNADistance() + g.getMPCDistance() +g.getOutDegreeDistance()) + consistenceWeights); | 330 | if(configuration.realisticGuidance == RealisticGuidance.MPC) { |
331 | return g.getMPCDistance(); | ||
332 | }else if(configuration.realisticGuidance == RealisticGuidance.NodeActivity) { | ||
333 | return g.getNADistance(); | ||
334 | }else if(configuration.realisticGuidance == RealisticGuidance.OutDegree) { | ||
335 | return g.getOutDegreeDistance(); | ||
336 | }else if(configuration.realisticGuidance == RealisticGuidance.NodeType) { | ||
337 | return g.getNodeTypeDistance(); | ||
338 | }else if(configuration.realisticGuidance == RealisticGuidance.Composite) { | ||
339 | double consistenceWeights = 5 * factor / (configuration.typeScopes.maxNewElements + 2) * (1- 1.0/(1+violation)); | ||
340 | |||
341 | if(domain == Domain.Yakindumm) { | ||
342 | return(100.0 *(g.getNodeTypeDistance()) + 5*(g.getNADistance() + 5*g.getMPCDistance() +g.getOutDegreeDistance()) + consistenceWeights); | ||
343 | }else { | ||
344 | return 10*(g.getNodeTypeDistance()) + 5*(g.getNADistance() + g.getMPCDistance() +2*g.getOutDegreeDistance()) + consistenceWeights; | ||
345 | } | ||
346 | |||
347 | }else if(configuration.realisticGuidance == RealisticGuidance.Composite_Without_Violations) { | ||
348 | if(domain == Domain.Yakindumm) { | ||
349 | return 100.0 *(g.getNodeTypeDistance()) + 5*(g.getNADistance() + g.getMPCDistance() +g.getOutDegreeDistance()); | ||
350 | }else { | ||
351 | return 10*(g.getNodeTypeDistance()) + 5*(g.getNADistance() + g.getMPCDistance() + 2*g.getOutDegreeDistance()); | ||
352 | } | ||
353 | }else { | ||
354 | return violation; | ||
355 | } | ||
334 | } | 356 | } |
335 | 357 | ||
336 | private int getNumberOfViolations(Collection<ViatraQueryMatcher<? extends IPatternMatch>> matchers) { | 358 | private int getNumberOfViolations(Collection<ViatraQueryMatcher<? extends IPatternMatch>> matchers) { |
@@ -392,6 +414,8 @@ public class HillClimbingOnRealisticMetricStrategyForModelGeneration implements | |||
392 | 414 | ||
393 | private void checkForSolution(final Fitness fittness) { | 415 | private void checkForSolution(final Fitness fittness) { |
394 | if (fittness.isSatisifiesHardObjectives()) { | 416 | if (fittness.isSatisifiesHardObjectives()) { |
417 | System.out.println("Solution Found!!"); | ||
418 | System.out.println("# violations: " + (getNumberOfViolations(mustMatchers))); | ||
395 | if (solutionStoreWithDiversityDescriptor.isDifferent(context)) { | 419 | if (solutionStoreWithDiversityDescriptor.isDifferent(context)) { |
396 | solutionStoreWithCopy.newSolution(context); | 420 | solutionStoreWithCopy.newSolution(context); |
397 | solutionStoreWithDiversityDescriptor.newSolution(context); | 421 | solutionStoreWithDiversityDescriptor.newSolution(context); |
diff --git a/Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.reasoner/src/hu/bme/mit/inf/dslreasoner/viatrasolver/reasoner/dse/ModelGenerationCompositeObjective.xtend b/Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.reasoner/src/hu/bme/mit/inf/dslreasoner/viatrasolver/reasoner/dse/ModelGenerationCompositeObjective.xtend index 2489c751..9fc6853c 100644 --- a/Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.reasoner/src/hu/bme/mit/inf/dslreasoner/viatrasolver/reasoner/dse/ModelGenerationCompositeObjective.xtend +++ b/Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.reasoner/src/hu/bme/mit/inf/dslreasoner/viatrasolver/reasoner/dse/ModelGenerationCompositeObjective.xtend | |||
@@ -26,15 +26,22 @@ class ModelGenerationCompositeObjective implements IObjective{ | |||
26 | val ScopeObjective scopeObjective | 26 | val ScopeObjective scopeObjective |
27 | val List<UnfinishedMultiplicityObjective> unfinishedMultiplicityObjectives | 27 | val List<UnfinishedMultiplicityObjective> unfinishedMultiplicityObjectives |
28 | val UnfinishedWFObjective unfinishedWFObjective | 28 | val UnfinishedWFObjective unfinishedWFObjective |
29 | var boolean isWFOptional = false; | ||
29 | 30 | ||
30 | public new( | 31 | public new( |
31 | ScopeObjective scopeObjective, | 32 | ScopeObjective scopeObjective, |
32 | List<UnfinishedMultiplicityObjective> unfinishedMultiplicityObjectives, | 33 | List<UnfinishedMultiplicityObjective> unfinishedMultiplicityObjectives, |
33 | UnfinishedWFObjective unfinishedWFObjective) | 34 | UnfinishedWFObjective unfinishedWFObjective, |
35 | boolean isWFOptional) | ||
34 | { | 36 | { |
35 | this.scopeObjective = scopeObjective | 37 | this.scopeObjective = scopeObjective |
36 | this.unfinishedMultiplicityObjectives = unfinishedMultiplicityObjectives | 38 | this.unfinishedMultiplicityObjectives = unfinishedMultiplicityObjectives |
37 | this.unfinishedWFObjective = unfinishedWFObjective | 39 | this.unfinishedWFObjective = unfinishedWFObjective |
40 | this.isWFOptional = isWFOptional; | ||
41 | } | ||
42 | |||
43 | def getIsWFOptional(){ | ||
44 | return this.isWFOptional; | ||
38 | } | 45 | } |
39 | 46 | ||
40 | override init(ThreadContext context) { | 47 | override init(ThreadContext context) { |
@@ -45,7 +52,7 @@ class ModelGenerationCompositeObjective implements IObjective{ | |||
45 | 52 | ||
46 | override createNew() { | 53 | override createNew() { |
47 | return new ModelGenerationCompositeObjective( | 54 | return new ModelGenerationCompositeObjective( |
48 | this.scopeObjective, this.unfinishedMultiplicityObjectives, this.unfinishedWFObjective) | 55 | this.scopeObjective, this.unfinishedMultiplicityObjectives, this.unfinishedWFObjective, this.isWFOptional) |
49 | } | 56 | } |
50 | 57 | ||
51 | override getComparator() { Comparators.LOWER_IS_BETTER } | 58 | override getComparator() { Comparators.LOWER_IS_BETTER } |
@@ -53,7 +60,6 @@ class ModelGenerationCompositeObjective implements IObjective{ | |||
53 | var sum = 0.0 | 60 | var sum = 0.0 |
54 | val scopeFitnes = scopeObjective.getFitness(context) | 61 | val scopeFitnes = scopeObjective.getFitness(context) |
55 | //val unfinishedMultiplicitiesFitneses = unfinishedMultiplicityObjectives.map[x|x.getFitness(context)] | 62 | //val unfinishedMultiplicitiesFitneses = unfinishedMultiplicityObjectives.map[x|x.getFitness(context)] |
56 | val unfinishedWFsFitness = unfinishedWFObjective.getFitness(context) | ||
57 | 63 | ||
58 | sum+=scopeFitnes | 64 | sum+=scopeFitnes |
59 | var multiplicity = 0.0 | 65 | var multiplicity = 0.0 |
@@ -61,7 +67,12 @@ class ModelGenerationCompositeObjective implements IObjective{ | |||
61 | multiplicity+=multiplicityObjective.getFitness(context)//*0.5 | 67 | multiplicity+=multiplicityObjective.getFitness(context)//*0.5 |
62 | } | 68 | } |
63 | sum+=multiplicity | 69 | sum+=multiplicity |
64 | sum += unfinishedWFsFitness//*0.5 | 70 | |
71 | // the WF can be optional when generating realistic models | ||
72 | if(!isWFOptional){ | ||
73 | val unfinishedWFsFitness = unfinishedWFObjective.getFitness(context) | ||
74 | sum += unfinishedWFsFitness//*0.5 | ||
75 | } | ||
65 | 76 | ||
66 | //println('''Sum=«sum»|Scope=«scopeFitnes»|Multiplicity=«multiplicity»|WFs=«unfinishedWFsFitness»''') | 77 | //println('''Sum=«sum»|Scope=«scopeFitnes»|Multiplicity=«multiplicity»|WFs=«unfinishedWFsFitness»''') |
67 | 78 | ||
@@ -70,6 +81,9 @@ class ModelGenerationCompositeObjective implements IObjective{ | |||
70 | 81 | ||
71 | override getLevel() { 2 } | 82 | override getLevel() { 2 } |
72 | override getName() { "CompositeUnfinishednessObjective"} | 83 | override getName() { "CompositeUnfinishednessObjective"} |
84 | def getObjective(){ | ||
85 | return this.unfinishedMultiplicityObjectives; | ||
86 | } | ||
73 | 87 | ||
74 | override isHardObjective() { true } | 88 | override isHardObjective() { true } |
75 | override satisifiesHardObjective(Double fitness) { fitness <= 0.001 } | 89 | override satisifiesHardObjective(Double fitness) { fitness <= 0.001 } |