Search in sources :

Example 1 with UndirectedEdge

use of org._3pq.jgrapht.edge.UndirectedEdge 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)

Example 2 with UndirectedEdge

use of org._3pq.jgrapht.edge.UndirectedEdge in project Smiles2Monomers by yoann-dufresne.

the class Neighborhood method calculate.

public void calculate(ContractedGraph cg) {
    this.clear();
    for (Object o : cg.vertexSet()) {
        Vertex v = (Vertex) o;
        if (v.id.startsWith("?"))
            continue;
        int nb = 0;
        for (Object o2 : cg.edgesOf(v)) {
            UndirectedEdge e = (UndirectedEdge) o2;
            Vertex source = (Vertex) e.getSource();
            Vertex target = (Vertex) e.getTarget();
            if (source.id.startsWith("?") || target.id.startsWith("?"))
                nb++;
        }
        if (nb > 0)
            this.put(v, nb);
    }
}
Also used : Vertex(model.graph.ContractedGraph.Vertex) UndirectedEdge(org._3pq.jgrapht.edge.UndirectedEdge)

Example 3 with UndirectedEdge

use of org._3pq.jgrapht.edge.UndirectedEdge in project Smiles2Monomers by yoann-dufresne.

the class RemoveMostNeighboorsMatchs method adaptGraph.

private void adaptGraph(ContractedGraph cg, Vertex v) {
    for (Object o : cg.edgesOf(v)) {
        UndirectedEdge ue = (UndirectedEdge) o;
        Vertex source = (Vertex) ue.getSource();
        if (source.id.startsWith("?"))
            source.id = "";
        Vertex target = (Vertex) ue.getTarget();
        if (target.id.startsWith("?"))
            target.id = "";
    }
}
Also used : Vertex(model.graph.ContractedGraph.Vertex) UndirectedEdge(org._3pq.jgrapht.edge.UndirectedEdge)

Example 4 with UndirectedEdge

use of org._3pq.jgrapht.edge.UndirectedEdge in project Smiles2Monomers by yoann-dufresne.

the class Biconnected method getSegments.

/*
	 * Find segments in a biconnected graph
	 */
@SuppressWarnings("unchecked")
public List<Segment> getSegments(SimpleCycle mainCycle) {
    List<Segment> segments = new ArrayList<>();
    Set<UndirectedEdge> absents = new HashSet<>();
    // Add all graph vertices
    Iterator<UndirectedEdge> iv = this.edgeSet().iterator();
    while (iv.hasNext()) absents.add(iv.next());
    // Remove main cycle vertices.
    Iterator<UndirectedEdge> ic = mainCycle.edgeSet().iterator();
    while (ic.hasNext()) absents.remove(ic.next());
    while (absents.size() != 0) {
        // Depth first search for segments
        Set<Atom> segV = new HashSet<>();
        Set<UndirectedEdge> segE = new HashSet<>();
        Stack<UndirectedEdge> stack = new Stack<>();
        UndirectedEdge first = absents.iterator().next();
        stack.push(first);
        segE.add(first);
        while (!stack.isEmpty()) {
            Set<UndirectedEdge> edges = new HashSet<>();
            UndirectedEdge e = stack.pop();
            // Add neighbors edges non already folloed
            edges.addAll(this.edgesOf(e.getSource()));
            edges.addAll(this.edgesOf(e.getTarget()));
            for (UndirectedEdge neighbor : edges) if (absents.contains(neighbor)) {
                stack.push(neighbor);
                absents.remove(neighbor);
            }
            // Add verticies
            segV.add((Atom) e.getSource());
            segV.add((Atom) e.getTarget());
        }
        // Segment creation
        Segment seg = new Segment(segV, segE);
        segments.add(seg);
    }
    return segments;
}
Also used : UndirectedEdge(org._3pq.jgrapht.edge.UndirectedEdge) ArrayList(java.util.ArrayList) Atom(org.openscience.cdk.Atom) HashSet(java.util.HashSet) Stack(java.util.Stack)

Example 5 with UndirectedEdge

use of org._3pq.jgrapht.edge.UndirectedEdge in project Smiles2Monomers by yoann-dufresne.

the class CompatibilityGraph method isCompatible.

@SuppressWarnings("unchecked")
public boolean isCompatible(SimpleCycle mainCycle, Segment s1, Segment s2) {
    Set<Atom> inCycle = new HashSet<>(mainCycle.vertexSet());
    Stack<Atom> stack = new Stack<>();
    // Init
    Iterator<Atom> i = inCycle.iterator();
    Atom init = null;
    do {
        init = i.next();
    } while (!s2.containsVertex(init));
    inCycle.remove(init);
    stack.push(init);
    // follow path
    while (!stack.isEmpty()) {
        Atom a = stack.pop();
        if (s1.containsVertex(a))
            continue;
        List<UndirectedEdge> edges = mainCycle.edgesOf(a);
        for (UndirectedEdge e : edges) {
            if (inCycle.contains(e.getSource())) {
                inCycle.remove(e.getSource());
                stack.push((Atom) e.getSource());
            }
            if (inCycle.contains(e.getTarget())) {
                inCycle.remove(e.getTarget());
                stack.push((Atom) e.getTarget());
            }
        }
    }
    // Is compatible ?
    for (Atom a : inCycle) if (s2.containsVertex(a)) {
        return false;
    }
    return true;
}
Also used : UndirectedEdge(org._3pq.jgrapht.edge.UndirectedEdge) Atom(org.openscience.cdk.Atom) HashSet(java.util.HashSet) Stack(java.util.Stack)

Aggregations

UndirectedEdge (org._3pq.jgrapht.edge.UndirectedEdge)5 HashSet (java.util.HashSet)3 Atom (org.openscience.cdk.Atom)3 ArrayList (java.util.ArrayList)2 Stack (java.util.Stack)2 Vertex (model.graph.ContractedGraph.Vertex)2 Set (java.util.Set)1 BiconnectivityInspector (org.openscience.cdk.graph.BiconnectivityInspector)1