-
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.
New System model (2.2) [ANT-2208] (#2500)
- Loading branch information
Showing
12 changed files
with
775 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,126 @@ | ||
/* | ||
** 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/>. | ||
*/ | ||
|
||
#include <ranges> | ||
|
||
#include <antares/study/system-model/component.h> | ||
|
||
namespace Antares::Study::SystemModel | ||
{ | ||
|
||
static void checkComponentDataValidity(const ComponentData& data) | ||
{ | ||
// Check that mandatory attributes are not empty | ||
if (data.id.empty()) | ||
{ | ||
throw std::invalid_argument("A component can't have an empty id"); | ||
} | ||
if (data.model == nullptr) | ||
{ | ||
throw std::invalid_argument("A component can't have an empty model"); | ||
} | ||
if (data.scenario_group_id.empty()) | ||
{ | ||
throw std::invalid_argument("A component can't have an empty scenario_group_id"); | ||
} | ||
// Check that parameters values are coherent with the model | ||
if (data.model->Parameters().size() != data.parameter_values.size()) | ||
{ | ||
throw std::invalid_argument( | ||
"The component has " + std::to_string(data.parameter_values.size()) | ||
+ " parameter(s), but its model has " + std::to_string(data.model->Parameters().size())); | ||
} | ||
for (const auto param: data.model->Parameters() | std::views::keys) | ||
{ | ||
if (!data.parameter_values.contains(param)) | ||
{ | ||
throw std::invalid_argument("The component has no value for parameter '" + param + "'"); | ||
} | ||
} | ||
} | ||
|
||
Component::Component(const ComponentData& component_data) | ||
{ | ||
checkComponentDataValidity(component_data); | ||
data_ = std::move(component_data); | ||
} | ||
|
||
/** | ||
* \brief Sets the ID of the component. | ||
* | ||
* \param id The ID to set. | ||
* \return Reference to the ComponentBuilder object. | ||
*/ | ||
ComponentBuilder& ComponentBuilder::withId(const std::string_view id) | ||
{ | ||
data_.id = id; | ||
return *this; | ||
} | ||
|
||
/** | ||
* \brief Sets the model of the component. | ||
* | ||
* \param model The model to set. | ||
* \return Reference to the ComponentBuilder object. | ||
*/ | ||
ComponentBuilder& ComponentBuilder::withModel(Model* model) | ||
{ | ||
data_.model = model; | ||
return *this; | ||
} | ||
|
||
/** | ||
* \brief Sets the parameter values of the component. The parameters included should be all of the | ||
* model's parameters. | ||
* | ||
* \param parameter_values The map of parameter values to set. | ||
* \return Reference to the ComponentBuilder object. | ||
*/ | ||
ComponentBuilder& ComponentBuilder::withParameterValues( | ||
std::map<std::string, double> parameter_values) | ||
{ | ||
data_.parameter_values = std::move(parameter_values); | ||
return *this; | ||
} | ||
|
||
/** | ||
* \brief Sets the ID of the scenario group to which the component belongs. | ||
* | ||
* \param scenario_group_id The scenario group ID to set. | ||
* \return Reference to the ComponentBuilder object. | ||
*/ | ||
ComponentBuilder& ComponentBuilder::withScenarioGroupId(const std::string& scenario_group_id) | ||
{ | ||
data_.scenario_group_id = scenario_group_id; | ||
return *this; | ||
} | ||
|
||
/** | ||
* \brief Builds and returns the Component object. | ||
* | ||
* \return The constructed Component object. | ||
*/ | ||
Component ComponentBuilder::build() const | ||
{ | ||
return Component(data_); | ||
} | ||
|
||
} // namespace Antares::Study::SystemModel |
96 changes: 96 additions & 0 deletions
96
src/study/system-model/include/antares/study/system-model/component.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,96 @@ | ||
/* | ||
** 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 <map> | ||
|
||
#include "model.h" | ||
|
||
namespace Antares::Study::SystemModel | ||
{ | ||
|
||
/** | ||
* Defines the attributes of the Component class | ||
* Made into a struct to avoid duplication in ComponentBuilder | ||
*/ | ||
struct ComponentData | ||
{ | ||
std::string id; | ||
Model* model = nullptr; | ||
std::map<std::string, double> parameter_values; | ||
std::string scenario_group_id; | ||
}; | ||
|
||
/** | ||
* Defines an actual component of the simulated system. | ||
*/ | ||
class Component | ||
{ | ||
public: | ||
// Only allowing one private constructor (see below) to forbid empty Components | ||
Component() = delete; | ||
|
||
const std::string& Id() const | ||
{ | ||
return data_.id; | ||
} | ||
|
||
Model* getModel() const | ||
{ | ||
return data_.model; | ||
} | ||
|
||
double getParameterValue(const std::string& parameter_id) const | ||
{ | ||
if (!data_.parameter_values.contains(parameter_id)) | ||
{ | ||
throw std::invalid_argument("Parameter '" + parameter_id + "' not found in component '" | ||
+ data_.id + "'"); | ||
} | ||
return data_.parameter_values.at(parameter_id); | ||
} | ||
|
||
std::string getScenarioGroupId() const | ||
{ | ||
return data_.scenario_group_id; | ||
} | ||
|
||
private: | ||
// Only ComponentBuilder is allowed to build Component instances | ||
friend class ComponentBuilder; | ||
explicit Component(const ComponentData& component_data); | ||
ComponentData data_; | ||
}; | ||
|
||
class ComponentBuilder | ||
{ | ||
public: | ||
ComponentBuilder& withId(std::string_view id); | ||
ComponentBuilder& withModel(Model* model); | ||
ComponentBuilder& withParameterValues(std::map<std::string, double> parameter_values); | ||
ComponentBuilder& withScenarioGroupId(const std::string& scenario_group_id); | ||
Component build() const; | ||
|
||
private: | ||
ComponentData data_; | ||
}; | ||
|
||
} // namespace Antares::Study::SystemModel |
79 changes: 79 additions & 0 deletions
79
src/study/system-model/include/antares/study/system-model/system.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,79 @@ | ||
/* | ||
** 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 <unordered_map> | ||
|
||
#include "component.h" | ||
|
||
namespace Antares::Study::SystemModel | ||
{ | ||
|
||
/** | ||
* Defines the attributes of the System class | ||
* Made into a struct to avoid duplication in SystemBuilder | ||
*/ | ||
struct SystemData | ||
{ | ||
}; | ||
|
||
/** | ||
* Defines the simulated system. | ||
*/ | ||
class System | ||
{ | ||
public: | ||
// Only allowing one private constructor (see below) to forbid empty Systems | ||
System() = delete; | ||
System(System& other) = delete; | ||
|
||
const std::string& Id() const | ||
{ | ||
return id_; | ||
} | ||
|
||
const std::unordered_map<std::string, Component>& Components() const | ||
{ | ||
return components_; | ||
} | ||
|
||
private: | ||
// Only SystemBuilder is allowed to build System instances | ||
friend class SystemBuilder; | ||
System(std::string_view id, std::vector<Component> components); | ||
std::string id_; | ||
std::unordered_map<std::string, Component> components_; | ||
std::pair<std::string, Component> makeComponent(Component& component) const; | ||
}; | ||
|
||
class SystemBuilder | ||
{ | ||
public: | ||
SystemBuilder& withId(std::string_view id); | ||
SystemBuilder& withComponents(std::vector<Component>&& components); | ||
System build() const; | ||
|
||
private: | ||
std::string id_; | ||
std::vector<Component> components_; | ||
}; | ||
|
||
} // namespace Antares::Study::SystemModel |
Oops, something went wrong.