/** * Remove switches of components which have no connected equipment, * i.e for which all vertices objects are null. * * @param topo The node-breaker view of a voltage level. */ public static void removeIsolatedSwitches(VoltageLevel.NodeBreakerView topo) { Objects.requireNonNull(topo, "Node breaker topology view is null."); int[] nodes = topo.getNodes(); final TIntSet encountered = new TIntHashSet(); final Set<Switch> encounteredSwitches = new HashSet<>(); for (int n : nodes) { if (encountered.contains(n) || topo.getTerminal(n) == null) { continue; } encountered.add(n); topo.traverse(n, (n1, sw, n2) -> { encountered.add(n2); encounteredSwitches.add(sw); return topo.getTerminal(n2) == null; }); } List<Switch> toRemove = topo.getSwitchStream().filter(sw -> !encounteredSwitches.contains(sw)).collect(Collectors.toList()); for (Switch sw : toRemove) { topo.removeSwitch(sw.getId()); } }
private void writeNodeBreakerTopologyInternalConnections(VoltageLevel vl, NetworkXmlWriterContext context) { VoltageLevel.NodeBreakerView topo = vl.getNodeBreakerView(); int[] nodes = topo.getNodes(); // There is no way in IIDM to obtain the list of internal connections, // we have to traverse all connectivity and consider an internal connection // when there are two nodes linked with an edge that does not have an // associated object final TIntSet explored = new TIntHashSet(); for (int n : nodes) { if (explored.contains(n)) { continue; } explored.add(n); topo.traverse(n, (n1, sw, n2) -> { explored.add(n2); if (sw == null) { writeNodeBreakerTopologyInternalConnection(n1, n2, context); } return true; }); } }