예제 #1
0
        static void Main(string[] args)
        {
            CGraph graph1    = CGraph.CreateGraph();
            CGraph graph2    = CGraph.CreateGraph();
            CGraph rootGraph = CGraph.CreateGraph();

            // CREATE A GRAPH FROM A CSV FILE
            // We call the CreateGraphFromCSV where the edges are given as comma separated
            // tuples in curly brackets. Sole nodes can be given inside curle brackets. This
            // method assigns node labels as given in the file using the native graph labeller
            CGraph graph3 = CGraph.CreateGraphFromCSV("csvGraph.txt");

            CGraph.CCloneGraphOperation cloner = new CGraph.CCloneGraphOperation();
            CGraph graph3Clone = cloner.CloneGraph(graph3);


            CGraph.CMergeGraphOperation joiner = new CGraph.CMergeGraphOperation();
            joiner.MergeGraph(graph3);

            CGraph mergedGraph = joiner.MergeGraph(graph3Clone);

            Console.WriteLine("{0}", mergedGraph.ToString());
            // The graph can be printed using the specified graph printer which optionally can
            // take a label contructor. If the label contractor is ommited that printer will recieve
            // labels from the native graph labeller. In this case this what it happens
            graph3.RegisterGraphPrinter(new CGraphVizPrinter(graph3));
            graph3Clone.RegisterGraphPrinter(new CGraphVizPrinter(graph3Clone));
            mergedGraph.RegisterGraphPrinter(new CGraphVizPrinter(mergedGraph));
            // The graph uses the registered printers to print the graph to the specified output
            graph3.Generate(@"E:\MyPrivateWork\MyApps\MyLibraries\GraphLibrary\TestGraphLibrary\bin\Debug\test3.dot", true);
            graph3Clone.Generate(@"E:\MyPrivateWork\MyApps\MyLibraries\GraphLibrary\TestGraphLibrary\bin\Debug\test3Clone.dot", true);
            mergedGraph.Generate(@"E:\MyPrivateWork\MyApps\MyLibraries\GraphLibrary\TestGraphLibrary\bin\Debug\MergeTest.dot", true);

            /*
             *          AlgorithmDataRecord ioargs =
             *              GAlg_LeaderFinder_Builder.Create().
             *                  Input_SourceGraph(graph3).
             *              End();
             *
             *          GAlg_LeaderFinder bbFinder = new GAlg_LeaderFinder(ioargs);
             *          bbFinder.Init();
             * /*
             *          GAlg_BasicBlocks bbCreate = new GAlg_BasicBlocks(graph3,bbFinder);
             *          bbCreate.Init();
             *
             *          // We call the CreateGraphFromCSV where the edges are given as comma separated
             *          // tuples in curly brackets. Sole nodes can be given inside curle brackets. This
             *          // method assigns node labels as given in the file using the native graph labeller
             *          CGraph graph4 = CGraph.CreateGraphFromCSV("csvGraph1.txt");
             *
             *          graph4.RegisterGraphPrinter(new CGraphVizPrinter(graph4));
             *          // The graph uses the registered printers to print the graph to the specified output
             *          graph4.Generate(@"E:\MyPrivateWork\MyApps\MyLibraries\GraphLibrary\TestGraphLibrary\bin\Debug\test4.dot", true);
             *
             *          GAlg_ExtendedBasicBlockFinder ebbFinder = new GAlg_ExtendedBasicBlockFinder(graph4);
             *          ebbFinder.Init();
             *
             *          // We call the CreateGraphFromCSV where the edges are given as comma separated
             *          // tuples in curly brackets. Sole nodes can be given inside curle brackets. This
             *          // method assigns node labels as given in the file using the native graph labeller
             *          CGraph graph5 = CGraph.CreateGraphFromCSV("csvGraph2.txt");
             *
             *          graph5.RegisterGraphPrinter(new CGraphVizPrinter(graph5));
             *          // The graph uses the registered printers to print the graph to the specified output
             *          graph5.Generate(@"E:\MyPrivateWork\MyApps\MyLibraries\GraphLibrary\TestGraphLibrary\bin\Debug\csvGraph2.dot", true);
             *
             *          GAlg_DFSSpanningTree dfsSpanningTree = new GAlg_DFSSpanningTree(graph5);
             *          dfsSpanningTree.Init();
             *
             *          dfsSpanningTree.m_dfsSpanningTree.RegisterGraphPrinter(new CDFSSpanningTreeGraphvizPrinter(dfsSpanningTree.m_dfsSpanningTree));
             *          dfsSpanningTree.m_dfsSpanningTree.Generate(@"E:\MyPrivateWork\MyApps\MyLibraries\GraphLibrary\TestGraphLibrary\bin\Debug\ST.dot", true);
             *
             *          // CREATE A GRAPH FROM RANDOM GRAPH GENERATORS
             *          // A random graph with the specified number of nodes and edges can be generated
             *          // using the GenerateGraph_RandomGraph method. The nodes are labelled in the native
             *          // graph labeller using their serial numbers
             *          graph1.GenerateGraph_RandomGraph(10,40,GraphType.GT_UNDIRECTED);
             *          // The graph can be printed using the specified graph printer which optionally can
             *          // take a label contructor. If the label contractor is ommited that printer will recieve
             *          // labels from the native graph labeller. In this case this what it happens
             *          graph1.RegisterGraphPrinter(new CGraphVizPrinter(graph1));
             *          // The graph uses the registered printers to print the graph to the specified output
             *          //graph1.Generate(@"E:\MyPrivateWork\MyApps\MyLibraries\GraphLibrary\TestGraphLibrary\bin\Debug\graph1.dot", true);
             *
             *          graph2.GenerateGraph_RandomGraph(10,40,GraphType.GT_UNDIRECTED);
             *          graph2.RegisterGraphPrinter(new CGraphVizPrinter(graph2));
             *          //graph2.Generate(@"E:\MyPrivateWork\MyApps\MyLibraries\GraphLibrary\TestGraphLibrary\bin\Debug\graph2.dot", true);*/
        }
