Skip to content
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

Add optimization options in OR-Tools / XPRESS, refactor #1837

Merged
merged 44 commits into from
May 16, 2024
Merged
Show file tree
Hide file tree
Changes from 31 commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
e7c21b0
Version 8.8.0-rc4
flomnes Nov 21, 2023
83dc5b5
Add solver parameters from command line
tbittar Dec 5, 2023
06f6fbd
Run CI on CentOS7
flomnes Dec 6, 2023
dce2220
Merge remote-tracking branch 'origin/develop' into fix/xpress-perf
flomnes Dec 6, 2023
ccba98f
Update URL
flomnes Dec 5, 2023
3178830
Merge remote-tracking branch 'github/develop' into fix/xpress-perf
flomnes Dec 21, 2023
0707458
Merge remote-tracking branch 'github/develop' into fix/xpress-perf
flomnes Dec 21, 2023
12c11ff
Reformat + use OptimizationOptions
flomnes Dec 21, 2023
23f67dc
Add CMake target for Optimization options
flomnes Dec 21, 2023
1657b29
Merge branch 'develop' into fix/xpress-perf
tbittar Mar 21, 2024
a79dc3a
Merge remote-tracking branch 'origin/develop' into fix/xpress-perf
tbittar Mar 21, 2024
56a1cd6
Fix conflicts after rebase
tbittar Mar 28, 2024
39492c8
Set generic parameters from generaldata.ini
tbittar Mar 28, 2024
e5ef606
Fix typo
tbittar Mar 29, 2024
7808ea9
Set solver parameters only once and closer to solve
tbittar Apr 2, 2024
e25baf6
Add some const qualifiers
tbittar Apr 8, 2024
3aca9c2
Gather all solverLogs and ortools options in optimization options
tbittar Apr 8, 2024
59e60a7
Remove use basis config
tbittar Apr 9, 2024
5d2beb6
Merge branch 'develop' into fix/xpress-perf
flomnes Apr 9, 2024
fa8ee43
Add solver specific parameters check
tbittar Apr 9, 2024
fe6add0
Add unit tests
tbittar Apr 11, 2024
7ea6f86
Merge branch 'develop' into fix/xpress-perf
tbittar Apr 11, 2024
9ef4d87
Clarify tests and free solver when not needed anymore
tbittar Apr 12, 2024
1c084a8
Add docs
tbittar Apr 12, 2024
b7da5c3
update tests
tbittar Apr 12, 2024
28b4e82
Fix tests
tbittar Apr 12, 2024
db4b662
Take into account (almost all) PR remarks
tbittar Apr 16, 2024
30dc39f
Fix cmake
tbittar Apr 16, 2024
fb2e8b6
Perform specific parameters check only in solve
tbittar Apr 23, 2024
5afadd1
Restore command line option management
tbittar Apr 23, 2024
2a7154f
Allow to set solver parameters from command line, define xpress and s…
tbittar Apr 23, 2024
54ef5e4
Merge branch 'develop' into fix/xpress-perf
tbittar Apr 25, 2024
1282466
Differentiate between xpress and scip parameters
tbittar Apr 25, 2024
2d7cefc
Factorize code
tbittar Apr 26, 2024
bb5e9a9
Merge branch 'develop' into fix/xpress-perf
tbittar May 6, 2024
2f03618
Update docs
tbittar May 6, 2024
166b261
Fix bugs from previous merge
tbittar May 6, 2024
a5aecb2
Fix bug
tbittar May 6, 2024
b8a1128
Merge branch 'develop' into fix/xpress-perf
tbittar May 16, 2024
c563243
Fix typo
tbittar May 16, 2024
2c8d2df
remove unused declarations
tbittar May 16, 2024
a124741
Simplify spec (remove generaldata.ini new stuff, unify CLI options)
flomnes May 16, 2024
49a30ba
Fix changelog
flomnes May 16, 2024
dca22ca
f
flomnes May 16, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ toc_depth: 2
--------------------
### Improvements
* STS groups are now "dynamic" : group names are no longer fixed by code, user is free to define these groups.
* When xpress or scip solver is selected (using ortools), solver specific parameters can be specified in the generaldata.ini (#1837)

## 9.0.0
--------------------
Expand Down
1 change: 1 addition & 0 deletions docs/reference-guide/10-command_line.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ _In all cases, arguments " –h" or "–help" can be used to get help_
|-m, --mps-export | Export anonymous mps weekly or daily optimal UC+dispatch linear |
|-s, --named-mps-problems | Export named mps weekly or daily optimal UC+dispatch linear |
|--solver-logs | Print solver logs |
|--solver-parameters | Set solver specific parameters: <ul><li>With Xpress : `--solver-parameters="param1 value1 param2 value2"`</li><li>With SCIP : `--solver-parameters="param1 value1, param2 value2"`</li></ul> Command-line parameters override those specified in generaldata.ini within `xpress-parameters` or `scip-parameters` fields |
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is markdown, not HTML. Please remove markups and use the markdown syntax instead.

Copy link
Contributor

@tbittar tbittar Apr 24, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A bullet list inside a table does not render well if I use the markdown syntax, therefore I switch to html for this particular feature: https://stackoverflow.com/questions/19950648/how-to-write-lists-inside-a-markdown-table It renders well on the readthedocs.

Does this have an impact elsewhere ? PDF generation maybe ?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should try to avoid html as much as possible too


- Misc.

Expand Down
23 changes: 16 additions & 7 deletions docs/reference-guide/13-file-format.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# Study format changes
This is a list of all recent changes that came with new Antares Simulator features. The main goal of this document is to lower the costs of changing existing interfaces, both GUI and scripts.
## v9.1.0
## Input
### Hydro Maximum Generation/Pumping Power
### Input
#### Hydro Maximum Generation/Pumping Power
* For time series ![Migration diagram](migration.png "Migration diagram"), for more details, see [this Python script](migration.py)
* In the existing file **settings/scenariobuilder.dat**, under **&lt;ruleset&gt;** section following properties added: **hgp,&lt;area&gt;,&lt;year&gt; = &lt;hgp-value&gt;**

Expand All @@ -15,7 +15,7 @@ This implies that, inside one of the previous categories, the number of availabl

* [Logic changes](17-v91.md)

### Short term storage groups
#### Short term storage groups
STS groups in input are now "dynamic" : group names are no longer fixed by code, user is free to define these groups.

In the "thematic trimming" section, the new dynamic variable `STS by group` is now used to enable/disable all variables (level/injection/withdrawal) for all groups. The following variables are obsolete and must not be provided
Expand All @@ -38,18 +38,27 @@ Other5_level

The default value for group is "OTHER1".

## Output
### Hydro maximum generation/pumping power
#### Optimization : solver parameters (expert option)

In file **settings/generaldata.ini**, in section `optimization` add properties `xpress-parameters` and `scip-parameters` [str]. Default value = `empty string`. Allows to specify solver specific parameters in the following format :

- `xpress-parameters = param1 value1 param2 value2`,
- `scip-parameters = param1 value1, param2 value2`.

These parameters can also be set from the command-line using `--solver-parameters`. In this case command-line parameters override settings from `generaldata.ini`

### Output
#### Hydro maximum generation/pumping power
In existing directory `ts-numbers`, add sub-directory `hgp` containing TS numbers for hydro max pumping/generation, for each area.

### ST Storage
#### ST Storage
- Output columns for ST storage are capitalized. For any STS group name my_group, 3 output columns are created : `MY_GROUP_INJECTION`, `MY_GROUP_WITHDRAWAL`, `MY_GROUP_LEVEL`.
- If a group is empty, no column is produced.
- There is now a variable number of columns in files values-XXX.txt, depending on the groups of ST storages provided by the user. Note that groups are case-insensitive, for example `battery`, `Battery` and `BATTERY` all represent the same group. If no ST storage exist for a given area, no variables associated to ST storages will be produced.

## v9.0.0
### Input
### Study version
#### Study version
Breaking change in the study format, file **study.antares**
```
version = 900
Expand Down
2 changes: 1 addition & 1 deletion src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -464,4 +464,4 @@ endif()
include(CPack)

#Last. We need all target defined
add_subdirectory(packaging)
# add_subdirectory(packaging)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Revert this

2 changes: 2 additions & 0 deletions src/libs/antares/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ add_subdirectory(sys)
add_subdirectory(utils)
add_subdirectory(writer)

add_subdirectory(optimization-options)

set(HEADERS
include/antares/antares/antares.h
include/antares/antares/constants.h
Expand Down
6 changes: 3 additions & 3 deletions src/libs/antares/InfoCollection/StudyInfoCollector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -141,17 +141,17 @@ void StudyInfoCollector::solverVersionToFileContent(FileContent& file_content)

void StudyInfoCollector::ORToolsUsed(FileContent& file_content)
{
const bool& ortoolsUsed = study_.parameters.ortoolsUsed;
const bool& ortoolsUsed = study_.parameters.optOptions.ortoolsUsed;
file_content.addItemToSection("study", "ortools used", ortoolsUsed ? "true" : "false");
}

void StudyInfoCollector::ORToolsSolver(FileContent& file_content)
{
const bool& ortoolsUsed = study_.parameters.ortoolsUsed;
const bool& ortoolsUsed = study_.parameters.optOptions.ortoolsUsed;
std::string ortoolsSolver = "none";
if (ortoolsUsed)
{
ortoolsSolver = study_.parameters.ortoolsSolver;
ortoolsSolver = study_.parameters.optOptions.ortoolsSolver;
}
file_content.addItemToSection("study", "ortools solver", ortoolsSolver);
}
Expand Down
15 changes: 8 additions & 7 deletions src/libs/antares/checks/checkLoadedInputData.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ void checkStudyVersion(const AnyString& optStudyFolder)
throw Error::InvalidStudy(optStudyFolder);

if (version > StudyVersion::latest())
throw Error::InvalidVersion(version.toString(),StudyVersion::latest().toString());
throw Error::InvalidVersion(version.toString(), StudyVersion::latest().toString());
}
// CHECK incompatible de choix simultané des options « simplex range= daily » et « hydro-pricing
// = MILP ».
Expand Down Expand Up @@ -150,8 +150,9 @@ void checkMinStablePower(bool tsGenThermal, const Antares::Data::AreaList& areas
// Number of columns for Fuel & CO2 cost in thermal clusters must be one, or same as the number of
// TS
template<class ExceptionT>
static void checkThermalColumnNumber(const Antares::Data::AreaList& areas,
Antares::Data::TimeSeries::TS Antares::Data::EconomicInputData::*matrix)
static void checkThermalColumnNumber(
const Antares::Data::AreaList& areas,
Antares::Data::TimeSeries::TS Antares::Data::EconomicInputData::*matrix)
{
ExceptionT exception;
bool error = false;
Expand All @@ -178,14 +179,14 @@ static void checkThermalColumnNumber(const Antares::Data::AreaList& areas,

void checkFuelCostColumnNumber(const Antares::Data::AreaList& areas)
{
checkThermalColumnNumber<Antares::Error::IncompatibleFuelCostColumns>(areas,
&Antares::Data::EconomicInputData::fuelcost);
checkThermalColumnNumber<Antares::Error::IncompatibleFuelCostColumns>(
areas, &Antares::Data::EconomicInputData::fuelcost);
}

void checkCO2CostColumnNumber(const Antares::Data::AreaList& areas)
{
checkThermalColumnNumber<Antares::Error::IncompatibleCO2CostColumns>(areas,
&Antares::Data::EconomicInputData::co2cost);
checkThermalColumnNumber<Antares::Error::IncompatibleCO2CostColumns>(
areas, &Antares::Data::EconomicInputData::co2cost);
}

} // namespace Antares::Check
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,20 @@
** You should have received a copy of the Mozilla Public Licence 2.0
** along with Antares_Simulator. If not, see <https://opensource.org/license/mpl-2-0/>.
*/
#include "antares/study/fwd.h"
#include "antares/optimization-options/options.h"

namespace Antares::Check
{

void checkOrtoolsUsage(Antares::Data::UnitCommitmentMode ucMode,
bool ortoolsUsed,
const std::string& solverName);

void checkOrtoolsSolverSpecificParameters(
const Antares::Data::UnitCommitmentMode& ucMode,
const Antares::Solver::Optimization::OptimizationOptions& optOptions);

void checkStudyVersion(const AnyString& optStudyFolder);

void checkSimplexRangeHydroPricing(Antares::Data::SimplexOptimization optRange,
Expand Down
34 changes: 25 additions & 9 deletions src/libs/antares/exception/LoadingError.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,18 +62,34 @@ InvalidSimulationMode::InvalidSimulationMode() :
{
}

static std::string InvalidSolverHelper(const std::string& solver, const std::string& availableSolvers)
static std::string InvalidSolverHelper(const std::string& solver,
const std::string& availableSolvers)
{
std::ostringstream message;
message
<< "Can't use solver '"
<< solver
<< "' : it does not match any available OR-Tools solver. Possible choices are "
<< availableSolvers;
return message.str();
std::ostringstream message;
message << "Can't use solver '" << solver
<< "' : it does not match any available OR-Tools solver. Possible choices are "
<< availableSolvers;
return message.str();
}

InvalidSolver::InvalidSolver(const std::string& solver, const std::string& availableSolvers) : LoadingError(InvalidSolverHelper(solver, availableSolvers))
InvalidSolver::InvalidSolver(const std::string& solver, const std::string& availableSolvers) :
LoadingError(InvalidSolverHelper(solver, availableSolvers))
{
}

static std::string InvalidSolverSpecificParametersHelper(const std::string& solver,
const std::string& solverParameters)
{
std::ostringstream message;
message << "Specific parameters '" << solverParameters << "' are not valid or not supported for solver "
<< solver;
return message.str();
}

InvalidSolverSpecificParameters::InvalidSolverSpecificParameters(
const std::string& solver,
const std::string& solverParameters) :
LoadingError(InvalidSolverSpecificParametersHelper(solver, solverParameters))
{
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,12 @@ class InvalidSolver : public LoadingError
explicit InvalidSolver(const std::string& solver, const std::string& availableSolverList);
};

class InvalidSolverSpecificParameters : public LoadingError
{
public:
explicit InvalidSolverSpecificParameters(const std::string& solver, const std::string& solverParameters);
};

class InvalidStudy : public LoadingError
{
public:
Expand Down
10 changes: 10 additions & 0 deletions src/libs/antares/optimization-options/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
set(PROJ optimization-options)

add_library(${PROJ} INTERFACE)

target_include_directories(${PROJ}
INTERFACE
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
)

add_library(Antares::${PROJ} ALIAS ${PROJ})
pet-mit marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*
** Copyright 2007-2024, RTE (https://www.rte-france.com)
** See AUTHORS.txt
** SPDX-License-Identifier: MPL-2.0
** This file is part of Antares-Simulator,
** Adequacy and Performance assessment for interconnected energy networks.
**
** Antares_Simulator is free software: you can redistribute it and/or modify
** it under the terms of the Mozilla Public Licence 2.0 as published by
** the Mozilla Foundation, either version 2 of the License, or
** (at your option) any later version.
**
** Antares_Simulator is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** Mozilla Public Licence 2.0 for more details.
**
** You should have received a copy of the Mozilla Public Licence 2.0
** along with Antares_Simulator. If not, see <https://opensource.org/license/mpl-2-0/>.
*/

#pragma once

namespace Antares::Solver::Optimization {
struct OptimizationOptions
{
//! Force ortools use
bool ortoolsUsed = false;
//! The solver name, sirius is the default
std::string ortoolsSolver = "sirius";
bool solverLogs = false;
std::string solverParameters = "";
};
}
10 changes: 4 additions & 6 deletions src/libs/antares/study/include/antares/study/load-options.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@

#include <yuni/yuni.h>
#include <yuni/core/string.h>
#include <antares/optimization-options/options.h>

#include "parameters.h"

namespace Antares
Expand Down Expand Up @@ -62,8 +64,6 @@ class StudyLoadOptions
bool mpsToExport;
//! named problems
bool namedProblems = false;
//! enable solver logs
bool solverLogs = false;
//! Ignore all constraints
bool ignoreConstraints;
//! Simulation mode
Expand All @@ -79,10 +79,8 @@ class StudyLoadOptions
//! A non-zero value if the data will be used for a simulation
bool usedByTheSolver;

//! Force ortools use
bool ortoolsUsed;
//! THe solver name, sirius is the default
std::string ortoolsSolver = "sirius";
//! All options related to optimization
Antares::Solver::Optimization::OptimizationOptions optOptions;

//! Temporary string for passing log message
mutable Yuni::String logMessage;
Expand Down
15 changes: 5 additions & 10 deletions src/libs/antares/study/include/antares/study/parameters.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
#include "version.h"

#include <antares/study/UnfeasibleProblemBehavior.hpp>
#include <antares/optimization-options/options.h>

namespace Antares::Data
{
Expand Down Expand Up @@ -511,25 +512,19 @@ class Parameters final
uint seed[seedMax];
//@}

//! \name Ortools configuration
//@{
//! Define if ortools is used
bool ortoolsUsed;
//! Ortool solver used for simulation
std::string ortoolsSolver;
//@}

// Format of results. Currently, only single files or zip archive are supported
ResultFormat resultFormat = legacyFilesDirectories;

// Naming constraints and variables in problems
bool namedProblems;

// solver logs
bool solverLogs;
// All options related to optimization
Antares::Solver::Optimization::OptimizationOptions optOptions;

private:
//! Load data from an INI file
bool loadFromINI(const IniFile& ini, StudyVersion& version, const StudyLoadOptions& options);
bool loadFromINI(const IniFile& ini, const StudyVersion& version, const StudyLoadOptions& options);

void resetPlayedYears(uint nbOfYears);

Expand Down
3 changes: 1 addition & 2 deletions src/libs/antares/study/load-options.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,7 @@ StudyLoadOptions::StudyLoadOptions() :
enableParallel(false),
forceParallel(false),
maxNbYearsInParallel(0),
usedByTheSolver(false),
ortoolsUsed(false)
usedByTheSolver(false)
{
}

Expand Down
Loading
Loading