-
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 2 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 |
---|---|---|
|
@@ -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,9 @@ 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: " << availableOrToolsSolversString(LINEAR) << std::endl; | ||
std::cout << "Available quadratic solvers: " << availableOrToolsSolversString(QUADRATIC) | ||
<< std::endl; | ||
} | ||
} // namespace | ||
|
||
|
@@ -275,7 +277,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(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(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,22 @@ 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, getAvailableOrtoolsMpSolverName()); | ||
checkSolverExists(options.optOptions.quadraticSolver, getAvailableOrtoolsQuadraticSolverName()); | ||
} | ||
|
||
void Settings::checkAndSetStudyFolder(const std::string& folder) | ||
{ | ||
// The study folder | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,8 +23,15 @@ | |
#include "antares/solver/optimisation/constraints/constraint_builder_utils.h" | ||
#include "antares/solver/optimisation/opt_fonctions.h" | ||
|
||
bool OPT_PilotageOptimisationQuadratique(PROBLEME_HEBDO* problemeHebdo) | ||
bool OPT_PilotageOptimisationQuadratique(const OptimizationOptions& options, | ||
PROBLEME_HEBDO* problemeHebdo) | ||
{ | ||
if (options.quadraticSolver != "sirius") | ||
{ | ||
const std::string notFound = "Solver " + options.quadraticSolver | ||
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. I don’t understand this condition |
||
+ " not supported for quadratic problems optimization."; | ||
throw new std::invalid_argument(notFound); | ||
} | ||
if (!problemeHebdo->LeProblemeADejaEteInstancie) | ||
{ | ||
OPT_ConstruireLaListeDesVariablesOptimiseesDuProblemeQuadratique(problemeHebdo); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -35,23 +35,43 @@ | |
|
||
using namespace operations_research; | ||
|
||
enum SolverClass | ||
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. Use enum class |
||
{ | ||
LINEAR, | ||
QUADRATIC | ||
}; | ||
|
||
void ORTOOLS_EcrireJeuDeDonneesLineaireAuFormatMPS(MPSolver* solver, | ||
Antares::Solver::IResultWriter& writer, | ||
const std::string& filename); | ||
|
||
/*! | ||
* \brief Return list of available ortools solver name on our side | ||
* \brief Return list of available ortools solver names on our side | ||
* | ||
* \return List of available ortools solver names | ||
*/ | ||
std::list<std::string> getAvailableOrtoolsSolverNames(SolverClass solverClass); | ||
|
||
/*! | ||
* \brief Return list of available ortools linear solver names on our side | ||
* | ||
* \return List of available ortools linear solver names | ||
*/ | ||
std::list<std::string> getAvailableOrtoolsMpSolverName(); | ||
|
||
/*! | ||
* \brief Return list of available ortools quadratic solver names on our side | ||
* | ||
* \return List of available ortools solver name | ||
* \return List of available ortools quadratic solver names | ||
*/ | ||
std::list<std::string> getAvailableOrtoolsSolverName(); | ||
std::list<std::string> getAvailableOrtoolsQuadraticSolverName(); | ||
|
||
/*! | ||
* \brief Return a single string containing all solvers available, separated by a ", " and ending | ||
* with a ".". | ||
* | ||
*/ | ||
std::string availableOrToolsSolversString(); | ||
std::string availableOrToolsSolversString(SolverClass solverClass); | ||
|
||
/*! | ||
* \brief Create a MPSolver with correct linear or mixed variant | ||
|
@@ -68,7 +88,7 @@ class OrtoolsUtils | |
public: | ||
struct SolverNames | ||
{ | ||
std::string LPSolverName, MIPSolverName; | ||
std::string LPSolverName, MIPSolverName, QuadraticSolverName; | ||
}; | ||
static const std::map<std::string, struct SolverNames> solverMap; | ||
}; |
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 line :
By any chance, would you mean (instead) :
?