diff options
author | 2018-05-14 12:55:47 +0200 | |
---|---|---|
committer | 2018-05-14 12:55:47 +0200 | |
commit | a993b72eb3e038897767c79d054467a6986d2085 (patch) | |
tree | 6ebd0c0e4d074bc7a97651e780c228014dccf42d /Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretation2logic/src/hu/bme/mit/inf | |
parent | derived feature -> partial relation bugfix (diff) | |
download | VIATRA-Generator-a993b72eb3e038897767c79d054467a6986d2085.tar.gz VIATRA-Generator-a993b72eb3e038897767c79d054467a6986d2085.tar.zst VIATRA-Generator-a993b72eb3e038897767c79d054467a6986d2085.zip |
Moved partial model management is moved to one project (+1 PM edge fix)
Diffstat (limited to 'Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretation2logic/src/hu/bme/mit/inf')
3 files changed, 0 insertions, 330 deletions
diff --git a/Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretation2logic/src/hu/bme/mit/inf/dslreasoner/viatrasolver/partialinterpretation2logic/InstanceModel2Logic.xtend b/Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretation2logic/src/hu/bme/mit/inf/dslreasoner/viatrasolver/partialinterpretation2logic/InstanceModel2Logic.xtend deleted file mode 100644 index d2b59754..00000000 --- a/Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretation2logic/src/hu/bme/mit/inf/dslreasoner/viatrasolver/partialinterpretation2logic/InstanceModel2Logic.xtend +++ /dev/null | |||
@@ -1,22 +0,0 @@ | |||
1 | package hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretation2logic | ||
2 | |||
3 | import hu.bme.mit.inf.dslreasoner.ecore2logic.Ecore2Logic_Trace | ||
4 | import hu.bme.mit.inf.dslreasoner.logic.model.builder.TracedOutput | ||
5 | import hu.bme.mit.inf.dslreasoner.logic.model.logicproblem.LogicProblem | ||
6 | import java.util.List | ||
7 | import org.eclipse.emf.ecore.EObject | ||
8 | import hu.bme.mit.inf.dslreasoner.logic.model.builder.TypeScopes | ||
9 | |||
10 | class InstanceModel2Logic { | ||
11 | val InstanceModel2PartialInterpretation instanceModel2PartialInterpretation = new InstanceModel2PartialInterpretation | ||
12 | val PartialInterpretation2Logic partialInterpretation2Logic = new PartialInterpretation2Logic | ||
13 | |||
14 | public def transform( | ||
15 | TracedOutput<LogicProblem, Ecore2Logic_Trace> metamodelTranslationResult, | ||
16 | List<EObject> objects) | ||
17 | { | ||
18 | val res1 = instanceModel2PartialInterpretation.transform(metamodelTranslationResult,objects,true) | ||
19 | this.partialInterpretation2Logic.transformPartialIntepretation2Logic(metamodelTranslationResult.output,res1) | ||
20 | return metamodelTranslationResult//.output | ||
21 | } | ||
22 | } \ No newline at end of file | ||
diff --git a/Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretation2logic/src/hu/bme/mit/inf/dslreasoner/viatrasolver/partialinterpretation2logic/InstanceModel2PartialInterpretation.xtend b/Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretation2logic/src/hu/bme/mit/inf/dslreasoner/viatrasolver/partialinterpretation2logic/InstanceModel2PartialInterpretation.xtend deleted file mode 100644 index 9a737ab9..00000000 --- a/Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretation2logic/src/hu/bme/mit/inf/dslreasoner/viatrasolver/partialinterpretation2logic/InstanceModel2PartialInterpretation.xtend +++ /dev/null | |||
@@ -1,144 +0,0 @@ | |||
1 | package hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretation2logic | ||
2 | |||
3 | import hu.bme.mit.inf.dslreasoner.ecore2logic.Ecore2Logic | ||
4 | import hu.bme.mit.inf.dslreasoner.ecore2logic.Ecore2Logic_Trace | ||
5 | import hu.bme.mit.inf.dslreasoner.logic.model.builder.TracedOutput | ||
6 | import hu.bme.mit.inf.dslreasoner.logic.model.builder.TypeScopes | ||
7 | import hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.DefinedElement | ||
8 | import hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.LogiclanguageFactory | ||
9 | import hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.TypeDeclaration | ||
10 | import hu.bme.mit.inf.dslreasoner.logic.model.logicproblem.LogicProblem | ||
11 | import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage.PartialInterpretationInitialiser | ||
12 | import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage.Problem2PartialInterpretationTrace | ||
13 | import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage.partialinterpretation.PartialRelationInterpretation | ||
14 | import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage.partialinterpretation.PartialinterpretationFactory | ||
15 | import java.util.HashMap | ||
16 | import java.util.List | ||
17 | import java.util.Map | ||
18 | import org.eclipse.emf.common.util.Enumerator | ||
19 | import org.eclipse.emf.ecore.EObject | ||
20 | import org.eclipse.emf.ecore.resource.Resource | ||
21 | |||
22 | import static extension hu.bme.mit.inf.dslreasoner.util.CollectionsUtil.* | ||
23 | |||
24 | class InstanceModel2PartialInterpretation { | ||
25 | val extension LogiclanguageFactory factory = LogiclanguageFactory.eINSTANCE | ||
26 | val extension PartialinterpretationFactory factory2 = PartialinterpretationFactory.eINSTANCE | ||
27 | val Ecore2Logic ecore2Logic = new Ecore2Logic | ||
28 | val partialInterpretationInitialiser = new PartialInterpretationInitialiser | ||
29 | |||
30 | public def transform( | ||
31 | TracedOutput<LogicProblem, Ecore2Logic_Trace> metamodelTranslationResult, | ||
32 | Resource resource, | ||
33 | boolean withID) | ||
34 | { | ||
35 | val objects = resource.allContents.toList | ||
36 | return transform(metamodelTranslationResult,objects,withID) | ||
37 | } | ||
38 | |||
39 | public def transform( | ||
40 | TracedOutput<LogicProblem, Ecore2Logic_Trace> metamodelTranslationResult, | ||
41 | List<EObject> objects, | ||
42 | boolean withID) | ||
43 | { | ||
44 | val problem = metamodelTranslationResult.output | ||
45 | val ecore2LogicTrace = metamodelTranslationResult.trace | ||
46 | val tracedOutput = partialInterpretationInitialiser.initialisePartialInterpretation(problem, new TypeScopes) | ||
47 | val partialInterpretation = tracedOutput.output | ||
48 | val partialInterpretationTrace = tracedOutput.trace | ||
49 | |||
50 | val Map<EObject,DefinedElement> object2DefinedElement = new HashMap | ||
51 | |||
52 | // EObject -> DefinedElement | ||
53 | for(objectIndex : 0..<objects.size) { | ||
54 | val object = objects.get(objectIndex) | ||
55 | val element = createDefinedElement => [ | ||
56 | it.name = if(withID) | ||
57 | { '''PartialObject«objectIndex»''' } else | ||
58 | { null } | ||
59 | ] | ||
60 | |||
61 | // Add element to interpretation | ||
62 | partialInterpretation.newElements += element | ||
63 | |||
64 | // Define the types | ||
65 | val type = ecore2Logic.TypeofEClass(ecore2LogicTrace,object.eClass) as TypeDeclaration | ||
66 | val interpretation = type.lookup(partialInterpretationTrace.type2Interpretation) | ||
67 | interpretation.elements += element | ||
68 | interpretation.supertypeInterpretation.forEach[elements += element] | ||
69 | |||
70 | // Trace handling | ||
71 | object2DefinedElement.put(object, element) | ||
72 | } | ||
73 | |||
74 | val referencesUsed = ecore2Logic.allReferencesInScope(ecore2LogicTrace).toSet | ||
75 | val attributesUsed = ecore2Logic.allAttributesInScope(ecore2LogicTrace).toSet | ||
76 | for(source : objects) { | ||
77 | // Translating the references | ||
78 | for(reference : source.eClass.EAllReferences.filter[ | ||
79 | referencesUsed.contains(it) && !it.derived]) | ||
80 | { | ||
81 | val type = ecore2Logic.relationOfReference(ecore2LogicTrace,reference) | ||
82 | val interpretation = type.lookup(partialInterpretationTrace.relation2Interpretation) | ||
83 | val sourceElement = source.lookup(object2DefinedElement) | ||
84 | if(reference.isMany) { | ||
85 | val listOfTargets = source.eGet(reference) as List<? extends EObject> | ||
86 | for(target : listOfTargets) { | ||
87 | if(target !== null && object2DefinedElement.containsKey(target)) { | ||
88 | val targetElement = target.lookup(object2DefinedElement) | ||
89 | translateLink(interpretation,sourceElement,targetElement) | ||
90 | } | ||
91 | } | ||
92 | } else { | ||
93 | val target = source.eGet(reference) as EObject | ||
94 | if(target !== null && object2DefinedElement.containsKey(target)) { | ||
95 | val targetElement = target.lookup(object2DefinedElement) | ||
96 | translateLink(interpretation,sourceElement,targetElement) | ||
97 | } | ||
98 | } | ||
99 | } | ||
100 | |||
101 | // Transforming the attributes | ||
102 | for(attribute : source.eClass.EAllAttributes.filter[attributesUsed.contains(it) && !it.derived]) { | ||
103 | val type = ecore2Logic.relationOfAttribute(ecore2LogicTrace,attribute) | ||
104 | val interpretation = type.lookup(partialInterpretationTrace.relation2Interpretation) | ||
105 | val sourceElement = source.lookup(object2DefinedElement) | ||
106 | if(attribute.isMany) { | ||
107 | val listOfTargets = source.eGet(attribute) as List<? extends EObject> | ||
108 | for(target : listOfTargets) { | ||
109 | val value = translateValue(target,ecore2LogicTrace,partialInterpretationTrace) | ||
110 | if(value !== null) { | ||
111 | translateLink(interpretation,sourceElement,value) | ||
112 | } | ||
113 | } | ||
114 | } else { | ||
115 | val target = source.eGet(attribute) | ||
116 | if(target !== null) { | ||
117 | val value = translateValue(target,ecore2LogicTrace,partialInterpretationTrace) | ||
118 | if(value !== null) { | ||
119 | translateLink(interpretation,sourceElement,value) | ||
120 | } | ||
121 | } | ||
122 | } | ||
123 | } | ||
124 | } | ||
125 | |||
126 | return partialInterpretation | ||
127 | } | ||
128 | |||
129 | protected def translateLink(PartialRelationInterpretation interpretation, DefinedElement source, DefinedElement target) { | ||
130 | interpretation.relationlinks += createBinaryElementRelationLink => [it.param1 = source it.param2 = target] | ||
131 | } | ||
132 | |||
133 | dispatch protected def translateValue(Enumerator value, Ecore2Logic_Trace ecore2LogicTrace, Problem2PartialInterpretationTrace partialInterpretationTrace) { | ||
134 | val term = this.ecore2Logic.Literal(ecore2LogicTrace,value) | ||
135 | if(term instanceof DefinedElement) { | ||
136 | return term | ||
137 | } | ||
138 | else throw new AssertionError('''term should be a defined element?''') | ||
139 | } | ||
140 | |||
141 | dispatch protected def translateValue(Object value, Ecore2Logic_Trace ecore2LogicTrace, Problem2PartialInterpretationTrace partialInterpretationTrace) { | ||
142 | //throw new UnsupportedOperationException('''Mapping of «value.class.simpleName» in partial models is currently not supported!''') | ||
143 | } | ||
144 | } \ No newline at end of file | ||
diff --git a/Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretation2logic/src/hu/bme/mit/inf/dslreasoner/viatrasolver/partialinterpretation2logic/PartialInterpretation2Logic.xtend b/Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretation2logic/src/hu/bme/mit/inf/dslreasoner/viatrasolver/partialinterpretation2logic/PartialInterpretation2Logic.xtend deleted file mode 100644 index 09a7fa60..00000000 --- a/Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretation2logic/src/hu/bme/mit/inf/dslreasoner/viatrasolver/partialinterpretation2logic/PartialInterpretation2Logic.xtend +++ /dev/null | |||
@@ -1,164 +0,0 @@ | |||
1 | package hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretation2logic | ||
2 | |||
3 | import hu.bme.mit.inf.dslreasoner.logic.model.builder.LogicProblemBuilder | ||
4 | import hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.LogiclanguageFactory | ||
5 | import hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.SymbolicDeclaration | ||
6 | import hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.Type | ||
7 | import hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.TypeDeclaration | ||
8 | import hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.TypeDefinition | ||
9 | import hu.bme.mit.inf.dslreasoner.logic.model.logicproblem.LogicProblem | ||
10 | import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage.partialinterpretation.BinaryElementRelationLink | ||
11 | import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage.partialinterpretation.PartialInterpretation | ||
12 | import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage.partialinterpretation.PartialRelationInterpretation | ||
13 | import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage.partialinterpretation.PartialTypeInterpratation | ||
14 | import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage.partialinterpretation.RelationLink | ||
15 | import java.util.ArrayList | ||
16 | import java.util.HashMap | ||
17 | import java.util.HashSet | ||
18 | import java.util.Map | ||
19 | import java.util.Set | ||
20 | import org.eclipse.xtend.lib.annotations.Data | ||
21 | |||
22 | import static extension hu.bme.mit.inf.dslreasoner.util.CollectionsUtil.* | ||
23 | import hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.DefinedElement | ||
24 | import hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.SymbolicValue | ||
25 | |||
26 | @Data class PartialInterpretation2Logic_Trace { | ||
27 | Map<DefinedElement,DefinedElement> new2Old = new HashMap | ||
28 | |||
29 | Map<TypeDeclaration, TypeDefinition> definedPart = new HashMap | ||
30 | Map<TypeDeclaration, TypeDeclaration> undefinedPart = new HashMap | ||
31 | Set<Type> originalTypes = new HashSet | ||
32 | Set<TypeDeclaration> splittedTypes = new HashSet | ||
33 | } | ||
34 | |||
35 | class PartialInterpretation2Logic { | ||
36 | val extension LogiclanguageFactory factory = LogiclanguageFactory.eINSTANCE | ||
37 | val extension LogicProblemBuilder builder = new LogicProblemBuilder | ||
38 | |||
39 | def transformPartialIntepretation2Logic(LogicProblem p, PartialInterpretation i) { | ||
40 | val trace = new PartialInterpretation2Logic_Trace() | ||
41 | trace.originalTypes.addAll(p.types) | ||
42 | if(! i.newElements.empty) { | ||
43 | |||
44 | // Elements adding | ||
45 | addExistingElementToProblem(p,i,trace) | ||
46 | |||
47 | // Types | ||
48 | for(partialTypeDeclaration : i.partialtypeinterpratation) { | ||
49 | splitTypeIntoTwo(p,partialTypeDeclaration,trace) | ||
50 | } | ||
51 | connectSplittings(p,trace) | ||
52 | |||
53 | // Relations | ||
54 | for(partialRelationInterpretation : i.partialrelationinterpretation) { | ||
55 | //println(partialRelationInterpretation.interpretationOf.name) | ||
56 | relationLinksToAssertion(p,partialRelationInterpretation,trace) | ||
57 | } | ||
58 | } | ||
59 | } | ||
60 | |||
61 | private def addExistingElementToProblem(LogicProblem p, PartialInterpretation i,PartialInterpretation2Logic_Trace trace) { | ||
62 | val newElements = new ArrayList(i.newElements) | ||
63 | var newElementIndex = 1 | ||
64 | for(newElement : newElements) { | ||
65 | newElement.name = '''o «newElementIndex++»''' | ||
66 | p.elements += newElement | ||
67 | } | ||
68 | } | ||
69 | |||
70 | private def splitTypeIntoTwo(LogicProblem p, PartialTypeInterpratation partialTypeDeclaration,PartialInterpretation2Logic_Trace trace) { | ||
71 | if(!partialTypeDeclaration.elements.empty) { | ||
72 | val declaration = partialTypeDeclaration.interpretationOf | ||
73 | |||
74 | val definedPart = createTypeDefinition => [ | ||
75 | it.name = '''«declaration.name» DefinedPart''' | ||
76 | it.elements += partialTypeDeclaration.elements | ||
77 | it.isAbstract = declaration.isIsAbstract | ||
78 | ] | ||
79 | val undefinedPart = createTypeDeclaration => [ | ||
80 | it.name = '''«declaration.name» UndefinedPart''' | ||
81 | it.isAbstract = declaration.isIsAbstract | ||
82 | ] | ||
83 | declaration.isAbstract = true | ||
84 | |||
85 | trace.definedPart.put(declaration,definedPart) | ||
86 | trace.undefinedPart.put(declaration,undefinedPart) | ||
87 | trace.splittedTypes.add(declaration) | ||
88 | p.add(definedPart) | ||
89 | p.add(undefinedPart) | ||
90 | Supertype(definedPart,declaration) | ||
91 | Supertype(undefinedPart,declaration) | ||
92 | |||
93 | for(containment : p.containmentHierarchies) { | ||
94 | if(containment.typesOrderedInHierarchy.contains(declaration)) { | ||
95 | containment.typesOrderedInHierarchy += definedPart | ||
96 | containment.typesOrderedInHierarchy += undefinedPart | ||
97 | } | ||
98 | } | ||
99 | } | ||
100 | } | ||
101 | |||
102 | private def connectSplittings(LogicProblem p,PartialInterpretation2Logic_Trace trace) { | ||
103 | val originalTypes = p.types.filter[originalType(trace)].toList | ||
104 | for(type : originalTypes) { | ||
105 | val superTypes = new ArrayList(type.supertypes.filter[originalType(trace)].toList) | ||
106 | for(supertype : superTypes) { | ||
107 | if(type.isSplitted(trace)) { | ||
108 | if(supertype.isSplitted(trace)) { | ||
109 | Supertype((type as TypeDeclaration).lookup(trace.definedPart), (supertype as TypeDeclaration).lookup(trace.definedPart)) | ||
110 | Supertype((type as TypeDeclaration).lookup(trace.undefinedPart), (supertype as TypeDeclaration).lookup(trace.undefinedPart)) | ||
111 | } else { | ||
112 | // Do nothing | ||
113 | } | ||
114 | } else { | ||
115 | if(supertype.isSplitted(trace)) { | ||
116 | Supertype(type, (supertype as TypeDeclaration).lookup(trace.undefinedPart)) | ||
117 | } else if(supertype instanceof TypeDefinition) { | ||
118 | // Do nothing | ||
119 | } | ||
120 | } | ||
121 | } | ||
122 | } | ||
123 | } | ||
124 | |||
125 | private def originalType(Type type,PartialInterpretation2Logic_Trace trace) { | ||
126 | return trace.originalTypes.contains(type) | ||
127 | } | ||
128 | private def isSplitted(Type t, PartialInterpretation2Logic_Trace trace) { | ||
129 | trace.splittedTypes.contains(t) | ||
130 | } | ||
131 | |||
132 | private def relationLinksToAssertion(LogicProblem p, PartialRelationInterpretation r,PartialInterpretation2Logic_Trace trace) { | ||
133 | val relation = r.interpretationOf | ||
134 | val links = r.relationlinks | ||
135 | if(links.size == 0) { | ||
136 | return | ||
137 | } else { | ||
138 | val term = if(links.size == 1) { | ||
139 | createLink(links.head,relation) | ||
140 | } else { | ||
141 | links.map[link|createLink(link,relation)].And | ||
142 | } | ||
143 | val assertion = Assertion('''PartialInterpretation «r.interpretationOf.name»''',term) | ||
144 | //val error= assertion.eAllContents.toIterable.filter(SymbolicValue).filter[it.symbolicReference === null] | ||
145 | //error.forEach[println("error")] | ||
146 | p.add(assertion) | ||
147 | } | ||
148 | |||
149 | } | ||
150 | |||
151 | def private createLink(RelationLink link, SymbolicDeclaration relationDeclaration) { | ||
152 | if(link instanceof BinaryElementRelationLink) { | ||
153 | if((link.param1 !== null) && (link.param2 !== null)) { | ||
154 | return createSymbolicValue=>[ | ||
155 | it.symbolicReference=relationDeclaration | ||
156 | it.parameterSubstitutions += createSymbolicValue => [it.symbolicReference = link.param1] | ||
157 | it.parameterSubstitutions += createSymbolicValue => [it.symbolicReference = link.param2] | ||
158 | ] | ||
159 | } else { | ||
160 | throw new IllegalArgumentException | ||
161 | } | ||
162 | } else throw new UnsupportedOperationException | ||
163 | } | ||
164 | } \ No newline at end of file | ||