diff options
Diffstat (limited to 'Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage/src/hu/bme/mit/inf/dslreasoner/viatrasolver/partialinterpretationlanguage/statecoder/NeighbourhoodBasedStateCoderFactory.xtend')
1 files changed, 16 insertions, 5 deletions
diff --git a/Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage/src/hu/bme/mit/inf/dslreasoner/viatrasolver/partialinterpretationlanguage/statecoder/NeighbourhoodBasedStateCoderFactory.xtend b/Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage/src/hu/bme/mit/inf/dslreasoner/viatrasolver/partialinterpretationlanguage/statecoder/NeighbourhoodBasedStateCoderFactory.xtend index f19ac30f..04c49506 100644 --- a/Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage/src/hu/bme/mit/inf/dslreasoner/viatrasolver/partialinterpretationlanguage/statecoder/NeighbourhoodBasedStateCoderFactory.xtend +++ b/Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage/src/hu/bme/mit/inf/dslreasoner/viatrasolver/partialinterpretationlanguage/statecoder/NeighbourhoodBasedStateCoderFactory.xtend | |||
@@ -9,6 +9,7 @@ import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage.par | |||
9 | import java.util.ArrayList | 9 | import java.util.ArrayList |
10 | import java.util.Map | 10 | import java.util.Map |
11 | import org.eclipse.viatra.query.runtime.api.IPatternMatch | 11 | import org.eclipse.viatra.query.runtime.api.IPatternMatch |
12 | import org.eclipse.viatra.query.runtime.api.IQuerySpecification | ||
12 | 13 | ||
13 | class NeighbourhoodBasedStateCoderFactory extends AbstractNeighbourhoodBasedStateCoderFactory { | 14 | class NeighbourhoodBasedStateCoderFactory extends AbstractNeighbourhoodBasedStateCoderFactory { |
14 | new() { | 15 | new() { |
@@ -38,6 +39,7 @@ class NeighbourhoodBasedHashStateCoderFactory extends AbstractNeighbourhoodBased | |||
38 | 39 | ||
39 | class NeighbourhoodBasedPartialInterpretationStateCoder<ModelRep, NodeRep> extends AbstractNeighbourhoodBasedPartialInterpretationStateCoder { | 40 | class NeighbourhoodBasedPartialInterpretationStateCoder<ModelRep, NodeRep> extends AbstractNeighbourhoodBasedPartialInterpretationStateCoder { |
40 | val PartialInterpretation2NeighbourhoodRepresentation<ModelRep, NodeRep> calculator | 41 | val PartialInterpretation2NeighbourhoodRepresentation<ModelRep, NodeRep> calculator |
42 | val Map<IQuerySpecification<?>, String> fullyQualifiedNames = newHashMap | ||
41 | var Map<DefinedElement, ? extends NodeRep> nodeRepresentations = null | 43 | var Map<DefinedElement, ? extends NodeRep> nodeRepresentations = null |
42 | var ModelRep modelRepresentation = null | 44 | var ModelRep modelRepresentation = null |
43 | 45 | ||
@@ -55,27 +57,36 @@ class NeighbourhoodBasedPartialInterpretationStateCoder<ModelRep, NodeRep> exten | |||
55 | modelRepresentation = code.modelRepresentation | 57 | modelRepresentation = code.modelRepresentation |
56 | nodeRepresentations = code.nodeRepresentations | 58 | nodeRepresentations = code.nodeRepresentations |
57 | } | 59 | } |
60 | |||
61 | private def getFullyQualifiedNameCached(IQuerySpecification<?> specification) { | ||
62 | fullyQualifiedNames.computeIfAbsent(specification, [fullyQualifiedName]) | ||
63 | } | ||
58 | 64 | ||
59 | override doCreateActivationCode(IPatternMatch match) { | 65 | override doCreateActivationCode(IPatternMatch match) { |
60 | val size = match.specification.parameters.size | 66 | val size = match.specification.parameters.size |
61 | val res = new ArrayList(size) | 67 | var int hash = 0 |
62 | var int equivalenceHash = 0 | ||
63 | val prime = 31 | 68 | val prime = 31 |
64 | 69 | ||
65 | for (var int index = 0; index < size; index++) { | 70 | for (var int index = 0; index < size; index++) { |
66 | val matchArgument = match.get(index) | 71 | val matchArgument = match.get(index) |
67 | res.add(getCode(matchArgument)) | 72 | val code = getCode(matchArgument) |
73 | val codeNumber = if (code === null) { | ||
74 | 0 | ||
75 | } else { | ||
76 | code.hashCode | ||
77 | } | ||
78 | hash = prime * hash + codeNumber | ||
68 | for (var i = 0; i < index; i++) { | 79 | for (var i = 0; i < index; i++) { |
69 | val number = if (matchArgument === match.get(i)) { | 80 | val number = if (matchArgument === match.get(i)) { |
70 | 1 | 81 | 1 |
71 | } else { | 82 | } else { |
72 | 0 | 83 | 0 |
73 | } | 84 | } |
74 | equivalenceHash = prime * equivalenceHash + number | 85 | hash = prime * hash + number |
75 | } | 86 | } |
76 | } | 87 | } |
77 | 88 | ||
78 | match.specification.fullyQualifiedName -> (res -> equivalenceHash).hashCode | 89 | match.specification.fullyQualifiedNameCached -> hash |
79 | } | 90 | } |
80 | 91 | ||
81 | def private getCode(Object o) { | 92 | def private getCode(Object o) { |