From 5f1117a84bc3c24ec71d6bcb9d3f2badffca28c2 Mon Sep 17 00:00:00 2001 From: OszkarSemerath Date: Sat, 24 Feb 2018 20:56:42 -0500 Subject: Execution update --- .../application/execution/SolverLoader.xtend | 77 +++++++++++++++++++--- 1 file changed, 68 insertions(+), 9 deletions(-) (limited to 'Application/hu.bme.mit.inf.dslreasoner.application/src/hu/bme/mit/inf/dslreasoner/application/execution/SolverLoader.xtend') diff --git a/Application/hu.bme.mit.inf.dslreasoner.application/src/hu/bme/mit/inf/dslreasoner/application/execution/SolverLoader.xtend b/Application/hu.bme.mit.inf.dslreasoner.application/src/hu/bme/mit/inf/dslreasoner/application/execution/SolverLoader.xtend index dcd89981..9ae1ba6b 100644 --- a/Application/hu.bme.mit.inf.dslreasoner.application/src/hu/bme/mit/inf/dslreasoner/application/execution/SolverLoader.xtend +++ b/Application/hu.bme.mit.inf.dslreasoner.application/src/hu/bme/mit/inf/dslreasoner/application/execution/SolverLoader.xtend @@ -1,13 +1,17 @@ package hu.bme.mit.inf.dslreasoner.application.execution -import hu.bme.mit.inf.dslreasoner.application.applicationConfiguration.Solver -import java.util.Map +import hu.bme.mit.inf.dlsreasoner.alloy.reasoner.AlloyBackendSolver import hu.bme.mit.inf.dlsreasoner.alloy.reasoner.AlloySolver -import hu.bme.mit.inf.dslreasoner.smt.reasoner.SMTSolver -import hu.bme.mit.inf.dslreasoner.viatrasolver.reasoner.ViatraReasoner import hu.bme.mit.inf.dlsreasoner.alloy.reasoner.AlloySolverConfiguration +import hu.bme.mit.inf.dslreasoner.application.applicationConfiguration.Solver +import hu.bme.mit.inf.dslreasoner.logic.model.builder.LogicSolverConfiguration +import hu.bme.mit.inf.dslreasoner.smt.reasoner.SMTSolver import hu.bme.mit.inf.dslreasoner.smt.reasoner.SmtSolverConfiguration +import hu.bme.mit.inf.dslreasoner.viatrasolver.reasoner.ViatraReasoner import hu.bme.mit.inf.dslreasoner.viatrasolver.reasoner.ViatraReasonerConfiguration +import java.util.Map +import java.util.Optional +import org.eclipse.xtext.xbase.lib.Functions.Function1 class SolverLoader { def loadSolver(Solver solver, Map config) { @@ -18,11 +22,66 @@ class SolverLoader { } } - def loadSolverConfig(Solver solver, Map config) { - switch(solver) { - case ALLOY_SOLVER: return new AlloySolverConfiguration - case SMT_SOLVER: return new SmtSolverConfiguration - case VIATRA_SOLVER: return new ViatraReasonerConfiguration + + + private def Optional getAsType( + Map config, + String key, + ScriptConsole console, + Function1 parser, + Class requestedType) + { + if(config.containsKey(key)) { + val stringValue = config.get(key) + try{ + val parsedValue = parser.apply(stringValue) + return Optional.of(parsedValue) + } catch(Exception e) { + console.writeError('''Unable to parse configuration value for "«key»" to «requestedType.simpleName»!''') + return Optional::empty + } + } else { + return Optional::empty + } + } + private def getAsInteger(Map config, String key, ScriptConsole console) { + return getAsType(config,key,console,[x|Integer.parseInt(x)],Integer) + } + private def getAsBoolean(Map config, String key, ScriptConsole console) { + return getAsType(config,key,console,[x|Boolean.parseBoolean(x)],Boolean) + } + private def getAsDouble(Map config, String key, ScriptConsole console) { + return getAsType(config,key,console,[x|Double.parseDouble(x)],Double) + } + + def loadSolverConfig( + Solver solver, + Map config, + ScriptConsole console) + { + if(solver === Solver::ALLOY_SOLVER) { + return new AlloySolverConfiguration => [c| + config.getAsInteger("symmetry",console) + .ifPresent[c.symmetry = it] + config.getAsType("solver",console,[x|AlloyBackendSolver::valueOf(x)],AlloyBackendSolver) + .ifPresent[c.solver = it] + ] + } else if(solver === Solver::SMT_SOLVER) { + return new SmtSolverConfiguration => [c| + config.getAsBoolean("fixRandomSeed",console).ifPresent[c.fixRandomSeed = it] + ] + } else if(solver === Solver::VIATRA_SOLVER) { + return new ViatraReasonerConfiguration => [c| + ] + } else { + throw new UnsupportedOperationException('''Unknown solver: «solver»''') } } + + def dispatch void setRunIndex(AlloySolverConfiguration config, Map parameters, int runIndex, ScriptConsole console) { + parameters.getAsBoolean("randomise",console).ifPresent[config.randomise = runIndex] + } + def dispatch void setRunIndex(LogicSolverConfiguration config, Map parameters, int runIndex, ScriptConsole console) { + + } } \ No newline at end of file -- cgit v1.2.3-70-g09d2