예제 #1
0
                /// <inheritdoc/>
                public override int[][] Apply(int[][] graph, int length)
                {
                    InitialCycles  ic = InitialCycles.OfBiconnectedComponent(graph, length);
                    RelevantCycles rc = new RelevantCycles(ic);

                    return(new EssentialCycles(rc, ic).GetPaths());
                }
예제 #2
0
        public virtual void Size_cyclophane_odd()
        {
            int[][]        cyclophane_even = CyclophaneEven;
            RelevantCycles relevant        = new RelevantCycles(cyclophane_even);

            Assert.AreEqual(3, relevant.Count());
        }
예제 #3
0
        public virtual void Size_anthracene()
        {
            int[][]        anthracene = Anthracene;
            RelevantCycles relevant   = new RelevantCycles(anthracene);

            Assert.AreEqual(3, relevant.Count());
        }
예제 #4
0
        public virtual void Size_napthalene()
        {
            int[][]        napthalene = Naphthalene;
            RelevantCycles relevant   = new RelevantCycles(napthalene);

            Assert.AreEqual(2, relevant.Count());
        }
예제 #5
0
        public virtual void Size_bicyclo()
        {
            int[][]        bicyclo  = Bicyclo;
            RelevantCycles relevant = new RelevantCycles(bicyclo);

            Assert.AreEqual(3, relevant.Count());
        }
예제 #6
0
        public virtual void Size_norbornane()
        {
            int[][]        norbornane = Norbornane;
            RelevantCycles relevant   = new RelevantCycles(norbornane);

            Assert.AreEqual(2, relevant.Count());
        }
예제 #7
0
        public virtual void Paths_anthracene()
        {
            int[][]        anthracene = Anthracene;
            RelevantCycles relevant   = new RelevantCycles(anthracene);

            int[][] paths = relevant.GetPaths();
            Assert.AreEqual(3, paths.Length);
            int[][] expected = new int[][] { new[] { 5, 0, 1, 2, 3, 4, 5 }, new[] { 9, 6, 5, 4, 7, 8, 9 }, new[] { 9, 8, 10, 11, 12, 13, 9 } };
            Assert.IsTrue(Compares.AreOrderLessDeepEqual(expected, paths));
        }
예제 #8
0
        public virtual void Paths_napthalene()
        {
            int[][]        napthalene = Naphthalene;
            RelevantCycles relevant   = new RelevantCycles(napthalene);

            int[][] paths = relevant.GetPaths();
            Assert.AreEqual(2, paths.Length);
            int[][] expected = new int[][] { new[] { 5, 0, 1, 2, 3, 4, 5 }, new[] { 5, 4, 7, 8, 9, 6, 5 } };
            Assert.IsTrue(Compares.AreOrderLessDeepEqual(expected, paths));
        }
예제 #9
0
        public virtual void Paths_bicyclo()
        {
            int[][]        bicyclo  = Bicyclo;
            RelevantCycles relevant = new RelevantCycles(bicyclo);

            int[][] paths = relevant.GetPaths();
            Assert.AreEqual(3, paths.Length);
            int[][] expected = new int[][] { new[] { 5, 0, 1, 2, 3, 4, 5 }, new[] { 5, 0, 1, 2, 7, 6, 5 }, new[] { 5, 4, 3, 2, 7, 6, 5 } };
            Assert.IsTrue(Compares.AreOrderLessDeepEqual(expected, paths));
        }
예제 #10
0
        public virtual void Paths_norbornane()
        {
            int[][]        norbornane = Norbornane;
            RelevantCycles relevant   = new RelevantCycles(norbornane);

            int[][] paths = relevant.GetPaths();
            Assert.AreEqual(2, paths.Length);
            int[][] expected = new int[][] { new[] { 5, 6, 2, 1, 0, 5 }, new[] { 5, 6, 2, 3, 4, 5 } };
            Assert.IsTrue(Compares.AreOrderLessDeepEqual(expected, paths));
        }
