public void ConvertToMatrix(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.IsDirected = isDirected;
            rgg.Generate(net);

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

            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");
        }
Esempio n. 2
0
        /// <summary>
        /// Creates an instance of IRandomGenerator appropriate to <paramref name="imp"/> and <paramref name="structure"/>.
        /// The returned object can be used to create a randome network.  How to use:<code>
        ///    IRandomGenerator rg = new ToolMakerCreateRandomGenerator(NetworkObjectImplementation.Sigma, NetworkObjectStructure.AdjacencyList);
        ///    rg.NodeCount = 10;
        ///    rg.EdgeCount = 20;
        ///    INetwork network = rg.Generate();
        /// </code>
        /// </summary>
        /// <param name="imp">The NetworkObjectImplementation of the desired random network.</param>
        /// <param name="structure">The NetworkObjectStructure of the desired random network</param>
        /// <returns>An IRandomGenerator instance</returns>
        internal static IRandomGenerator CreateRandomGenerator(NetworkObjectImplementation imp, NetworkObjectStructure structure)
        {
            IRandomGenerator tool = null;
            if (imp == NetworkObjectImplementation.Default)
            {
                if (structure == NetworkObjectStructure.AdjacencyList || structure == NetworkObjectStructure.Default)
                    tool = new AdjacentList.Y.AdjListRandomGenerator();
                else if (structure == NetworkObjectStructure.Matrix)
                    tool = new BlueSpider.Blob.Network.Matrix.CSpace.MatrixRandomGenerator();
            }
            else if (imp == NetworkObjectImplementation.Psi)
            {
                if (structure == NetworkObjectStructure.AdjacencyList || structure == NetworkObjectStructure.Default)
                    tool = new AdjacentList.Y.AdjListRandomGenerator();
            }
            else if (imp == NetworkObjectImplementation.Gamma)
            {
                if (structure == NetworkObjectStructure.Matrix || structure == NetworkObjectStructure.Default)
                    tool = new BlueSpider.Blob.Network.Matrix.CSpace.MatrixRandomGenerator();
            }

            return tool;
        }
        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));
            }
        }
Esempio n. 4
0
 internal IRandomGenerator _CreateRandomGenerator(NetworkObjectImplementation imp, NetworkObjectStructure structure)
 {
     IRandomGenerator tool = null;
     if (imp == NetworkObjectImplementation.Sigma)
     {
         if (structure == NetworkObjectStructure.AdjacencyList || structure == NetworkObjectStructure.Default)
         {
             tool = new BlueSpider.Blob.Regular.Network.AdjList.SimpleAdjListRandomGenerator();
         }
         else if (structure == NetworkObjectStructure.Matrix)
         {
             throw new NotImplementedException();
         }
     }
     return tool;
 }
Esempio n. 5
0
 /// <summary>
 /// Creates an instance of IRandomGenerator appropriate to <paramref name="imp"/> and <paramref name="structure"/>.
 /// The returned object can be used to create a randome network.  How to use:<code>
 ///    IRandomGenerator rg = new ToolMakerCreateRandomGenerator(NetworkObjectImplementation.Sigma, NetworkObjectStructure.AdjacencyList);
 ///    rg.NodeCount = 10;
 ///    rg.EdgeCount = 20;
 ///    INetwork network = rg.Generate();
 /// </code>
 /// </summary>
 /// <param name="imp">The NetworkObjectImplementation of the desired random network.</param>
 /// <param name="structure">The NetworkObjectStructure of the desired random network</param>
 /// <returns>An IRandomGenerator instance</returns>
 public IRandomGenerator CreateRandomGenerator(NetworkObjectImplementation imp, NetworkObjectStructure structure)
 {
     return _CreateRandomGenerator(imp, structure);
 }
Esempio n. 6
0
        public void CreateRandomGenerator_NotSupported(NetworkObjectImplementation imp, NetworkObjectStructure structure)
        {
            IRandomGenerator rgg = _Provider._CreateRandomGenerator(imp, structure);

            Assert.IsNull(rgg, "The returned IRandomGenerator should be null");
        }
Esempio n. 7
0
 public void CreateRandomGenerator_NotImplemented(NetworkObjectImplementation imp, NetworkObjectStructure structure)
 {
     IRandomGenerator rgg = _Provider._CreateRandomGenerator(imp, structure);
 }
Esempio n. 8
0
        public void CreateRandomGenerator(NetworkObjectImplementation imp, NetworkObjectStructure structure, Type expectedType)
        {
            IRandomGenerator rgg = _Provider._CreateRandomGenerator(imp, structure);

            Assert.IsNotNull(rgg, "The returned IRandomGenerator should not be null");
            Assert.IsInstanceOfType(expectedType, rgg, string.Format("Concrete type for the IRandomGenerator should be of type {0}", expectedType));
        }