From 27187323b760bd7bba5e16cc75fadb041888e2c8 Mon Sep 17 00:00:00 2001 From: OszkarSemerath Date: Wed, 20 Jun 2018 14:42:23 +0200 Subject: Fixing multiple "true" and "false" objects --- .../model/PartialInterpretation.aird | 149 ++++++++------------- .../InstanceModel2PartialInterpretation.xtend | 2 +- .../PartialInterpretation2Logic.xtend | 3 +- .../PartialInterpretationInitialiser.xtend | 135 ++++++++++++------- .../dse/BestFirstStrategyForModelGeneration.java | 10 ++ 5 files changed, 154 insertions(+), 145 deletions(-) (limited to 'Solvers') diff --git a/Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage/model/PartialInterpretation.aird b/Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage/model/PartialInterpretation.aird index 35b87922..7fba84f6 100644 --- a/Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage/model/PartialInterpretation.aird +++ b/Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage/model/PartialInterpretation.aird @@ -583,22 +583,6 @@ - - - - - - - - - - - - - - - - @@ -663,30 +647,6 @@ - - - - - - - - - - - - - - - - - - - - - - - - @@ -1115,7 +1075,7 @@ - + @@ -1124,11 +1084,10 @@ KEEP_LOCATION KEEP_SIZE KEEP_RATIO - + backgroundColor foregroundColor - italic - + @@ -1296,28 +1255,18 @@ - + KEEP_LOCATION KEEP_SIZE KEEP_RATIO - - + + italic + - - - - - - bold - - - - - @@ -1366,21 +1315,6 @@ - - - - - - - - labelSize - - - labelSize - - - - @@ -1411,6 +1345,12 @@ + + + bold + + + @@ -1434,11 +1374,19 @@ + + + + + + + + - + @@ -1501,7 +1449,7 @@ - + @@ -1554,7 +1502,7 @@ - + @@ -1592,7 +1540,7 @@ - + @@ -1609,7 +1557,7 @@ - + @@ -1641,11 +1589,11 @@ - + - + @@ -1672,7 +1620,7 @@ - + @@ -1688,7 +1636,7 @@ - + @@ -1736,7 +1684,7 @@ - + @@ -1800,7 +1748,7 @@ - + @@ -1816,7 +1764,7 @@ - + @@ -1832,7 +1780,7 @@ - + @@ -1848,7 +1796,7 @@ - + @@ -1906,7 +1854,7 @@ - + @@ -1915,6 +1863,22 @@ + + + + + bold + + + + + + + + bold + + + @@ -3063,7 +3027,7 @@ - + @@ -3073,7 +3037,7 @@ - + @@ -3334,11 +3298,10 @@ KEEP_LOCATION KEEP_SIZE KEEP_RATIO - + backgroundColor foregroundColor - italic - + diff --git a/Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage/src/hu/bme/mit/inf/dslreasoner/viatrasolver/partialinterpretation2logic/InstanceModel2PartialInterpretation.xtend b/Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage/src/hu/bme/mit/inf/dslreasoner/viatrasolver/partialinterpretation2logic/InstanceModel2PartialInterpretation.xtend index 9a737ab9..f4fc1fce 100644 --- a/Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage/src/hu/bme/mit/inf/dslreasoner/viatrasolver/partialinterpretation2logic/InstanceModel2PartialInterpretation.xtend +++ b/Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage/src/hu/bme/mit/inf/dslreasoner/viatrasolver/partialinterpretation2logic/InstanceModel2PartialInterpretation.xtend @@ -54,7 +54,7 @@ class InstanceModel2PartialInterpretation { val object = objects.get(objectIndex) val element = createDefinedElement => [ it.name = if(withID) - { '''PartialObject«objectIndex»''' } else + { '''o «objectIndex»''' } else { null } ] diff --git a/Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage/src/hu/bme/mit/inf/dslreasoner/viatrasolver/partialinterpretation2logic/PartialInterpretation2Logic.xtend b/Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage/src/hu/bme/mit/inf/dslreasoner/viatrasolver/partialinterpretation2logic/PartialInterpretation2Logic.xtend index e4ad4295..5d8d9313 100644 --- a/Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage/src/hu/bme/mit/inf/dslreasoner/viatrasolver/partialinterpretation2logic/PartialInterpretation2Logic.xtend +++ b/Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage/src/hu/bme/mit/inf/dslreasoner/viatrasolver/partialinterpretation2logic/PartialInterpretation2Logic.xtend @@ -23,6 +23,7 @@ import org.eclipse.emf.ecore.util.EcoreUtil import org.eclipse.xtend.lib.annotations.Data import static extension hu.bme.mit.inf.dslreasoner.util.CollectionsUtil.* +import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage.partialinterpretation.PrimitiveElement @Data class PartialInterpretation2Logic_Trace { Map new2Old = new HashMap @@ -66,7 +67,7 @@ class PartialInterpretation2Logic { // newElement.name = '''o «newElementIndex++»''' // p.elements += newElement // } - p.elements += i.newElements + p.elements += i.newElements.filter[!it instanceof PrimitiveElement] } private def splitTypeIntoTwo(LogicProblem p, PartialComplexTypeInterpretation partialTypeDeclaration,PartialInterpretation2Logic_Trace trace) { diff --git a/Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage/src/hu/bme/mit/inf/dslreasoner/viatrasolver/partialinterpretationlanguage/PartialInterpretationInitialiser.xtend b/Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage/src/hu/bme/mit/inf/dslreasoner/viatrasolver/partialinterpretationlanguage/PartialInterpretationInitialiser.xtend index cdc79743..2a350d53 100644 --- a/Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage/src/hu/bme/mit/inf/dslreasoner/viatrasolver/partialinterpretationlanguage/PartialInterpretationInitialiser.xtend +++ b/Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage/src/hu/bme/mit/inf/dslreasoner/viatrasolver/partialinterpretationlanguage/PartialInterpretationInitialiser.xtend @@ -2,8 +2,6 @@ package hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage import hu.bme.mit.inf.dslreasoner.logic.model.builder.TracedOutput import hu.bme.mit.inf.dslreasoner.logic.model.builder.TypeScopes -import hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.ConstantDeclaration -import hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.FunctionDeclaration import hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.LogiclanguageFactory import hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.RelationDeclaration import hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.Type @@ -12,12 +10,18 @@ import hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.TypeDefinition import hu.bme.mit.inf.dslreasoner.logic.model.logicproblem.LogicProblem import hu.bme.mit.inf.dslreasoner.logic.model.patterns.SupertypeStar import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage.partial2logicannotations.PartialModelRelation2Assertion +import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage.partialinterpretation.BooleanElement +import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage.partialinterpretation.IntegerElement +import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage.partialinterpretation.PartialBooleanInterpretation import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage.partialinterpretation.PartialComplexTypeInterpretation -import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage.partialinterpretation.PartialConstantInterpretation -import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage.partialinterpretation.PartialFunctionInterpretation +import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage.partialinterpretation.PartialIntegerInterpretation import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage.partialinterpretation.PartialInterpretation +import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage.partialinterpretation.PartialRealInterpretation import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage.partialinterpretation.PartialRelationInterpretation +import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage.partialinterpretation.PartialStringInterpretation import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage.partialinterpretation.PartialinterpretationFactory +import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage.partialinterpretation.RealElement +import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage.partialinterpretation.StringElement import java.math.BigDecimal import java.util.HashMap import java.util.Map @@ -30,8 +34,19 @@ import org.eclipse.xtend.lib.annotations.Data import static extension hu.bme.mit.inf.dslreasoner.util.CollectionsUtil.* @Data class Problem2PartialInterpretationTrace { - Map type2Interpretation = new HashMap - Map relation2Interpretation = new HashMap + Map type2Interpretation + PrimitiveValueTrace primitiveValues + Map relation2Interpretation +} +@Data class PrimitiveValueTrace { + PartialBooleanInterpretation booleanInterpretation + Map booleanMap + PartialIntegerInterpretation integerInterpretation + Map integerMap + PartialRealInterpretation realInterpretation + Map realMap + PartialStringInterpretation stringInterpretation + Map stringMap } /** @@ -48,34 +63,49 @@ class PartialInterpretationInitialiser { LogicProblem problem, TypeScopes typeScopes) { - - val trace = new Problem2PartialInterpretationTrace - - val res = createPartialInterpretation => [ - it.problem = problem + val res = createPartialInterpretation + res.problem = problem - // Initialise primitive elements - initBooleans(it) - initIntegers(it, typeScopes.knownIntegers, typeScopes.minNewIntegers, typeScopes.maxNewIntegers) - initReals(it, typeScopes.knownReals, typeScopes.minNewReals, typeScopes.maxNewReals) - initStrings(it,typeScopes.knownStrings, typeScopes.minNewStrings, typeScopes.maxNewStrings) - // Initialise complex elements - initElements(it, - typeScopes.minNewElementsByType, - typeScopes.maxNewElementsByType, - typeScopes.minNewElements, - typeScopes.maxNewElements, - trace - ) + // Initialise primitive elements + val booleanType = initBooleans(res) + val integerType = initIntegers(res, typeScopes.knownIntegers, typeScopes.minNewIntegers, typeScopes.maxNewIntegers) + val realType = initReals(res, typeScopes.knownReals, typeScopes.minNewReals, typeScopes.maxNewReals) + val stringType= initStrings(res,typeScopes.knownStrings, typeScopes.minNewStrings, typeScopes.maxNewStrings) + val primitiveTrace = createPrimitiveTrace(booleanType, integerType, realType, stringType) + // Initialise complex elements + + val type2Interpretation = initElements(res, + typeScopes.minNewElementsByType, + typeScopes.maxNewElementsByType, + typeScopes.minNewElements, + typeScopes.maxNewElements) - // Initialise relations - initRelations(it,trace) - ] + // Initialise relations + val relation2Interpretation = initRelations(res) + val trace = new Problem2PartialInterpretationTrace(type2Interpretation,primitiveTrace,relation2Interpretation) return new TracedOutput(res,trace) } - def protected boolean initBooleans(PartialInterpretation partialInterpretation) { + def createPrimitiveTrace( + PartialBooleanInterpretation booleanType, + PartialIntegerInterpretation integerType, + PartialRealInterpretation realType, + PartialStringInterpretation stringType) + { + return new PrimitiveValueTrace( + booleanType, + booleanType.elements.filter(BooleanElement).toMap[value], + integerType, + integerType.elements.filter(IntegerElement).toMap[value], + realType, + realType.elements.filter(RealElement).toMap[value], + stringType, + stringType.elements.filter(StringElement).toMap[value] + ) + } + + def protected initBooleans(PartialInterpretation partialInterpretation) { val booleanInterpretation = createPartialBooleanInterpretation partialInterpretation.partialtypeinterpratation += booleanInterpretation @@ -86,6 +116,8 @@ class PartialInterpretationInitialiser { val falseElement = createBooleanElement => [it.name = "false" it.value = false it.valueSet = true] booleanInterpretation.elements += falseElement partialInterpretation.newElements+=falseElement + + return booleanInterpretation } def protected initIntegers(PartialInterpretation partialInterpretation, SortedSet knownIntegers, int minNewIntegers, int maxNewIntegers) { @@ -100,6 +132,8 @@ class PartialInterpretationInitialiser { if(maxNewIntegers>0) { throw new UnsupportedOperationException('''Unspecified Integers are currently not supported!''') } + + return integerInterpretation } def protected initReals(PartialInterpretation partialInterpretation, SortedSet knownReals, int minNewReals, int maxNewReals) { @@ -114,6 +148,7 @@ class PartialInterpretationInitialiser { if(maxNewReals>0) { throw new UnsupportedOperationException('''Unspecified Real values are currently not supported!''') } + return realInterpretation } def protected initStrings(PartialInterpretation partialInterpretation, SortedSet knownStrings, int minNewStrings, int maxNewStrings) { @@ -128,13 +163,15 @@ class PartialInterpretationInitialiser { if(maxNewStrings>0) { throw new UnsupportedOperationException('''Unspecified String values are currently not supported!''') } + + return stringInterpretation } def protected initElements(PartialInterpretation interpretation, Map minNewElementsByType, Map maxNewElementsByType, - int minNewElements, int maxNewElements, - Problem2PartialInterpretationTrace trace) + int minNewElements, int maxNewElements) { + val Map type2Interpretation = new HashMap val engine = ViatraQueryEngine.on(new EMFScope(interpretation.problem)) // Elements interpretation.minNewElements = minNewElements @@ -146,37 +183,45 @@ class PartialInterpretationInitialiser { } for(typeDeclaration : interpretation.problem.types.filter(TypeDeclaration)) { - val typeInterpretation = typeDeclaration.initialisePartialTypeInterpretation(engine,trace) + val typeInterpretation = typeDeclaration.initialisePartialTypeInterpretation(engine) interpretation.partialtypeinterpratation += typeInterpretation + type2Interpretation.put(typeDeclaration,typeInterpretation) } - interpretation.problem.connectSuperypes(trace) + interpretation.problem.connectSuperypes(type2Interpretation) + return type2Interpretation } - def private connectSuperypes(LogicProblem problem, Problem2PartialInterpretationTrace trace) { + def private connectSuperypes(LogicProblem problem, Map trace) { for(typeDeclaration : problem.types.filter(TypeDeclaration)) { val supertypes = typeDeclaration.transitiveClosurePlus[it.supertypes] for(supertype : supertypes.filter(TypeDeclaration)) { - typeDeclaration.lookup(trace.type2Interpretation).supertypeInterpretation += supertype.lookup(trace.type2Interpretation) + typeDeclaration.lookup(trace).supertypeInterpretation += supertype.lookup(trace) //println('''«typeDeclaration.name» --> «supertype.name»''') } } } - def private initRelations(PartialInterpretation interpretation, Problem2PartialInterpretationTrace trace) { - interpretation.partialrelationinterpretation += interpretation.problem.relations.filter(RelationDeclaration) - .map[initialisePartialRelationInterpretation(trace)] + def private initRelations(PartialInterpretation interpretation) { + val Map relation2Interpretation = new HashMap + for(relation : interpretation.problem.relations.filter(RelationDeclaration)) { + val partialInterpretation = relation.initialisePartialRelationInterpretation + interpretation.partialrelationinterpretation += partialInterpretation + relation2Interpretation.put(relation,partialInterpretation) + } for(pMR2A : interpretation.problem.annotations.filter(PartialModelRelation2Assertion)) { val relation = pMR2A.targetRelation - val r = relation.lookup(trace.relation2Interpretation) + val r = relation.lookup(relation2Interpretation) r.relationlinks+=pMR2A.links.map[EcoreUtil.copy(it)] } // interpretation.partialfunctioninterpretation += interpretation.problem.functions.filter(FunctionDeclaration) // .map[initialisePartialFunctionInterpretation(trace)] // interpretation.partialconstantinterpretation += interpretation.problem.constants.filter(ConstantDeclaration) // .map[initialisePartialConstantDeclaration(trace)] + + return relation2Interpretation } - def private initialisePartialTypeInterpretation(TypeDeclaration t, ViatraQueryEngine engine, Problem2PartialInterpretationTrace trace) { + def private initialisePartialTypeInterpretation(TypeDeclaration t, ViatraQueryEngine engine) { val supertypeMatcher = SupertypeStar.Matcher.on(engine) val res = createPartialComplexTypeInterpretation => [ it.interpretationOf = t @@ -184,11 +229,10 @@ class PartialInterpretationInitialiser { .filter(TypeDefinition) .map[elements].flatten ] - trace.type2Interpretation.put(t,res) return res } - def private initialisePartialRelationInterpretation(RelationDeclaration r, Problem2PartialInterpretationTrace trace) { + def private initialisePartialRelationInterpretation(RelationDeclaration r) { val res = createPartialRelationInterpretation => [ it.interpretationOf = r if(r.parameters.size==2) { @@ -196,15 +240,6 @@ class PartialInterpretationInitialiser { it.param2 = r.parameters.get(1) } else throw new UnsupportedOperationException ] - trace.relation2Interpretation.put(r,res) return res } - - def private PartialConstantInterpretation initialisePartialConstantDeclaration(ConstantDeclaration c, Problem2PartialInterpretationTrace trace) { - throw new UnsupportedOperationException - } - - def private PartialFunctionInterpretation initialisePartialFunctionInterpretation(FunctionDeclaration f, Problem2PartialInterpretationTrace trace) { - throw new UnsupportedOperationException - } } \ No newline at end of file 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 e73d97b3..7862262b 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 @@ -112,6 +112,13 @@ public class BestFirstStrategyForModelGeneration implements IStrategy { this.solutionStore = context.getGlobalContext().getSolutionStore(); ViatraQueryEngine engine = context.getQueryEngine(); +// // TODO: visualisation +// matchers = new LinkedList>(); +// for(IQuerySpecification> p : this.method.getAllPatterns()) { +// System.out.println(p.getSimpleName()); +// ViatraQueryMatcher matcher = p.getMatcher(engine); +// matchers.add(matcher); +// } this.solutionStoreWithCopy = new SolutionStoreWithCopy(); this.solutionStoreWithDiversityDescriptor = new SolutionStoreWithDiversityDescriptor(configuration.diversityRequirement); @@ -181,6 +188,9 @@ public class BestFirstStrategyForModelGeneration implements IStrategy { context.executeAcitvationId(nextActivation); visualiseCurrentState(); +// for(ViatraQueryMatcher matcher : matchers) { +// System.out.println(matcher.getPatternName() + " - " + matcher.getAllValues("element")); +// } boolean consistencyCheckResult = checkConsistency(currentTrajectoryWithFittness); if(consistencyCheckResult == true) { continue mainLoop; } -- cgit v1.2.3-54-g00ecf