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;
}
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);
}
}
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 = "";
}
}
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;
}
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;
}
Aggregations