Esempio n. 1
0
            /// <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));
            }
Esempio n. 2
0
            /// <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));
            }
Esempio n. 3
0
 public virtual void SequentialSubgraph()
 {
     int[][] graph    = new int[][] { new int[] { 1, 2 }, new int[] { 0, 2 }, new int[] { 0, 1 } };
     int[][] subgraph = GraphUtil.Subgraph(graph, new int[] { 0, 1 });
     int[][] expected = new int[][] { new int[] { 1 }, new int[] { 0 } };
     Assert.IsTrue(Compares.AreDeepEqual(expected, subgraph));
 }
Esempio n. 4
0
 public virtual void IntermittentSubgraph()
 {
     int[][]
             graph    = new int[][] { new int[] { 1, 2 }, new int[] { 0, 2, 3 }, new int[] { 0, 1 }, new int[] { 1 } };
     int[][] subgraph = GraphUtil.Subgraph(graph, new int[] { 0, 2, 3 });
     int[][] expected = new int[][] { new int[] { 1 }, new int[] { 0 }, new int[] { } };
     Assert.IsTrue(Compares.AreDeepEqual(expected, subgraph));
 }
Esempio n. 5
0
        public void Main()
        {
            var naphthalene = TestMoleculeFactory.MakeNaphthalene();

            #region Subgraph
            int[][] g  = GraphUtil.ToAdjList(naphthalene);
            int[]   vs = new int[] { 0, 1, 2, 3, 4, 5 };

            int[][] h = GraphUtil.Subgraph(g, vs);
            // for the vertices in h, the provided 'vs' gives the original index
            for (int v = 0; v < h.Length; v++)
            {
                // vs[v] is 'v' in 'g'
            }
            #endregion
        }
Esempio n. 6
0
 public virtual void ResizeSubgraph()
 {
     int[][] graph = new int[][] {
         new int[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14 },
         new int[] { 0 }, new int[] { 0 }, new int[] { 0 }, new int[] { 0 },
         new int[] { 0 }, new int[] { 0 }, new int[] { 0 }, new int[] { 0 },
         new int[] { 0 }, new int[] { 0 }, new int[] { 0 }, new int[] { 0 },
         new int[] { 0 }, new int[] { 0 }
     };
     int[][] subgraph = GraphUtil.Subgraph(graph, new int[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 });
     int[][] expected = new int[][] {
         new int[] { 1, 2, 3, 4, 5, 6, 7, 8, 9 },
         new int[] { 0 }, new int[] { 0 }, new int[] { 0 }, new int[] { 0 },
         new int[] { 0 }, new int[] { 0 }, new int[] { 0 }, new int[] { 0 },
         new int[] { 0 },
     };
     Assert.IsTrue(Compares.AreDeepEqual(expected, subgraph));
 }
Esempio n. 7
0
        public static void Main(string[] args)
        {
            // convert the molecule to adjacency list - may be redundant in future
            IAtomContainer m = TestMoleculeFactory.MakeAlphaPinene();

            int[][] g = GraphUtil.ToAdjList(m);

            // efficient computation/partitioning of the ring systems
            RingSearch rs = new RingSearch(m, g);

            // isolated cycles don't need to be run
            rs.Isolated();

            // process fused systems separately
            foreach (var fused in rs.Fused())
            {
                const int maxDegree = 100;
                // given the fused subgraph, max cycle size is
                // the number of vertices
                AllCycles ac = new AllCycles(GraphUtil.Subgraph(g, fused), fused.Length, maxDegree);
                // cyclic walks
                int[][] paths = ac.GetPaths();
            }
        }