예제 #2
0
        static void Main(string[] args)
        {
            // 1. Create a graph
            CGraph mgraph = CGraph.CreateGraph();

            CGraphNode x = mgraph.CreateGraphNode <CGraphNode>("x");
            CGraphNode y = mgraph.CreateGraphNode <CGraphNode>("y");
            CGraphNode z = mgraph.CreateGraphNode <CGraphNode>("z");
            CGraphNode t = mgraph.CreateGraphNode <CGraphNode>("t");
            CGraphNode s = mgraph.CreateGraphNode <CGraphNode>("s");

            mgraph.AddGraphEdge <CGraphEdge, CGraphNode>(t, x, GraphType.GT_DIRECTED);
            mgraph.AddGraphEdge <CGraphEdge, CGraphNode>(t, y, GraphType.GT_DIRECTED);
            mgraph.AddGraphEdge <CGraphEdge, CGraphNode>(t, z, GraphType.GT_DIRECTED);
            mgraph.AddGraphEdge <CGraphEdge, CGraphNode>(x, t, GraphType.GT_DIRECTED);
            mgraph.AddGraphEdge <CGraphEdge, CGraphNode>(y, x, GraphType.GT_DIRECTED);
            mgraph.AddGraphEdge <CGraphEdge, CGraphNode>(y, z, GraphType.GT_DIRECTED);
            mgraph.AddGraphEdge <CGraphEdge, CGraphNode>(z, x, GraphType.GT_DIRECTED);
            mgraph.AddGraphEdge <CGraphEdge, CGraphNode>(z, s, GraphType.GT_DIRECTED);
            mgraph.AddGraphEdge <CGraphEdge, CGraphNode>(s, t, GraphType.GT_DIRECTED);
            mgraph.AddGraphEdge <CGraphEdge, CGraphNode>(s, y, GraphType.GT_DIRECTED);

            // 2. Associate weights with the edges of the graph
            CGraphQueryInfo <int, int, int> weights = new CGraphQueryInfo <int, int, int>(mgraph, 255);

            weights.CreateInfo(y, x, -3);
            weights.CreateInfo(x, t, -2);
            weights.CreateInfo(t, x, 5);
            weights.CreateInfo(z, x, 7);
            weights.CreateInfo(y, z, 9);
            weights.CreateInfo(t, y, 8);
            weights.CreateInfo(t, z, -4);
            weights.CreateInfo(s, t, 6);
            weights.CreateInfo(s, y, 7);
            weights.CreateInfo(z, s, 2);

            mgraph.RegisterGraphPrinter(new CGraphVizPrinter(mgraph));
            // The graph uses the registered printers to print the graph to the specified output
            mgraph.Generate(@"D:\MyPrivateWork\MyApps\MyApplications\EDUFLEX\GraphLibrary\TestSerialization\bin\Debug\test.dot", true);

            BinaryFormatter saver    = new BinaryFormatter();
            XmlSerializer   xmlsaver = new XmlSerializer(typeof(CGraph));

            using (Stream stream = new FileStream("graph.g", FileMode.Create, FileAccess.Write)) {
                saver.Serialize(stream, mgraph);
            }

            CGraph deserializedGraph;

            using (Stream stream = new FileStream("graph.g", FileMode.Open, FileAccess.Read)) {
                deserializedGraph = (CGraph)saver.Deserialize(stream);
            }

            deserializedGraph.RegisterGraphPrinter(new CGraphVizPrinter(mgraph));
            // The graph uses the registered printers to print the graph to the specified output
            deserializedGraph.Generate(@"D:\MyPrivateWork\MyApps\MyApplications\EDUFLEX\GraphLibrary\TestSerialization\bin\Debug\regentest.dot", true);

            using (Stream stream = new FileStream("graph.xml", FileMode.Create, FileAccess.Write)) {
                xmlsaver.Serialize(stream, mgraph);
            }
        }