diff options
author | OszkarSemerath <oszka@152.66.252.189> | 2017-06-10 19:05:05 +0200 |
---|---|---|
committer | OszkarSemerath <oszka@152.66.252.189> | 2017-06-10 19:05:05 +0200 |
commit | 60f01f46ba232ed6416054f0a6115cb2a9b70b4e (patch) | |
tree | 5edf8aeb07abc51f3fec63bbd15c926e1de09552 /Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage/src/hu/bme/mit/inf/dslreasoner/viatrasolver/partialinterpretationlanguage/statecoder/IdentifierBasedStateCoderFactory.xtend | |
parent | Initial commit, migrating from SVN (diff) | |
download | VIATRA-Generator-60f01f46ba232ed6416054f0a6115cb2a9b70b4e.tar.gz VIATRA-Generator-60f01f46ba232ed6416054f0a6115cb2a9b70b4e.tar.zst VIATRA-Generator-60f01f46ba232ed6416054f0a6115cb2a9b70b4e.zip |
Migrating Additional projects
Diffstat (limited to 'Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage/src/hu/bme/mit/inf/dslreasoner/viatrasolver/partialinterpretationlanguage/statecoder/IdentifierBasedStateCoderFactory.xtend')
1 files changed, 129 insertions, 0 deletions
diff --git a/Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage/src/hu/bme/mit/inf/dslreasoner/viatrasolver/partialinterpretationlanguage/statecoder/IdentifierBasedStateCoderFactory.xtend b/Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage/src/hu/bme/mit/inf/dslreasoner/viatrasolver/partialinterpretationlanguage/statecoder/IdentifierBasedStateCoderFactory.xtend new file mode 100644 index 00000000..c421ace6 --- /dev/null +++ b/Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage/src/hu/bme/mit/inf/dslreasoner/viatrasolver/partialinterpretationlanguage/statecoder/IdentifierBasedStateCoderFactory.xtend | |||
@@ -0,0 +1,129 @@ | |||
1 | package hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage.statecoder | ||
2 | |||
3 | import hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.DefinedElement | ||
4 | import hu.bme.mit.inf.dslreasoner.logic.model.logicproblem.LogicProblem | ||
5 | import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage.partialinterpretation.BinaryElementRelationLink | ||
6 | import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage.partialinterpretation.PartialInterpretation | ||
7 | import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage.partialinterpretation.PartialRelationInterpretation | ||
8 | import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage.partialinterpretation.PartialTypeInterpratation | ||
9 | import java.util.ArrayList | ||
10 | import java.util.Comparator | ||
11 | import java.util.LinkedList | ||
12 | import java.util.List | ||
13 | import java.util.SortedSet | ||
14 | import java.util.TreeSet | ||
15 | import org.eclipse.emf.common.notify.Notifier | ||
16 | import org.eclipse.viatra.dse.statecode.IStateCoder | ||
17 | import org.eclipse.viatra.dse.statecode.IStateCoderFactory | ||
18 | import org.eclipse.viatra.query.runtime.api.IPatternMatch | ||
19 | import org.eclipse.xtend.lib.annotations.Accessors | ||
20 | import org.eclipse.xtend.lib.annotations.Data | ||
21 | |||
22 | class IdentifierBasedStateCoderFactory implements IStateCoderFactory{ | ||
23 | |||
24 | val List<IdentifierBasedStateCoder> statecoders = new LinkedList | ||
25 | synchronized override createStateCoder() { | ||
26 | val res = new IdentifierBasedStateCoder | ||
27 | statecoders += res | ||
28 | return res | ||
29 | } | ||
30 | def getSumStatecoderRuntime() { | ||
31 | statecoders.map[statecoderRuntime].reduce[p1, p2|p1+p2] | ||
32 | } | ||
33 | } | ||
34 | |||
35 | @Data | ||
36 | class RelationStatecoder { | ||
37 | String relationName | ||
38 | SortedSet<Pair<Integer,Integer>> links; | ||
39 | |||
40 | static val comparator= new Comparator<Pair<Integer,Integer>>() { | ||
41 | override compare(Pair<Integer, Integer> o1, Pair<Integer, Integer> o2) { | ||
42 | if(o1.key > o2.key) { | ||
43 | return 1 | ||
44 | } else if(o1.key < o2.key) { | ||
45 | return -1 | ||
46 | } else { | ||
47 | return Integer.compare(o1.value,o2.value) | ||
48 | } | ||
49 | } | ||
50 | } | ||
51 | |||
52 | new(String relationName) { | ||
53 | this.relationName = relationName | ||
54 | links = new TreeSet(comparator) | ||
55 | } | ||
56 | } | ||
57 | |||
58 | @Data | ||
59 | class IdentifierBasedStateCode { | ||
60 | int numberOfNewElement | ||
61 | SortedSet<RelationStatecoder> relationStatecoders | ||
62 | |||
63 | private static val comparator = new Comparator<RelationStatecoder>() { | ||
64 | override compare(RelationStatecoder o1, RelationStatecoder o2) { | ||
65 | o1.relationName.compareTo(o2.relationName) | ||
66 | } | ||
67 | } | ||
68 | |||
69 | public new(int numberOfNewElements) { | ||
70 | this.numberOfNewElement = numberOfNewElements | ||
71 | this.relationStatecoders = new TreeSet(comparator) | ||
72 | } | ||
73 | } | ||
74 | |||
75 | class IdentifierBasedStateCoder implements IStateCoder{ | ||
76 | var PartialInterpretation model = null | ||
77 | |||
78 | @Accessors(PUBLIC_GETTER) var long statecoderRuntime = 0 | ||
79 | |||
80 | override createActivationCode(IPatternMatch match) { | ||
81 | val startTime = System.nanoTime | ||
82 | val res = new ArrayList(match.parameterNames.size) | ||
83 | var index = 0 | ||
84 | while(index < match.parameterNames.size) { | ||
85 | res.add(getID(match.get(index))) | ||
86 | index++ | ||
87 | } | ||
88 | statecoderRuntime += (System.nanoTime - startTime) | ||
89 | return match.specification.fullyQualifiedName -> res | ||
90 | } | ||
91 | |||
92 | override createStateCode() { | ||
93 | val startTime = System.nanoTime | ||
94 | val res = new IdentifierBasedStateCode(model.newElements.size) | ||
95 | for(relation : model.partialrelationinterpretation) { | ||
96 | val relationCoder = new RelationStatecoder(relation.interpretationOf.name) | ||
97 | for(link: relation.relationlinks.filter(BinaryElementRelationLink)) { | ||
98 | relationCoder.links+=link.param1.ID -> link.param2.ID | ||
99 | } | ||
100 | res.relationStatecoders+=relationCoder | ||
101 | } | ||
102 | statecoderRuntime += (System.nanoTime - startTime) | ||
103 | return res | ||
104 | } | ||
105 | |||
106 | def getID(Object element) { | ||
107 | if(element instanceof DefinedElement) { | ||
108 | val container = element.eContainer | ||
109 | if(container instanceof LogicProblem) { | ||
110 | return -container.elements.indexOf(element)-1 | ||
111 | } else if(container instanceof PartialInterpretation){ | ||
112 | return container.newElements.indexOf(element)+1 | ||
113 | } | ||
114 | } else if(element instanceof PartialInterpretation || element instanceof LogicProblem) { | ||
115 | return 0 | ||
116 | } else if(element instanceof PartialRelationInterpretation) { | ||
117 | return element.interpretationOf.name.hashCode | ||
118 | } else if(element instanceof PartialTypeInterpratation) { | ||
119 | return element.interpretationOf.name.hashCode | ||
120 | } else { | ||
121 | println(element) | ||
122 | throw new UnsupportedOperationException('''Unsupported type: «element.class.simpleName»''') | ||
123 | } | ||
124 | } | ||
125 | |||
126 | override init(Notifier notifier) { | ||
127 | model = notifier as PartialInterpretation | ||
128 | } | ||
129 | } \ No newline at end of file | ||