示例#1
0
        static void Main(string[] args)
        {
            UndirectedGraph<int> lGraph = new UndirectedGraph<int>();
            lGraph.AddVertex(1);
            lGraph.AddVertex(2);
            lGraph.AddVertex(3);
            lGraph.AddVertex(4);
            lGraph.AddVertex(5);
            lGraph.AddVertex(6);
            lGraph.AddVertex(7);
            lGraph.AddVertex(8);

            lGraph.Connect(lGraph[1], lGraph[2]);
            lGraph.Connect(lGraph[2], lGraph[3]);
            lGraph.Connect(lGraph[7], lGraph[3]);
            lGraph.Connect(lGraph[5], lGraph[7]);
            lGraph.Connect(lGraph[2], lGraph[6]);
            lGraph.Connect(lGraph[5], lGraph[4]);
            lGraph.Connect(lGraph[4], lGraph[3]);
            lGraph.Connect(lGraph[7], lGraph[8]);
            lGraph.Connect(lGraph[7], lGraph[1]);

            foreach (var lVertex in lGraph.GetVertices())
            {
                Console.WriteLine("Stupeň uzlu {0} = {1}",lVertex.Value, lGraph.GetVertexDegree(lVertex));
            }

            ISequence<int> lSeq = new Sequence<int>();
            lSeq.MakeSequence(new Edge<int>(8, 2), new Edge<int>(2, 5), new Edge<int>(5, 1), new Edge<int>(1, 3));
            //Console.WriteLine("Is Closed Sequence: " + lSeq.IsClosedSquence());
            Console.WriteLine("Is Graph Sequence: " + lSeq.IsGraphSequence(lGraph));
            Console.WriteLine("Is Move: " + lSeq.IsMove());
            Console.WriteLine("Is Path: " + lSeq.IsPath());

            foreach (var lVertex in lGraph.GetVertices())
            {
                var lSousedi = lGraph.GetVertices(lVertex);
                Console.Write("Sousedé uzlu {0} = ", lVertex.Value);
                foreach (var nVertex in lSousedi)
                {
                    Console.Write("{0}, ", nVertex.Value);
                }
                Console.WriteLine("");
            }

            var lGr = new UndirectedGraph<int>();
            lGr.AddVertex(18);
            lGr.AddVertex(20);
            lGr.AddVertex(13);
            lGr.AddVertex(11);
            lGr.AddVertex(20);

            lGr.Connect(lGr[13], lGr[11]);
            lGr.Connect(lGr[20], lGr[11]);
            lGr.Connect(lGr[13], lGr[18]);
            lGr.Connect(lGr[18], lGr[13]);
            lGr.Connect(lGr[11], lGr[18]);
            lGr.Connect(lGr[20], lGr[13]);

            lGraph.Join(lGr, new Edge<int>(1, 11));
            foreach (var lVertex in lGraph.GetVertices())
            {
                var lSousedi = lGraph.GetVertices(lVertex);
                Console.Write("Sousedé uzlu {0} = ", lVertex.Value);
                foreach (var nVertex in lSousedi)
                {
                    Console.Write("{0}, ", nVertex.Value);
                }
                Console.WriteLine("");
            }

            var lGraf = new UndirectedValuedGraph<int>();
            lGraf.AddVertex(1);
            lGraf.AddVertex(2);
            lGraf.AddVertex(3);
            lGraf.AddVertex(4);
            lGraf.AddVertex(5);
            lGraf.AddVertex(6);

            lGraf.Connect(lGraf[1], lGraf[2], 2);
            lGraf.Connect(lGraf[1], lGraf[3], 2);
            lGraf.Connect(lGraf[1], lGraf[4], 1);
            lGraf.Connect(lGraf[1], lGraf[5], 2);
            lGraf.Connect(lGraf[1], lGraf[6], 3);
            lGraf.Connect(lGraf[2], lGraf[3], 3);
            lGraf.Connect(lGraf[2], lGraf[4], 4);
            lGraf.Connect(lGraf[2], lGraf[5], 1);
            lGraf.Connect(lGraf[2], lGraf[6], 3);
            lGraf.Connect(lGraf[3], lGraf[4], 1);
            lGraf.Connect(lGraf[3], lGraf[5], 2);
            lGraf.Connect(lGraf[3], lGraf[6], 1);
            lGraf.Connect(lGraf[4], lGraf[5], 2);
            lGraf.Connect(lGraf[4], lGraf[6], 3);
            lGraf.Connect(lGraf[5], lGraf[6], 3);

            var lVys = lGraf.GetSpanningTree();
            var lSeznam = lVys.WideSearch(lGraf[6]);

            Console.ReadKey();
        }