From c0c5a1644cc221352b8b9b370eea6a87677ba948 Mon Sep 17 00:00:00 2001 From: Kristóf Marussy Date: Sat, 15 Jun 2019 20:56:47 -0400 Subject: Try fix statecode bug Modified graph width calculation to not depend on order of nodes --- .../reasoner/optimization/MatchCostObjective.xtend | 52 ++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.reasoner/src/hu/bme/mit/inf/dslreasoner/viatrasolver/reasoner/optimization/MatchCostObjective.xtend (limited to 'Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.reasoner/src/hu/bme/mit/inf/dslreasoner/viatrasolver/reasoner/optimization/MatchCostObjective.xtend') diff --git a/Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.reasoner/src/hu/bme/mit/inf/dslreasoner/viatrasolver/reasoner/optimization/MatchCostObjective.xtend b/Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.reasoner/src/hu/bme/mit/inf/dslreasoner/viatrasolver/reasoner/optimization/MatchCostObjective.xtend new file mode 100644 index 00000000..a0c6a2c1 --- /dev/null +++ b/Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.reasoner/src/hu/bme/mit/inf/dslreasoner/viatrasolver/reasoner/optimization/MatchCostObjective.xtend @@ -0,0 +1,52 @@ +package hu.bme.mit.inf.dslreasoner.viatrasolver.reasoner.optimization + +import com.google.common.collect.ImmutableList +import java.util.Collection +import org.eclipse.viatra.dse.base.ThreadContext +import org.eclipse.viatra.query.runtime.api.IPatternMatch +import org.eclipse.viatra.query.runtime.api.IQuerySpecification +import org.eclipse.viatra.query.runtime.api.ViatraQueryMatcher +import org.eclipse.xtend.lib.annotations.Data + +@Data +class MatchCostElement { + val IQuerySpecification> querySpecification + val double weight +} + +class MatchCostObjective extends DirectionalThresholdObjective { + val Collection costElements + Collection matchers + + new(String name, Collection costElements, ObjectiveKind kind, ObjectiveThreshold threshold, + int level) { + super(name, kind, threshold, level) + this.costElements = costElements + } + + override createNew() { + new MatchCostObjective(name, costElements, kind, threshold, level) + } + + override init(ThreadContext context) { + val queryEngine = context.queryEngine + matchers = ImmutableList.copyOf(costElements.map [ + val matcher = querySpecification.getMatcher(queryEngine) + new CostElementMatcher(matcher, weight) + ]) + } + + override protected getRawFitness(ThreadContext context) { + var double cost = 0 + for (it : matchers) { + cost += weight * matcher.countMatches + } + cost + } + + @Data + private static class CostElementMatcher { + val ViatraQueryMatcher matcher + val double weight + } +} -- cgit v1.2.3-54-g00ecf