예제 #11
0
        public virtual void Paths_cyclophane_even()
        {
            int[][]        cyclophane_even = CyclophaneEven;
            RelevantCycles relevant        = new RelevantCycles(cyclophane_even);

            int[][] paths = relevant.GetPaths();
            Assert.AreEqual(3, paths.Length);
            int[][] expected = new int[][] { new int[] { 3, 2, 1, 0, 5, 4, 3 }, new int[] { 3, 6, 7, 8, 9, 10, 11, 0, 1, 2, 3 },
                                             new int[] { 3, 6, 7, 8, 9, 10, 11, 0, 5, 4, 3 } };
            Assert.IsTrue(Compares.AreOrderLessDeepEqual(expected, paths));
        }
예제 #12
0
        void Main()
        {
            {
                #region
                // using NCDK.Graphs.GraphUtil;
                IAtomContainer m = TestMoleculeFactory.MakeAnthracene();

                // compute on the whole graph
                RelevantCycles relevant = new RelevantCycles(ToAdjList(m));

                // it is much faster to compute on the separate ring systems of the molecule
                int[][]    graph      = ToAdjList(m);
                RingSearch ringSearch = new RingSearch(m, graph);

                // all isolated cycles are relevant
                foreach (int[] isolated in ringSearch.Isolated())
                {
                    int[] path = Cycle(graph, isolated);
                }

                // compute the relevant cycles for each system
                foreach (int[] fused in ringSearch.Fused())
                {
                    int[][]        subgraph           = Subgraph(graph, fused);
                    RelevantCycles relevantOfSubgraph = new RelevantCycles(subgraph);

                    foreach (int[] path in relevantOfSubgraph.GetPaths())
                    {
                        // convert the sub graph vertices back to the super graph indices
                        for (int i = 0; i < path.Length; i++)
                        {
                            path[i] = fused[path[i]];
                        }
                    }
                }
                #endregion
            }
            {
                IAtomContainer mol = null;
                #region GetPaths
                RelevantCycles relevant = new RelevantCycles(ToAdjList(mol));

                // ensure the number is manageable
                if (relevant.Count() < 100)
                {
                    foreach (int[] path in relevant.GetPaths())
                    {
                        // process the path
                    }
                }
                #endregion
            }
        }
예제 #13
0
        /// <summary>
        /// Determine the essential cycles from a precomputed set of initial cycles
        /// and relevant cycles.
        /// </summary>
        /// <param name="relevant"></param>
        /// <param name="initial">a molecule graph</param>
        internal EssentialCycles(RelevantCycles relevant, InitialCycles initial)
        {
            CheckNotNull(relevant, nameof(relevant), "No RelevantCycles provided");
            this.initial   = CheckNotNull(initial, nameof(initial), "No InitialCycles provided");
            this.basis     = new GreedyBasis(initial.GetNumberOfCycles(), initial.GetNumberOfEdges());
            this.essential = new List <Cycle>();

            // for each cycle added to the basis, if it can be
            // replaced with one of equal size it is non-essential
            foreach (var cycles in GroupByLength(relevant))
            {
                foreach (var c in GetMembersOfBasis(cycles))
                {
                    if (IsEssential(c, cycles))
                    {
                        essential.Add(c);
                    }
                }
            }
        }
예제 #14
0
        /// <summary>
        /// Reconstruct all relevant cycles and group then by length.
        /// </summary>
        /// <param name="relevant">precomputed relevant cycles</param>
        /// <returns>all relevant cycles groped by weight</returns>
        private IEnumerable <IList <Cycle> > GroupByLength(RelevantCycles relevant)
        {
            List <Cycle> cycle_list = new List <Cycle>();

            foreach (var path in relevant.GetPaths())
            {
                var last = cycle_list.LastOrDefault();
                if (last != null && path.Length > last.Path.Length)
                {
                    yield return(cycle_list);

                    cycle_list = new List <Cycle>();
                }
                cycle_list.Add(new MyCycle(this, path));
            }
            if (cycle_list.Count > 0)
            {
                yield return(cycle_list);
            }
            yield break;
        }