-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Modeler 2.5a: Add parameters and YAML parser (#2539)
Co-authored-by: payetvin <[email protected]> Co-authored-by: Vincent Payet <[email protected]>
- Loading branch information
1 parent
a570a0e
commit 5d4c168
Showing
15 changed files
with
179 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
add_subdirectory(api) | ||
add_subdirectory(ortoolsImpl) | ||
add_subdirectory(parameters) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
add_library(modeler-parameters | ||
include/antares/solver/modeler/parameters/modelerParameters.h | ||
include/antares/solver/modeler/parameters/parseModelerParameters.h | ||
parseModelerParameters.cpp | ||
encoder.hxx) | ||
|
||
target_link_libraries(modeler-parameters | ||
PRIVATE | ||
yaml-cpp | ||
Antares::io) | ||
|
||
target_include_directories(modeler-parameters | ||
PUBLIC | ||
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
#include <antares/solver/modeler/parameters/modelerParameters.h> | ||
|
||
#include "yaml-cpp/yaml.h" | ||
|
||
namespace YAML | ||
{ | ||
template<> | ||
struct convert<Antares::Solver::ModelerParameters> | ||
{ | ||
static bool decode(const Node& node, Antares::Solver::ModelerParameters& rhs) | ||
{ | ||
if (!node.IsMap()) | ||
{ | ||
return false; | ||
} | ||
rhs.solver = node["solver"].as<std::string>(); | ||
rhs.solverLogs = node["solver-logs"].as<bool>(false); | ||
rhs.solverParameters = node["solver-parameters"].as<std::string>(); | ||
rhs.noOutput = node["no-output"].as<bool>(false); | ||
return true; | ||
} | ||
}; | ||
} // namespace YAML |
18 changes: 18 additions & 0 deletions
18
src/solver/modeler/parameters/include/antares/solver/modeler/parameters/modelerParameters.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
#pragma once | ||
|
||
#include <string> | ||
|
||
namespace Antares::Solver | ||
{ | ||
struct ModelerParameters | ||
{ | ||
// OR-Tools solver to be used for the simulation | ||
std::string solver; | ||
// Display solver logs ON/OFF | ||
bool solverLogs = false; | ||
// Specific solver parameters | ||
std::string solverParameters; | ||
// Write output results | ||
bool noOutput = false; | ||
}; | ||
} // namespace Antares::Solver |
11 changes: 11 additions & 0 deletions
11
...ver/modeler/parameters/include/antares/solver/modeler/parameters/parseModelerParameters.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
#pragma once | ||
|
||
#include <filesystem> | ||
|
||
#include <antares/solver/modeler/parameters/modelerParameters.h> | ||
|
||
namespace Antares::Solver | ||
{ | ||
|
||
ModelerParameters parseModelerParameters(const std::filesystem::path& path); | ||
} // namespace Antares::Solver |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
#include <filesystem> | ||
#include <fstream> | ||
|
||
#include <antares/io/file.h> | ||
|
||
#include "encoder.hxx" | ||
|
||
namespace Antares::Solver | ||
{ | ||
ModelerParameters parseModelerParameters(const std::filesystem::path& path) | ||
{ | ||
const auto contents = Antares::IO::readFile(path); | ||
YAML::Node root = YAML::Load(contents); | ||
return root.as<ModelerParameters>(); | ||
} | ||
} // namespace Antares::Solver |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,3 @@ | ||
find_package(yaml-cpp REQUIRED) | ||
|
||
set(SOURCES | ||
parser.cpp | ||
converter.cpp | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
add_subdirectory(api) | ||
add_subdirectory(parameters) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
# Zip writer | ||
add_executable(parse-parameters testParametersParsing.cpp) | ||
|
||
target_link_libraries(parse-parameters | ||
PRIVATE | ||
Boost::unit_test_framework | ||
modeler-parameters | ||
test_utils_unit | ||
) | ||
|
||
set_target_properties(parse-parameters PROPERTIES FOLDER Unit-tests/test-writer) | ||
|
||
add_test(NAME parse-parameters COMMAND parse-parameters) | ||
set_tests_properties(parse-parameters PROPERTIES LABELS unit) |
74 changes: 74 additions & 0 deletions
74
src/tests/src/solver/modeler/parameters/testParametersParsing.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
/* | ||
* 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/>. | ||
*/ | ||
#define WIN32_LEAN_AND_MEAN | ||
|
||
#include <fstream> | ||
#define BOOST_TEST_MODULE parse modeler parameters | ||
|
||
#include <boost/test/unit_test.hpp> | ||
|
||
#include <antares/solver/modeler/parameters/parseModelerParameters.h> | ||
|
||
#include "files-system.h" | ||
|
||
BOOST_AUTO_TEST_SUITE(read_modeler_parameters) | ||
|
||
BOOST_AUTO_TEST_CASE(all_properties_set) | ||
{ | ||
const auto working_tmp_dir = CREATE_TMP_DIR_BASED_ON_TEST_NAME(); | ||
const auto fileP = working_tmp_dir / "parameters.yaml"; | ||
{ | ||
std::ofstream param(fileP); | ||
param << R"( | ||
solver: sirius | ||
solver-logs: false | ||
solver-parameters: PRESOLVE 1 | ||
no-output: true)"; | ||
} | ||
|
||
auto params = Antares::Solver::parseModelerParameters(fileP); | ||
BOOST_CHECK_EQUAL(params.solver, "sirius"); | ||
BOOST_CHECK_EQUAL(params.solverLogs, false); | ||
BOOST_CHECK_EQUAL(params.solverParameters, "PRESOLVE 1"); | ||
BOOST_CHECK_EQUAL(params.noOutput, true); | ||
} | ||
|
||
BOOST_AUTO_TEST_CASE(all_properties_set_out_of_order) | ||
{ | ||
const auto working_tmp_dir = CREATE_TMP_DIR_BASED_ON_TEST_NAME(); | ||
const auto fileP = working_tmp_dir / "parameters.yaml"; | ||
{ | ||
std::ofstream param(fileP); | ||
param << R"( | ||
solver-logs: false | ||
solver: sirius | ||
solver-parameters: PRESOLVE 1 | ||
no-output: true)"; | ||
} | ||
|
||
auto params = Antares::Solver::parseModelerParameters(fileP); | ||
BOOST_CHECK_EQUAL(params.solver, "sirius"); | ||
BOOST_CHECK_EQUAL(params.solverLogs, false); | ||
BOOST_CHECK_EQUAL(params.solverParameters, "PRESOLVE 1"); | ||
BOOST_CHECK_EQUAL(params.noOutput, true); | ||
} | ||
|
||
BOOST_AUTO_TEST_SUITE_END() |