Esempio n. 1
0
        /// <summary>
        /// Generate the relevant cycle basis from a precomputed set of initial
        /// cycles.
        /// </summary>
        /// <param name="initial">set of initial cycles.</param>
        /// <exception cref="System.ArgumentNullException">null InitialCycles provided</exception>
        internal RelevantCycles(InitialCycles initial)
        {
            CheckNotNull(initial, nameof(initial), "No InitialCycles provided");

            this.basis = new GreedyBasis(initial.GetNumberOfCycles(), initial.GetNumberOfEdges());

            // processing by size add cycles which are independent of smaller cycles
            foreach (var length in initial.Lengths)
            {
                basis.AddAll(Independent(initial.GetCyclesOfLength(length)));
            }
        }
Esempio n. 2
0
        public virtual void AddAll()
        {
            var c1 = new Mock <Cycle>((InitialCycles)null, (ShortestPaths)null, (int[])null);
            var c2 = new Mock <Cycle>((InitialCycles)null, (ShortestPaths)null, (int[])null);

            c1.SetupGet(c => c.EdgeVector).Returns(new BitArray(0));
            c1.SetupGet(c => c.EdgeVector).Returns(new BitArray(0));
            c2.SetupGet(c => c.EdgeVector).Returns(new BitArray(0));
            var basis = new GreedyBasis(2, 0);

            Assert.IsTrue(basis.Members.Count == 0);
            basis.AddAll(new[] { c1.Object, c2.Object });
            Assert.IsTrue(basis.Members.Contains(c1.Object));
            Assert.IsTrue(basis.Members.Contains(c2.Object));
        }
Esempio n. 3
0
        public virtual void Size()
        {
            var basis = new GreedyBasis(3, 12);

            Assert.AreEqual(0, basis.Count);
            var c1 = new Mock <Cycle>((InitialCycles)null, (ShortestPaths)null, (int[])null);
            var c2 = new Mock <Cycle>((InitialCycles)null, (ShortestPaths)null, (int[])null);
            var c3 = new Mock <Cycle>((InitialCycles)null, (ShortestPaths)null, (int[])null);

            c1.SetupGet(c => c.EdgeVector).Returns(BitArrays.FromString("111000000000"));
            c2.SetupGet(c => c.EdgeVector).Returns(BitArrays.FromString("000111000000"));
            c3.SetupGet(c => c.EdgeVector).Returns(BitArrays.FromString("111111000000"));
            basis.Add(c1.Object);
            Assert.AreEqual(1, basis.Count);
            basis.Add(c2.Object);
            Assert.AreEqual(2, basis.Count);
            basis.Add(c3.Object);
            Assert.AreEqual(3, basis.Count);
        }
Esempio n. 4
0
        public virtual void SubSetOfBasis()
        {
            var c1 = new Mock <Cycle>((InitialCycles)null, (ShortestPaths)null, (int[])null);
            var c2 = new Mock <Cycle>((InitialCycles)null, (ShortestPaths)null, (int[])null);
            var c3 = new Mock <Cycle>((InitialCycles)null, (ShortestPaths)null, (int[])null);

            c1.SetupGet(c => c.EdgeVector).Returns(BitArrays.FromString("111000000000"));
            c2.SetupGet(c => c.EdgeVector).Returns(BitArrays.FromString("000111000000"));
            c3.SetupGet(c => c.EdgeVector).Returns(BitArrays.FromString("011110000000"));
            c1.SetupGet(c => c.Length).Returns(3);
            c2.SetupGet(c => c.Length).Returns(3);
            c3.SetupGet(c => c.Length).Returns(4);
            var basis = new GreedyBasis(3, 12);

            Assert.IsFalse(basis.IsSubsetOfBasis(c3.Object));
            basis.Add(c1.Object);
            Assert.IsFalse(basis.IsSubsetOfBasis(c3.Object));
            basis.Add(c2.Object);
            Assert.IsTrue(basis.IsSubsetOfBasis(c3.Object));
        }
Esempio n. 5
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);
                    }
                }
            }
        }
Esempio n. 6
0
        /// <summary>
        /// Generate the minimum cycle basis from a precomputed set of initial
        /// cycles. This constructor allows on to specify that the graph is
        /// connected which allows an optimisation to be used.
        /// </summary>
        /// <param name="initial">set of initial cycles.</param>
        /// <param name="connected">the graph is known to be connected</param>
        /// <exception cref="System.ArgumentNullException">null InitialCycles provided</exception>
        internal MinimumCycleBasis(InitialCycles initial, bool connected)
        {
            CheckNotNull(initial, nameof(initial), "No InitialCycles provided");

            this.graph = initial.Graph;
            this.basis = new GreedyBasis(initial.GetNumberOfCycles(), initial.GetNumberOfEdges());

            // a undirected unweighted connected graph there are |E| - (|V| + 1)
            // cycles in the minimum basis
            int lim = connected ? initial.GetNumberOfEdges() - graph.Length + 1 : int.MaxValue;

            // processing by size add cycles which are independent of smaller cycles
            foreach (var cycle in initial.GetCycles())
            {
                if (basis.Count < lim && basis.IsIndependent(cycle))
                {
                    basis.Add(cycle);
                }
            }
        }