Commit 26229f4d authored by Christoph Richter's avatar Christoph Richter
Browse files

Enhanced CLI

parent 81c842b8
Pipeline #67178 passed with stage
in 3 minutes and 38 seconds
package de.monticore.lang.monticar.generator.cpp;
import de.monticore.lang.embeddedmontiarc.embeddedmontiarc._symboltable.ExpandedComponentInstanceSymbol;
import de.monticore.lang.monticar.generator.cpp.optimizationSolver.solver.Solver;
import de.monticore.lang.monticar.generator.cpp.resolver.Resolver;
import de.monticore.lang.monticar.generator.order.simulator.AbstractSymtab;
import de.monticore.lang.tagging._symboltable.TaggingResolver;
import de.se_rwth.commons.logging.Log;
import org.apache.commons.cli.*;
......@@ -22,6 +22,13 @@ public class GeneratorEMAMOpt2CppCli {
public static final Option OPTION_FLAG_AUTOPILOT_ADAPTER = Option.builder().longOpt("flag-generate-autopilot-adapter").desc("optional flag indicating if autopilot adapter should be generated").hasArg(false).required(false).build();
public static final Option OPTION_FLAG_CHECK_MODEL_DIR = Option.builder().longOpt("check-model-dir").desc("optional flag indicating if model dir should be checked for creation of component and stream list").hasArg(false).required(false).build();
public static final Option OPTION_FLAG_SERVER_WRAPPER = Option.builder().longOpt("flag-generate-server-wrapper").desc("optional flag indicating if model should be wrapped into a server").hasArg(false).required(false).build();
public static final Option OPTION_FLAG_GENERATE_CMAKE = Option.builder().longOpt("flag-generate-cmake").desc("optional flag indicating if model should be additionally generate CMake files").hasArg(false).required(false).build();
public static final Option OPTION_PREFERED_SOLVER = Option.builder("s").longOpt("prefered-solver").desc("prefered solver (IPOPT, CPLEX)").hasArg(true).required(false).build();
public static final Option OPTION_IPOPT_PRINT_LEVEL = Option.builder().longOpt("print-level").desc("verbosity of IPOPT solver output from 0-12").hasArg(true).required(false).build();
public static final Option OPTION_IPOPT_MAX_ITER = Option.builder().longOpt("max-iter").desc("maximal number of iterations.").hasArg(true).required(false).build();
public static final Option OPTION_IPOPT_NUMERIC_TOL = Option.builder().longOpt("numeric-tol").desc("approximate accuracy in first order necessary conditions").hasArg(true).required(false).build();
public static final Option OPTION_IPOPT_POINT_PERMUTATION = Option.builder().longOpt("point-permutation-radius").desc("maximum amount of random permutation").hasArg(true).required(false).build();
private GeneratorEMAMOpt2CppCli() {
}
......@@ -47,6 +54,8 @@ public class GeneratorEMAMOpt2CppCli {
options.addOption(OPTION_FLAG_SERVER_WRAPPER);
options.addOption(OPTION_FLAG_ALGEBRAIC);
options.addOption(OPTION_FLAG_THREADING);
options.addOption(OPTION_FLAG_GENERATE_CMAKE);
options.addOption(OPTION_PREFERED_SOLVER);
return options;
}
......@@ -79,6 +88,8 @@ public class GeneratorEMAMOpt2CppCli {
g.setGenerateAutopilotAdapter(cliArgs.hasOption(OPTION_FLAG_AUTOPILOT_ADAPTER.getLongOpt()));
g.setUseAlgebraicOptimizations(cliArgs.hasOption(OPTION_FLAG_ALGEBRAIC.getLongOpt()));
g.setUseThreadingOptimization(cliArgs.hasOption(OPTION_FLAG_THREADING.getLongOpt()));
g.setGenerateCMake(cliArgs.hasOption(OPTION_FLAG_GENERATE_CMAKE.getLongOpt()));
setPreferedSolverFromArg(g, cliArgs.getOptionValue(OPTION_PREFERED_SOLVER.getOpt()));
try {
if (componentSymbol != null) {
......@@ -93,6 +104,18 @@ public class GeneratorEMAMOpt2CppCli {
}
private static void setPreferedSolverFromArg(GeneratorEMAMOpt2CPP g, String optionValue) {
if (optionValue != null) {
if (optionValue.contentEquals("IPOPT")) {
g.setPreferedSolver(Solver.Cplex);
} else if (optionValue.contentEquals("CPLEX")) {
g.setPreferedSolver(Solver.Cplex);
} else {
Log.warn(String.format("Solver %s not found. Using default solver instead."));
}
}
}
private static ExpandedComponentInstanceSymbol resolveSymbol(Resolver resolver, String rootModelName) {
ExpandedComponentInstanceSymbol componentSymbol = (ExpandedComponentInstanceSymbol) resolver.getExpandedComponentInstanceSymbol(rootModelName).orElse(null);
if (componentSymbol == null) {
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment