-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Parse user models described as CPP - Expect to read one library per content - Only accept yaml content as std::string - Output object is Antares::Solver::ModelParser::Library - CMake : remove WITH_YAMLCPP (always ON) --------- Co-authored-by: Florian Omnès <[email protected]>
- Loading branch information
1 parent
ac5218c
commit 2d77d87
Showing
14 changed files
with
938 additions
and
33 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
find_package(yaml-cpp REQUIRED) | ||
|
||
set(SOURCES | ||
parser.cpp | ||
#encoders.hxx | ||
include/antares/solver/modelParser/parser.h | ||
) | ||
|
||
# Create the library | ||
add_library(modelParser STATIC ${SOURCES}) | ||
add_library(Antares::modelParser ALIAS modelParser) | ||
|
||
# Specify include directories | ||
target_include_directories(modelParser | ||
PUBLIC | ||
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include> | ||
) | ||
|
||
# Link dependencies (if any) | ||
target_link_libraries(modelParser | ||
PRIVATE | ||
yaml-cpp | ||
) | ||
|
||
install(DIRECTORY include/antares | ||
DESTINATION "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,167 @@ | ||
|
||
/* | ||
* Copyright 2007-2024, RTE (https://www.rte-france.com) | ||
* See AUTHORS.txt | ||
* SPDX-License-Identifier: MPL-2.0 | ||
* This file is part of Antares-Simulator, | ||
* Adequacy and Performance assessment for interconnected energy networks. | ||
* | ||
* Antares_Simulator is free software: you can redistribute it and/or modify | ||
* it under the terms of the Mozilla Public Licence 2.0 as published by | ||
* the Mozilla Foundation, either version 2 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* Antares_Simulator is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* Mozilla Public Licence 2.0 for more details. | ||
* | ||
* You should have received a copy of the Mozilla Public Licence 2.0 | ||
* along with Antares_Simulator. If not, see <https://opensource.org/license/mpl-2-0/>. | ||
*/ | ||
|
||
#pragma once | ||
|
||
#include "antares/solver/modelParser/model.h" | ||
|
||
#include "yaml-cpp/yaml.h" | ||
|
||
// Implement convert specializations | ||
namespace YAML | ||
{ | ||
template<> | ||
struct convert<Antares::Solver::ModelParser::Parameter> | ||
{ | ||
static bool decode(const Node& node, Antares::Solver::ModelParser::Parameter& rhs) | ||
{ | ||
if (!node.IsMap()) | ||
{ | ||
return false; | ||
} | ||
rhs.name = node["name"].as<std::string>(); | ||
rhs.time_dependent = node["time-dependent"].as<bool>(); | ||
rhs.scenario_dependent = node["scenario-dependent"].as<bool>(); | ||
return true; | ||
} | ||
}; | ||
|
||
template<> | ||
struct convert<Antares::Solver::ModelParser::Variable> | ||
{ | ||
static bool decode(const Node& node, Antares::Solver::ModelParser::Variable& rhs) | ||
{ | ||
if (!node.IsMap()) | ||
{ | ||
return false; | ||
} | ||
rhs.name = node["name"].as<std::string>(); | ||
rhs.lower_bound = node["lower-bound"].as<double>(); | ||
rhs.upper_bound = node["upper-bound"].as<double>(); | ||
return true; | ||
} | ||
}; | ||
|
||
template<> | ||
struct convert<Antares::Solver::ModelParser::Port> | ||
{ | ||
static bool decode(const Node& node, Antares::Solver::ModelParser::Port& rhs) | ||
{ | ||
if (!node.IsMap()) | ||
{ | ||
return false; | ||
} | ||
rhs.name = node["name"].as<std::string>(); | ||
rhs.type = node["type"].as<std::string>(); | ||
return true; | ||
} | ||
}; | ||
|
||
template<> | ||
struct convert<Antares::Solver::ModelParser::PortFieldDefinition> | ||
{ | ||
static bool decode(const Node& node, Antares::Solver::ModelParser::PortFieldDefinition& rhs) | ||
{ | ||
if (!node.IsMap()) | ||
{ | ||
return false; | ||
} | ||
rhs.port = node["port"].as<std::string>(); | ||
rhs.field = node["field"].as<std::string>(); | ||
rhs.definition = node["definition"].as<std::string>(); | ||
return true; | ||
} | ||
}; | ||
|
||
template<> | ||
struct convert<Antares::Solver::ModelParser::Constraint> | ||
{ | ||
static bool decode(const Node& node, Antares::Solver::ModelParser::Constraint& rhs) | ||
{ | ||
if (!node.IsMap()) | ||
{ | ||
return false; | ||
} | ||
rhs.name = node["name"].as<std::string>(); | ||
rhs.expression = node["expression"].as<std::string>(); | ||
return true; | ||
} | ||
}; | ||
|
||
template<> | ||
struct convert<Antares::Solver::ModelParser::Model> | ||
{ | ||
static bool decode(const Node& node, Antares::Solver::ModelParser::Model& rhs) | ||
{ | ||
if (!node.IsMap()) | ||
{ | ||
return false; | ||
} | ||
rhs.id = node["id"].as<std::string>(); | ||
rhs.description = node["description"].as<std::string>(); | ||
rhs.parameters = node["parameters"] | ||
.as<std::vector<Antares::Solver::ModelParser::Parameter>>(); | ||
rhs.variables = node["variables"].as<std::vector<Antares::Solver::ModelParser::Variable>>(); | ||
rhs.ports = node["ports"].as<std::vector<Antares::Solver::ModelParser::Port>>(); | ||
rhs.port_field_definitions = node["port-field-definitions"] | ||
.as<std::vector< | ||
Antares::Solver::ModelParser::PortFieldDefinition>>(); | ||
rhs.constraints = node["constraints"] | ||
.as<std::vector<Antares::Solver::ModelParser::Constraint>>(); | ||
rhs.objective = node["objective"].as<std::string>(); | ||
return true; | ||
} | ||
}; | ||
|
||
template<> | ||
struct convert<Antares::Solver::ModelParser::PortType> | ||
{ | ||
static bool decode(const Node& node, Antares::Solver::ModelParser::PortType& rhs) | ||
{ | ||
if (!node.IsMap()) | ||
{ | ||
return false; | ||
} | ||
rhs.id = node["id"].as<std::string>(); | ||
rhs.description = node["description"].as<std::string>(); | ||
for (const auto& field: node["fields"]) | ||
{ | ||
rhs.fields.push_back(field["name"].as<std::string>()); | ||
} | ||
return true; | ||
} | ||
}; | ||
|
||
template<> | ||
struct convert<Antares::Solver::ModelParser::Library> | ||
{ | ||
static bool decode(const Node& node, Antares::Solver::ModelParser::Library& rhs) | ||
{ | ||
rhs.id = node["id"].as<std::string>(); | ||
rhs.description = node["description"].as<std::string>(); | ||
rhs.port_types = node["port-types"] | ||
.as<std::vector<Antares::Solver::ModelParser::PortType>>(); | ||
rhs.models = node["models"].as<std::vector<Antares::Solver::ModelParser::Model>>(); | ||
return true; | ||
} | ||
}; | ||
} // namespace YAML |
91 changes: 91 additions & 0 deletions
91
src/solver/modelParser/include/antares/solver/modelParser/model.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,91 @@ | ||
|
||
/* | ||
* Copyright 2007-2024, RTE (https://www.rte-france.com) | ||
* See AUTHORS.txt | ||
* SPDX-License-Identifier: MPL-2.0 | ||
* This file is part of Antares-Simulator, | ||
* Adequacy and Performance assessment for interconnected energy networks. | ||
* | ||
* Antares_Simulator is free software: you can redistribute it and/or modify | ||
* it under the terms of the Mozilla Public Licence 2.0 as published by | ||
* the Mozilla Foundation, either version 2 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* Antares_Simulator is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* Mozilla Public Licence 2.0 for more details. | ||
* | ||
* You should have received a copy of the Mozilla Public Licence 2.0 | ||
* along with Antares_Simulator. If not, see <https://opensource.org/license/mpl-2-0/>. | ||
*/ | ||
|
||
#pragma once | ||
#include <string> | ||
#include <vector> | ||
|
||
namespace Antares::Solver::ModelParser | ||
{ | ||
// Define structures | ||
struct Parameter | ||
{ | ||
std::string name; | ||
bool time_dependent; | ||
bool scenario_dependent; | ||
}; | ||
|
||
struct Variable | ||
{ | ||
std::string name; | ||
double lower_bound; | ||
double upper_bound; | ||
}; | ||
|
||
struct Port | ||
{ | ||
std::string name; | ||
std::string type; | ||
}; | ||
|
||
struct PortFieldDefinition | ||
{ | ||
std::string port; | ||
std::string field; | ||
std::string definition; | ||
}; | ||
|
||
struct Constraint | ||
{ | ||
std::string name; | ||
std::string expression; | ||
}; | ||
|
||
struct Model | ||
{ | ||
std::string id; | ||
std::string description; | ||
std::vector<Parameter> parameters; | ||
std::vector<Variable> variables; | ||
std::vector<Port> ports; | ||
std::vector<PortFieldDefinition> port_field_definitions; | ||
std::vector<Constraint> constraints; | ||
std::string objective; | ||
}; | ||
|
||
struct PortType | ||
{ | ||
std::string id; | ||
std::string description; | ||
// Small optimization: we only need the name of the fields | ||
// No need for an intermediate struct "field" with just a string "name" member | ||
std::vector<std::string> fields; | ||
}; | ||
|
||
struct Library | ||
{ | ||
std::string id; | ||
std::string description; | ||
std::vector<PortType> port_types; | ||
std::vector<Model> models; | ||
}; | ||
} // namespace Antares::Solver::ModelParser |
Oops, something went wrong.