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.partialinterpretationlanguage/src/hu/bme/mit/inf/dslreasoner/viatrasolver/partialinterpretation2logic/PartialInterpretation2Logic.xtend | |
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.partialinterpretationlanguage/src/hu/bme/mit/inf/dslreasoner/viatrasolver/partialinterpretation2logic/PartialInterpretation2Logic.xtend')
1 files changed, 172 insertions, 0 deletions
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 new file mode 100644 index 00000000..3a85536b --- /dev/null +++ b/Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage/src/hu/bme/mit/inf/dslreasoner/viatrasolver/partialinterpretation2logic/PartialInterpretation2Logic.xtend | |||
@@ -0,0 +1,172 @@ | |||
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.DefinedElement | ||
5 | import hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.LogiclanguageFactory | ||
6 | import hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.SymbolicDeclaration | ||
7 | import hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.Type | ||
8 | import hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.TypeDeclaration | ||
9 | import hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.TypeDefinition | ||
10 | import hu.bme.mit.inf.dslreasoner.logic.model.logicproblem.LogicProblem | ||
11 | import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage.partial2logicannotations.Partial2logicannotationsFactory | ||
12 | import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage.partialinterpretation.BinaryElementRelationLink | ||
13 | import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage.partialinterpretation.PartialInterpretation | ||
14 | import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage.partialinterpretation.PartialRelationInterpretation | ||
15 | import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage.partialinterpretation.PartialTypeInterpratation | ||
16 | import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage.partialinterpretation.RelationLink | ||
17 | import java.util.ArrayList | ||
18 | import java.util.HashMap | ||
19 | import java.util.HashSet | ||
20 | import java.util.Map | ||
21 | import java.util.Set | ||
22 | import org.eclipse.emf.ecore.util.EcoreUtil | ||
23 | import org.eclipse.xtend.lib.annotations.Data | ||
24 | |||
25 | import static extension hu.bme.mit.inf.dslreasoner.util.CollectionsUtil.* | ||
26 | |||
27 | @Data class PartialInterpretation2Logic_Trace { | ||
28 | Map<DefinedElement,DefinedElement> new2Old = new HashMap | ||
29 | |||
30 | Map<TypeDeclaration, TypeDefinition> definedPart = new HashMap | ||
31 | Map<TypeDeclaration, TypeDeclaration> undefinedPart = new HashMap | ||
32 | Set<Type> originalTypes = new HashSet | ||
33 | Set<TypeDeclaration> splittedTypes = new HashSet | ||
34 | } | ||
35 | |||
36 | class PartialInterpretation2Logic { | ||
37 | val extension LogiclanguageFactory factory = LogiclanguageFactory.eINSTANCE | ||
38 | val extension LogicProblemBuilder builder = new LogicProblemBuilder | ||
39 | |||
40 | def transformPartialIntepretation2Logic(LogicProblem p, PartialInterpretation i) { | ||
41 | val trace = new PartialInterpretation2Logic_Trace() | ||
42 | trace.originalTypes.addAll(p.types) | ||
43 | if(! i.newElements.empty) { | ||
44 | |||
45 | // Elements adding | ||
46 | addExistingElementToProblem(p,i,trace) | ||
47 | |||
48 | // Types | ||
49 | for(partialTypeDeclaration : i.partialtypeinterpratation) { | ||
50 | splitTypeIntoTwo(p,partialTypeDeclaration,trace) | ||
51 | } | ||
52 | connectSplittings(p,trace) | ||
53 | |||
54 | // Relations | ||
55 | for(partialRelationInterpretation : i.partialrelationinterpretation) { | ||
56 | //println(partialRelationInterpretation.interpretationOf.name) | ||
57 | relationLinksToAssertion(p,partialRelationInterpretation,trace) | ||
58 | } | ||
59 | } | ||
60 | } | ||
61 | |||
62 | private def addExistingElementToProblem(LogicProblem p, PartialInterpretation i,PartialInterpretation2Logic_Trace trace) { | ||
63 | // val newElements = new ArrayList(i.newElements) | ||
64 | // var newElementIndex = 1 | ||
65 | // for(newElement : newElements) { | ||
66 | // newElement.name = '''o «newElementIndex++»''' | ||
67 | // p.elements += newElement | ||
68 | // } | ||
69 | p.elements += i.newElements | ||
70 | } | ||
71 | |||
72 | private def splitTypeIntoTwo(LogicProblem p, PartialTypeInterpratation partialTypeDeclaration,PartialInterpretation2Logic_Trace trace) { | ||
73 | if(!partialTypeDeclaration.elements.empty) { | ||
74 | val declaration = partialTypeDeclaration.interpretationOf | ||
75 | |||
76 | val definedPart = createTypeDefinition => [ | ||
77 | it.name = '''«declaration.name» DefinedPart''' | ||
78 | it.elements += partialTypeDeclaration.elements | ||
79 | it.isAbstract = declaration.isIsAbstract | ||
80 | ] | ||
81 | val undefinedPart = createTypeDeclaration => [ | ||
82 | it.name = '''«declaration.name» UndefinedPart''' | ||
83 | it.isAbstract = declaration.isIsAbstract | ||
84 | ] | ||
85 | declaration.isAbstract = true | ||
86 | |||
87 | trace.definedPart.put(declaration,definedPart) | ||
88 | trace.undefinedPart.put(declaration,undefinedPart) | ||
89 | trace.splittedTypes.add(declaration) | ||
90 | p.add(definedPart) | ||
91 | p.add(undefinedPart) | ||
92 | Supertype(definedPart,declaration) | ||
93 | Supertype(undefinedPart,declaration) | ||
94 | |||
95 | for(containment : p.containmentHierarchies) { | ||
96 | if(containment.typesOrderedInHierarchy.contains(declaration)) { | ||
97 | containment.typesOrderedInHierarchy += definedPart | ||
98 | containment.typesOrderedInHierarchy += undefinedPart | ||
99 | } | ||
100 | } | ||
101 | } | ||
102 | } | ||
103 | |||
104 | private def connectSplittings(LogicProblem p,PartialInterpretation2Logic_Trace trace) { | ||
105 | val originalTypes = p.types.filter[originalType(trace)].toList | ||
106 | for(type : originalTypes) { | ||
107 | val superTypes = new ArrayList(type.supertypes.filter[originalType(trace)].toList) | ||
108 | for(supertype : superTypes) { | ||
109 | if(type.isSplitted(trace)) { | ||
110 | if(supertype.isSplitted(trace)) { | ||
111 | Supertype((type as TypeDeclaration).lookup(trace.definedPart), (supertype as TypeDeclaration).lookup(trace.definedPart)) | ||
112 | Supertype((type as TypeDeclaration).lookup(trace.undefinedPart), (supertype as TypeDeclaration).lookup(trace.undefinedPart)) | ||
113 | } else { | ||
114 | // Do nothing | ||
115 | } | ||
116 | } else { | ||
117 | if(supertype.isSplitted(trace)) { | ||
118 | Supertype(type, (supertype as TypeDeclaration).lookup(trace.undefinedPart)) | ||
119 | } else if(supertype instanceof TypeDefinition) { | ||
120 | // Do nothing | ||
121 | } | ||
122 | } | ||
123 | } | ||
124 | } | ||
125 | } | ||
126 | |||
127 | private def originalType(Type type,PartialInterpretation2Logic_Trace trace) { | ||
128 | return trace.originalTypes.contains(type) | ||
129 | } | ||
130 | private def isSplitted(Type t, PartialInterpretation2Logic_Trace trace) { | ||
131 | trace.splittedTypes.contains(t) | ||
132 | } | ||
133 | |||
134 | private def relationLinksToAssertion(LogicProblem p, PartialRelationInterpretation r,PartialInterpretation2Logic_Trace trace) { | ||
135 | val relation = r.interpretationOf | ||
136 | val links = r.relationlinks | ||
137 | if(links.size == 0) { | ||
138 | // No assertion for empty relations | ||
139 | return | ||
140 | } else { | ||
141 | val term = if(links.size == 1) { | ||
142 | createLink(links.head,relation) | ||
143 | } else { | ||
144 | links.map[link|createLink(link,relation)].And | ||
145 | } | ||
146 | val assertion = Assertion('''PartialInterpretation «r.interpretationOf.name»''',term) | ||
147 | val ^annotation= Partial2logicannotationsFactory.eINSTANCE.createPartialModelRelation2Assertion | ||
148 | ^annotation.target = assertion | ||
149 | ^annotation.targetRelation = relation | ||
150 | ^annotation.links += links.map[EcoreUtil.copy(it)] | ||
151 | //val error= assertion.eAllContents.toIterable.filter(SymbolicValue).filter[it.symbolicReference === null] | ||
152 | //error.forEach[println("error")] | ||
153 | p.add(assertion) | ||
154 | p.annotations+= ^annotation | ||
155 | } | ||
156 | |||
157 | } | ||
158 | |||
159 | def private createLink(RelationLink link, SymbolicDeclaration relationDeclaration) { | ||
160 | if(link instanceof BinaryElementRelationLink) { | ||
161 | if((link.param1 !== null) && (link.param2 !== null)) { | ||
162 | return createSymbolicValue=>[ | ||
163 | it.symbolicReference=relationDeclaration | ||
164 | it.parameterSubstitutions += createSymbolicValue => [it.symbolicReference = link.param1] | ||
165 | it.parameterSubstitutions += createSymbolicValue => [it.symbolicReference = link.param2] | ||
166 | ] | ||
167 | } else { | ||
168 | throw new IllegalArgumentException | ||
169 | } | ||
170 | } else throw new UnsupportedOperationException | ||
171 | } | ||
172 | } \ No newline at end of file | ||