diff --git a/src/tools/batchrun/main.cpp b/src/tools/batchrun/main.cpp index e2fb2e2278..9a31f4ecdf 100644 --- a/src/tools/batchrun/main.cpp +++ b/src/tools/batchrun/main.cpp @@ -85,163 +85,32 @@ int main(int argc, const char* argv[]) // Initializing the toolbox Antares::Resources::Initialize(argc, argv, true); - // options - std::string optInput; - std::string ortoolsSolver; - bool optNoTSImport = false; - bool optIgnoreAllConstraints = false; - bool optForceExpansion = false; - bool optForceEconomy = false; - bool optForceAdequacy = false; - bool optForce = false; - bool optYearByYear = false; - bool optNoOutput = false; - bool optParallel = false; - bool optVerbose = false; - bool ortoolsUsed = false; - Nullable optYears; - Nullable optSolver; - Nullable optName; - Nullable optForceParallel; - - // Command Line options + if (argc < 2) { - // Parser - GetOpt::Parser options; - // - options.addParagraph(String() << "Antares Batch Simulation Launcher v" << VersionToCString() - << "\n"); - // Input - options.addParagraph("Studies"); - options.add(optInput, 'i', "input", "The input folder, where to find some studies"); - - // Simulation mode - options.addParagraph("\nSimulation mode"); - options.addFlag(optForceExpansion, - ' ', - "economy", - "Force the simulation(s) in expansion mode"); - options.addFlag(optForceEconomy, ' ', "economy", "Force the simulation(s) in economy mode"); - options.addFlag(optForceAdequacy, - ' ', - "adequacy", - "Force the simulation(s) in adequacy mode"); - - options.addParagraph("\nParameters"); - options.add(optName, 'n', "name", "Set the name of the new simulation outputs"); - options.add(optYears, 'y', "year", "Override the number of MC years"); - options.addFlag(optForce, 'f', "force", "Ignore all warnings at loading"); - options.addFlag(optNoOutput, - ' ', - "no-output", - "Do not write the results in the output folder"); - options.addFlag(optYearByYear, - ' ', - "year-by-year", - "Force the writing of the result output for each year"); - - options.addParagraph("\nOptimization"); - options.addFlag(optNoTSImport, - ' ', - "no-ts-import", - "Do not import timeseries into the input folder."); - options.addFlag(optIgnoreAllConstraints, ' ', "no-constraints", "Ignore all constraints"); - - options.addParagraph("\nExtras"); - options.add(optSolver, ' ', "solver", "Specify the antares-solver location"); - options.addFlag(optParallel, - 'p', - "parallel", - "Enable the parallel computation of MC years"); - options.add(optForceParallel, - ' ', - "force-parallel", - "Override the max number of years computed simultaneously"); - - // add option for ortools use - // --use-ortools - options.addFlag(ortoolsUsed, ' ', "use-ortools", "Use ortools library to launch solver"); - - //--ortools-solver - options.add(ortoolsSolver, - ' ', - "ortools-solver", - "Ortools solver used for simulation (only available with use-ortools " - "option)\nAvailable solver list : " - + availableOrToolsSolversString()); - - options.remainingArguments(optInput); - // Version - options.addParagraph("\nMisc."); - bool optVersion = false; - options.addFlag(optVersion, 'v', "version", "Print the version and exit"); - options.addFlag(optVerbose, ' ', "verbose", "Displays study runs outputs"); - - if (options(argc, argv) == GetOpt::ReturnCode::error) - { - return options.errors() ? 1 : 0; - } + logs.error() << "Usage " << argv[0] << " optInput [other options]"; + return EXIT_FAILURE; + } - if (optVersion) - { - PrintVersionToStdCout(); - return 0; - } + const bool optVerbose = false; + // Command Line options + { + const std::string optInput(argv[1]); if (optInput.empty()) { logs.error() << "A folder input is required."; return EXIT_FAILURE; } - if (optForceExpansion and optForceAdequacy) - { - logs.error() << "contradictory options: --expansion and --adequacy"; - return EXIT_FAILURE; - } - - if (optForceEconomy and optForceAdequacy) - { - logs.error() << "contradictory options: --economy and --adequacy"; - return EXIT_FAILURE; - } - - if (ortoolsUsed) - { - const auto availableSolvers = getAvailableOrtoolsSolverName(); - if (auto it = std::find(availableSolvers.begin(), - availableSolvers.end(), - ortoolsSolver); - it == availableSolvers.end()) - { - logs.error() << "Please specify a solver using --ortools-solver. Available solvers " - << availableOrToolsSolversString() << ""; - return EXIT_FAILURE; - } - } - // Source Folder logs.debug() << "Folder : `" << optInput << '`'; String solver; - if (optSolver.empty()) + Solver::FindLocation(solver); + if (solver.empty()) { - Solver::FindLocation(solver); - if (solver.empty()) - { - logs.fatal() << "The solver has not been found"; - return EXIT_FAILURE; - } - } - else - { - std::string tmp = *optSolver; - fs::path solverPath = fs::absolute(tmp).lexically_normal(); - if (!fs::exists(solverPath)) - { - logs.fatal() << "The solver has not been found. specify --solver=" << solver; - return EXIT_FAILURE; - } + logs.fatal() << "The solver has not been found"; + return EXIT_FAILURE; } logs.info() << " Solver: '" << solver << "'"; @@ -257,7 +126,7 @@ int main(int argc, const char* argv[]) { if (finder.list.size() > 1) { - logs.info() << "Found " << finder.list.size() << " studyies"; + logs.info() << "Found " << finder.list.size() << " studies"; } else { @@ -265,14 +134,6 @@ int main(int argc, const char* argv[]) } logs.info() << "Starting..."; - if (!(!optName)) - { - String name; - name = *optName; - name.replace("\"", "\\\""); - *optName = name; - } - // The folder that contains the solver String dirname; IO::parent_path(dirname, solver); @@ -307,57 +168,24 @@ int main(int argc, const char* argv[]) cmd << "call "; // why is it required for working ??? } cmd << "\"" << solver << "\""; - if (optForce) - { - cmd << " --force"; - } - if (optForceExpansion) - { - cmd << " --economy"; - } - if (optForceEconomy) - { - cmd << " --economy"; - } - if (optForceAdequacy) - { - cmd << " --adequacy"; - } - if (!(!optName)) - { - cmd << " --name=\"" << *optName << "\""; - } - if (!(!optYears)) - { - cmd << " --year=" << *optYears; - } - if (optNoOutput) - { - cmd << " --no-output"; - } - if (optYearByYear) - { - cmd << " --year-by-year"; - } - if (optNoTSImport) - { - cmd << " --no-ts-import"; - } - if (optIgnoreAllConstraints) - { - cmd << " --no-constraints"; - } - if (optParallel) - { - cmd << " --parallel"; - } - if (optForceParallel) - { - cmd << " --force-parallel=" << *optForceParallel; - } - if (ortoolsUsed) + + // argv[0] => executable name + // argv[1] => directory name + for (int ii = 2; ii < argc; ii++) { - cmd << " --use-ortools --ortools-solver=" << ortoolsSolver; + const std::string arg(argv[ii]); + if (arg.find(" ") == std::string::npos) + { + cmd << " " << arg; + } + else + { + // Wrap spaces around quotes, if any + // example + // antares-batchrun directory --use-ortools --ortools-solver xpress + // --solver-parameters "PRESOLVE 1" + cmd << " \"" << arg << "\""; + } } cmd << " \"" << studypath << "\"";