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 --- .../CompositeDirectionalThresholdObjective.xtend | 62 ++++++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100644 Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.reasoner/src/hu/bme/mit/inf/dslreasoner/viatrasolver/reasoner/optimization/CompositeDirectionalThresholdObjective.xtend (limited to 'Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.reasoner/src/hu/bme/mit/inf/dslreasoner/viatrasolver/reasoner/optimization/CompositeDirectionalThresholdObjective.xtend') diff --git a/Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.reasoner/src/hu/bme/mit/inf/dslreasoner/viatrasolver/reasoner/optimization/CompositeDirectionalThresholdObjective.xtend b/Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.reasoner/src/hu/bme/mit/inf/dslreasoner/viatrasolver/reasoner/optimization/CompositeDirectionalThresholdObjective.xtend new file mode 100644 index 00000000..0aa442f5 --- /dev/null +++ b/Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.reasoner/src/hu/bme/mit/inf/dslreasoner/viatrasolver/reasoner/optimization/CompositeDirectionalThresholdObjective.xtend @@ -0,0 +1,62 @@ +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 + +class CompositeDirectionalThresholdObjective extends DirectionalThresholdObjective { + val Collection objectives + + new(String name, Collection objectives) { + this(name, objectives, getKind(objectives), getThreshold(objectives), getLevel(objectives)) + } + + new(String name, DirectionalThresholdObjective... objectives) { + this(name, objectives as Collection) + } + + protected new(String name, Iterable objectives, ObjectiveKind kind, + ObjectiveThreshold threshold, int level) { + super(name, kind, threshold, level) + this.objectives = ImmutableList.copyOf(objectives) + } + + override createNew() { + new CompositeDirectionalThresholdObjective(name, objectives.map[createNew as DirectionalThresholdObjective], + kind, threshold, level) + } + + override init(ThreadContext context) { + for (objective : objectives) { + objective.init(context) + } + } + + override protected getRawFitness(ThreadContext context) { + var double fitness = 0 + for (objective : objectives) { + fitness += objective.getFitness(context) + } + fitness + } + + private static def getKind(Collection objectives) { + val kinds = objectives.map[kind].toSet + if (kinds.size != 1) { + throw new IllegalArgumentException("Passed objectives must have the same kind") + } + kinds.head + } + + private static def getThreshold(Collection objectives) { + objectives.map[threshold].reduce[a, b|a.merge(b)] + } + + private static def int getLevel(Collection objectives) { + val levels = objectives.map[level].toSet + if (levels.size != 1) { + throw new IllegalArgumentException("Passed objectives must have the same level") + } + levels.head + } +} -- cgit v1.2.3-54-g00ecf