Exemplo n.º 1
0
        /// <summary>
        /// Given a list of cycles return those which are independent (⊕-sum)
        /// from the current basis.
        /// </summary>
        /// <param name="cycles">cycles of a given .Length</param>
        /// <returns>cycles which were independent</returns>
        private List <Cycle> Independent(IEnumerable <Cycle> cycles)
        {
            var independent = new List <Cycle>();

            foreach (var cycle in cycles)
            {
                if (basis.IsIndependent(cycle))
                {
                    independent.Add(cycle);
                }
            }
            return(independent);
        }
Exemplo n.º 2
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);
                }
            }
        }
Exemplo n.º 3
0
        public virtual void Independence()
        {
            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"));
            c1.SetupGet(c => c.Length).Returns(3);
            c2.SetupGet(c => c.Length).Returns(3);
            c3.SetupGet(c => c.Length).Returns(6);
            var basis = new GreedyBasis(3, 12);

            Assert.IsTrue(basis.IsIndependent(c1.Object));
            Assert.IsTrue(basis.IsIndependent(c2.Object));
            Assert.IsTrue(basis.IsIndependent(c3.Object));
            basis.Add(c1.Object);
            Assert.IsTrue(basis.IsIndependent(c2.Object));
            Assert.IsTrue(basis.IsIndependent(c2.Object));
            basis.Add(c2.Object);
            Assert.IsFalse(basis.IsIndependent(c3.Object));
        }