Skip to content

Commit 3a910f5

Browse files
minor re-organize
Signed-off-by: Jerry Guo <Jerry.Jinfeng.Guo@alliander.com>
1 parent fc2efee commit 3a910f5

File tree

2 files changed

+24
-22
lines changed

2 files changed

+24
-22
lines changed

power_grid_model_c/power_grid_model/include/power_grid_model/optimizer/tap_position_optimizer.hpp

Lines changed: 23 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -74,30 +74,31 @@ struct RegulatedTrafoProperties {
7474
Idx id{};
7575
ControlSide control_side{};
7676

77-
bool operator<(const RegulatedTrafoProperties& other) const {
78-
return std::tie(this->id, this->control_side) < std::tie(other.id, other.control_side);
79-
}
77+
auto operator<=>(RegulatedTrafoProperties const& other) const = default;
8078
};
8179

82-
struct RegulatedObjects {
83-
std::set<Idx> transformers{};
84-
std::set<Idx> transformers3w{};
85-
std::set<RegulatedTrafoProperties> trafos{};
86-
std::set<RegulatedTrafoProperties> trafos3w{};
87-
88-
template <typename TrafoType> // not really necessary to be templated, but just in case
89-
std::pair<bool, ControlSide> contains(TrafoType const& trafos_set, Idx const& id) const {
90-
auto it = std::find_if(trafos_set.begin(), trafos_set.end(),
91-
[&](const RegulatedTrafoProperties& trafo) { return trafo.id == id; });
92-
if (it != trafos_set.end()) {
93-
return {true, it->control_side};
94-
}
95-
return {false, ControlSide{}}; // no default invalid control side, won't be used by logic
96-
}
80+
using RegulatedTrafos = std::set<RegulatedTrafoProperties>;
9781

98-
std::pair<bool, ControlSide> contains_trafo(Idx const& id) const { return contains(trafos, id); }
82+
inline std::pair<bool, ControlSide> regulated_trafos_contain(RegulatedTrafos const& trafos_set, Idx const& id) {
83+
if (auto it = std::find_if(trafos_set.begin(), trafos_set.end(),
84+
[&](RegulatedTrafoProperties const& trafo) { return trafo.id == id; });
85+
it != trafos_set.end()) {
86+
return {true, it->control_side};
87+
}
88+
return {false, ControlSide{}}; // no default invalid control side, won't be used by logic
89+
}
9990

100-
std::pair<bool, ControlSide> contains_trafo3w(Idx const& id) const { return contains(trafos3w, id); }
91+
struct RegulatedObjects {
92+
// (TODO: jguo) old way, to be removed
93+
// std::set<Idx> transformers{};
94+
// std::set<Idx> transformers3w{};
95+
RegulatedTrafos trafos{};
96+
RegulatedTrafos trafos3w{};
97+
98+
std::pair<bool, ControlSide> contains_trafo(Idx const& id) const { return regulated_trafos_contain(trafos, id); }
99+
std::pair<bool, ControlSide> contains_trafo3w(Idx const& id) const {
100+
return regulated_trafos_contain(trafos3w, id);
101+
}
101102
};
102103

103104
using TransformerGraph = boost::compressed_sparse_row_graph<boost::directedS, TrafoGraphVertex, TrafoGraphEdge,
@@ -241,10 +242,10 @@ inline auto retrieve_regulator_info(State const& state) -> RegulatedObjects {
241242
}
242243
auto const control_side = regulator.control_side();
243244
if (regulator.regulated_object_type() == ComponentType::branch) {
244-
regulated_objects.transformers.emplace(regulator.regulated_object());
245+
// regulated_objects.transformers.emplace(regulator.regulated_object());
245246
regulated_objects.trafos.emplace(RegulatedTrafoProperties{regulator.regulated_object(), control_side});
246247
} else {
247-
regulated_objects.transformers3w.emplace(regulator.regulated_object());
248+
// regulated_objects.transformers3w.emplace(regulator.regulated_object());
248249
regulated_objects.trafos3w.emplace(RegulatedTrafoProperties{regulator.regulated_object(), control_side});
249250
}
250251
}

tests/cpp_unit_tests/test_tap_position_optimizer.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,7 @@ TEST_CASE("Test Transformer ranking") {
256256
CHECK(actual_edges_prop == expected_edges_prop);
257257
}
258258

259+
// (TODO: jguo) old way, to be removed
259260
SUBCASE("Automatic tap unsupported tap side at LV") {
260261
TestState bad_state;
261262
std::vector<NodeInput> bad_nodes{{0, 50e3}, {1, 10e3}};

0 commit comments

Comments
 (0)