-
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.
Modeler 2.4c: portfield substitution (#2406)
Co-authored-by: OMNES Florian <[email protected]>
- Loading branch information
Showing
5 changed files
with
178 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
59 changes: 59 additions & 0 deletions
59
...er/expressions/include/antares/solver/expressions/visitors/PortfieldSubstitutionVisitor.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,59 @@ | ||
/* | ||
** 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 "antares/solver/expressions/visitors/CloneVisitor.h" | ||
|
||
namespace Antares::Solver::Visitors | ||
{ | ||
|
||
struct KeyHasher | ||
{ | ||
std::size_t operator()(const Nodes::PortFieldNode& n) const; | ||
}; | ||
|
||
/** | ||
* @brief Represents the context for performing substitutions in a syntax tree. | ||
*/ | ||
struct PortfieldSubstitutionContext | ||
{ | ||
std::unordered_map<Nodes::PortFieldNode, Nodes::Node*, KeyHasher> portfield; | ||
}; | ||
|
||
/** | ||
* @brief Represents a visitor for substituting portfield nodes in a syntax tree. | ||
*/ | ||
class PortfieldSubstitutionVisitor: public CloneVisitor | ||
{ | ||
public: | ||
PortfieldSubstitutionVisitor(Registry<Nodes::Node>& registry, | ||
PortfieldSubstitutionContext& ctx); | ||
|
||
PortfieldSubstitutionContext& ctx_; | ||
std::string name() const override; | ||
|
||
private: | ||
// Only override visit method for PortField, clone the rest | ||
Nodes::Node* visit(const Nodes::PortFieldNode* node) override; | ||
}; | ||
} // namespace Antares::Solver::Visitors |
61 changes: 61 additions & 0 deletions
61
src/solver/expressions/visitors/PortfieldSubstitutionVisitor.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,61 @@ | ||
/* | ||
** 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 <boost/functional/hash.hpp> | ||
|
||
#include <antares/solver/expressions/nodes/ExpressionsNodes.h> | ||
#include <antares/solver/expressions/visitors/PortfieldSubstitutionVisitor.h> | ||
|
||
namespace Antares::Solver::Visitors | ||
{ | ||
|
||
PortfieldSubstitutionVisitor::PortfieldSubstitutionVisitor(Registry<Nodes::Node>& registry, | ||
PortfieldSubstitutionContext& ctx): | ||
CloneVisitor(registry), | ||
ctx_(ctx) | ||
{ | ||
} | ||
|
||
Nodes::Node* PortfieldSubstitutionVisitor::visit(const Nodes::PortFieldNode* node) | ||
{ | ||
if (auto it = ctx_.portfield.find(*node); it != ctx_.portfield.end()) | ||
{ | ||
return it->second; | ||
} | ||
|
||
return CloneVisitor::visit(node); | ||
} | ||
|
||
std::string PortfieldSubstitutionVisitor::name() const | ||
{ | ||
return "PortfieldSubstitutionVisitor"; | ||
} | ||
|
||
std::size_t KeyHasher::operator()(const Nodes::PortFieldNode& n) const | ||
{ | ||
std::size_t seed = 0; | ||
|
||
boost::hash_combine(seed, boost::hash_value(n.getPortName())); | ||
boost::hash_combine(seed, boost::hash_value(n.getFieldName())); | ||
|
||
return seed; | ||
} | ||
|
||
} // namespace Antares::Solver::Visitors |
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 @@ | ||
antares-solver : /home/payetvin/Antares_Simulator/_build/solver/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