/// <inheritdoc/> public Cycles Find(IAtomContainer molecule, int[][] graph, int length) { RingSearch ringSearch = new RingSearch(molecule, graph); if (this.predefinedLength < length) { length = this.predefinedLength; } IList <int[]> walks = new List <int[]>(6); // all isolated cycles are relevant - all we need to do is walk around // the vertices in the subset 'isolated' foreach (var isolated in ringSearch.Isolated()) { if (isolated.Length <= length) { walks.Add(GraphUtil.Cycle(graph, isolated)); } } // each biconnected component which isn't an isolated cycle is processed // separately as a subgraph. foreach (var fused in ringSearch.Fused()) { // make a subgraph and 'apply' the cycle computation - the walk // (path) is then lifted to the original graph foreach (var cycle in FindInFused(GraphUtil.Subgraph(graph, fused), length)) { walks.Add(Lift(cycle, fused)); } } return(new Cycles(walks.ToArray(), molecule, null)); }
/// <inheritdoc/> public Cycles Find(IAtomContainer molecule, int length) { var bondMap = EdgeToBondMap.WithSpaceFor(molecule); var graph = GraphUtil.ToAdjList(molecule, bondMap); var ringSearch = new RingSearch(molecule, graph); var walks = new List <int[]>(6); // all isolated cycles are relevant - all we need to do is walk around // the vertices in the subset 'isolated' foreach (var isolated in ringSearch.Isolated()) { if (isolated.Length <= length) { walks.Add(GraphUtil.Cycle(graph, isolated)); } } // each biconnected component which isn't an isolated cycle is processed // separately as a subgraph. foreach (var fused in ringSearch.Fused()) { // make a subgraph and 'apply' the cycle computation - the walk // (path) is then lifted to the original graph foreach (var cycle in Apply(GraphUtil.Subgraph(graph, fused), length)) { walks.Add(Lift(cycle, fused)); } } return(new Cycles(walks.ToArray(), molecule, bondMap)); }
public virtual void TestCycle() { // 0-1-2-3-4-5- int[][] g = new int[][] { new int[] { 1, 5 }, new int[] { 0, 2 }, new int[] { 1, 3 }, new int[] { 2, 4 }, new int[] { 3, 5 }, new int[] { 4, 0 } }; int[] path = GraphUtil.Cycle(g, new int[] { 0, 3, 4, 1, 5, 2 }); Assert.IsTrue(Compares.AreDeepEqual(new int[] { 0, 1, 2, 3, 4, 5, 0 }, path)); }
public virtual void TestAcyclic2() { // 0-1-2 3-4-5- (2 and 3) not connected int[][] g = new int[][] { new int[] { 1 }, new int[] { 0, 2 }, new int[] { 1 }, new int[] { 4 }, new int[] { 3, 5 }, new int[] { 4 } }; GraphUtil.Cycle(g, new int[] { 0, 3, 4, 1, 5, 2 }); }
public virtual void TestAcyclic() { // 0-1-2-3-4-5 (5 and 0 not connected) int[][] g = new int[][] { new int[] { 1 }, new int[] { 0, 2 }, new int[] { 1, 3 }, new int[] { 2, 4 }, new int[] { 3, 5 }, new int[] { 4 } }; GraphUtil.Cycle(g, new int[] { 0, 3, 4, 1, 5, 2 }); }