public void Convert(int n, int m, bool isDirected, Type expectedType)
        {
            AdjList net = new AdjList(Guid.NewGuid(), isDirected);
            AdjListRandomGenerator rgg = new AdjListRandomGenerator();
            rgg.NodeCount = n;
            rgg.EdgeCount = m;
            rgg.AllowSelfLoops = true;
            rgg.AllowMultiEdges = false;
            rgg.IsDirected = isDirected;
            rgg.Generate(net);

            INetwork mtrx = _Converter.Convert(net);

            Assert.IsNotNull(mtrx, "Resulting matrix should not be null");
            Assert.IsInstanceOfType(expectedType, mtrx, "Matrix type should match expected type");
            Assert.AreEqual(net.IsDirected, mtrx.IsDirected, "Directedness should match");
            Assert.AreEqual(net.NodeCount, mtrx.NodeCount, "NodeCount should match");
            Assert.AreEqual(net.EdgeCount, mtrx.EdgeCount, "EdgeCount should match");
        }
        public void ConvertToMatrix_VerifyEdges(int n, int m, bool isDirected, NetworkObjectImplementation imp, Type expectedType)
        {
            AdjList net = new AdjList(Guid.NewGuid(), isDirected);
            AdjListRandomGenerator rgg = new AdjListRandomGenerator();
            rgg.NodeCount = n;
            rgg.EdgeCount = m;
            rgg.AllowSelfLoops = true;
            rgg.AllowMultiEdges = false;
            rgg.Generate(net);

            INetworkMatrix mtrx = _Converter.ConvertToMatrix(net, imp);

            INode srcNode = null;
            INode destNode = null;
            int i=0;
            int j=0;
            double val = 0.0;

            foreach (IEdge edge in net.EdgeEnumerator)
            {
                srcNode = edge.SourceNode;
                destNode = edge.DestinationNode;
                i = srcNode.Index;
                j = destNode.Index;
                val = mtrx[i, j];
                Assert.AreNotEqual(0.0, val, string.Format("Entry [{0},{1}] should not be 0.0 for an edge.", i,j));
            }
        }
예제 #3
0
파일: NetGenerator.cs 프로젝트: BgRva/Blob1
        public static INetworkAdjList GenerateAdjList(Guid id, int n, int m, bool directed, bool allowSelfLoops, bool allowCycles, bool allowMultiEdges)
        {
            AdjList net = new AdjList(id, directed);
            AdjListRandomGenerator rgg = new AdjListRandomGenerator();
            rgg.NodeCount = n;
            rgg.EdgeCount = m;
            rgg.AllowCycles = allowCycles;
            rgg.AllowSelfLoops = allowSelfLoops;
            rgg.AllowMultiEdges = allowMultiEdges;
            rgg.IsDirected = directed;
            rgg.Generate(net);
            net.Name = string.Copy(Name);

            return net;
        }