diff --git a/docs/reference-guide/16-xpress.md b/docs/reference-guide/16-xpress.md new file mode 100644 index 0000000000..591e086fbe --- /dev/null +++ b/docs/reference-guide/16-xpress.md @@ -0,0 +1,47 @@ +# Usage with FICO® Xpress Optimization + +## Introduction +The FICO Xpress optimizer is a commercial optimization solver for linear programming (LP), mixed integer linear programming (MILP), convex quadratic programming (QP), convex quadratically constrained quadratic programming (QCQP), second-order cone programming (SOCP) and their mixed integer counterparts. + +Antares Solver only uses LP, with plans to use MILP at some point in the future. Various benchmarks have revealed that Xpress allows faster simulations than Sirius on large studies. + +## Using Xpress in the command-line +``` +antares-x.y-solver --use-ortools --ortools-solver xpress [options] +``` + +## Setup +The `XPRESSDIR` env variable must point to the Xpress install directory. The author strongly suggest placing this in your .bashrc if you use Bash +``` +export XPRESSDIR=path/to/xpress/install/dir +``` + +An Xpress install directory looks like this. Actually, only these files are required, the rest are unnecessary +``` +xpress814 <= XPRESSDIR +└── lib + ├── libxprs.so -> libxprs.so.40 + ├── libxprs.so.40 <= The Xpress shared library + └── xpauth.xpr <= A valid licence +``` + +## Checking that Xpress works +After setting up Xpress, the following command line should display a line if Xpress is installed and a valid licence is found. +``` +antares-x.y-solver --list-solvers | grep xpress +``` + +## Compatibility +Antares Simulator 8.x has been shown to work with Xpress 8.13.0. Trying to use other versions may work, but can lead to crashes. + +## Known issues +### Performance issues with Xpress 9.x +The following Xpress versions suffer a performance regression that makes them unsuitable for use with Antares Simulator +- 9.0.x +- 9.1.x +- 9.2.x + +As of Q3 2023, it is best to stick to Xpress 8.13.0 for best performance + +### Community license is very restrictive +FICO offers a Community License for testing purposes. It should be noted however that it is extremely restrictive. You may experience issues when trying to run Antares Solver with this license, even on small test-cases. diff --git a/src/libs/antares/CMakeLists.txt b/src/libs/antares/CMakeLists.txt index bad0221dc3..2eb1d0059f 100644 --- a/src/libs/antares/CMakeLists.txt +++ b/src/libs/antares/CMakeLists.txt @@ -335,6 +335,7 @@ set(SRC_XCAST source_group("study\\xcast" FILES ${SRC_XCAST}) add_subdirectory(benchmarking) +add_subdirectory(InfoCollection) add_subdirectory(io) add_subdirectory(exception) @@ -508,7 +509,6 @@ target_link_libraries(libantares-core yuni-static-uuid Boost::boost Antares::memory - date logs exception checks @@ -517,9 +517,12 @@ target_link_libraries(libantares-core inifile io array - correlation object benchmarking + Antares::date + + PRIVATE + Antares::correlation ) import_std_libs(libantares-core) diff --git a/src/libs/antares/InfoCollection/CMakeLists.txt b/src/libs/antares/InfoCollection/CMakeLists.txt new file mode 100644 index 0000000000..ad9266c1ec --- /dev/null +++ b/src/libs/antares/InfoCollection/CMakeLists.txt @@ -0,0 +1,35 @@ +set(PROJ infoCollection) +set(HEADERS + include/antares/${PROJ}/StudyInfoCollector.h +) +set(SRC_PROJ + ${HEADERS} + StudyInfoCollector.cpp +) +source_group("misc\\${PROJ}" FILES ${SRC_PROJ}) + +add_library(${PROJ} ${SRC_PROJ}) +add_library(Antares::${PROJ} ALIAS ${PROJ}) + +target_link_libraries(${PROJ} + PRIVATE + yuni-static-core + PUBLIC + Antares::benchmarking +) + +target_include_directories(${PROJ} + PUBLIC + ${CMAKE_SOURCE_DIR}/libs #study + ${CMAKE_SOURCE_DIR}/libs/antares/date #parameters -> date + ${CMAKE_SOURCE_DIR}/libs/antares/array #links + ${CMAKE_SOURCE_DIR}/libs/antares/logs #study -> binding constraint -> matrix -> jit + ${CMAKE_SOURCE_DIR}/libs/antares/io #study -> binding constraint -> matrix + ${CMAKE_SOURCE_DIR}/libs/antares/writer #study + ${CMAKE_SOURCE_DIR}/libs/antares/exception #enum -> exception + ${CMAKE_SOURCE_DIR}/libs/antares/jit # something,something -> jit + ${CMAKE_SOURCE_DIR}/libs/antares/memory/include #study -> BC -> link -> memory + ${CMAKE_SOURCE_DIR}/libs/antares/inifile #study -> inifile + PUBLIC + ${CMAKE_CURRENT_SOURCE_DIR}/include +) diff --git a/src/libs/antares/benchmarking/info_collectors.cpp b/src/libs/antares/InfoCollection/StudyInfoCollector.cpp similarity index 76% rename from src/libs/antares/benchmarking/info_collectors.cpp rename to src/libs/antares/InfoCollection/StudyInfoCollector.cpp index 34b15d8868..05f9894f12 100644 --- a/src/libs/antares/benchmarking/info_collectors.cpp +++ b/src/libs/antares/InfoCollection/StudyInfoCollector.cpp @@ -1,13 +1,15 @@ -#include -#include -#include -#include -#include +// +// Created by marechaljas on 22/08/23. +// + +#include "antares/infoCollection/StudyInfoCollector.h" +#include "antares/benchmarking/DurationCollector.h" +#include "antares/benchmarking/file_content.h" +#include "../../../config.h" using namespace Antares::Data; +namespace Benchmarking { -namespace Benchmarking -{ // Collecting data study // --------------------------- void StudyInfoCollector::toFileContent(FileContent& file_content) @@ -82,17 +84,17 @@ void StudyInfoCollector::enabledBindingConstraintsCountToFileContent(FileContent { switch (activeContraints[i]->type()) { - case BindingConstraint::Type::typeHourly: - nbEnabledHourlyBC++; - break; - case BindingConstraint::Type::typeDaily: - nbEnabledDailyBC++; - break; - case BindingConstraint::Type::typeWeekly: - nbEnabledWeeklyBC++; - break; - default: - break; + case BindingConstraint::Type::typeHourly: + nbEnabledHourlyBC++; + break; + case BindingConstraint::Type::typeDaily: + nbEnabledDailyBC++; + break; + case BindingConstraint::Type::typeWeekly: + nbEnabledWeeklyBC++; + break; + default: + break; } } @@ -105,7 +107,7 @@ void StudyInfoCollector::enabledBindingConstraintsCountToFileContent(FileContent void StudyInfoCollector::unitCommitmentModeToFileContent(FileContent& file_content) { const char* unitCommitment - = UnitCommitmentModeToCString(study_.parameters.unitCommitment.ucMode); + = UnitCommitmentModeToCString(study_.parameters.unitCommitment.ucMode); file_content.addItemToSection("study", "unit commitment", unitCommitment); } @@ -118,7 +120,7 @@ void StudyInfoCollector::solverVersionToFileContent(FileContent& file_content) { // Example : 8.3.0 -> 830 const unsigned int version - = 100 * ANTARES_VERSION_HI + 10 * ANTARES_VERSION_LO + ANTARES_VERSION_BUILD; + = 100 * ANTARES_VERSION_HI + 10 * ANTARES_VERSION_LO + ANTARES_VERSION_BUILD; file_content.addItemToSection("study", "antares version", version); } @@ -147,27 +149,7 @@ void SimulationInfoCollector::toFileContent(FileContent& file_content) file_content.addItemToSection("optimization problem", "variables", opt_info_.nbVariables); file_content.addItemToSection("optimization problem", "constraints", opt_info_.nbConstraints); file_content.addItemToSection( - "optimization problem", "non-zero coefficients", opt_info_.nbNonZeroCoeffs); -} - -// Collecting durations from simulation -// ------------------------------------- -void DurationCollector::toFileContent(FileContent& file_content) -{ - for (const auto& element : duration_items_) - { - const std::string& name = element.first; - const auto& durations = element.second; - const int64_t duration_sum = accumulate(durations.begin(), durations.end(), (int64_t)0); - - file_content.addDurationItem(name, (unsigned int)duration_sum, (int)durations.size()); - } -} - -void DurationCollector::addDuration(const std::string& name, int64_t duration) -{ - const std::lock_guard lock(mutex_); - duration_items_[name].push_back(duration); + "optimization problem", "non-zero coefficients", opt_info_.nbNonZeroCoeffs); } -} // namespace Benchmarking +} \ No newline at end of file diff --git a/src/libs/antares/benchmarking/antares/benchmarking/info_collectors.h b/src/libs/antares/InfoCollection/include/antares/infoCollection/StudyInfoCollector.h similarity index 56% rename from src/libs/antares/benchmarking/antares/benchmarking/info_collectors.h rename to src/libs/antares/InfoCollection/include/antares/infoCollection/StudyInfoCollector.h index 092decdd04..bb3b1f1df8 100644 --- a/src/libs/antares/benchmarking/antares/benchmarking/info_collectors.h +++ b/src/libs/antares/InfoCollection/include/antares/infoCollection/StudyInfoCollector.h @@ -1,25 +1,13 @@ -#pragma once - -#include -#include -#include -#include +// +// Created by marechaljas on 22/08/23. +// -#include "file_content.h" -#include +#pragma once -namespace Benchmarking -{ -struct OptimizationInfo -{ - unsigned int nbVariables = 0; - unsigned int nbConstraints = 0; - unsigned int nbNonZeroCoeffs = 0; -}; +#include "antares/study/study.h" -/* - === Info collectors === -*/ +namespace Benchmarking { +class FileContent; class StudyInfoCollector { @@ -47,46 +35,22 @@ class StudyInfoCollector const Antares::Data::Study& study_; }; -class SimulationInfoCollector -{ -public: - SimulationInfoCollector(const OptimizationInfo& optInfo) : opt_info_(optInfo){}; - void toFileContent(FileContent& file_content); - -private: - const OptimizationInfo& opt_info_; -}; - -class IDurationCollector -{ -public: - virtual void addDuration(const std::string& name, int64_t duration) = 0; -}; - -class NullDurationCollector : public IDurationCollector +struct OptimizationInfo { -public: - NullDurationCollector() = default; - void addDuration(const std::string& /* name */, int64_t /* duration */) override - { /* Do nothing */ - } + unsigned int nbVariables = 0; + unsigned int nbConstraints = 0; + unsigned int nbNonZeroCoeffs = 0; }; -class DurationCollector : public IDurationCollector +class SimulationInfoCollector { public: - DurationCollector() = default; + SimulationInfoCollector(const OptimizationInfo& optInfo) : opt_info_(optInfo){}; void toFileContent(FileContent& file_content); - void addDuration(const std::string& name, int64_t duration) override; private: - std::map> duration_items_; - - // Durations can be added in a context of multi-threading, so we need to protect - // these additions from thread concurrency - std::mutex mutex_; + const OptimizationInfo& opt_info_; }; - -} // namespace Benchmarking +} \ No newline at end of file diff --git a/src/libs/antares/array/CMakeLists.txt b/src/libs/antares/array/CMakeLists.txt index 8f9f865699..5c212269d3 100644 --- a/src/libs/antares/array/CMakeLists.txt +++ b/src/libs/antares/array/CMakeLists.txt @@ -1,12 +1,12 @@ set(SRC_MATRIX antares/array/matrix.h - antares/array/array1d.h antares/array/matrix.hxx matrix.cpp ) source_group("array" FILES ${SRC_MATRIX}) add_library(array ${SRC_MATRIX}) +add_library(Antares::array ALIAS array) target_link_libraries(array PRIVATE diff --git a/src/libs/antares/array/antares/array/array1d.h b/src/libs/antares/array/antares/array/array1d.h deleted file mode 100644 index 4c8a617e65..0000000000 --- a/src/libs/antares/array/antares/array/array1d.h +++ /dev/null @@ -1,127 +0,0 @@ -/* -** Copyright 2007-2023 RTE -** Authors: Antares_Simulator Team -** -** This file is part of Antares_Simulator. -** -** Antares_Simulator is free software: you can redistribute it and/or modify -** it under the terms of the GNU General Public License as published by -** the Free Software Foundation, either version 3 of the License, or -** (at your option) any later version. -** -** There are special exceptions to the terms and conditions of the -** license as they are applied to this software. View the full text of -** the exceptions in file COPYING.txt in the directory of this software -** distribution -** -** 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 -** GNU General Public License for more details. -** -** You should have received a copy of the GNU General Public License -** along with Antares_Simulator. If not, see . -** -** SPDX-License-Identifier: licenceRef-GPL3_WITH_RTE-Exceptions -*/ -#ifndef __ANTARES_LIBS_ARRAY_ARRAY_1D_H__ -#define __ANTARES_LIBS_ARRAY_ARRAY_1D_H__ - -/*! -** \defgroup array1d 1D-Array -** \ingroup toolbox -*/ - -/*! -** \brief Load an integer 1D array from a file -** \ingroup array1d -** -** \param filename The filename to read -** \param[out] data The data structure to fill -** \param height The size of the structure -** \return A non-zero value if the operation was successful, 0 otherwise -*/ -int Array1DLoadFromFile(const char filename[], double data[], const int height); - -/*! -** \brief Save a 1D-Array into a file -** \ingroup array1d -** -** \param filename The target filename -** \param data The array to store -** \param count The number of items in the array -** \return A non-zero value if the operation was successful, 0 otherwise -*/ -int Array1DSaveToFile(const char filename[], - const double data[], - const int count, - uint precision = 6); - -/*! -** \brief Check if all values are strictly positive -** -** \param msg The message to put in logs if an error occurs -** \param data The 1D-array -** \param count The size of the array -** \return A non-zero value if all values are strictly positive -*/ -int Array1DCheckStrictlyPositiveValues(const char msg[], const double data[], const int count); - -/*! -** \brief Check if all values are positive or null -** -** \param msg The message to put in logs if an error occurs -** \param data The 1D-array -** \param count The size of the array -** \return A non-zero value if all values are strictly positive -*/ -int Array1DCheckPositiveValues(const char msg[], const double data[], const int count); - -/*! -** \brief Check if all values are negative or null -** -** \param msg The message to put in logs if an error occurs -** \param data The 1D-array -** \param count The size of the array -** \return A non-zero value if all values are strictly positive -*/ -int Array1DCheckNegativeValues(const char msg[], const double data[], const int count); - -/*! -** \brief Check if all values are within a range -** -** \param msg The message to put in logs if an error occurs -** \param data The 1D-array -** \param count The size of the array -** \param minV The minimum value -** \param maxV The maximum value -** \return A non-zero value if all values are strictly positive -*/ -int Array1DCheckForValuesInRange(const char msg[], - const double data[], - const int count, - const double minV, - const double maxV); - -/*! -** \brief Check if all values are greater than or equal to a given number -** -** \param msg The message to put in logs if an error occurs -** \param data The 1D-array -** \param count The size of the array -** \return A non-zero value if all values are strictly positive -*/ -int Array1DCheckGreaterOrEqual(const char msg[], - const double data[], - const int count, - const double v); - -/*! -** \brief Set all values of a 1D-Array -** -** \param data The 1D-array -** \param count The size of the array -*/ -void Array1DSetValues(double data[], const int count, const double value); - -#endif /* __ANTARES_LIBS_ARRAY_ARRAY_1D_H__ */ diff --git a/src/libs/antares/array/array1d.cpp b/src/libs/antares/array/array1d.cpp deleted file mode 100644 index a2cca42dd5..0000000000 --- a/src/libs/antares/array/array1d.cpp +++ /dev/null @@ -1,317 +0,0 @@ -/* -** Copyright 2007-2023 RTE -** Authors: Antares_Simulator Team -** -** This file is part of Antares_Simulator. -** -** Antares_Simulator is free software: you can redistribute it and/or modify -** it under the terms of the GNU General Public License as published by -** the Free Software Foundation, either version 3 of the License, or -** (at your option) any later version. -** -** There are special exceptions to the terms and conditions of the -** license as they are applied to this software. View the full text of -** the exceptions in file COPYING.txt in the directory of this software -** distribution -** -** 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 -** GNU General Public License for more details. -** -** You should have received a copy of the GNU General Public License -** along with Antares_Simulator. If not, see . -** -** SPDX-License-Identifier: licenceRef-GPL3_WITH_RTE-Exceptions -*/ - -#include -#include -#include -#include -#include -#include "array1d.h" -#include "../logs.h" - -#define ARRAY_BUFFER_SIZE 1024 * 256 /* 256Ko */ - -#ifdef YUNI_OS_MSVC -#define ANTARES_MATRIX_SNPRINTF sprintf_s -#else -#define ANTARES_MATRIX_SNPRINTF snprintf -#endif - -using namespace Antares; -using namespace Yuni; - -template -static int Array1DLoadFromBuffer(const char* filename, U& data, double values[], const int height) -{ - logs.debug() << " :: loading `" << filename << "'"; - // Position - Yuni::String::Size offset = 0; - int y = 0; - uint pos; - int errorCount = 6; - // char* pend; - - while (y < height and offset < data.size()) - { - // Starting the reading of the begining of the line - pos = offset; - if ((offset = data.find('\n', offset)) != Yuni::String::npos) - { - data[offset] = '\0'; - AnyString cell(data.c_str() + pos, offset - pos); - if (!cell) - { - logs.warning() << filename << ": empty data at line " << (y + 1) << ", assuming 0"; - values[y] = 0.; - } - else - { - double v; - if (!cell.to(v)) - { - if (errorCount) - { - logs.warning() << filename << ": invalid decimal value at line " << (y + 1) - << ", assuming 0"; - if (!(--errorCount)) - logs.warning() << " ... (skipped)"; - } - values[y] = 0.; - } - else - values[y] = v; - } - /* - // Adding the value - if (data[pos] == '0' and data[pos + 1] == '\0') - { - values[y] = 0.; - } - else - { - // Convert string into double - values[y] = strtod(data.c_str() + pos, &pend); - if (!(pend and '\0' == *pend)) - { - values[y] = 0.; - if (errorCount) - { - logs.warning() << '`' << filename - << "`: Invalid format: Decimal value expected (y:" << y - << ", offset:" << (uint)pos << "byte)"; if (!(--errorCount)) logs.warning() << " ... - (skipped)"; - } - } - } - */ - - pos = ++offset; - } - - // Go to the next line - ++y; - - } // while (y ...) - - // Not enough lines to describe our matrix - if (y < height) - { - logs.warning() << filename << ": not enough rows (expected " << height << ", got " << y - << ')'; - - // Initialize missing values - while (y < height) - { - values[y] = 0.; - ++y; - } - return 0; - } - return 1; -} - -int Array1DLoadFromFile(const char* filename, double* data, const int height) -{ - assert(NULL != data); - if (NULL != filename and '\0' != *filename) - { - // Get a file descriptor - const uint64 size = IO::File::Size(filename); - - if (size) - { - IO::File::Stream file(filename); - if (file.opened()) - { - Clob buffer; - buffer.resize((String::Size)size); - - // Read the entire file - file >> buffer; - // Adding a final \n to make sure we have a line return at the end of the file - buffer += '\n'; - - // Load the data - return Array1DLoadFromBuffer(filename, buffer, data, height); - } - logs.error() << "I/O error: " << filename << ": Impossible to load the file"; - memset(data, 0, sizeof(double) * height); - } - else - { - logs.warning() << filename << ": The file should not be empty"; - memset(data, 0, sizeof(double) * height); - } - } - return 0; -} - -int Array1DSaveToFile(const char filename[], const double data[], const int count, uint precision) -{ - assert(NULL != filename); - logs.debug() << " :: writing `" << filename << "` (h:" << count << ')'; - - // Open the file for reading - IO::File::Stream file; - if (file.openRW(filename)) - { - if (count) - { - const char* format; - switch (precision) - { - // The 0 value in first - case 0: - format = "%.0f\n"; - break; - // Then 6 - case 6: - format = "%.6f\n"; - break; - // All other entry - case 1: - format = "%.1f\n"; - break; - case 2: - format = "%.2f\n"; - break; - case 3: - format = "%.3f\n"; - break; - case 4: - format = "%.4f\n"; - break; - case 5: - format = "%.5f\n"; - break; - default: - format = "%.6f\n"; - break; - } - - char buffer[128]; - for (int i = 0; i < count; ++i) - { - if (Math::Zero(data[i])) - { - file += "0\n"; - } - else - { - if (!precision or fabs(data[i] - floor(data[i])) < YUNI_EPSILON) - ANTARES_MATRIX_SNPRINTF(buffer, sizeof(buffer), "%.0f\n", data[i]); - else - ANTARES_MATRIX_SNPRINTF(buffer, sizeof(buffer), format, data[i]); - file += (const char*)buffer; - } - } - } - return 1; - } - logs.error() << "I/O error: " << filename << ": Impossible to write the file"; - return 0; -} - -int Array1DCheckStrictlyPositiveValues(const char msg[], const double data[], const int count) -{ - for (int i = 0; i < count; ++i) - { - if (data[i] <= 0.) - { - logs.error() << msg << ": At least one value is not strictly positive (at " << i << ')'; - return 0; - } - } - return 1; -} - -int Array1DCheckPositiveValues(const char msg[], const double data[], const int count) -{ - for (int i = 0; i < count; ++i) - { - if (data[i] < 0.) - { - logs.error() << msg << ": At least one value is not positive (at " << i << ')'; - return 0; - } - } - return 1; -} - -int Array1DCheckNegativeValues(const char msg[], const double data[], const int count) -{ - for (int i = 0; i < count; ++i) - { - if (data[i] > 0.) - { - logs.error() << msg << ": At least one value is not negative (at " << i << ')'; - return 0; - } - } - return 1; -} - -void Array1DSetValues(double data[], const int count, const double value) -{ - for (int i = 0; i < count; ++i) - data[i] = value; -} - -int Array1DCheckForValuesInRange(const char msg[], - const double data[], - const int count, - const double minV, - const double maxV) -{ - for (int i = 0; i < count; ++i) - { - if (data[i] < minV or data[i] > maxV) - { - logs.error() << msg << ": All values must be within the range [" << minV << ',' << maxV - << ']'; - return 0; - } - } - return 1; -} - -int Array1DCheckGreaterOrEqual(const char msg[], - const double data[], - const int count, - const double v) -{ - int i = 0; - for (; i < count; ++i) - { - if (data[i] < v) - { - logs.error() << msg << ": All values must be equal to or greater than " << v; - return 0; - } - } - return 1; -} diff --git a/src/libs/antares/benchmarking/CMakeLists.txt b/src/libs/antares/benchmarking/CMakeLists.txt index 91c30bd0c0..965272f9c5 100644 --- a/src/libs/antares/benchmarking/CMakeLists.txt +++ b/src/libs/antares/benchmarking/CMakeLists.txt @@ -1,30 +1,21 @@ set(SRC_BENCHMARKING timer.cpp - info_collectors.cpp - antares/benchmarking/file_content.h - antares/benchmarking/timer.h - antares/benchmarking/info_collectors.h + DurationCollector.cpp + include/antares/benchmarking/file_content.h + include/antares/benchmarking/timer.h + include/antares/benchmarking/DurationCollector.h file_content.cpp - ) +) source_group("misc\\benchmarking" FILES ${SRC_BENCHMARKING}) add_library(benchmarking ${SRC_BENCHMARKING} ) +add_library(Antares::benchmarking ALIAS benchmarking) target_include_directories(benchmarking PUBLIC - ${CMAKE_SOURCE_DIR}/libs #study - ${CMAKE_SOURCE_DIR}/libs/antares/date #parameters -> date - ${CMAKE_SOURCE_DIR}/libs/antares/array #links - ${CMAKE_SOURCE_DIR}/libs/antares/logs #study -> binding constraint -> matrix -> jit - ${CMAKE_SOURCE_DIR}/libs/antares/io #study -> binding constraint -> matrix - ${CMAKE_SOURCE_DIR}/libs/antares/writer #study - ${CMAKE_SOURCE_DIR}/libs/antares/exception #enum -> exception - ${CMAKE_SOURCE_DIR}/libs/antares/jit # something,something -> jit - ${CMAKE_SOURCE_DIR}/libs/antares/memory/include #study -> BC -> link -> memory - PUBLIC - ${CMAKE_CURRENT_SOURCE_DIR} + ${CMAKE_CURRENT_SOURCE_DIR}/include ) target_link_libraries(benchmarking diff --git a/src/libs/antares/benchmarking/DurationCollector.cpp b/src/libs/antares/benchmarking/DurationCollector.cpp new file mode 100644 index 0000000000..b3a4f488a9 --- /dev/null +++ b/src/libs/antares/benchmarking/DurationCollector.cpp @@ -0,0 +1,22 @@ +#include +#include +#include "antares/benchmarking/DurationCollector.h" + +namespace Benchmarking { + +void DurationCollector::addDuration(const std::string& name, int64_t duration) +{ + const std::lock_guard lock(mutex_); + duration_items_[name].push_back(duration); +} + +void DurationCollector::toFileContent(FileContent& file_content) +{ + for (const auto& [name, durations] : duration_items_) + { + const int64_t duration_sum = accumulate(durations.begin(), durations.end(), (int64_t)0); + + file_content.addDurationItem(name, (unsigned int)duration_sum, (int)durations.size()); + } +} +} // namespace Benchmarking diff --git a/src/libs/antares/benchmarking/include/antares/benchmarking/DurationCollector.h b/src/libs/antares/benchmarking/include/antares/benchmarking/DurationCollector.h new file mode 100644 index 0000000000..511cfb554e --- /dev/null +++ b/src/libs/antares/benchmarking/include/antares/benchmarking/DurationCollector.h @@ -0,0 +1,44 @@ +#pragma once + +#include +#include +#include +#include + +#include "file_content.h" + +namespace Benchmarking +{ + +class IDurationCollector +{ +public: + virtual void addDuration(const std::string& name, int64_t duration) = 0; +}; + +class NullDurationCollector : public IDurationCollector +{ +public: + NullDurationCollector() = default; + void addDuration(const std::string& /* name */, int64_t /* duration */) override + { /* Do nothing */ + } +}; + +class DurationCollector : public IDurationCollector +{ +public: + DurationCollector() = default; + + void toFileContent(FileContent& file_content); + void addDuration(const std::string& name, int64_t duration) override; + +private: + std::map> duration_items_; + + // Durations can be added in a context of multi-threading, so we need to protect + // these additions from thread concurrency + std::mutex mutex_; +}; + +} // namespace Benchmarking diff --git a/src/libs/antares/benchmarking/antares/benchmarking/file_content.h b/src/libs/antares/benchmarking/include/antares/benchmarking/file_content.h similarity index 100% rename from src/libs/antares/benchmarking/antares/benchmarking/file_content.h rename to src/libs/antares/benchmarking/include/antares/benchmarking/file_content.h diff --git a/src/libs/antares/benchmarking/antares/benchmarking/timer.h b/src/libs/antares/benchmarking/include/antares/benchmarking/timer.h similarity index 100% rename from src/libs/antares/benchmarking/antares/benchmarking/timer.h rename to src/libs/antares/benchmarking/include/antares/benchmarking/timer.h diff --git a/src/libs/antares/correlation/CMakeLists.txt b/src/libs/antares/correlation/CMakeLists.txt index ae5fd4359d..e9def03ddc 100644 --- a/src/libs/antares/correlation/CMakeLists.txt +++ b/src/libs/antares/correlation/CMakeLists.txt @@ -5,18 +5,21 @@ set(SRC_CORRELATION ) source_group("correlation" FILES ${SRC_CORRELATION}) -add_library(correlation ${SRC_CORRELATION}) +add_library(correlation + ${SRC_CORRELATION} +) +add_library(Antares::correlation ALIAS correlation) target_link_libraries(correlation PRIVATE yuni-static-core - inifile - array + Antares::inifile + Antares::array + ) target_include_directories(correlation PRIVATE - ${CMAKE_SOURCE_DIR}/libs/solver ${CMAKE_SOURCE_DIR}/libs/ #area -> antares/study/parameters/adq-patch-params.h ${CMAKE_SOURCE_DIR}/libs/antares/date #area -> antares/study/parameters/adq-patch-params.h -> date ${CMAKE_SOURCE_DIR}/libs/antares/writer #area -> antares/parts/thermal/cluster -> writer diff --git a/src/libs/antares/study/area/area.h b/src/libs/antares/study/area/area.h index 54ac507f7b..18869ea709 100644 --- a/src/libs/antares/study/area/area.h +++ b/src/libs/antares/study/area/area.h @@ -38,7 +38,6 @@ #include #include "links.h" #include "ui.h" -#include "antares/study/parameters/adq-patch-params.h" #include "constants.h" #include "antares/study/filter.h" diff --git a/src/libs/antares/study/area/list.cpp b/src/libs/antares/study/area/list.cpp index 119d82e94a..40136969d9 100644 --- a/src/libs/antares/study/area/list.cpp +++ b/src/libs/antares/study/area/list.cpp @@ -27,15 +27,11 @@ #include "../../antares.h" #include -#include #include "../study.h" #include #include "area.h" -#include #include #include -#include "../../config.h" -#include "../filter.h" #include "constants.h" #include "antares/study/parts/parts.h" #include "antares/study/parts/load/prepro.h" diff --git a/src/libs/antares/study/fwd.h b/src/libs/antares/study/fwd.h index bef7efce24..85a08863a1 100644 --- a/src/libs/antares/study/fwd.h +++ b/src/libs/antares/study/fwd.h @@ -539,19 +539,15 @@ mpsExportStatus stringToMPSexportStatus(const AnyString& value); } // namespace Data } // namespace Antares -namespace Antares -{ -namespace Data -{ -namespace ScenarioBuilder +namespace Antares::Data::ScenarioBuilder { class Rules; class TSNumberRules; class Sets; -} // namespace ScenarioBuilder -} // namespace Data -} // namespace Antares +} // namespace Antares::Data::ScenarioBuilder + + namespace Benchmarking { diff --git a/src/libs/antares/study/load.cpp b/src/libs/antares/study/load.cpp index 503fff0a04..35b9fca6c5 100644 --- a/src/libs/antares/study/load.cpp +++ b/src/libs/antares/study/load.cpp @@ -27,7 +27,7 @@ #include #include "study.h" #include "version.h" -#include +#include #include "scenario-builder/sets.h" #include "ui-runtimeinfos.h" diff --git a/src/libs/antares/study/parts/hydro/container.cpp b/src/libs/antares/study/parts/hydro/container.cpp index d8657a65fb..c7705b0ae0 100644 --- a/src/libs/antares/study/parts/hydro/container.cpp +++ b/src/libs/antares/study/parts/hydro/container.cpp @@ -29,8 +29,6 @@ #include "container.h" #include #include "datatransfer.h" -#include - using namespace Antares; using namespace Yuni; diff --git a/src/libs/antares/study/parts/hydro/prepro.cpp b/src/libs/antares/study/parts/hydro/prepro.cpp index 6e272b71b7..053ac05a2a 100644 --- a/src/libs/antares/study/parts/hydro/prepro.cpp +++ b/src/libs/antares/study/parts/hydro/prepro.cpp @@ -31,7 +31,6 @@ #include "../../study.h" #include "prepro.h" #include -#include #include using namespace Antares; diff --git a/src/libs/antares/study/parts/thermal/ecoInput.cpp b/src/libs/antares/study/parts/thermal/ecoInput.cpp index 9c868cfb26..8241f07b77 100644 --- a/src/libs/antares/study/parts/thermal/ecoInput.cpp +++ b/src/libs/antares/study/parts/thermal/ecoInput.cpp @@ -32,7 +32,6 @@ #include "../../study.h" #include "ecoInput.h" #include -#include using namespace Yuni; diff --git a/src/libs/antares/study/parts/thermal/prepro.cpp b/src/libs/antares/study/parts/thermal/prepro.cpp index 090de14a57..d4cb3b654b 100644 --- a/src/libs/antares/study/parts/thermal/prepro.cpp +++ b/src/libs/antares/study/parts/thermal/prepro.cpp @@ -32,7 +32,6 @@ #include "../../study.h" #include "prepro.h" #include -#include using namespace Yuni; diff --git a/src/libs/antares/study/save.cpp b/src/libs/antares/study/save.cpp index 6e3e03cb6a..f8dea51ebd 100644 --- a/src/libs/antares/study/save.cpp +++ b/src/libs/antares/study/save.cpp @@ -26,7 +26,7 @@ */ #include "study.h" -#include +#include #include "scenario-builder/sets.h" #include #include diff --git a/src/libs/antares/study/study.h b/src/libs/antares/study/study.h index b384e4294a..e442b8c1f4 100644 --- a/src/libs/antares/study/study.h +++ b/src/libs/antares/study/study.h @@ -56,9 +56,7 @@ #include -namespace Antares -{ -namespace Data +namespace Antares::Data { /*! ** \brief Antares Study @@ -721,8 +719,8 @@ YString StudyCreateOutputPath(StudyMode mode, const YString& folder, const YString& label, Yuni::sint64 startTime); -} // namespace Data -} // namespace Antares +} // namespace Antares::Data + #include "study.hxx" #include "runtime.h" diff --git a/src/libs/antares/study/version.cpp b/src/libs/antares/study/version.cpp index 86b32779aa..3bdda2ebfb 100644 --- a/src/libs/antares/study/version.cpp +++ b/src/libs/antares/study/version.cpp @@ -44,9 +44,7 @@ enum YUNI_STATIC_ASSERT((uint)versionFromCMake == (uint)Antares::Data::versionLatest, DiscrepancyBetweenCMakeVersionAndAntaresVersion); -namespace Antares -{ -namespace Data +namespace Antares::Data { static inline Version StudyFormatCheck(const String& headerFile) @@ -209,5 +207,5 @@ Version StudyTryToFindTheVersion(const AnyString& folder) bool StudyVersion::isStudyLatestVersion(std::string studyFolder) const { return StudyTryToFindTheVersion(studyFolder) == versionLatest; } -} // namespace Data -} // namespace Antares +} // namespace Antares::Data + diff --git a/src/libs/antares/study/version.h b/src/libs/antares/study/version.h index a56d002a36..c00210bef5 100644 --- a/src/libs/antares/study/version.h +++ b/src/libs/antares/study/version.h @@ -29,9 +29,7 @@ #include -namespace Antares -{ -namespace Data +namespace Antares::Data { /*! ** \brief Version of a study @@ -110,7 +108,7 @@ class StudyVersion { public: [[nodiscard]] bool isStudyLatestVersion(std::string studyFolder) const; }; -} // namespace Data -} // namespace Antares +} // namespace Antares::Data + #endif // __ANTARES_LIBS_STUDY_VERSION_H__ diff --git a/src/libs/antares/writer/CMakeLists.txt b/src/libs/antares/writer/CMakeLists.txt index 6895ef5590..f3ecc9076a 100644 --- a/src/libs/antares/writer/CMakeLists.txt +++ b/src/libs/antares/writer/CMakeLists.txt @@ -29,11 +29,11 @@ target_include_directories(result_writer target_link_libraries(result_writer PRIVATE + Antares::benchmarking yuni-static-core MINIZIP::minizip logs inifile - benchmarking io ) diff --git a/src/libs/antares/writer/antares/writer/writer_factory.h b/src/libs/antares/writer/antares/writer/writer_factory.h index 50e414e89b..2d728d7766 100644 --- a/src/libs/antares/writer/antares/writer/writer_factory.h +++ b/src/libs/antares/writer/antares/writer/writer_factory.h @@ -5,7 +5,7 @@ #include "i_writer.h" #include "result_format.h" -#include +#include namespace Antares::Solver { diff --git a/src/libs/antares/writer/private/zip_writer.h b/src/libs/antares/writer/private/zip_writer.h index cadc031625..cc4c06ce92 100644 --- a/src/libs/antares/writer/private/zip_writer.h +++ b/src/libs/antares/writer/private/zip_writer.h @@ -8,7 +8,7 @@ #include #include "antares/writer/i_writer.h" -#include +#include namespace Antares::Solver diff --git a/src/libs/antares/writer/writer_factory.cpp b/src/libs/antares/writer/writer_factory.cpp index 66ed04d6de..568c9ff87c 100644 --- a/src/libs/antares/writer/writer_factory.cpp +++ b/src/libs/antares/writer/writer_factory.cpp @@ -2,9 +2,7 @@ #include "private/immediate_file_writer.h" #include "private/zip_writer.h" -namespace Antares -{ -namespace Solver +namespace Antares::Solver { IResultWriter::Ptr resultWriterFactory(Antares::Data::ResultFormat fmt, const YString& folderOutput, @@ -21,5 +19,5 @@ IResultWriter::Ptr resultWriterFactory(Antares::Data::ResultFormat fmt, return std::make_shared(folderOutput.c_str()); } } -} // namespace Solver -} // namespace Antares +} // namespace Antares::Solver + diff --git a/src/libs/antares/writer/zip_writer.cpp b/src/libs/antares/writer/zip_writer.cpp index 014698b1ff..0b158b5b1a 100644 --- a/src/libs/antares/writer/zip_writer.cpp +++ b/src/libs/antares/writer/zip_writer.cpp @@ -2,7 +2,9 @@ #include // Yuni::IO::File::LoadFromFile #include "private/zip_writer.h" +#include "antares/logs/logs.h" #include +#include extern "C" { diff --git a/src/solver/CMakeLists.txt b/src/solver/CMakeLists.txt index 14ffd0d705..acf97067ae 100644 --- a/src/solver/CMakeLists.txt +++ b/src/solver/CMakeLists.txt @@ -94,9 +94,10 @@ set(ANTARES_SOLVER_LIBS ${ANTARES_SOLVER_LIBS} target_link_libraries(antares-solver PRIVATE ${ANTARES_SOLVER_LIBS} - benchmarking + Antares::benchmarking result_writer Antares::sys + Antares::infoCollection ) target_include_directories(antares-solver diff --git a/src/solver/application.cpp b/src/solver/application.cpp index db66217c71..2685a31c6e 100644 --- a/src/solver/application.cpp +++ b/src/solver/application.cpp @@ -18,6 +18,7 @@ #include "utils/ortools_utils.h" #include "../config.h" +#include #include #include @@ -39,9 +40,7 @@ void printSolvers() } } // namespace -namespace Antares -{ -namespace Solver +namespace Antares::Solver { Application::Application() { @@ -460,5 +459,5 @@ Application::~Application() LocalPolicy::Close(); } } -} // namespace Solver -} // namespace Antares +} // namespace Antares::Solver + diff --git a/src/solver/application.h b/src/solver/application.h index 40caaff1a9..c436db36f6 100644 --- a/src/solver/application.h +++ b/src/solver/application.h @@ -3,17 +3,16 @@ #include "misc/options.h" #include #include -#include +#include #include #include "simulation/simulation.h" +#include "antares/infoCollection/StudyInfoCollector.h" #include #include -namespace Antares -{ -namespace Solver +namespace Antares::Solver { class Application : public Yuni::IEventObserver { @@ -96,5 +95,5 @@ class Application : public Yuni::IEventObserver +#include #include namespace Antares diff --git a/src/solver/main/economy.cpp b/src/solver/main/economy.cpp index 3bc27c90b8..23c638d087 100644 --- a/src/solver/main/economy.cpp +++ b/src/solver/main/economy.cpp @@ -28,7 +28,7 @@ #include "../application.h" #include "../simulation/solver.h" #include "../simulation/economy.h" -#include +#include #include namespace Antares diff --git a/src/solver/simulation/CMakeLists.txt b/src/solver/simulation/CMakeLists.txt index d2bb729670..304e69059b 100644 --- a/src/solver/simulation/CMakeLists.txt +++ b/src/solver/simulation/CMakeLists.txt @@ -47,10 +47,6 @@ set(SRC_SIMULATION BindingConstraintsTimeSeriesNumbersWriter.h) source_group("simulation" FILES ${SRC_SIMULATION}) - - - - # # --- Library VARIABLES --- # @@ -60,4 +56,7 @@ add_library(libantares-solver-simulation target_include_directories(libantares-solver-simulation PUBLIC ${CMAKE_SOURCE_DIR}/solver/simulation) -target_link_libraries(libantares-solver-simulation PRIVATE libantares-core) +target_link_libraries(libantares-solver-simulation PRIVATE + libantares-core + Antares::infoCollection +) diff --git a/src/solver/simulation/adequacy.h b/src/solver/simulation/adequacy.h index 84672bca87..cf53193aad 100644 --- a/src/solver/simulation/adequacy.h +++ b/src/solver/simulation/adequacy.h @@ -34,6 +34,7 @@ #include "common-eco-adq.h" #include "solver.h" // for definition of type yearRandomNumbers +#include "antares/infoCollection/StudyInfoCollector.h" namespace Antares::Solver::Simulation { diff --git a/src/solver/simulation/economy.h b/src/solver/simulation/economy.h index cd597f5cab..421b961524 100644 --- a/src/solver/simulation/economy.h +++ b/src/solver/simulation/economy.h @@ -35,6 +35,7 @@ #include "base_post_process.h" #include "solver.h" // for definition of type yearRandomNumbers +#include "antares/infoCollection/StudyInfoCollector.h" namespace Antares::Solver::Simulation { diff --git a/src/solver/simulation/solver.h b/src/solver/simulation/solver.h index 6f36321171..baa975d3dd 100644 --- a/src/solver/simulation/solver.h +++ b/src/solver/simulation/solver.h @@ -30,7 +30,7 @@ #include #include #include // PowerFluctuations -#include +#include #include #include diff --git a/src/solver/ts-generator/hydro.cpp b/src/solver/ts-generator/hydro.cpp index 174a0f38c4..cb458bb4ad 100644 --- a/src/solver/ts-generator/hydro.cpp +++ b/src/solver/ts-generator/hydro.cpp @@ -28,7 +28,7 @@ #include #include "../simulation/sim_extern_variables_globales.h" #include "../aleatoire/alea_fonctions.h" -#include +#include #include #include #include "../misc/cholesky.h" diff --git a/src/tests/end-to-end/utils/CMakeLists.txt b/src/tests/end-to-end/utils/CMakeLists.txt index 3e8cf560e2..e15182d04d 100644 --- a/src/tests/end-to-end/utils/CMakeLists.txt +++ b/src/tests/end-to-end/utils/CMakeLists.txt @@ -9,6 +9,7 @@ target_link_libraries(test_utils libantares-solver-simulation PUBLIC ${Boost_UNIT_TEST_FRAMEWORK_LIBRARY} + Antares::infoCollection ) target_include_directories(test_utils diff --git a/src/tools/yby-aggregator/CMakeLists.txt b/src/tools/yby-aggregator/CMakeLists.txt index b83ceb82de..7784a75ed9 100644 --- a/src/tools/yby-aggregator/CMakeLists.txt +++ b/src/tools/yby-aggregator/CMakeLists.txt @@ -48,7 +48,6 @@ INSTALL(EXPORT antares-ybyaggregator set(YBY_AGGREGATOR_LIBS libantares-core - Antares::date Antares::logs yuni-static-core Antares::sys diff --git a/src/ui/simulator/CMakeLists.txt b/src/ui/simulator/CMakeLists.txt index 4aad2a34d8..fef536e46e 100644 --- a/src/ui/simulator/CMakeLists.txt +++ b/src/ui/simulator/CMakeLists.txt @@ -146,10 +146,10 @@ set(ANTARES_LIBS libantares-solver-constraints-builder libantares-solver-variable-info libantares-core - date yuni-static-core yuni-static-uuid libmodel_antares + Antares::date ) target_link_libraries(${execname}