Antares Simulator
Power System Simulator
decoders.hxx
1 
2 /*
3  * Copyright 2007-2025, RTE (https://www.rte-france.com)
4  * See AUTHORS.txt
5  * SPDX-License-Identifier: MPL-2.0
6  * This file is part of Antares-Simulator,
7  * Adequacy and Performance assessment for interconnected energy networks.
8  *
9  * Antares_Simulator is free software: you can redistribute it and/or modify
10  * it under the terms of the Mozilla Public Licence 2.0 as published by
11  * the Mozilla Foundation, either version 2 of the License, or
12  * (at your option) any later version.
13  *
14  * Antares_Simulator is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  * Mozilla Public Licence 2.0 for more details.
18  *
19  * You should have received a copy of the Mozilla Public Licence 2.0
20  * along with Antares_Simulator. If not, see <https://opensource.org/license/mpl-2-0/>.
21  */
22 
23 #pragma once
24 
25 #include "antares/io/inputs/yml-optim-config/OptimConfig.h"
26 
27 #include "yaml-cpp/yaml.h"
28 
29 // Implement convert specializations
30 namespace YAML
31 {
32 
33 // TODO this function is defined at least 3 times, deduplicate
34 template<typename T>
35 inline T as_fallback_default(const Node& n)
36 {
37  return n.as<T>(T());
38 }
39 
40 template<>
41 struct convert<Antares::IO::Inputs::YmlOptimConfig::Variable>
42 {
43  static bool decode(const Node& node, Antares::IO::Inputs::YmlOptimConfig::Variable& rhs)
44  {
45  if (!node.IsMap())
46  {
47  return false;
48  }
49  rhs.id = node["id"].as<std::string>();
50  rhs.location = node["location"].as<std::string>();
51  return true;
52  }
53 };
54 
55 template<>
56 struct convert<Antares::IO::Inputs::YmlOptimConfig::Constraint>
57 {
58  static bool decode(const Node& node, Antares::IO::Inputs::YmlOptimConfig::Constraint& rhs)
59  {
60  if (!node.IsMap())
61  {
62  return false;
63  }
64  rhs.id = node["id"].as<std::string>();
65  rhs.location = node["location"].as<std::string>();
66  return true;
67  }
68 };
69 
70 template<>
71 struct convert<Antares::IO::Inputs::YmlOptimConfig::Objective>
72 {
73  static bool decode(const Node& node, Antares::IO::Inputs::YmlOptimConfig::Objective& rhs)
74  {
75  if (!node.IsMap())
76  {
77  return false;
78  }
79  rhs.id = node["id"].as<std::string>();
80  rhs.location = node["location"].as<std::string>();
81 
82  return true;
83  }
84 };
85 
86 template<>
87 struct convert<Antares::IO::Inputs::YmlOptimConfig::Model>
88 {
89  static bool decode(const Node& node, Antares::IO::Inputs::YmlOptimConfig::Model& rhs)
90  {
91  rhs.id = node["id"].as<std::string>();
92  const auto& modelDecompositionNode = node["model-decomposition"];
93  rhs.variables = as_fallback_default<
94  std::vector<Antares::IO::Inputs::YmlOptimConfig::Variable>>(
95  modelDecompositionNode["variables"]);
96 
97  rhs.constraints = as_fallback_default<
98  std::vector<Antares::IO::Inputs::YmlOptimConfig::Constraint>>(
99  modelDecompositionNode["constraints"]);
100 
101  rhs.objectives = as_fallback_default<
102  std::vector<Antares::IO::Inputs::YmlOptimConfig::Objective>>(
103  modelDecompositionNode["objective-contributions"]);
104 
105  return true;
106  }
107 };
108 
109 } // namespace YAML
Definition: OptimConfig.h:50