-
Notifications
You must be signed in to change notification settings - Fork 2
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
Get switches and internal connections from given node (#391) #422
base: integration/v1.6.0
Are you sure you want to change the base?
Changes from all commits
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 |
---|---|---|
|
@@ -54,19 +54,29 @@ class UndirectedGraph { | |
|
||
const stdcxx::Reference<E>& getEdgeObject(unsigned long e) const; | ||
|
||
const_range<E> getEdgeObjectsConnectedToVertex(unsigned long vertex) const; | ||
|
||
const std::vector<unsigned long>& getEdgeConnectedToVertex(unsigned long vertex) const; | ||
|
||
const std::vector<unsigned long>& getEdgesConnectedToVertex(unsigned long vertex) const; | ||
|
||
const_range<E> getEdgeObjects() const; | ||
|
||
range<E> getEdgeObjects(); | ||
|
||
const_range<E> getEdgeObjects(unsigned long v1, unsigned long v2) const; | ||
|
||
const unsigned long& getEdgeVertex1(unsigned long edge) const; | ||
|
||
const unsigned long& getEdgeVertex2(unsigned long edge) const; | ||
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. To be discussed: not sure this is a good idea to return a reference here. |
||
|
||
const_range<unsigned long> getEdges() const; | ||
|
||
unsigned long getMaxVertex() const; | ||
|
||
unsigned long getVertex1(unsigned long e) const; | ||
const unsigned long& getVertex1(unsigned long e) const; | ||
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. To be discussed: I think it's not wrong, I had to update that in order to return a range in 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. I have to think a little bit more about the issue you encountered |
||
|
||
unsigned long getVertex2(unsigned long e) const; | ||
const unsigned long& getVertex2(unsigned long e) const; | ||
|
||
unsigned long getVertexCapacity() const; | ||
|
||
|
@@ -148,9 +158,9 @@ class UndirectedGraph<V, E>::Edge { | |
|
||
const stdcxx::Reference<E>& getObject() const; | ||
|
||
unsigned long getVertex1() const; | ||
const unsigned long& getVertex1() const; | ||
|
||
unsigned long getVertex2() const; | ||
const unsigned long& getVertex2() const; | ||
|
||
void setObject(const stdcxx::Reference<E>& object); | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,6 +12,7 @@ | |
#include <set> | ||
#include <string> | ||
|
||
#include <powsybl/PowsyblException.hpp> | ||
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. I'm not sure you should add this include in a header. |
||
#include <powsybl/iidm/VariantArray.hpp> | ||
#include <powsybl/iidm/VoltageLevel.hpp> | ||
#include <powsybl/math/UndirectedGraph.hpp> | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -213,6 +213,19 @@ stdcxx::const_range<unsigned long> NodeBreakerViewImpl::getNodes() const { | |
return m_voltageLevel.getGraph().getVertices(); | ||
} | ||
|
||
stdcxx::const_range<unsigned long> NodeBreakerViewImpl::getNodesInternalConnectedTo(unsigned long node) const { | ||
const auto& isNull = [this](const unsigned long& edge) { | ||
return !static_cast<bool>(m_voltageLevel.getGraph().getEdgeObject(edge)); | ||
}; | ||
|
||
const auto& mapper = [this, node](const unsigned long& edge) -> const unsigned long& { | ||
unsigned long vertex1 = m_voltageLevel.getGraph().getEdgeVertex1(edge); | ||
return vertex1 != node ? m_voltageLevel.getGraph().getEdgeVertex1(edge) : m_voltageLevel.getGraph().getEdgeVertex2(edge); | ||
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. We should avoid this useless call to |
||
}; | ||
|
||
return m_voltageLevel.getGraph().getEdgeConnectedToVertex(node) | boost::adaptors::filtered(isNull) | boost::adaptors::transformed(mapper); | ||
} | ||
|
||
stdcxx::CReference<Terminal> NodeBreakerViewImpl::getOptionalTerminal(unsigned long node) const { | ||
if (m_voltageLevel.getGraph().vertexExists(node)) { | ||
return stdcxx::cref<Terminal>(m_voltageLevel.getGraph().getVertexObject(node)); | ||
|
@@ -259,6 +272,30 @@ stdcxx::range<Switch> NodeBreakerViewImpl::getSwitches() { | |
return m_voltageLevel.getGraph().getEdgeObjects() | boost::adaptors::filtered(filter) | boost::adaptors::transformed(mapper); | ||
} | ||
|
||
stdcxx::const_range<Switch> NodeBreakerViewImpl::getSwitches(unsigned long node) const { | ||
const auto& notNull = [](const stdcxx::Reference<Switch>& sw) { | ||
return static_cast<bool>(sw); | ||
}; | ||
|
||
const auto& deref = [](const stdcxx::Reference<Switch>& sw) -> const Switch& { | ||
sebalaig marked this conversation as resolved.
Show resolved
Hide resolved
|
||
return sw.get(); | ||
}; | ||
|
||
return m_voltageLevel.getGraph().getEdgeObjectsConnectedToVertex(node) | boost::adaptors::filtered(notNull) | boost::adaptors::transformed(deref); | ||
} | ||
|
||
stdcxx::range<Switch> NodeBreakerViewImpl::getSwitches(unsigned long node) { | ||
const auto& notNull = [](const stdcxx::Reference<Switch>& sw) { | ||
return static_cast<bool>(sw); | ||
}; | ||
|
||
const auto& deref = [](const stdcxx::Reference<Switch>& sw) -> Switch& { | ||
return sw.get(); | ||
}; | ||
sebalaig marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
return m_voltageLevel.getGraph().getEdgeObjectsConnectedToVertex(node) | boost::adaptors::filtered(notNull) | boost::adaptors::transformed(deref); | ||
} | ||
|
||
stdcxx::CReference<Terminal> NodeBreakerViewImpl::getTerminal(unsigned long node) const { | ||
return stdcxx::cref(m_voltageLevel.getTerminal(node)); | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure we have to keep this method. It seems you backport the
IntStream getEdgeConnectedToVertexStream(int v);
method, but from my point of view, anS
is missing in the name of the method.