Beispiel #1
0
        public static void Build(int choice)
        {
            switch (choice)
            {
            case 1:
                graph = SetGraphTypeMenu();
                break;

            case 2:
                CheckGraphStatus();
                graph.AddVertex(
                    ConsoleHelpers.ReadLineAfterDisplayingMessage("Please enter a name for your vertex: "));
                break;

            case 3:
                CheckGraphStatus();
                ViewGraph.View(graph);
                break;

            case 4:
                CheckGraphStatus();
                ListVertex();
                var v1       = GetFirstVertex();
                var v2       = GetSecondVertex();
                var distance = GetDistance();
                AddAdjacency(v1, v2, distance);
                break;

            case 5:
                graph = (Graph)GraphBuilder.ValidRandom()[0];
                break;

            default: break;
            }
        }
Beispiel #2
0
        static void Main(string[] args)
        {
            Graph graph = null;

            while (true)
            {
                Console.Clear();
                int choice;
                Console.WriteLine("Please make a choice:");
                Console.WriteLine("1. Build Graph");
                Console.WriteLine("2. Import Graph");
                Console.WriteLine("3. Export Graph");
                Console.WriteLine("4. Traverse Graph");
                Console.WriteLine("5. View Current Graph");
                choice = int.Parse(Console.ReadLine());
                string path;

                switch (choice)
                {
                case 1:
                    BuildGraph.graph = graph;
                    BuildGraph.BuildMenu();
                    break;

                case 2:
                    path  = ConsoleHelpers.ReadLineAfterDisplayingMessage("Please enter the path to your graph xml file");
                    graph = Settings.Load(path);
                    break;

                case 3:
                    path = ConsoleHelpers.ReadLineAfterDisplayingMessage("Please enter path to save file to.");
                    Settings.Save(graph, path, Settings.GetType(graph), false);
                    break;

                case 4:
                    var i = 0;
                    foreach (var vertex in graph.MyGraph)
                    {
                        Console.WriteLine("{0}. {1}", ++i, vertex.VertexID);
                    }

                    var source = BuildGraph.GetFirstVertex();
                    var target = BuildGraph.GetSecondVertex();
                    GraphTraversal.TraverseGraph(graph, source, target);
                    break;

                case 5:
                    ViewGraph.View(graph);
                    break;

                default: break;
                }
            }
        }