diff --git a/.github/workflows/install-cmake-328/action.yml b/.github/workflows/install-cmake-328/action.yml
index a6f111746c..1cf045dbee 100644
--- a/.github/workflows/install-cmake-328/action.yml
+++ b/.github/workflows/install-cmake-328/action.yml
@@ -1,4 +1,4 @@
-name: "Install cmake 3.28 using devtoolset 10"
+name: "Install cmake 3.28 using devtoolset 10 if possible"
description: "Download and install system wide cmake 3.28"
runs:
@@ -7,7 +7,7 @@ runs:
- name: Build cmake
shell: bash
run: |
- source /opt/rh/devtoolset-10/enable
+ source /opt/rh/devtoolset-10/enable || true # Ignore error if devtoolset-10 is not available
yum -y install openssl-devel
wget https://github.com/Kitware/CMake/releases/download/v3.28.2/cmake-3.28.2.tar.gz
tar -xvf cmake-3.28.2.tar.gz
diff --git a/.github/workflows/sonarcloud.yml b/.github/workflows/sonarcloud.yml
index cfe5324d3c..e72287894d 100644
--- a/.github/workflows/sonarcloud.yml
+++ b/.github/workflows/sonarcloud.yml
@@ -1,6 +1,9 @@
name: SonarCloud
on:
+ push:
+ branches:
+ - develop
pull_request:
jobs:
diff --git a/.github/workflows/ubuntu.yml b/.github/workflows/ubuntu.yml
index 85713eeb70..88fc65ceac 100644
--- a/.github/workflows/ubuntu.yml
+++ b/.github/workflows/ubuntu.yml
@@ -29,7 +29,6 @@ env:
RUN_EXTENDED_TESTS: ${{ github.event_name == 'schedule' || inputs.run-tests == 'true' }}
REF: ${{ inputs.target_branch =='' && github.ref || inputs.target_branch}}
VCPKG_ROOT: ${{ github.workspace }}/vcpkg
- vcpkgPackages: yaml-cpp antlr4 boost-test
triplet: x64-linux
WX_CONFIG: /usr/bin/wx-config
@@ -115,6 +114,24 @@ jobs:
run: |
cmake --build _build -j$(nproc)
+ - name: Run API tests
+ run: |
+ cmake --install _build --prefix antares_install
+ cd src/api_client_example
+ cmake -B _build -S . \
+ -DCMAKE_C_COMPILER_LAUNCHER=ccache \
+ -DCMAKE_C_COMPILER=/usr/bin/gcc-10 \
+ -DCMAKE_CXX_COMPILER_LAUNCHER=ccache \
+ -DCMAKE_CXX_COMPILER=/usr/bin/g++-10 \
+ -DCMAKE_BUILD_TYPE=Release \
+ -DBUILD_TESTING=ON \
+ -DCMAKE_TOOLCHAIN_FILE=${{github.workspace}}/vcpkg/scripts/buildsystems/vcpkg.cmake \
+ -DVCPKG_TARGET_TRIPLET=x64-linux-release \
+ -DCMAKE_PREFIX_PATH="${{github.workspace}}/rte-antares-deps-Release;${{github.workspace}}/install;${{ env.ORTOOLS_DIR }}/install;${{github.workspace}}/antares_install;${{github.workspace}}/rte-antares-deps-Release;${{github.workspace}}/_build/vcpkg_installed/x64-linux-release"
+ cmake --build _build -j$(nproc)
+ cd _build
+ ctest -C Release --output-on-failure
+
# simtest
- name: Read simtest version
id: simtest-version
diff --git a/docs/Architecture_Decision_Records/Expose_cpp_API.md b/docs/Architecture_Decision_Records/Expose_cpp_API.md
index bae68cd5b4..fcc11c8a93 100644
--- a/docs/Architecture_Decision_Records/Expose_cpp_API.md
+++ b/docs/Architecture_Decision_Records/Expose_cpp_API.md
@@ -4,11 +4,11 @@
## Context
-Some clients (e.g. Xpansion) would prefer to use a library than a CLI tool. Exposing a library require exposing a public API.
-The API can be exposed either as pure C or as C++.
-A C API can always be developped as a facade on top of a C++ API.
-C++ API will not have to care about ABI compatibility because Simulator lib will be provided as static, meaning a client
-upgrading would need to be recompiled and relink with the new lib version.
+Several clients, such as Xpansion, express a preference for utilizing a library over a command-line interface (CLI) tool. Exposing a library necessitates the exposure of a public API.
+
+This API can be presented in either pure C or C++. It's worth noting that a C API can always serve as a facade atop a C++ API.
+
+In the case of a C++ API, concerns regarding ABI compatibility are alleviated, as the Simulator library is provided in a static form. Consequently, when a client upgrades, they would simply need to recompile and relink with the new version of the library.
## Decision
diff --git a/docs/Architecture_Decision_Records/separate_install_exe_api.md b/docs/Architecture_Decision_Records/separate_install_exe_api.md
new file mode 100644
index 0000000000..3a9662ec1d
--- /dev/null
+++ b/docs/Architecture_Decision_Records/separate_install_exe_api.md
@@ -0,0 +1,25 @@
+# Expose public C++ API
+
+## Status: Rejected [2024/04/11]
+
+## Context
+
+Originally, there exists a single install target designated to deploy the diverse Antares executables, predominantly packaged within the release assets. However, there's a rationale behind avoiding the creation of a unified package containing both executables and libraries, given that they cater to distinct user demographics. This mirrors the flexibility offered by package managers such as apt, where users can opt to install binary packages and separate development (devel) packages according to their requirements.
+
+## Decision
+
+Split installation into two targets
+
+Produce different assets/packages for each install targets.
+
+
+## Consequences
+
+* Mutltiplication of assets
+* Two install targets to manage
+* Users of executable not "polluted" by libraries
+
+## Reason for rejection
+
+The decision was rejected because it was deemed unnecessary to split the installation targets. It adds
+some difficulties for few benefits at the moment
\ No newline at end of file
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 862c7fdbc8..44715f0650 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -233,7 +233,7 @@ message(STATUS "OR-Tools tag ${ORTOOLS_TAG}")
FetchContent_MakeAvailable(ortools)
endif()
-find_package(minizip-ng)
+find_package(minizip-ng QUIET)
if (minizip-ng_FOUND)
add_library(MINIZIP::minizip ALIAS MINIZIP::minizip-ng)
else ()
@@ -267,6 +267,7 @@ add_subdirectory("ext/yuni/src")
OMESSAGE("") # empty line
# Sub Directories
+add_subdirectory(api)
add_subdirectory(libs) #antares-core fswalker
if(BUILD_UI)
diff --git a/src/api/API.cpp b/src/api/API.cpp
new file mode 100644
index 0000000000..38e9778eab
--- /dev/null
+++ b/src/api/API.cpp
@@ -0,0 +1,116 @@
+/*
+ * 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 .
+ */
+
+#include "API.h"
+#include "antares/solver/simulation/economy_mode.h"
+#include "antares/solver/simulation/adequacy_mode.h"
+#include "antares/solver/misc/options.h"
+#include "antares/infoCollection/StudyInfoCollector.h"
+#include "antares/benchmarking/DurationCollector.h"
+#include "antares/exception/LoadingError.hpp"
+#include
+#include
+
+namespace Antares::API
+{
+SimulationResults APIInternal::run(const IStudyLoader& study_loader)
+{
+ try {
+ study_ = study_loader.load();
+ } catch (const ::Antares::Error::StudyFolderDoesNotExist& e) {
+ Antares::API::Error err{.reason = e.what()};
+ return {
+ .simulationPath = "",
+ .antares_problems = {},
+ .error = err
+ };
+ }
+ return execute();
+}
+
+/**
+ * @brief The execute method is used to execute the simulation.
+ * @return SimulationResults object which contains the results of the simulation.
+ *
+ * This method is initialy a copy of Application::execute with some modifications hence the apparent dupllication
+ */
+SimulationResults APIInternal::execute() const
+{
+ // study_ == nullptr e.g when the -h flag is given
+ if (!study_)
+ {
+ using namespace std::string_literals;
+ Antares::API::Error err{.reason = "Couldn't create study"s};
+ return {.simulationPath{}, .antares_problems{}, .error = err};
+ }
+
+ study_->computePThetaInfForThermalClusters();
+
+ // Only those two fields are used un simulation
+ Settings settings;
+ settings.tsGeneratorsOnly = false;
+ settings.noOutput = false;
+
+ Benchmarking::DurationCollector durationCollector;
+ Benchmarking::OptimizationInfo optimizationInfo;
+ auto ioQueueService = std::make_shared();
+ ioQueueService->maximumThreadCount(1);
+ ioQueueService->start();
+ auto resultWriter = Solver::resultWriterFactory(
+ study_->parameters.resultFormat, study_->folderOutput, ioQueueService, durationCollector);
+ SimulationObserver simulationObserver;
+ // Run the simulation
+ switch (study_->runtime->mode)
+ {
+ case Data::SimulationMode::Economy:
+ case Data::SimulationMode::Expansion:
+ Solver::runSimulationInEconomicMode(*study_,
+ settings,
+ durationCollector,
+ *resultWriter,
+ optimizationInfo,
+ simulationObserver);
+ break;
+ case Data::SimulationMode::Adequacy:
+ Solver::runSimulationInAdequacyMode(*study_,
+ settings,
+ durationCollector,
+ *resultWriter,
+ optimizationInfo,
+ simulationObserver);
+ break;
+ default:
+ break;
+ }
+
+ // Importing Time-Series if asked
+ study_->importTimeseriesIntoInput();
+
+ // Stop the display of the progression
+ study_->progression.stop();
+ return
+ {
+ .simulationPath = study_->folderOutput.c_str(),
+ .antares_problems = simulationObserver.acquireLps(),
+ .error{}
+ };
+}
+} // namespace Antares::API
\ No newline at end of file
diff --git a/src/api/CMakeLists.txt b/src/api/CMakeLists.txt
new file mode 100644
index 0000000000..109c640578
--- /dev/null
+++ b/src/api/CMakeLists.txt
@@ -0,0 +1,42 @@
+add_library(solver_api)
+add_library(Antares::solver_api ALIAS solver_api)
+
+set(PUBLIC_HEADERS
+ include/antares/api/SimulationResults.h
+ include/antares/api/solver.h
+)
+
+set(PRIVATE_HEADERS
+ private/API.h
+ private/SimulationObserver.h
+)
+
+target_sources(solver_api
+ PRIVATE
+ solver.cpp
+ API.cpp
+ SimulationObserver.cpp
+ SimulationResults.cpp
+ ${PUBLIC_HEADERS}
+ ${PRIVATE_HEADERS}
+)
+
+target_include_directories(solver_api
+ PUBLIC
+ $
+ PRIVATE
+ $
+)
+
+target_link_libraries(solver_api
+ PRIVATE
+ Antares::study
+ Antares::study-loader
+ Antares::file-tree-study-loader
+ antares-solver-simulation
+ PUBLIC
+ Antares::lps
+)
+install(DIRECTORY include/antares
+ DESTINATION "include"
+)
\ No newline at end of file
diff --git a/src/api/SimulationObserver.cpp b/src/api/SimulationObserver.cpp
new file mode 100644
index 0000000000..7842ce8099
--- /dev/null
+++ b/src/api/SimulationObserver.cpp
@@ -0,0 +1,73 @@
+
+/*
+ * 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 .
+ */
+
+#include "SimulationObserver.h"
+
+#include "antares/solver/optimisation/HebdoProblemToLpsTranslator.h"
+
+namespace Antares::API
+{
+namespace
+{
+auto translate(const PROBLEME_HEBDO& problemeHebdo,
+ std::string_view name,
+ const Solver::HebdoProblemToLpsTranslator& translator,
+ const unsigned int year,
+ const unsigned int week)
+{
+ auto weekly_data = translator.translate(problemeHebdo.ProblemeAResoudre.get(), name);
+ Solver::ConstantDataFromAntares common_data;
+ if (year == 1 && week == 1)
+ {
+ common_data = translator.commonProblemData(problemeHebdo.ProblemeAResoudre.get());
+ }
+ return std::make_pair(common_data, weekly_data);
+}
+} // namespace
+
+void SimulationObserver::notifyHebdoProblem(const PROBLEME_HEBDO& problemeHebdo,
+ int optimizationNumber,
+ std::string_view name)
+{
+ if (optimizationNumber != 1)
+ {
+ return; // We only care about first optimization
+ }
+ Solver::HebdoProblemToLpsTranslator translator;
+ const unsigned int year = problemeHebdo.year + 1;
+ const unsigned int week = problemeHebdo.weekInTheYear + 1;
+ // common_data and weekly_data computed before the mutex lock to prevent blocking the thread
+ auto [common_data, weekly_data] = translate(problemeHebdo, name, translator, year, week);
+ std::lock_guard lock(mutex_);
+ if (year == 1 && week == 1)
+ {
+ lps_.setConstantData(common_data);
+ }
+ lps_.addWeeklyData({year, week}, weekly_data);
+}
+
+Solver::LpsFromAntares&& SimulationObserver::acquireLps() noexcept
+{
+ std::lock_guard lock(mutex_);
+ return std::move(lps_);
+}
+} // namespace Antares::API
diff --git a/src/api/SimulationResults.cpp b/src/api/SimulationResults.cpp
new file mode 100644
index 0000000000..63c5127a49
--- /dev/null
+++ b/src/api/SimulationResults.cpp
@@ -0,0 +1,22 @@
+/*
+ * 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 .
+ */
+
+#include "antares/api/SimulationResults.h"
diff --git a/src/api/include/antares/api/SimulationResults.h b/src/api/include/antares/api/SimulationResults.h
new file mode 100644
index 0000000000..5a5e93982a
--- /dev/null
+++ b/src/api/include/antares/api/SimulationResults.h
@@ -0,0 +1,62 @@
+/*
+ * 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 .
+ */
+
+#pragma once
+#include
+#include
+#include
+#include "antares/solver/lps/LpsFromAntares.h"
+
+namespace Antares::API
+{
+/**
+ * @struct Error
+ * @brief The Error structure is used to represent an error that occurred during the simulation.
+ */
+struct Error {
+ /**
+ * @brief The reason for the error.
+ */
+ std::string reason;
+};
+
+/**
+ * @struct SimulationResults
+ * @brief The SimulationResults structure is used to represent the results of a simulation.
+ * @details It contains the path to the simulation, weekly problems, and an optional error.
+ */
+struct [[nodiscard("Contains results and potential error")]] SimulationResults
+{
+ /**
+ * @brief The path to the simulation (output).
+ */
+ std::filesystem::path simulationPath;
+ /**
+ * @brief weekly problems
+ */
+ Antares::Solver::LpsFromAntares antares_problems;
+ /**
+ * @brief An optional error that occurred during the simulation.
+ */
+ std::optional error;
+};
+
+}
\ No newline at end of file
diff --git a/src/api/include/antares/api/solver.h b/src/api/include/antares/api/solver.h
new file mode 100644
index 0000000000..d016a9a08a
--- /dev/null
+++ b/src/api/include/antares/api/solver.h
@@ -0,0 +1,35 @@
+
+/*
+ * 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 .
+ */
+
+#pragma once
+#include "SimulationResults.h"
+
+namespace Antares::API
+{
+/**
+ * @brief The PerformSimulation function is used to perform a simulation.
+ * @param study_path The path to the study to be simulated.
+ * @return SimulationResults object which contains the results of the simulation.
+ * @exception noexcept This function does not throw exceptions.
+ */
+SimulationResults PerformSimulation(const std::filesystem::path& study_path) noexcept;
+} // namespace Antares::API
diff --git a/src/api/private/API.h b/src/api/private/API.h
new file mode 100644
index 0000000000..91f8a4e2d3
--- /dev/null
+++ b/src/api/private/API.h
@@ -0,0 +1,56 @@
+/*
+ * 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 .
+ */
+
+#pragma once
+#include
+
+#include
+#include "antares/api/SimulationResults.h"
+
+namespace Antares::Data
+{
+class Study;
+}
+
+namespace Antares::API
+{
+
+/**
+ * @class APIInternal
+ * @brief The APIInternal class is used to run simulations.
+ */
+class APIInternal
+{
+public:
+ /**
+ * @brief The run method is used to run the simulation.
+ * @param study_loader A pointer to an IStudyLoader object. The IStudyLoader object is used to
+ * load the study that will be simulated.
+ * @return SimulationResults object which contains the results of the simulation.
+ */
+ SimulationResults run(const IStudyLoader& study_loader);
+
+private:
+ std::shared_ptr study_;
+ SimulationResults execute() const;
+};
+
+} // namespace Antares::API
diff --git a/src/api/private/SimulationObserver.h b/src/api/private/SimulationObserver.h
new file mode 100644
index 0000000000..f2d78fc4eb
--- /dev/null
+++ b/src/api/private/SimulationObserver.h
@@ -0,0 +1,61 @@
+/*
+ * 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 .
+ */
+
+#pragma once
+#include
+#include
+
+namespace Antares::API
+{
+
+/**
+ * @class SimulationObserver
+ * @brief The SimulationObserver class is used to observe the simulation.
+ * @details It inherits from the ISimulationObserver interface and overrides the notifyHebdoProblem
+ * method.
+ */
+class SimulationObserver: public Solver::Simulation::ISimulationObserver
+{
+public:
+ /**
+ * @brief Used to notify of a solver HEBDO_PROBLEM.
+ * HEBDO_PROBLEM is assumed to be properly constructed and valid in order to build
+ * LpsFromAntares properly
+ * @param problemeHebdo A pointer to a PROBLEME_HEBDO object representing the problem.
+ * @param optimizationNumber The number of the optimization.
+ * @param name The name of the problem.
+ */
+ void notifyHebdoProblem(const PROBLEME_HEBDO& problemeHebdo,
+ int optimizationNumber,
+ std::string_view name) override;
+
+ /**
+ * @brief The acquireLps method is used to take ownership of Antares problems.
+ * @return An LpsFromAntares object containing the linear programming problems.
+ */
+ Solver::LpsFromAntares&& acquireLps() noexcept;
+
+private:
+ Solver::LpsFromAntares lps_;
+ std::mutex mutex_;
+};
+
+} // namespace Antares::API
diff --git a/src/api/solver.cpp b/src/api/solver.cpp
new file mode 100644
index 0000000000..6e2f7068ea
--- /dev/null
+++ b/src/api/solver.cpp
@@ -0,0 +1,46 @@
+/*
+ * 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 .
+ */
+
+#include
+#include "antares/file-tree-study-loader/FileTreeStudyLoader.h"
+#include "antares/study-loader/IStudyLoader.h"
+
+#include "private/API.h"
+
+namespace Antares::API
+{
+
+SimulationResults PerformSimulation(const std::filesystem::path& study_path) noexcept
+{
+ try
+ {
+ APIInternal api;
+ FileTreeStudyLoader study_loader(study_path);
+ return api.run(study_loader);
+ }
+ catch (const std::exception& e)
+ {
+ Antares::API::Error err{.reason = e.what()};
+ return SimulationResults{.simulationPath = study_path, .antares_problems{}, .error = err};
+ }
+}
+
+} // namespace Antares::API
diff --git a/src/api_client_example/CMakeLists.txt b/src/api_client_example/CMakeLists.txt
new file mode 100644
index 0000000000..570ee9341b
--- /dev/null
+++ b/src/api_client_example/CMakeLists.txt
@@ -0,0 +1,12 @@
+cmake_minimum_required(VERSION 3.5)
+
+PROJECT(API_client)
+
+set(CMAKE_CXX_STANDARD 20)
+
+add_subdirectory(src)
+
+include(CTest)
+if (BUILD_TESTING)
+ add_subdirectory(tests)
+endif ()
\ No newline at end of file
diff --git a/src/api_client_example/README.md b/src/api_client_example/README.md
new file mode 100644
index 0000000000..151b1d346b
--- /dev/null
+++ b/src/api_client_example/README.md
@@ -0,0 +1,3 @@
+Client for antares solver API
+
+To demonstrate as much capabilities as possible this client should stay stand alone this mean not added as a sub_directory for cmake
diff --git a/src/api_client_example/src/API_client.cpp b/src/api_client_example/src/API_client.cpp
new file mode 100644
index 0000000000..6489806c51
--- /dev/null
+++ b/src/api_client_example/src/API_client.cpp
@@ -0,0 +1,30 @@
+/*
+ * 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 .
+ */
+
+
+#include "API_client.h"
+
+#include
+
+Antares::API::SimulationResults solve(std::filesystem::path study_path) {
+ return Antares::API::PerformSimulation(std::move(study_path));
+}
+
diff --git a/src/api_client_example/src/API_client.h b/src/api_client_example/src/API_client.h
new file mode 100644
index 0000000000..5d8500649e
--- /dev/null
+++ b/src/api_client_example/src/API_client.h
@@ -0,0 +1,28 @@
+
+/*
+ * 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 .
+ */
+
+#pragma once
+
+#include
+#include
+
+Antares::API::SimulationResults solve(std::filesystem::path study_path);
diff --git a/src/api_client_example/src/CMakeLists.txt b/src/api_client_example/src/CMakeLists.txt
new file mode 100644
index 0000000000..55ebb33579
--- /dev/null
+++ b/src/api_client_example/src/CMakeLists.txt
@@ -0,0 +1,14 @@
+add_library(API_client)
+
+target_sources(API_client
+ PRIVATE
+ API_client.cpp
+ API_client.h
+)
+
+find_package(Antares REQUIRED)
+target_link_libraries(API_client PUBLIC Antares::solver_api)
+target_include_directories(API_client
+ PUBLIC
+ $
+)
\ No newline at end of file
diff --git a/src/api_client_example/tests/CMakeLists.txt b/src/api_client_example/tests/CMakeLists.txt
new file mode 100644
index 0000000000..1fc9c3cc89
--- /dev/null
+++ b/src/api_client_example/tests/CMakeLists.txt
@@ -0,0 +1,17 @@
+find_package(Boost COMPONENTS unit_test_framework REQUIRED)
+
+add_executable(test_client)
+
+target_sources(test_client
+ PRIVATE
+ test.cpp
+)
+
+target_link_libraries(test_client
+ PRIVATE
+ API_client
+ Boost::unit_test_framework
+)
+
+add_test(NAME testclient COMMAND test_client)
+set_property(TEST testclient PROPERTY LABELS integ)
\ No newline at end of file
diff --git a/src/api_client_example/tests/test.cpp b/src/api_client_example/tests/test.cpp
new file mode 100644
index 0000000000..4adee7bfd6
--- /dev/null
+++ b/src/api_client_example/tests/test.cpp
@@ -0,0 +1,37 @@
+/*
+ * 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 .
+ */
+
+#define BOOST_TEST_MODULE test_client_api
+
+#include
+#include "API_client.h"
+
+BOOST_AUTO_TEST_CASE(test_run) {
+ auto results = solve("dummy_study_test_client_api");
+ BOOST_CHECK(results.error);
+ BOOST_CHECK(!results.error->reason.empty());
+ auto c = results.error->reason;
+ std::cout << c << std::endl;
+ BOOST_CHECK(results.error->reason.find("Study") != std::string::npos);
+ BOOST_CHECK(results.error->reason.find("folder") != std::string::npos);
+ BOOST_CHECK(results.error->reason.find("not") != std::string::npos);
+ BOOST_CHECK(results.error->reason.find("exist") != std::string::npos);
+}
\ No newline at end of file
diff --git a/src/libs/antares/file-tree-study-loader/FileTreeStudyLoader.cpp b/src/libs/antares/file-tree-study-loader/FileTreeStudyLoader.cpp
index 5302c19263..8ff1c2730d 100644
--- a/src/libs/antares/file-tree-study-loader/FileTreeStudyLoader.cpp
+++ b/src/libs/antares/file-tree-study-loader/FileTreeStudyLoader.cpp
@@ -49,15 +49,10 @@ namespace
* @param study_path A string_view representing the study path.
* @return std::vector A vector of strings containing the prepared arguments.
*/
-[[nodiscard]] std::vector prepareArgs(std::span argv,
- std::string_view study_path)
+void prepareArgs(std::array& argv, std::span data)
{
- using namespace std::literals::string_literals;
- std::string arg0{""s};
- std::string arg1{study_path};
- argv[0] = arg0.data();
- argv[1] = arg1.data();
- return {std::move(arg0), std::move(arg1)};
+ argv[0] = data[0].data();
+ argv[1] = data[1].data();
}
} // namespace
@@ -66,8 +61,9 @@ std::unique_ptr FileTreeStudyLoader::load() const
using namespace std::literals::string_literals;
Antares::Solver::Application application;
constexpr unsigned int argc = 2;
+ std::array keep_alive{""s, study_path_.string()};
std::array argv;
- auto keep_alive = prepareArgs(argv, study_path_.string());
+ prepareArgs(argv, keep_alive);
application.prepare(argc, argv.data());
return application.acquireStudy();
diff --git a/src/libs/antares/inifile/CMakeLists.txt b/src/libs/antares/inifile/CMakeLists.txt
index a68b3f2786..089591f002 100644
--- a/src/libs/antares/inifile/CMakeLists.txt
+++ b/src/libs/antares/inifile/CMakeLists.txt
@@ -17,11 +17,11 @@ target_link_libraries(inifile
PRIVATE
io
logs
- Boost::boost
+ Boost::headers
)
target_include_directories(inifile
- PUBLIC
+ PUBLIC
$
)
diff --git a/src/libs/antares/study/CMakeLists.txt b/src/libs/antares/study/CMakeLists.txt
index c90d543fff..65ad5398a6 100644
--- a/src/libs/antares/study/CMakeLists.txt
+++ b/src/libs/antares/study/CMakeLists.txt
@@ -285,7 +285,6 @@ add_library(Antares::study ALIAS study)
target_link_libraries(study
PUBLIC
- Boost::boost
yuni-static-core
Antares::date #parameters
Antares::inifile #parameters
diff --git a/src/libs/antares/study/include/antares/study/parts/short-term-storage/cluster.h b/src/libs/antares/study/include/antares/study/parts/short-term-storage/cluster.h
index afe2e1976f..cc9af74015 100644
--- a/src/libs/antares/study/include/antares/study/parts/short-term-storage/cluster.h
+++ b/src/libs/antares/study/include/antares/study/parts/short-term-storage/cluster.h
@@ -1,23 +1,23 @@
/*
-** 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 .
-*/
+ * 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 .
+ */
#pragma once
#include
diff --git a/src/libs/antares/utils/utils.cpp b/src/libs/antares/utils/utils.cpp
index 047881b0e6..5f5efc9e9e 100644
--- a/src/libs/antares/utils/utils.cpp
+++ b/src/libs/antares/utils/utils.cpp
@@ -116,6 +116,8 @@ std::vector> splitStringIntoPairs(const std:
else
{
logs.warning() << "Error while parsing: " << token;
+ logs.warning() << "Correct format is: \"object1" << delimiter2 << "object2"
+ << delimiter1 << "object3" << delimiter2 << "object4\"";
}
}
diff --git a/src/packaging/CMakeLists.txt b/src/packaging/CMakeLists.txt
index 6d68ec5e38..868cd7a8ec 100644
--- a/src/packaging/CMakeLists.txt
+++ b/src/packaging/CMakeLists.txt
@@ -10,6 +10,8 @@ set(TARGET_LIBS #No alias
#not dependency is present since once a dependency is in the export set
#it is available for everything
+ solver_api #What we want to export
+
#solver_api
study
study-loader
@@ -33,6 +35,7 @@ set(TARGET_LIBS #No alias
exception
benchmarking
antares-solver-variable
+ lps
#study-loader
#nothing
diff --git a/src/packaging/Config.cmake.in b/src/packaging/Config.cmake.in
index 2cbf63a275..c9bcb039e1 100644
--- a/src/packaging/Config.cmake.in
+++ b/src/packaging/Config.cmake.in
@@ -1,8 +1,8 @@
@PACKAGE_INIT@
include(CMakeFindDependencyMacro)
-find_dependency(ortools REQUIRED)
-find_dependency(minizip-ng)
+find_dependency(Boost REQUIRED)
+find_package(minizip-ng QUIET) #Optional, don't use find_dependency it forces return in case of dep not found
if (minizip-ng_FOUND)
add_library(MINIZIP::minizip ALIAS MINIZIP::minizip-ng)
else ()
@@ -11,6 +11,8 @@ else ()
message (FATAL_ERROR "Minizip dependency (minizip or minizip-ng) not found.")
endif ()
endif ()
+find_dependency(ortools REQUIRED)
+find_dependency(sirius_solver REQUIRED)
include("${CMAKE_CURRENT_LIST_DIR}/AntaresTargets.cmake")
diff --git a/src/solver/CMakeLists.txt b/src/solver/CMakeLists.txt
index aeb17fb3a0..13ab3bfa6c 100644
--- a/src/solver/CMakeLists.txt
+++ b/src/solver/CMakeLists.txt
@@ -11,6 +11,7 @@ add_subdirectory(application)
add_subdirectory(constraints-builder)
add_subdirectory(hydro)
add_subdirectory(infeasible-problem-analysis)
+add_subdirectory(lps)
add_subdirectory(misc)
add_subdirectory(optimisation)
add_subdirectory(signal-handling)
diff --git a/src/solver/application/application.cpp b/src/solver/application/application.cpp
index d222ad88c0..90d5e559c5 100644
--- a/src/solver/application/application.cpp
+++ b/src/solver/application/application.cpp
@@ -34,7 +34,6 @@
#include
#include "antares/antares/version.h"
#include "antares/config/config.h"
-#include "antares/file-tree-study-loader/FileTreeStudyLoader.h"
#include "antares/signal-handling/public.h"
#include "antares/solver/misc/system-memory.h"
#include "antares/solver/misc/write-command-line.h"
@@ -410,20 +409,24 @@ void Application::execute()
void Application::runSimulationInEconomicMode()
{
+ Simulation::NullSimulationObserver observer;
Solver::runSimulationInEconomicMode(*pStudy,
pSettings,
pDurationCollector,
*resultWriter,
- pOptimizationInfo);
+ pOptimizationInfo,
+ observer);
}
void Application::runSimulationInAdequacyMode()
{
+ Simulation::NullSimulationObserver observer;
Solver::runSimulationInAdequacyMode(*pStudy,
pSettings,
pDurationCollector,
*resultWriter,
- pOptimizationInfo);
+ pOptimizationInfo,
+ observer);
}
static std::string timeToString()
diff --git a/src/solver/lps/CMakeLists.txt b/src/solver/lps/CMakeLists.txt
new file mode 100644
index 0000000000..8c3e48cab0
--- /dev/null
+++ b/src/solver/lps/CMakeLists.txt
@@ -0,0 +1,24 @@
+set(PROJ lps)
+set(HEADERS
+ include/antares/solver/lps/LpsFromAntares.h
+)
+set(SRC_PROJ
+ ${HEADERS}
+ LpsFromAntares.cpp
+)
+source_group("solver\\lps" FILES ${SRC_PROJ})
+
+add_library(${PROJ})
+target_sources(${PROJ} PRIVATE
+ ${SRC_PROJ}
+)
+add_library(Antares::${PROJ} ALIAS ${PROJ})
+
+target_include_directories(${PROJ}
+ PUBLIC
+ $
+)
+
+install(DIRECTORY include/antares
+ DESTINATION "include"
+)
\ No newline at end of file
diff --git a/src/solver/lps/LpsFromAntares.cpp b/src/solver/lps/LpsFromAntares.cpp
new file mode 100644
index 0000000000..a32484038d
--- /dev/null
+++ b/src/solver/lps/LpsFromAntares.cpp
@@ -0,0 +1,56 @@
+/*
+ * 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 .
+ */
+
+#include "antares/solver/lps/LpsFromAntares.h"
+
+namespace Antares::Solver
+{
+bool LpsFromAntares::empty() const
+{
+ return constantProblemData.VariablesCount == 0 || weeklyProblems.empty();
+}
+
+void LpsFromAntares::setConstantData(const ConstantDataFromAntares& data)
+{
+ constantProblemData = data;
+}
+
+void LpsFromAntares::addWeeklyData(WeeklyProblemId id, const WeeklyDataFromAntares& data)
+{
+ weeklyProblems.emplace(id, data);
+}
+
+const WeeklyDataFromAntares& LpsFromAntares::weeklyData(WeeklyProblemId id) const
+{
+ auto it = weeklyProblems.find(id);
+ if (it == weeklyProblems.end())
+ {
+ return WeeklyDataFromAntares(); // TODO Better error handling
+ }
+ return it->second;
+}
+
+size_t LpsFromAntares::weekCount() const noexcept
+{
+ return weeklyProblems.size();
+}
+
+} // namespace Antares::Solver
diff --git a/src/solver/lps/include/antares/solver/lps/LpsFromAntares.h b/src/solver/lps/include/antares/solver/lps/LpsFromAntares.h
new file mode 100644
index 0000000000..f85d99b060
--- /dev/null
+++ b/src/solver/lps/include/antares/solver/lps/LpsFromAntares.h
@@ -0,0 +1,149 @@
+
+/*
+ * 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 .
+ */
+
+#pragma once
+#include
+#include