Exemplo n.º 1
0
    // Use this for initialization
    void Start()
    {
        //测试图的基本功能
//		testGraphBasicOperation ();
        //从File读取图
        print("*********测试稠密图的读取文件获得数据*********");
        string     filename1 = "testG1.txt";
        string     filename2 = "testG2.txt";
        string     url       = FileHelper.FileNameHelper(filename1);
        bool       isDirect  = false;
        DenseGraph dGraph    = null;

        ReadGraph.ReadGraphFromFile(url, out dGraph, isDirect);
        dGraph.print();

        dGraph = null;
        ReadGraph.ReadGraphFromFile(url, out dGraph, isDirect);
        url = FileHelper.FileNameHelper(filename2);
        ReadGraph.ReadGraphFromFile(url, out dGraph, isDirect);
        dGraph.print();
        print("*******************************************");

        print("*********测试稀疏图的读取文件获得数据*********");
        url = FileHelper.FileNameHelper(filename1);
        SpareGraph sGraph = null;

        ReadGraph.ReadGraphFromFile(url, out sGraph, isDirect);
        sGraph.print();

        sGraph = null;
        ReadGraph.ReadGraphFromFile(url, out sGraph, isDirect);
        url = FileHelper.FileNameHelper(filename2);
        ReadGraph.ReadGraphFromFile(url, out sGraph, isDirect);
        sGraph.print();
    }
        public void ComponentTest()
        {
            string fileName   = @"Graph\testG1.txt";
            var    g1         = new SparseGraph <double>(13, false);
            var    gr1        = new ReadGraph <double>(g1, fileName);
            var    component1 = new Component <double>(g1);

            Console.WriteLine(component1.Count());
        }
        public void ShortestPathTest()
        {
            string fileName = @"Graph\testG2.txt";
            var    g1       = new SparseGraph <double>(7, false);
            var    gr1      = new ReadGraph <double>(g1, fileName);

            g1.Show();
            var path = new ShortestPath <double>(g1, 0);

            Console.WriteLine("BFS: ");
            path.ShowPath(6);
        }
Exemplo n.º 4
0
    // Use this for initialization
    void Start()
    {
        string     filename = "testG1.txt";
        SpareGraph sGraph   = null;
        string     url      = FileHelper.FileNameHelper(filename);

        ReadGraph.ReadGraphFromFile(url, out sGraph, false);
        sGraph.print();
        Components SpareGraphcomponent = new Components(sGraph);

        SpareGraphcomponent.MinLength1(0);
        SpareGraphcomponent.MinLength(0);
    }
        public void ReadGraphTest()
        {
            string fileName = @"Graph\testG1.txt";

            var g1  = new SparseGraph <double>(13, false);
            var rg1 = new ReadGraph <double>(g1, fileName);

            g1.Show();

            var g2  = new DenseGraph <double>(13, false);
            var rg2 = new ReadGraph <double>(g2, fileName);

            g2.Show();
        }
Exemplo n.º 6
0
    public void testNormalComponent()
    {
        print("******测试稠密图的深度优先搜索******");
        DenseGraph dGraph   = null;
        string     filename = "testG1.txt";
        string     url      = FileHelper.FileNameHelper(filename);

        ReadGraph.ReadGraphFromFile(url, out dGraph, false);
        Components DenseGraphcomponent = new Components(dGraph);

        print("******测试稀疏图的深度优先搜索******");
        SpareGraph sGraph = null;

        url = FileHelper.FileNameHelper(filename);
        ReadGraph.ReadGraphFromFile(url, out sGraph, false);
        sGraph.print();
        Components SpareGraphcomponent = new Components(sGraph);
    }
Exemplo n.º 7
0
        static void Main(string[] args)
        {
            string fileName = @"Graph\testG1.txt";
            var    g1       = new SparseGraph <double>(8, false);
            var    gr1      = new ReadGraph <double>(g1, fileName);

            g1.Show();

            // test Kruskal
            Console.WriteLine("Test Kruskal: ");
            var kruskalMST = new KruskalMST <double>(g1);
            var mst        = kruskalMST.MSTEdges;

            foreach (var edge in mst)
            {
                Console.WriteLine(edge);
            }
            Console.WriteLine("The MST weight is: " + kruskalMST.MSTWeight);
        }
Exemplo n.º 8
0
        public void TestPrimMST()
        {
            string fileName = @"Graph\testG1.txt";
            var    g1       = new SparseGraph <double>(8, false);
            var    gr1      = new ReadGraph <double>(g1, fileName);

            g1.Show();

            // test prim
            Console.WriteLine("Test Prim MST: ");
            var primMST = new PrimMST <double>(g1);
            var mst     = primMST.MSTEdges;

            foreach (var edge in mst)
            {
                Console.WriteLine(edge);
            }
            Console.WriteLine("The MST weight is: " + primMST.MSTWeight);
        }
Exemplo n.º 9
0
        public void TestLazyPrimMST()
        {
            string fileName = @"Graph\testG1.txt";
            var    g1       = new SparseGraph <double>(8, false);
            var    gr1      = new ReadGraph <double>(g1, fileName);

            g1.Show();

            // test lazy prim
            Console.WriteLine("Test Lazy Prim MST: ");
            var pq          = new MinHeap <Edge <double> >();
            var lazyPrimMST = new LazyPrimMST <double>(g1, pq);
            var mst         = lazyPrimMST.MSTEdges;

            foreach (var edge in mst)
            {
                Console.WriteLine(edge);
            }
            Console.WriteLine("The MST weight is: " + lazyPrimMST.MSTWeight);
        }