diff options
author | Kristóf Marussy <kris7topher@gmail.com> | 2019-08-14 18:26:33 +0200 |
---|---|---|
committer | Kristóf Marussy <kris7topher@gmail.com> | 2019-08-14 18:26:33 +0200 |
commit | fc84d3fe670331bc89fb1e4c44104bc1fc811438 (patch) | |
tree | 466da8333151c51d2e17075600f9452ed35835da /Tests/hu.bme.mit.inf.dslreasoner.run/src/hu/bme/mit/inf/dslreasoner/run/Ecore2LogicTraceBasedHint.xtend | |
parent | Be more lenient with rounding IP solver results (diff) | |
download | VIATRA-Generator-fc84d3fe670331bc89fb1e4c44104bc1fc811438.tar.gz VIATRA-Generator-fc84d3fe670331bc89fb1e4c44104bc1fc811438.tar.zst VIATRA-Generator-fc84d3fe670331bc89fb1e4c44104bc1fc811438.zip |
Measurements WIP
Diffstat (limited to 'Tests/hu.bme.mit.inf.dslreasoner.run/src/hu/bme/mit/inf/dslreasoner/run/Ecore2LogicTraceBasedHint.xtend')
-rw-r--r-- | Tests/hu.bme.mit.inf.dslreasoner.run/src/hu/bme/mit/inf/dslreasoner/run/Ecore2LogicTraceBasedHint.xtend | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/Tests/hu.bme.mit.inf.dslreasoner.run/src/hu/bme/mit/inf/dslreasoner/run/Ecore2LogicTraceBasedHint.xtend b/Tests/hu.bme.mit.inf.dslreasoner.run/src/hu/bme/mit/inf/dslreasoner/run/Ecore2LogicTraceBasedHint.xtend new file mode 100644 index 00000000..dc2de30c --- /dev/null +++ b/Tests/hu.bme.mit.inf.dslreasoner.run/src/hu/bme/mit/inf/dslreasoner/run/Ecore2LogicTraceBasedHint.xtend | |||
@@ -0,0 +1,56 @@ | |||
1 | package hu.bme.mit.inf.dslreasoner.run | ||
2 | |||
3 | import com.google.common.collect.ImmutableMap | ||
4 | import hu.bme.mit.inf.dslreasoner.ecore2logic.Ecore2Logic | ||
5 | import hu.bme.mit.inf.dslreasoner.ecore2logic.Ecore2Logic_Trace | ||
6 | import hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.RelationDeclaration | ||
7 | import hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.Type | ||
8 | import hu.bme.mit.inf.dslreasoner.viatrasolver.logic2viatra.cardinality.LinearTypeConstraintHint | ||
9 | import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage.partialinterpretation.PartialInterpretation | ||
10 | import java.util.Map | ||
11 | import org.eclipse.viatra.query.runtime.api.IPatternMatch | ||
12 | import org.eclipse.viatra.query.runtime.api.ViatraQueryMatcher | ||
13 | |||
14 | abstract class Ecore2LogicTraceBasedHint implements LinearTypeConstraintHint { | ||
15 | val Map<String, Type> nameToType | ||
16 | val Map<String, Map<String, RelationDeclaration>> nameToRelation | ||
17 | |||
18 | protected new(Ecore2Logic ecore2Logic, Ecore2Logic_Trace trace) { | ||
19 | nameToType = ImmutableMap.copyOf(ecore2Logic.allClassesInScope(trace).toMap[name].mapValues [ eClass | | ||
20 | ecore2Logic.TypeofEClass(trace, eClass) | ||
21 | ]) | ||
22 | nameToRelation = ImmutableMap.copyOf(ecore2Logic.allReferencesInScope(trace).groupBy[EContainingClass.name]. | ||
23 | mapValues [ references | | ||
24 | ImmutableMap.copyOf(references.toMap[name].mapValues [ reference | | ||
25 | ecore2Logic.relationOfReference(trace, reference) | ||
26 | ]) | ||
27 | ]) | ||
28 | } | ||
29 | |||
30 | protected def getType(String name) { | ||
31 | nameToType.get(name) | ||
32 | } | ||
33 | |||
34 | protected def relation(String typeName, String relationName) { | ||
35 | nameToRelation.get(typeName).get(relationName) | ||
36 | } | ||
37 | |||
38 | protected static def <T extends IPatternMatch> int countMatches(ViatraQueryMatcher<T> matcher, PartialInterpretation p) { | ||
39 | val match = matcher.newEmptyMatch | ||
40 | match.set(0, p.problem) | ||
41 | match.set(1, p) | ||
42 | matcher.countMatches(match) | ||
43 | } | ||
44 | |||
45 | protected static def <T extends IPatternMatch> int getCount(ViatraQueryMatcher<T> matcher, PartialInterpretation p) { | ||
46 | val match = matcher.newEmptyMatch | ||
47 | match.set(0, p.problem) | ||
48 | match.set(1, p) | ||
49 | val realMatch = matcher.getOneArbitraryMatch(match) | ||
50 | if (realMatch.present) { | ||
51 | realMatch.get.get(2) as Integer | ||
52 | } else { | ||
53 | 0 | ||
54 | } | ||
55 | } | ||
56 | } | ||