Search in sources :

Example 1 with BiconnectivityInspector

use of org.openscience.cdk.graph.BiconnectivityInspector in project Smiles2Monomers by yoann-dufresne.

the class Biconnected method createBiconnectedComponents.

/*
	 * Function to create biconned components
	 */
@SuppressWarnings("unchecked")
public static List<Biconnected> createBiconnectedComponents(UndirectedGraph g) {
    BiconnectivityInspector bi = new BiconnectivityInspector(g);
    List<Set<UndirectedEdge>> biconnecteds = bi.biconnectedSets();
    List<Biconnected> bcs = new ArrayList<>();
    for (Set<UndirectedEdge> edges : biconnecteds) {
        HashSet<Atom> vertices = new HashSet<>();
        Iterator<UndirectedEdge> i = edges.iterator();
        while (i.hasNext()) {
            UndirectedEdge e = i.next();
            vertices.add((Atom) e.getSource());
            vertices.add((Atom) e.getTarget());
        }
        Biconnected sg = new Biconnected(g, vertices, edges);
        bcs.add(sg);
    }
    return bcs;
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) UndirectedEdge(org._3pq.jgrapht.edge.UndirectedEdge) ArrayList(java.util.ArrayList) BiconnectivityInspector(org.openscience.cdk.graph.BiconnectivityInspector) Atom(org.openscience.cdk.Atom) HashSet(java.util.HashSet)

Aggregations

ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 Set (java.util.Set)1 UndirectedEdge (org._3pq.jgrapht.edge.UndirectedEdge)1 Atom (org.openscience.cdk.Atom)1 BiconnectivityInspector (org.openscience.cdk.graph.BiconnectivityInspector)1