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 } }