From 329ac27dfa84e9a07760bea75b36476dddcf29a7 Mon Sep 17 00:00:00 2001 From: Kristóf Marussy Date: Tue, 14 Jul 2020 10:45:03 +0200 Subject: Optimizations --- .../NeighbourhoodBasedStateCoderFactory.xtend | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) (limited to 'Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage/src/hu/bme/mit/inf/dslreasoner/viatrasolver/partialinterpretationlanguage/statecoder/NeighbourhoodBasedStateCoderFactory.xtend') 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 import java.util.ArrayList import java.util.Map import org.eclipse.viatra.query.runtime.api.IPatternMatch +import org.eclipse.viatra.query.runtime.api.IQuerySpecification class NeighbourhoodBasedStateCoderFactory extends AbstractNeighbourhoodBasedStateCoderFactory { new() { @@ -38,6 +39,7 @@ class NeighbourhoodBasedHashStateCoderFactory extends AbstractNeighbourhoodBased class NeighbourhoodBasedPartialInterpretationStateCoder extends AbstractNeighbourhoodBasedPartialInterpretationStateCoder { val PartialInterpretation2NeighbourhoodRepresentation calculator + val Map, String> fullyQualifiedNames = newHashMap var Map nodeRepresentations = null var ModelRep modelRepresentation = null @@ -55,27 +57,36 @@ class NeighbourhoodBasedPartialInterpretationStateCoder exten modelRepresentation = code.modelRepresentation nodeRepresentations = code.nodeRepresentations } + + private def getFullyQualifiedNameCached(IQuerySpecification specification) { + fullyQualifiedNames.computeIfAbsent(specification, [fullyQualifiedName]) + } override doCreateActivationCode(IPatternMatch match) { val size = match.specification.parameters.size - val res = new ArrayList(size) - var int equivalenceHash = 0 + var int hash = 0 val prime = 31 for (var int index = 0; index < size; index++) { val matchArgument = match.get(index) - res.add(getCode(matchArgument)) + val code = getCode(matchArgument) + val codeNumber = if (code === null) { + 0 + } else { + code.hashCode + } + hash = prime * hash + codeNumber for (var i = 0; i < index; i++) { val number = if (matchArgument === match.get(i)) { 1 } else { 0 } - equivalenceHash = prime * equivalenceHash + number + hash = prime * hash + number } } - match.specification.fullyQualifiedName -> (res -> equivalenceHash).hashCode + match.specification.fullyQualifiedNameCached -> hash } def private getCode(Object o) { -- cgit v1.2.3-70-g09d2