diff options
Diffstat (limited to 'Solvers/VIATRA-Solver')
3 files changed, 84 insertions, 33 deletions
diff --git a/Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage/src/hu/bme/mit/inf/dslreasoner/viatrasolver/partialinterpretation2logic/InstanceModel2Logic.xtend b/Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage/src/hu/bme/mit/inf/dslreasoner/viatrasolver/partialinterpretation2logic/InstanceModel2Logic.xtend index d2b59754..7cec6327 100644 --- a/Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage/src/hu/bme/mit/inf/dslreasoner/viatrasolver/partialinterpretation2logic/InstanceModel2Logic.xtend +++ b/Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage/src/hu/bme/mit/inf/dslreasoner/viatrasolver/partialinterpretation2logic/InstanceModel2Logic.xtend | |||
@@ -4,8 +4,8 @@ import hu.bme.mit.inf.dslreasoner.ecore2logic.Ecore2Logic_Trace | |||
4 | import hu.bme.mit.inf.dslreasoner.logic.model.builder.TracedOutput | 4 | import hu.bme.mit.inf.dslreasoner.logic.model.builder.TracedOutput |
5 | import hu.bme.mit.inf.dslreasoner.logic.model.logicproblem.LogicProblem | 5 | import hu.bme.mit.inf.dslreasoner.logic.model.logicproblem.LogicProblem |
6 | import java.util.List | 6 | import java.util.List |
7 | import java.util.Map | ||
7 | import org.eclipse.emf.ecore.EObject | 8 | import org.eclipse.emf.ecore.EObject |
8 | import hu.bme.mit.inf.dslreasoner.logic.model.builder.TypeScopes | ||
9 | 9 | ||
10 | class InstanceModel2Logic { | 10 | class InstanceModel2Logic { |
11 | val InstanceModel2PartialInterpretation instanceModel2PartialInterpretation = new InstanceModel2PartialInterpretation | 11 | val InstanceModel2PartialInterpretation instanceModel2PartialInterpretation = new InstanceModel2PartialInterpretation |
@@ -13,9 +13,10 @@ class InstanceModel2Logic { | |||
13 | 13 | ||
14 | public def transform( | 14 | public def transform( |
15 | TracedOutput<LogicProblem, Ecore2Logic_Trace> metamodelTranslationResult, | 15 | TracedOutput<LogicProblem, Ecore2Logic_Trace> metamodelTranslationResult, |
16 | List<EObject> objects) | 16 | List<EObject> objects, |
17 | Map<String, Map<String, String>> ignoredAttribs) | ||
17 | { | 18 | { |
18 | val res1 = instanceModel2PartialInterpretation.transform(metamodelTranslationResult,objects,true) | 19 | val res1 = instanceModel2PartialInterpretation.transform(metamodelTranslationResult, ignoredAttribs, objects,true) |
19 | this.partialInterpretation2Logic.transformPartialIntepretation2Logic(metamodelTranslationResult.output,res1) | 20 | this.partialInterpretation2Logic.transformPartialIntepretation2Logic(metamodelTranslationResult.output,res1) |
20 | return metamodelTranslationResult//.output | 21 | return metamodelTranslationResult//.output |
21 | } | 22 | } |
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 94959025..f2f43aaa 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 | |||
@@ -3,6 +3,7 @@ package hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretation2logic | |||
3 | import com.google.common.collect.ImmutableList | 3 | import com.google.common.collect.ImmutableList |
4 | import hu.bme.mit.inf.dslreasoner.ecore2logic.Ecore2Logic | 4 | import hu.bme.mit.inf.dslreasoner.ecore2logic.Ecore2Logic |
5 | import hu.bme.mit.inf.dslreasoner.ecore2logic.Ecore2Logic_Trace | 5 | import hu.bme.mit.inf.dslreasoner.ecore2logic.Ecore2Logic_Trace |
6 | import hu.bme.mit.inf.dslreasoner.logic.model.builder.LogicSolverConfiguration | ||
6 | import hu.bme.mit.inf.dslreasoner.logic.model.builder.TracedOutput | 7 | import hu.bme.mit.inf.dslreasoner.logic.model.builder.TracedOutput |
7 | import hu.bme.mit.inf.dslreasoner.logic.model.builder.TypeScopes | 8 | import hu.bme.mit.inf.dslreasoner.logic.model.builder.TypeScopes |
8 | import hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.DefinedElement | 9 | import hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.DefinedElement |
@@ -33,7 +34,8 @@ class InstanceModel2PartialInterpretation { | |||
33 | 34 | ||
34 | public def transform( | 35 | public def transform( |
35 | TracedOutput<LogicProblem, Ecore2Logic_Trace> metamodelTranslationResult, | 36 | TracedOutput<LogicProblem, Ecore2Logic_Trace> metamodelTranslationResult, |
36 | Resource resource, | 37 | Map<String, Map<String, String>> ignoredAttribs, |
38 | Resource resource, | ||
37 | boolean withID) | 39 | boolean withID) |
38 | { | 40 | { |
39 | val objectsBuilder = ImmutableList.builder | 41 | val objectsBuilder = ImmutableList.builder |
@@ -49,11 +51,12 @@ class InstanceModel2PartialInterpretation { | |||
49 | } | 51 | } |
50 | } | 52 | } |
51 | val objects = objectsBuilder.build | 53 | val objects = objectsBuilder.build |
52 | return transform(metamodelTranslationResult,objects,withID) | 54 | return transform(metamodelTranslationResult, ignoredAttribs, objects, withID) |
53 | } | 55 | } |
54 | 56 | ||
55 | public def transform( | 57 | public def transform( |
56 | TracedOutput<LogicProblem, Ecore2Logic_Trace> metamodelTranslationResult, | 58 | TracedOutput<LogicProblem, Ecore2Logic_Trace> metamodelTranslationResult, |
59 | Map<String, Map<String, String>> ignoredAttribs, | ||
57 | List<EObject> objects, | 60 | List<EObject> objects, |
58 | boolean withID) | 61 | boolean withID) |
59 | { | 62 | { |
@@ -63,7 +66,7 @@ class InstanceModel2PartialInterpretation { | |||
63 | val referencesUsed = ecore2Logic.allReferencesInScope(ecore2LogicTrace).toSet | 66 | val referencesUsed = ecore2Logic.allReferencesInScope(ecore2LogicTrace).toSet |
64 | val attributesUsed = ecore2Logic.allAttributesInScope(ecore2LogicTrace).toSet | 67 | val attributesUsed = ecore2Logic.allAttributesInScope(ecore2LogicTrace).toSet |
65 | 68 | ||
66 | val typeScope = createTypeScopesFromKnownAttributeValues(objects,attributesUsed) | 69 | val typeScope = createTypeScopesFromKnownAttributeValues(objects,attributesUsed, ignoredAttribs) |
67 | val tracedOutput = partialInterpretationInitialiser.initialisePartialInterpretation(problem, typeScope) | 70 | val tracedOutput = partialInterpretationInitialiser.initialisePartialInterpretation(problem, typeScope) |
68 | val partialInterpretation = tracedOutput.output | 71 | val partialInterpretation = tracedOutput.output |
69 | val partialInterpretationTrace = tracedOutput.trace | 72 | val partialInterpretationTrace = tracedOutput.trace |
@@ -119,23 +122,26 @@ class InstanceModel2PartialInterpretation { | |||
119 | 122 | ||
120 | // Transforming the attributes | 123 | // Transforming the attributes |
121 | for(attribute : source.eClass.EAllAttributes.filter[attributesUsed.contains(it) && !it.derived]) { | 124 | for(attribute : source.eClass.EAllAttributes.filter[attributesUsed.contains(it) && !it.derived]) { |
122 | val type = ecore2Logic.relationOfAttribute(ecore2LogicTrace,attribute) | 125 | val isIgnored = checkIfIgnored(source, attribute, ignoredAttribs) |
123 | val interpretation = type.lookup(partialInterpretationTrace.relation2Interpretation) | 126 | if (!isIgnored) { |
124 | val sourceElement = source.lookup(object2DefinedElement) | 127 | val type = ecore2Logic.relationOfAttribute(ecore2LogicTrace,attribute) |
125 | if(attribute.isMany) { | 128 | val interpretation = type.lookup(partialInterpretationTrace.relation2Interpretation) |
126 | val listOfTargets = source.eGet(attribute) as List<? extends EObject> | 129 | val sourceElement = source.lookup(object2DefinedElement) |
127 | for(target : listOfTargets) { | 130 | if(attribute.isMany) { |
128 | val value = translateValue(target,ecore2LogicTrace,partialInterpretationTrace) | 131 | val listOfTargets = source.eGet(attribute) as List<? extends EObject> |
129 | if(value !== null) { | 132 | for(target : listOfTargets) { |
130 | translateLink(interpretation,sourceElement,value) | 133 | val value = translateValue(target,ecore2LogicTrace,partialInterpretationTrace) |
134 | if(value !== null) { | ||
135 | translateLink(interpretation,sourceElement,value) | ||
136 | } | ||
131 | } | 137 | } |
132 | } | 138 | } else { |
133 | } else { | 139 | val target = source.eGet(attribute) |
134 | val target = source.eGet(attribute) | 140 | if(target !== null) { |
135 | if(target !== null) { | 141 | val value = translateValue(target,ecore2LogicTrace,partialInterpretationTrace) |
136 | val value = translateValue(target,ecore2LogicTrace,partialInterpretationTrace) | 142 | if(value !== null) { |
137 | if(value !== null) { | 143 | translateLink(interpretation,sourceElement,value) |
138 | translateLink(interpretation,sourceElement,value) | 144 | } |
139 | } | 145 | } |
140 | } | 146 | } |
141 | } | 147 | } |
@@ -144,21 +150,29 @@ class InstanceModel2PartialInterpretation { | |||
144 | 150 | ||
145 | return partialInterpretation | 151 | return partialInterpretation |
146 | } | 152 | } |
147 | 153 | ||
148 | private def createTypeScopesFromKnownAttributeValues(List<EObject> objects, Set<EAttribute> attributesUsed) { | 154 | private def createTypeScopesFromKnownAttributeValues( |
155 | List<EObject> objects, | ||
156 | Set<EAttribute> attributesUsed, | ||
157 | Map<String, Map<String, String>> ignoredAttribs) | ||
158 | { | ||
149 | val Set<Integer> integers = new HashSet | 159 | val Set<Integer> integers = new HashSet |
150 | val Set<Double> reals = new HashSet | 160 | val Set<Double> reals = new HashSet |
151 | val Set<String> strings = new HashSet | 161 | val Set<String> strings = new HashSet |
152 | for(object: objects) { | 162 | for (object : objects) { |
153 | for(attribute : object.eClass.EAllAttributes.filter[attributesUsed.contains(it)]) { | 163 | for (attribute : object.eClass.EAllAttributes.filter[attributesUsed.contains(it)]) { |
154 | val value = object.eGet(attribute) | 164 | val isIgnored = checkIfIgnored(object, attribute, ignoredAttribs) |
155 | if(value !== null) { | 165 | |
156 | if(value instanceof List<?>) { | 166 | if(!isIgnored) { |
157 | for(v : value) { | 167 | val value = object.eGet(attribute) |
158 | shortValue(v,integers,reals,strings) | 168 | if(value !== null) { |
169 | if(value instanceof List<?>) { | ||
170 | for(v : value) { | ||
171 | shortValue(v,integers,reals,strings) | ||
172 | } | ||
173 | } else { | ||
174 | shortValue(value,integers,reals,strings) | ||
159 | } | 175 | } |
160 | } else { | ||
161 | shortValue(value,integers,reals,strings) | ||
162 | } | 176 | } |
163 | } | 177 | } |
164 | } | 178 | } |
@@ -169,6 +183,40 @@ class InstanceModel2PartialInterpretation { | |||
169 | it.knownStrings += strings | 183 | it.knownStrings += strings |
170 | ] | 184 | ] |
171 | } | 185 | } |
186 | private def boolean checkIfIgnored( | ||
187 | EObject object, | ||
188 | EAttribute attribute, | ||
189 | Map<String, Map<String, String>> ignoredAttribs | ||
190 | ) { | ||
191 | val classInIgnored = ignoredAttribs.get(object.eClass.name) | ||
192 | val mayIgnored = ( | ||
193 | classInIgnored !== null && classInIgnored.containsKey(attribute.name)) | ||
194 | |||
195 | var isIgnored = false | ||
196 | if (mayIgnored) { | ||
197 | val specificIgnoredValue = classInIgnored.get(attribute.name) | ||
198 | if (specificIgnoredValue.equals("*")) | ||
199 | isIgnored = true | ||
200 | else { | ||
201 | val value = object.eGet(attribute) | ||
202 | if (typeof(Number).isAssignableFrom(value.class)) { | ||
203 | isIgnored = (Double.valueOf(specificIgnoredValue) == value) | ||
204 | } else { | ||
205 | isIgnored = specificIgnoredValue.equals(value) | ||
206 | } | ||
207 | } | ||
208 | } | ||
209 | // DEBUG | ||
210 | // println("DEBUG BEGINNING") | ||
211 | // println(object) | ||
212 | // println(attribute) | ||
213 | // println(value) | ||
214 | // | ||
215 | // println("MAYIGNORE " + mayIgnored) | ||
216 | // println("ISIGNORED " + isIgnored) | ||
217 | // END DEBUG | ||
218 | return isIgnored | ||
219 | } | ||
172 | private def dispatch shortValue(Boolean value, Set<Integer> integers, Set<Double> reals, Set<String> strings) { | 220 | private def dispatch shortValue(Boolean value, Set<Integer> integers, Set<Double> reals, Set<String> strings) { |
173 | // Do nothing | 221 | // Do nothing |
174 | } | 222 | } |
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 759f434b..fbcd6e1d 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 | |||
@@ -16,6 +16,7 @@ import hu.bme.mit.inf.dslreasoner.viatrasolver.reasoner.optimization.ObjectiveKi | |||
16 | import hu.bme.mit.inf.dslreasoner.viatrasolver.reasoner.optimization.ObjectiveThreshold | 16 | import hu.bme.mit.inf.dslreasoner.viatrasolver.reasoner.optimization.ObjectiveThreshold |
17 | import java.util.LinkedList | 17 | import java.util.LinkedList |
18 | import java.util.List | 18 | import java.util.List |
19 | import java.util.Map | ||
19 | import java.util.Set | 20 | import java.util.Set |
20 | import org.eclipse.xtext.xbase.lib.Functions.Function1 | 21 | import org.eclipse.xtext.xbase.lib.Functions.Function1 |
21 | 22 | ||
@@ -78,6 +79,7 @@ class ViatraReasonerConfiguration extends LogicSolverConfiguration { | |||
78 | public var calculateObjectCreationCosts = false | 79 | public var calculateObjectCreationCosts = false |
79 | public NumericSolverSelection numericSolverSelection = NumericSolverSelection.DREAL_DOCKER //currently defaulted to DREAL | 80 | public NumericSolverSelection numericSolverSelection = NumericSolverSelection.DREAL_DOCKER //currently defaulted to DREAL |
80 | public var drealLocalPath = "<path-to-dreal>"; | 81 | public var drealLocalPath = "<path-to-dreal>"; |
82 | public var Map<String, Map<String, String>> ignoredAttributesMap = null; | ||
81 | 83 | ||
82 | public var ScopePropagatorStrategy scopePropagatorStrategy = new ScopePropagatorStrategy.Polyhedral( | 84 | public var ScopePropagatorStrategy scopePropagatorStrategy = new ScopePropagatorStrategy.Polyhedral( |
83 | PolyhedralScopePropagatorConstraints.Relational, PolyhedralScopePropagatorSolver.Clp) | 85 | PolyhedralScopePropagatorConstraints.Relational, PolyhedralScopePropagatorSolver.Clp) |