-
Notifications
You must be signed in to change notification settings - Fork 25
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support more quadratic solvers #2574
base: develop
Are you sure you want to change the base?
Changes from all commits
6ea9578
b5e422e
6511c37
271e62c
c49ca2e
d5d90f0
be5564e
070ea47
0aa9b80
45397d7
6760369
085f4cc
5b48ed5
81b4998
d9d8c42
c7ac13f
6629576
445d5ec
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
v9.11-rte1.1 | ||
v9.11-rte1.2 |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -145,8 +145,11 @@ void StudyInfoCollector::solverVersionToFileContent(FileContent& file_content) | |
|
||
void StudyInfoCollector::ORToolsSolver(FileContent& file_content) | ||
{ | ||
std::string solverName = study_.parameters.optOptions.ortoolsSolver; | ||
file_content.addItemToSection("study", "ortools solver", solverName); | ||
std::string linearSolverName = study_.parameters.optOptions.linearSolver; | ||
file_content.addItemToSection("study", "linear solver", linearSolverName); | ||
|
||
std::string quadraticSolverName = study_.parameters.optOptions.linearSolver; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. About line : std::string quadraticSolverName = study_.parameters.optOptions.linearSolver; By any chance, would you mean (instead) : std::string quadraticSolverName = study_.parameters.optOptions.quadraticSolver; ? |
||
file_content.addItemToSection("study", "quadratic solver", quadraticSolverName); | ||
} | ||
|
||
// Collecting data optimization problem | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1283,8 +1283,10 @@ bool Parameters::loadFromINI(const IniFile& ini, const StudyVersion& version) | |
void Parameters::handleOptimizationOptions(const StudyLoadOptions& options) | ||
{ | ||
// Options only set from the command-line | ||
optOptions.ortoolsSolver = options.optOptions.ortoolsSolver; | ||
optOptions.solverParameters = options.optOptions.solverParameters; | ||
optOptions.linearSolver = options.optOptions.linearSolver; | ||
optOptions.linearSolverParameters = options.optOptions.linearSolverParameters; | ||
optOptions.quadraticSolver = options.optOptions.quadraticSolver; | ||
optOptions.quadraticSolverParameters = options.optOptions.quadraticSolverParameters; | ||
|
||
// Options that can be set both in command-line and file | ||
optOptions.solverLogs = options.optOptions.solverLogs || optOptions.solverLogs; | ||
Comment on lines
+1286
to
1292
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Instead of these 5 lines, it would be better to have : optOptions = options.optOptions; But because of the last line, it seems we can't do that. |
||
|
@@ -1780,8 +1782,11 @@ void Parameters::prepareForSimulation(const StudyLoadOptions& options) | |
logs.info() << " :: ignoring solution export"; | ||
} | ||
|
||
logs.info() << " :: solver " << options.optOptions.ortoolsSolver | ||
<< " is used for problem resolution"; | ||
logs.info() << " :: solver " << options.optOptions.linearSolver | ||
<< " is used for linear problem resolution"; | ||
|
||
logs.info() << " :: solver " << options.optOptions.quadraticSolver | ||
<< " is used for quadratic problem resolution"; | ||
|
||
// indicated that Problems will be named | ||
if (namedProblems) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -48,7 +48,10 @@ namespace | |
{ | ||
void printSolvers() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In the scope of this PR ? (not sure) printSolvers() :
Moreover printSolvers is called from handleOptions which has a very non expressive and probably wrong name and, besides printing, does very strange things. |
||
{ | ||
std::cout << "Available solvers: " << availableOrToolsSolversString() << std::endl; | ||
std::cout << "Available linear solvers: " // NOSONAR | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
<< availableOrToolsSolversString(SolverClass::LINEAR) << std::endl; // NOSONAR | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. availableOrToolsSolversString(...) ==> availableSolversList(...), shorter and clearer. |
||
std::cout << "Available quadratic solvers: " // NOSONAR | ||
<< availableOrToolsSolversString(SolverClass::QUADRATIC) << std::endl; // NOSONAR | ||
} | ||
} // namespace | ||
|
||
|
@@ -275,7 +278,7 @@ void Application::postParametersChecks() const | |
{ // Some more checks require the existence of pParameters, hence of a study. | ||
// Their execution is delayed up to this point. | ||
checkSolverMILPincompatibility(pParameters->unitCommitment.ucMode, | ||
pParameters->optOptions.ortoolsSolver); | ||
pParameters->optOptions.linearSolver); | ||
|
||
checkSimplexRangeHydroPricing(pParameters->simplexOptimizationRange, | ||
pParameters->hydroPricing.hpMode); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,6 +27,8 @@ | |
#include <limits> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Many headers inclusion unnecessary here :
|
||
#include <string.h> | ||
|
||
#include <boost/algorithm/string/join.hpp> | ||
|
||
#include <yuni/yuni.h> | ||
|
||
#include <antares/antares/constants.h> | ||
|
@@ -75,22 +77,53 @@ std::unique_ptr<Yuni::GetOpt::Parser> CreateParser(Settings& settings, StudyLoad | |
"force-parallel", | ||
"Override the max number of years computed simultaneously"); | ||
|
||
//--linear-solver | ||
parser->add(options.optOptions.linearSolver, | ||
' ', | ||
"linear-solver", | ||
"Solver used for linear optimizations during simulation\nAvailable solver list : " | ||
+ availableOrToolsSolversString(SolverClass::LINEAR)); | ||
|
||
//--solver | ||
parser->add(options.optOptions.ortoolsSolver, | ||
parser->add(options.optOptions.linearSolver, | ||
' ', | ||
"solver", | ||
"Solver used for simulation\nAvailable solver list : " | ||
+ availableOrToolsSolversString()); | ||
"Deprecated, use linear-solver instead."); | ||
|
||
//--solver-parameters | ||
//--linear-solver-parameters | ||
parser->add( | ||
options.optOptions.solverParameters, | ||
options.optOptions.linearSolverParameters, | ||
' ', | ||
"solver-parameters", | ||
"Set solver-specific parameters, for instance --solver-parameters=\"THREADS 1 PRESOLVE 1\"" | ||
"linear-solver-parameters", | ||
"Set linear solver-specific parameters, for instance --linear-solver-parameters=\"THREADS 1 " | ||
"PRESOLVE 1\"" | ||
"for XPRESS or --solver-parameters=\"parallel/maxnthreads 1, lp/presolving TRUE\" for SCIP." | ||
"Syntax is solver-dependent, and only supported for SCIP & XPRESS."); | ||
|
||
//--solver-parameters | ||
parser->add(options.optOptions.linearSolverParameters, | ||
' ', | ||
"solver-parameters", | ||
"Deprecated, use linear-solver-parameters instead."); | ||
|
||
//--quadratic-solver | ||
parser->add( | ||
options.optOptions.quadraticSolver, | ||
' ', | ||
"quadratic-solver", | ||
"Solver used for quadratic optimizations during simulation\nAvailable solver list : " | ||
+ availableOrToolsSolversString(SolverClass::QUADRATIC)); | ||
|
||
//--quadratic-solver-parameters | ||
parser->add( | ||
options.optOptions.quadraticSolverParameters, | ||
' ', | ||
"quadratic-solver-parameters", | ||
"Set quadratic solver-specific parameters, for instance " | ||
"--quadratic-solver-parameters=\"THREADS 1 PRESOLVE 1\"" | ||
"for XPRESS or --solver-parameters=\"parallel/maxnthreads 1, lp/presolving TRUE\" for SCIP." | ||
"Syntax is solver-dependent."); | ||
|
||
parser->addParagraph("\nParameters"); | ||
// --name | ||
parser->add(settings.simulationName, | ||
|
@@ -246,7 +279,7 @@ void checkAndCorrectSettingsAndOptions(Settings& settings, Data::StudyLoadOption | |
} | ||
|
||
options.checkForceSimulationMode(); | ||
checkOrtoolsSolver(options.optOptions); | ||
checkSolvers(options); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We should rename checkSolvers(options.solverOptions); (indeed, |
||
|
||
// no-output and force-zip-output | ||
if (settings.noOutput && settings.forceZipOutput) | ||
|
@@ -255,19 +288,24 @@ void checkAndCorrectSettingsAndOptions(Settings& settings, Data::StudyLoadOption | |
} | ||
} | ||
|
||
void checkOrtoolsSolver(const Antares::Solver::Optimization::OptimizationOptions& optOptions) | ||
void checkSolverExists(std::string solverName, const std::list<std::string> availableSolversList) | ||
{ | ||
const std::string& solverName = optOptions.ortoolsSolver; | ||
const std::list<std::string> availableSolverList = getAvailableOrtoolsSolverName(); | ||
|
||
// Check if solver is available | ||
bool found = (std::ranges::find(availableSolverList, solverName) != availableSolverList.end()); | ||
bool found = std::ranges::find(availableSolversList, solverName) != availableSolversList.end(); | ||
if (!found) | ||
{ | ||
throw Error::InvalidSolver(optOptions.ortoolsSolver, availableOrToolsSolversString()); | ||
throw Error::InvalidSolver(solverName, boost::algorithm::join(availableSolversList, ",")); | ||
} | ||
} | ||
|
||
void checkSolvers(StudyLoadOptions& options) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. checkSolvers(...) could be renamed into checkForSolversExistence(...) |
||
{ | ||
checkSolverExists(options.optOptions.linearSolver, | ||
getAvailableSolverNames(SolverClass::LINEAR)); | ||
checkSolverExists(options.optOptions.quadraticSolver, | ||
getAvailableSolverNames(SolverClass::QUADRATIC)); | ||
} | ||
|
||
void Settings::checkAndSetStudyFolder(const std::string& folder) | ||
{ | ||
// The study folder | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -198,18 +198,18 @@ void HourlyCSRProblem::setProblemCost() | |
} | ||
} | ||
|
||
void HourlyCSRProblem::solveProblem(uint week, int year) | ||
void HourlyCSRProblem::solveProblem(uint week, int year, const OptimizationOptions& options) | ||
{ | ||
Comment on lines
+201
to
202
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
ADQ_PATCH_CSR(problemeAResoudre_, *this, adqPatchParams_, week, year); | ||
ADQ_PATCH_CSR(options, problemeAResoudre_, *this, adqPatchParams_, week, year); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not strictly related to the current PR |
||
} | ||
|
||
void HourlyCSRProblem::run(uint week, uint year) | ||
void HourlyCSRProblem::run(uint week, uint year, const OptimizationOptions& options) | ||
{ | ||
calculateCsrParameters(); | ||
buildProblemVariables(); | ||
buildProblemConstraintsLHS(); | ||
setVariableBounds(); | ||
buildProblemConstraintsRHS(); | ||
setProblemCost(); | ||
solveProblem(week, year); | ||
solveProblem(week, year, options); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
About QP : don't hesitate to be more explicit and indicate quadratic problem as in the PR's title