All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.powsybl.cgmes.conversion.elements.hvdc.Islands Maven / Gradle / Ivy

There is a newer version: 6.6.0
Show newest version
/**
 * Copyright (c) 2020, 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/.
 */

package com.powsybl.cgmes.conversion.elements.hvdc;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

/**
 *
 * @author Luma Zamarreño {@literal }
 * @author José Antonio Marqués {@literal }
 */
class Islands {
    private final List> islandsNodes;

    // The island includes dcNodes(topological or connectivity) and the
    // acNodes(topological or connectivity) at both ends of the transformer
    Islands(Adjacency adjacency) {
        islandsNodes = new ArrayList<>();

        Set visitedNodes = new HashSet<>();
        adjacency.get().keySet().forEach(nodeId -> {
            if (visitedNodes.contains(nodeId)) {
                return;
            }
            ArrayList adjacentNodes = computeAdjacentNodes(nodeId,
                adjacency, visitedNodes);
            islandsNodes.add(adjacentNodes);
        });
    }

    private static ArrayList computeAdjacentNodes(String nodeId,
        Adjacency adjacency, Set visitedNodes) {

        ArrayList adjacentNodes = new ArrayList<>();
        adjacentNodes.add(nodeId);
        visitedNodes.add(nodeId);

        int k = 0;
        while (k < adjacentNodes.size()) {
            String node = adjacentNodes.get(k);
            if (adjacency.get().containsKey(node)) {
                adjacency.get().get(node).forEach(adjacent -> {
                    if (visitedNodes.contains(adjacent.node)) {
                        return;
                    }
                    adjacentNodes.add(adjacent.node);
                    visitedNodes.add(adjacent.node);
                });
            }
            k++;
        }
        return adjacentNodes;
    }

    List> getIslandsNodes() {
        return islandsNodes;
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy