-
Notifications
You must be signed in to change notification settings - Fork 11
[WIP] Check too far generator voltage remote control #1119
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
7dbba4b
18db0ad
04fd630
1b61b80
ecacea0
37bc4c6
3fede3d
936cc66
df97ff4
d4e082d
084eccb
0625c7d
73ff722
f1ea70b
60ad03a
8553815
e6ba659
cd3e1c0
f0a45dc
8247d88
fbbf0ed
1f1141d
bc4bb8c
68e2d10
6e566fd
9c8c5b2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,57 @@ | ||
| /** | ||
| * Copyright (c) 2024, RTE (http://www.rte-france.com) | ||
| * This Source Code Form is subject to the terms of the Mozilla Public | ||
| * License, v. 2.0. If a copy of the MPL was not distributed with this | ||
| * file, You can obtain one at http://mozilla.org/MPL/2.0/. | ||
| * SPDX-License-Identifier: MPL-2.0 | ||
| */ | ||
|
|
||
| package com.powsybl.openloadflow.util; | ||
|
|
||
| import com.powsybl.openloadflow.network.LfBus; | ||
|
|
||
| import java.util.HashSet; | ||
| import java.util.Objects; | ||
| import java.util.Set; | ||
| import java.util.stream.Collectors; | ||
|
|
||
| /** | ||
| * @author Sylvestre Prabakaran {@literal <sylvestre.prabakaran at rte-france.com>} | ||
| */ | ||
| public final class BusDistance { | ||
|
|
||
| private BusDistance() { | ||
| } | ||
|
|
||
| /** | ||
| * Breadth first search algorithm to compute distance between two LfBus in a network | ||
| * @param bus1 first LfBus (from which the breadth first search starts) | ||
SylvestreSakti marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| * @param bus2 second LfBus (searched bus) | ||
| * @param maxDistanceSearch the algorithm searches until this range and stops after this limit (or if every bus have been checked) | ||
| * @return measured distance (number of branches) or Integer.MAX_VALUE if bus2 is not found | ||
SylvestreSakti marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| */ | ||
| public static int distanceBetweenBuses(LfBus bus1, LfBus bus2, int maxDistanceSearch) { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is an unusual way to implement a BFS. We can do it much simpler without these kind of set manipulation (busesToCheck.removeAll(checkedBuses)). Also we should take care for a BFS to have an orderer neighbors traversal (be careful with HashSets)
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you add a unit test for the method with various cases (exected distance, farther than maxDistance etc..)
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Reading again more conventional ways to implement breadth First Search (e.g. https://www.baeldung.com/java-breadth-first-search), I don't know (or I don't find) simpler ways to implement this. Here I chose this way of using sets for multiple reasons :
With this way of iteration (levels of distance) is it important to have an ordered neighbors traversal ?
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ok |
||
| Objects.requireNonNull(bus1); | ||
| Objects.requireNonNull(bus2); | ||
| if (bus1.equals(bus2)) { | ||
| return 0; | ||
| } | ||
| Set<LfBus> busesToCheck = new HashSet<>(); | ||
| Set<LfBus> checkedBuses = new HashSet<>(); | ||
| busesToCheck.add(bus1); | ||
| checkedBuses.add(bus1); | ||
| for (int distance = 1; distance <= maxDistanceSearch; distance++) { | ||
| busesToCheck = busesToCheck.stream() | ||
| .flatMap(bus -> bus.findNeighbors().keySet().stream()) | ||
| .collect(Collectors.toSet()); | ||
| busesToCheck.removeAll(checkedBuses); | ||
| if (busesToCheck.contains(bus2)) { | ||
| return distance; | ||
| } else if (busesToCheck.isEmpty()) { | ||
| return Integer.MAX_VALUE; | ||
| } | ||
| checkedBuses.addAll(busesToCheck); | ||
| } | ||
| return Integer.MAX_VALUE; | ||
| } | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.