Skip to content

Commit

Permalink
fix some compile err
Browse files Browse the repository at this point in the history
  • Loading branch information
payetvin committed Dec 10, 2024
1 parent 27fc0fc commit 493a629
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 195 deletions.
1 change: 1 addition & 0 deletions src/solver/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ add_subdirectory(lps)
add_subdirectory(misc)
add_subdirectory(modelConverter)
add_subdirectory(modelParser)
add_subdirectory(systemParser)
add_subdirectory(modeler)
add_subdirectory(optimisation)
add_subdirectory(signal-handling)
Expand Down
188 changes: 1 addition & 187 deletions src/solver/systemParser/encoders.hxx
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

/*
* Copyright 2007-2024, RTE (https://www.rte-france.com)
* See AUTHORS.txt
Expand All @@ -22,197 +21,12 @@

#pragma once

#include "antares/solver/systemParser/Library.h"
#include "antares/solver/systemParser/library.h"

#include "yaml-cpp/yaml.h"

// Implement convert specializations
namespace YAML
{

/**
* @brief shortend to default construct a value when node is null
* @tparam T Type to convert the node to
* @param n node
* @return Object of type T
* It's just to simplify repertitve and verbose lines
* as_fallback_default<std::vector<Antares::Solver::ModelParser::Parameter>>(
node["parameters"]) is equivalent to
node["parameters"].as<std::vector<Antares::Solver::ModelParser::Parameter>>(std::vector<Antares::Solver::ModelParser::Parameter>())
*/
template<typename T>
inline T as_fallback_default(const Node& n)
{
return n.as<T>(T());
}

template<>
struct convert<Antares::Solver::modelParser::Parameter>
{
static bool decode(const Node& node, Antares::Solver::ModelParser::Parameter& rhs)
{
if (!node.IsMap())
{
return false;
}
rhs.id = node["id"].as<std::string>();
rhs.time_dependent = node["time-dependent"].as<bool>(true);
rhs.scenario_dependent = node["scenario-dependent"].as<bool>(true);
return true;
}
};

template<>
struct convert<Antares::Solver::ModelParser::ValueType>
{
static bool decode(const Node& node, Antares::Solver::ModelParser::ValueType& rhs)
{
if (!node.IsScalar())
{
return false;
}
const auto value = node.as<std::string>();
if (value == "continuous")
{
rhs = Antares::Solver::ModelParser::ValueType::CONTINUOUS;
}
else if (value == "integer")
{
rhs = Antares::Solver::ModelParser::ValueType::INTEGER;
}
else if (value == "boolean")
{
rhs = Antares::Solver::ModelParser::ValueType::BOOL;
}
else
{
return false;
}
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.id = node["id"].as<std::string>();
rhs.lower_bound = node["lower-bound"].as<std::string>("");
rhs.upper_bound = node["upper-bound"].as<std::string>("");
rhs.variable_type = node["variable-type"].as<Antares::Solver::ModelParser::ValueType>(
Antares::Solver::ModelParser::ValueType::CONTINUOUS);
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.id = node["id"].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.id = node["id"].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 = as_fallback_default<std::vector<Antares::Solver::ModelParser::Parameter>>(
node["parameters"]);
rhs.variables = as_fallback_default<std::vector<Antares::Solver::ModelParser::Variable>>(
node["variables"]);
rhs.ports = as_fallback_default<std::vector<Antares::Solver::ModelParser::Port>>(
node["ports"]);
rhs.port_field_definitions = as_fallback_default<
std::vector<Antares::Solver::ModelParser::PortFieldDefinition>>(
node["port-field-definitions"]);
rhs.constraints = as_fallback_default<
std::vector<Antares::Solver::ModelParser::Constraint>>(node["constraints"]);
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["id"].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 = as_fallback_default<std::vector<Antares::Solver::ModelParser::PortType>>(
node["port-types"]);
rhs.models = node["models"].as<std::vector<Antares::Solver::ModelParser::Model>>();
return true;
}
};
} // namespace YAML
Original file line number Diff line number Diff line change
Expand Up @@ -34,19 +34,19 @@ struct Parameter
std::string value;
};

struct Components
struct Component
{
std::string id;
std::string model;
std::string scenarioGroup;
std::vector<Parameters> parameters;
std::vector<Parameter> parameters;
};

struct System
{
std::string id;
std::vector<std::string> libraries;
std::vector<Components> components;
std::vector<Component> components;

// will be implemented later
// std::vector<Connections> connections;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

/*
* Copyright 2007-2024, RTE (https://www.rte-france.com)
* See AUTHORS.txt
Expand All @@ -21,7 +20,7 @@
*/

#pragma once
#include "antares/solver/systemParser/Library.h"
#include "antares/solver/systemParser/library.h"

namespace Antares::Solver::SystemParser
{
Expand Down
6 changes: 3 additions & 3 deletions src/solver/systemParser/parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,18 @@

#include "antares/solver/systemParser/parser.h"

#include "antares/solver/systemParser/Library.h"
#include "antares/solver/systemParser/library.h"

#include "encoders.hxx"

namespace Antares::Solver::SystemParser
{

Library Parser::parse(const std::string& content)
System Parser::parse(const std::string& content)
{
YAML::Node root = YAML::Load(content);

System system = root["system"].as<Library>();
System system = root["system"].as<System>();

return system;
}
Expand Down

0 comments on commit 493a629

Please sign in to comment.