Skip to content

Commit ebe0692

Browse files
Merge pull request #70 from alliander-opensource/fix/bug-bus-reorder
Bug in bus reorder
2 parents 305b3c9 + ef8daa7 commit ebe0692

File tree

2 files changed

+18
-15
lines changed

2 files changed

+18
-15
lines changed

include/power_grid_model/topology.hpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,9 @@ class Topology {
319319
continue;
320320
}
321321
GraphIdx const j = (GraphIdx)node_status_[global_j];
322-
boost::add_edge(i, j, graph);
322+
if (!boost::edge(i, j, graph).second) {
323+
boost::add_edge(i, j, graph);
324+
}
323325
}
324326
}
325327
// start minimum degree ordering

tests/cpp_unit_tests/test_topology.cpp

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -60,29 +60,29 @@
6060
* 5 \ 6 10 2
6161
* | v | v |
6262
* [0:s0] --0--> [1] --1--> [2]
63-
* ^ ^ ^
64-
* | -11-/ |
63+
* ^ ^ <- 12- ^
64+
* | -11-/ parallel |
6565
* 7 / |
6666
* | / |
6767
* [6] -----------------8--
6868
*
6969
* Math model after reodering
7070
*
71-
* [4] <---4--[1] <--3- [3]
71+
* [4] <---4--[0] <--3- [3]
7272
* ^ \ ^ / ^
7373
* | 9---- | / |
7474
* 5 \ 6 10 2
7575
* | v | v |
76-
* [2:s0] --0--> [5] --1--> [6]
77-
* ^ ^ ^
78-
* | -11-/ |
76+
* [2:s0] --0--> [5] --1--> [1]
77+
* ^ ^ <- 12- ^
78+
* | -11-/ parallel |
7979
* 7 / |
8080
* | / |
81-
* [0] -----------------8--
81+
* [6] -----------------8--
8282
*
8383
* Extra fill-in:
84-
* (2, 6) by removing node 0
85-
* (3, 4) by removing node 1
84+
* (3, 4) by removing node 0
85+
* (3, 6) by removing node 1
8686
* (4, 6) by removing node 2
8787
*/
8888

@@ -317,22 +317,23 @@ TEST_CASE("Test cycle reorder") {
317317
{3, 4}, // 3
318318
{4, 5}, // 4
319319
{0, 5}, // 5
320-
{6, 0}, // 6
321-
{4, 5}, // 7
320+
{1, 4}, // 6
321+
{6, 0}, // 7
322322
{6, 2}, // 8
323323
{5, 1}, // 9
324324
{3, 1}, // 10
325325
{6, 1}, // 11
326+
{6, 5}, // 12
326327
};
327328
comp_topo.source_node_idx = {0};
328329
// component connection
329330
ComponentConnections comp_conn{};
330-
comp_conn.branch_connected = std::vector<BranchConnected>(12, {1, 1});
331-
comp_conn.branch_phase_shift = std::vector<double>(12, 0.0);
331+
comp_conn.branch_connected = std::vector<BranchConnected>(13, {1, 1});
332+
comp_conn.branch_phase_shift = std::vector<double>(13, 0.0);
332333
comp_conn.source_connected = {1};
333334
// result
334335
ComponentToMathCoupling comp_coup_ref{};
335-
comp_coup_ref.node = {{0, 2}, {0, 5}, {0, 6}, {0, 3}, {0, 1}, {0, 4}, {0, 0}};
336+
comp_coup_ref.node = {{0, 2}, {0, 5}, {0, 1}, {0, 3}, {0, 0}, {0, 4}, {0, 6}};
336337

337338
Topology topo{comp_topo, comp_conn};
338339
auto pair = topo.build_topology();

0 commit comments

Comments
 (0)