Пример #1
1
        public static Graph<int> DijkstrasAlg(Graph<int> graph)
        {
            List<Node<int>> nodeset = graph.nodeset.ToList<Node<int>>();
            Graph<int> sptGraph = new Graph<int>();

            while (nodeset.Count > 0)
            {
                Minheapify(nodeset);
                Node<int> root = nodeset[0];
                nodeset.RemoveAt(0);
                Node<int> sptNode = new Node<int>(root.data);

                if (root.parent != null)
                {
                    sptGraph.AddEdge(sptNode, root.parent, root.key);
                    root.parent = null;
                }

                for (int i = 0; i < root.neighbors.Count; i++)
                {
                    if (root.neighbors[i].key > (root.cost[i] + root.key))
                    {
                        root.neighbors[i].key = root.cost[i] + root.key;
                        root.neighbors[i].parent = sptNode;
                    }
                }
            }

            sptGraph.printGraph();
            return sptGraph;
        }
Пример #2
0
        public GraphLayout()
        {
#if SILVERLIGHT
            this.DefaultStyleKey = typeof(GraphLayout);
#endif

            if (DesignerProperties.GetIsInDesignMode(this))
            {
                var graph = new Graph<string, Edge<string>>();
                var a = "A";
                var b = "B";
                var c = "C";
                var d = "D";
                var e = "E";
                var f = "F";
                graph.AddVertex(a);
                graph.AddVertex(b);
                graph.AddVertex(c);
                graph.AddVertex(d);
                graph.AddVertex(e);
                graph.AddVertex(f);
                graph.AddEdge(new Edge<string>(a, b));
                graph.AddEdge(new Edge<string>(a, c));
                graph.AddEdge(new Edge<string>(a, d));
                graph.AddEdge(new Edge<string>(b, c));
                graph.AddEdge(new Edge<string>(b, d));
                graph.AddEdge(new Edge<string>(c, d));
                graph.AddEdge(new Edge<string>(e, f));
                graph.AddEdge(new Edge<string>(e, c));
                graph.AddEdge(new Edge<string>(c, f));
                this.Graph = graph;
                graph.Ratio = 0.5;
            }
        }
Пример #3
0
        //Time: O(E logV) using adjacency list rep (using BFS on keys)
        //Find minimum spanning tree (connected nodes with min cost edges, E = V-1)
        //1. Place the graph in min heap (using keys)
        //2. Extract the min key node and add to MST graph
        //3. Update the keys of adjacent nodes (if key > cost then update)
        //4. Minheapify the remaining nodes in the graph and repeat from step 2 until the entire list is empty
        private static Graph<int> PrimsAlg(Graph<int> graph)
        {
            Graph<int> mstGraph = new Graph<int>(); //Generate a new MST graph
            List<Node<int>> nodeset = graph.nodeset.ToList<Node<int>>();    //Create a new list of nodes from existing graph, so that we don't modify the given graph
            while (nodeset.Count > 0)
            {
                Minheapify(nodeset);    //Place the list in MinHeap
                Node<int> root = nodeset[0];    //Extract Min node
                Node<int> mstNode = new Node<int>(root.data);   //Create a new node for MST graph
                if (root.parent != null)    //Add nodes and edges between them
                {
                    mstGraph.AddEdge(mstNode, root.parent, root.key);
                    root.parent = null; //reset the parent node
                }

                nodeset.RemoveAt(0);    //Extract root node (remove from list)

                for(int i = 0; i< root.neighbors.Count; i++)
                {
                    if (root.neighbors[i].key > root.cost[i])   //Update keys of neighboring nodes if the min node
                    {
                        root.neighbors[i].key = root.cost[i];
                        root.neighbors[i].parent = mstNode;
                    }
                }
            }
            mstGraph.printGraph();
            return mstGraph;
        }
Пример #4
0
        public MainWindowViewModel()
        {
            var graph = new Graph<Person>();
            var a = new Person();
            var b = new Person();
            var c = new Person();

            graph.AddVertex(a);
            graph.AddVertex(b);
            graph.AddVertex(c);

            graph.AddEdge(new Edge<Person>(c, a));

            this.Graph = graph;
        }
Пример #5
0
        /// <summary>
        /// Reads size, amount of edges and edges list
        /// </summary>
        static Graph AskGraphFromConsole()
        {
            Console.WriteLine("Type graph size (amount of vertexes):");
            int graphSize = int.Parse(Console.ReadLine());
            var graph     = new Graphs.Graph(graphSize);

            Console.WriteLine("Type amount of edges:");
            int edgesAmount = int.Parse(Console.ReadLine());

            for (int i = 0; i < edgesAmount; ++i)
            {
                Console.WriteLine("Type edge (just pair of numbers):");
                string[] edgeInput = Console.ReadLine().Split(' ');
                if (edgeInput.Length < 2)
                {
                    throw new Exception("Bad input");
                }
                int begin = int.Parse(edgeInput[0]);
                int end   = int.Parse(edgeInput[1]);
                graph.AddEdge(begin, end);
            }
            return(graph);
        }
Пример #6
0
        public static void DoTiling(Graphs.Graph g, List <Vector> p, List <int> set)
        {
            if (g.Edges.Count <= 0)
            {
                return;
            }

            var r = new Vector(g.Edges[0].V1.X, g.Edges[0].V1.Y).Distance(new Vector(g.Edges[0].V2.X, g.Edges[0].V2.Y));

            var edgesToAdd = new List <Tuple <int, int> >();

            for (int i = 0; i < set.Count; i++)
            {
                g.Vertices[set[i]].Padding = 0.02f;
                g.Vertices[set[i]].Style   = "_RedDotStyle";

                for (int j = i + 1; j < set.Count; j++)
                {
                    if (p[set[i]].Distance(p[set[j]]) < 3 * r - MinDelta)
                    {
                        edgesToAdd.Add(new Tuple <int, int>(set[i], set[j]));
                    }
                }
            }

            foreach (var e in edgesToAdd)
            {
                var vs = new List <int>()
                {
                    e.Item1, e.Item2
                };
                var nonIncident = edgesToAdd.Where(ea => !vs.Contains(ea.Item1) && !vs.Contains(ea.Item2)).ToList();

                if (nonIncident.Any(ea => SegmentsIntersect(g.Vertices[e.Item1], g.Vertices[e.Item2], g.Vertices[ea.Item1], g.Vertices[ea.Item2])))
                {
                    continue;
                }

                var between = g.Vertices.Where(v => OnLineSegment(g.Vertices[e.Item1], g.Vertices[e.Item2], v)).Where(v => v != g.Vertices[e.Item1] && v != g.Vertices[e.Item2]).ToList();

                var thickness = 6;
                if (between.Count == 0)
                {
                    g.AddEdge(g.Vertices[e.Item1], g.Vertices[e.Item2], Edge.Orientations.None, 1, thickness, "_GreenEdgeStyle");
                }
                else
                {
                    for (int i = 0; i < between.Count; i++)
                    {
                        var ee = g.GetEdge(between[i], g.Vertices[e.Item1]);
                        if (ee != null)
                        {
                            ee.Style     = "_GreenEdgeStyle";
                            ee.Thickness = thickness;
                        }

                        ee = g.GetEdge(between[i], g.Vertices[e.Item2]);
                        if (ee != null)
                        {
                            ee.Thickness = thickness;
                            ee.Style     = "_GreenEdgeStyle";
                        }
                    }
                }
            }
        }
        public MainWindowViewModel()
        {
            var graph = new Graph<Person>();
            var a = new Person(graph) { Name = "Jonh", Avatar = "./Avatars/avatar1.jpg" };
            var b = new Person(graph) { Name = "Michael", Avatar = "./Avatars/avatar2.gif" };
            var c = new Person(graph) { Name = "Kenny" };
            var d = new Person(graph) { Name = "Lisa" };
            var e = new Person(graph) { Name = "Lucy", Avatar = "./Avatars/avatar3.jpg" };
            var f = new Person(graph) { Name = "Ted Mosby" };
            var g = new Person(graph) { Name = "Glen" };
            var h = new Person(graph) { Name = "Alice", Avatar = "./Avatars/avatar1.jpg" };

            graph.AddVertex(a);
            graph.AddVertex(b);
            graph.AddVertex(c);
            graph.AddVertex(d);
            graph.AddVertex(e);
            graph.AddVertex(f);

            var subGraph = new SubGraph<Person> { Label = "Work" };
            graph.AddSubGraph(subGraph);
            subGraph.AddVertex(g);
            subGraph.AddVertex(h);
            graph.AddEdge(new Edge<Person>(g, h));
            graph.AddEdge(new Edge<Person>(a, g));

            var subGraph2 = new SubGraph<Person> {Label = "School"};
            graph.AddSubGraph(subGraph2);
            var loner = new Person(graph) { Name = "Loner", Avatar = "./Avatars/avatar1.jpg" };
            subGraph2.AddVertex(loner);
            graph.AddEdge(new Edge<SubGraph<Person>>(subGraph, subGraph2) { Label = "Link between groups" } );

            graph.AddEdge(new Edge<Person>(c, d) { Label = "In love", DestinationArrowLabel = "boyfriend", SourceArrowLabel = "girlfriend" });

            graph.AddEdge(new Edge<Person>(c, g, new Arrow(), new Arrow()));
            graph.AddEdge(new Edge<Person>(c, a, new Arrow()) { Label = "Boss" });
            graph.AddEdge(new Edge<Person>(d, h, new DiamondArrow(), new DiamondArrow()));
            graph.AddEdge(new Edge<Person>(f, h, new DiamondArrow(), new DiamondArrow()));
            graph.AddEdge(new Edge<Person>(f, loner, new DiamondArrow(), new DiamondArrow()));
            graph.AddEdge(new Edge<Person>(f, b, new DiamondArrow(), new DiamondArrow()));
            graph.AddEdge(new Edge<Person>(e, g, new Arrow(), new Arrow()) { Label = "Siblings" });

            this.Graph = graph;
            this.Graph.Changed += GraphChanged;
            this.NewPersonName = "Enter new name";
        	this.UpdatePersonNewName = "Enter new name";
        }
Пример #8
0
        public MainWindowViewModel()
        {
            //load dot file
            var parser = Dot.AntlrParser.AntlrParserAdapter<string>.GetParser();
            var dotFileReader = new StreamReader(@"D:\Github\LiveActive\SmartAnalyzer\Projects\callgraph.dot");
            var result = parser.Parse(dotFileReader);
               // if (result != null)
               //     this.Graph = result;

            var graph = new Graph<Person>();
            var a = new Person(graph) { Name = "Jonh", Avatar = "./Avatars/avatar1.jpg" };
            var b = new Person(graph) { Name = "Michael", Avatar = "./Avatars/avatar2.gif" };
            var c = new Person(graph) { Name = "Kenny" };
            var d = new Person(graph) { Name = "Lisa" };
            var e = new Person(graph) { Name = "Lucy", Avatar = "./Avatars/avatar3.jpg" };
            var f = new Person(graph) { Name = "Ted Mosby" };
            var g = new Person(graph) { Name = "Glen" };
            var h = new Person(graph) { Name = "Alice", Avatar = "./Avatars/avatar1.jpg" };

            graph.AddVertex(a);
            graph.AddVertex(b);
            graph.AddVertex(c);
            graph.AddVertex(d);
            graph.AddVertex(e);
            graph.AddVertex(f);

            var subGraph = new SubGraph<Person> { Label = "Work" };
            graph.AddSubGraph(subGraph);
            subGraph.AddVertex(g);
            subGraph.AddVertex(h);
            graph.AddEdge(new Edge<Person>(g, h));
            graph.AddEdge(new Edge<Person>(a, g));

            var subGraph2 = new SubGraph<Person> {Label = "School"};
            graph.AddSubGraph(subGraph2);
            var loner = new Person(graph) { Name = "Loner", Avatar = "./Avatars/avatar1.jpg" };
            subGraph2.AddVertex(loner);
            graph.AddEdge(new Edge<SubGraph<Person>>(subGraph, subGraph2) { Label = "Link between groups" } );

            graph.AddEdge(new Edge<Person>(c, d) { Label = "In love", DestinationArrowLabel = "boyfriend", SourceArrowLabel = "girlfriend" });

            graph.AddEdge(new Edge<Person>(c, g, new Arrow(), new Arrow()));
            graph.AddEdge(new Edge<Person>(c, a, new Arrow()) { Label = "Boss" });
            graph.AddEdge(new Edge<Person>(d, h, new DiamondArrow(), new DiamondArrow()));
            graph.AddEdge(new Edge<Person>(f, h, new DiamondArrow(), new DiamondArrow()));
            graph.AddEdge(new Edge<Person>(f, loner, new DiamondArrow(), new DiamondArrow()));
            graph.AddEdge(new Edge<Person>(f, b, new DiamondArrow(), new DiamondArrow()));
            graph.AddEdge(new Edge<Person>(e, g, new Arrow(), new Arrow()) { Label = "Siblings" });

            this.Graph = graph;
            this.Graph.Changed += GraphChanged;
            this.NewPersonName = "Enter new name";
            this.UpdatePersonNewName = "Enter new name";
        }
        static void Main(string[] args)
        {
            Graph <string> graph = new Graph <string>(false, false);

            Node <string> nodePK = graph.AddNode("PK");
            Node <string> nodeLU = graph.AddNode("LU");
            Node <string> nodePD = graph.AddNode("PD");
            Node <string> nodeWM = graph.AddNode("WM");
            Node <string> nodeMZ = graph.AddNode("MZ");
            Node <string> nodeSW = graph.AddNode("SW");
            Node <string> nodeMA = graph.AddNode("MA");
            Node <string> nodeSL = graph.AddNode("SL");
            Node <string> nodeLD = graph.AddNode("LD");
            Node <string> nodeKP = graph.AddNode("KP");
            Node <string> nodePM = graph.AddNode("PM");
            Node <string> nodeZP = graph.AddNode("ZP");
            Node <string> nodeWP = graph.AddNode("WP");
            Node <string> nodeLB = graph.AddNode("LB");
            Node <string> nodeDS = graph.AddNode("DS");
            Node <string> nodeOP = graph.AddNode("OP");

            graph.AddEdge(nodePK, nodeLU);
            graph.AddEdge(nodePK, nodeSW);
            graph.AddEdge(nodePK, nodeMA);
            graph.AddEdge(nodeLU, nodeSW);
            graph.AddEdge(nodeLU, nodeMZ);
            graph.AddEdge(nodeLU, nodePD);
            graph.AddEdge(nodePD, nodeMZ);
            graph.AddEdge(nodePD, nodeWM);
            graph.AddEdge(nodeWM, nodeKP);
            graph.AddEdge(nodeWM, nodePM);
            graph.AddEdge(nodeWM, nodeMZ);
            graph.AddEdge(nodeMZ, nodeKP);
            graph.AddEdge(nodeMZ, nodeLD);
            graph.AddEdge(nodeMZ, nodeSW);
            graph.AddEdge(nodeSW, nodeLD);
            graph.AddEdge(nodeSW, nodeSL);
            graph.AddEdge(nodeSW, nodeMA);
            graph.AddEdge(nodeMA, nodeSL);
            graph.AddEdge(nodeSL, nodeOP);
            graph.AddEdge(nodeSL, nodeLD);
            graph.AddEdge(nodeLD, nodeOP);
            graph.AddEdge(nodeLD, nodeWP);
            graph.AddEdge(nodeLD, nodeKP);
            graph.AddEdge(nodeKP, nodeWP);
            graph.AddEdge(nodeKP, nodePM);
            graph.AddEdge(nodePM, nodeZP);
            graph.AddEdge(nodePM, nodeLB);
            graph.AddEdge(nodePM, nodeWP);
            graph.AddEdge(nodeZP, nodeLB);
            graph.AddEdge(nodeWP, nodeDS);
            graph.AddEdge(nodeWP, nodeOP);
            graph.AddEdge(nodeWP, nodeLB);
            graph.AddEdge(nodeLB, nodeDS);
            graph.AddEdge(nodeDS, nodeOP);

            int[] colors = graph.Color();
            for (int i = 0; i < colors.Length; i++)
            {
                Console.WriteLine($"{graph.Nodes[i].Data}: {colors[i]}");
            }
        }
        static void Main(string[] args)
        {
            Graph <string> graph = new Graph <string>(false, true);

            Node <string> nodeB1 = graph.AddNode("B1");
            Node <string> nodeB2 = graph.AddNode("B2");
            Node <string> nodeB3 = graph.AddNode("B3");
            Node <string> nodeB4 = graph.AddNode("B4");
            Node <string> nodeB5 = graph.AddNode("B5");
            Node <string> nodeB6 = graph.AddNode("B6");
            Node <string> nodeR1 = graph.AddNode("R1");
            Node <string> nodeR2 = graph.AddNode("R2");
            Node <string> nodeR3 = graph.AddNode("R3");
            Node <string> nodeR4 = graph.AddNode("R4");
            Node <string> nodeR5 = graph.AddNode("R5");
            Node <string> nodeR6 = graph.AddNode("R6");

            graph.AddEdge(nodeB1, nodeB2, 2);
            graph.AddEdge(nodeB1, nodeB3, 20);
            graph.AddEdge(nodeB1, nodeB4, 30);
            graph.AddEdge(nodeB2, nodeB3, 30);
            graph.AddEdge(nodeB2, nodeB4, 20);
            graph.AddEdge(nodeB3, nodeB4, 2);
            graph.AddEdge(nodeB2, nodeR2, 25);
            graph.AddEdge(nodeB4, nodeR4, 25);
            graph.AddEdge(nodeR1, nodeR2, 1);
            graph.AddEdge(nodeR2, nodeR3, 1);
            graph.AddEdge(nodeR3, nodeR4, 1);
            graph.AddEdge(nodeR1, nodeR5, 75);
            graph.AddEdge(nodeR3, nodeR6, 100);
            graph.AddEdge(nodeR5, nodeR6, 3);
            graph.AddEdge(nodeR6, nodeB5, 3);
            graph.AddEdge(nodeB5, nodeB6, 6);
            graph.AddEdge(nodeR6, nodeB6, 10);

            Console.WriteLine("Minimum Spanning Tree - Kruskal's Algorithm:");
            List <Edge <string> > mstKruskal = graph.MinimumSpanningTreeKruskal();

            mstKruskal.ForEach(e => Console.WriteLine(e));
            Console.WriteLine("Total cost: " + mstKruskal.Sum(e => e.Weight));

            Console.WriteLine("\nMinimum Spanning Tree - Prim's Algorithm:");
            List <Edge <string> > mstPrim = graph.MinimumSpanningTreePrim();

            mstPrim.ForEach(e => Console.WriteLine(e));
            Console.WriteLine("Total cost: " + mstPrim.Sum(e => e.Weight));
        }
        static void Main(string[] args)
        {
            // Undirected and unweighted edges
            // Graph<int> graph = new Graph<int>(false, false);

            // Node<int> n1 = graph.AddNode(1);
            // Node<int> n2 = graph.AddNode(2);
            // Node<int> n3 = graph.AddNode(3);
            // Node<int> n4 = graph.AddNode(4);
            // Node<int> n5 = graph.AddNode(5);
            // Node<int> n6 = graph.AddNode(6);
            // Node<int> n7 = graph.AddNode(7);
            // Node<int> n8 = graph.AddNode(8);

            // graph.AddEdge(n1, n2);
            // graph.AddEdge(n1, n3);
            // graph.AddEdge(n2, n4);
            // graph.AddEdge(n3, n4);
            // graph.AddEdge(n4, n5);
            // graph.AddEdge(n4, n8);
            // graph.AddEdge(n5, n6);
            // graph.AddEdge(n5, n7);
            // graph.AddEdge(n5, n8);
            // graph.AddEdge(n6, n7);
            // graph.AddEdge(n7, n8);

            // ---

            // Undirected and weighted edges
            // Graph<int> graph = new Graph<int>(false, true);

            // Node<int> n1 = graph.AddNode(1);
            // Node<int> n2 = graph.AddNode(2);
            // Node<int> n3 = graph.AddNode(3);
            // Node<int> n4 = graph.AddNode(4);
            // Node<int> n5 = graph.AddNode(5);
            // Node<int> n6 = graph.AddNode(6);
            // Node<int> n7 = graph.AddNode(7);
            // Node<int> n8 = graph.AddNode(8);

            // graph.AddEdge(n1, n2, 3);
            // graph.AddEdge(n1, n3, 5);
            // graph.AddEdge(n2, n4, 4);
            // graph.AddEdge(n3, n4, 12);
            // graph.AddEdge(n4, n5, 9);
            // graph.AddEdge(n4, n8, 8);
            // graph.AddEdge(n5, n6, 4);
            // graph.AddEdge(n5, n7, 5);
            // graph.AddEdge(n5, n8, 1);
            // graph.AddEdge(n6, n7, 6);
            // graph.AddEdge(n7, n8, 20);
            // graph.AddEdge(n2, n6, 20);
            // graph.AddEdge(n2, n5, 20);

            // ---

            // Directed and weighted edges
            Graph <int> graph = new Graph <int>(true, true);

            Node <int> n1 = graph.AddNode(1);
            Node <int> n2 = graph.AddNode(2);
            Node <int> n3 = graph.AddNode(3);
            Node <int> n4 = graph.AddNode(4);
            Node <int> n5 = graph.AddNode(5);
            Node <int> n6 = graph.AddNode(6);
            Node <int> n7 = graph.AddNode(7);
            Node <int> n8 = graph.AddNode(8);

            graph.AddEdge(n1, n2, 9);
            graph.AddEdge(n1, n3, 5);
            graph.AddEdge(n2, n1, 3);
            graph.AddEdge(n2, n4, 18);
            graph.AddEdge(n3, n4, 12);
            graph.AddEdge(n4, n2, 2);
            graph.AddEdge(n4, n8, 8);
            graph.AddEdge(n5, n4, 9);
            graph.AddEdge(n5, n6, 2);
            graph.AddEdge(n5, n7, 5);
            graph.AddEdge(n5, n8, 3);
            graph.AddEdge(n6, n7, 1);
            graph.AddEdge(n7, n5, 4);
            graph.AddEdge(n7, n8, 6);
            graph.AddEdge(n8, n5, 3);

            Console.WriteLine("Minimum Spanning Tree - Kruskal's Algorithm:");
            List <Edge <int> > mstKruskal = graph.MinimumSpanningTreeKruskal();

            mstKruskal.ForEach(e => Console.WriteLine(e));

            Console.WriteLine("\nMinimum Spanning Tree - Prim's Algorithm:");
            List <Edge <int> > mstPrim = graph.MinimumSpanningTreePrim();

            mstPrim.ForEach(e => Console.WriteLine(e));

            Console.WriteLine("\nShortest Path - Dijkstra's Algorithm:");
            List <Edge <int> > path = graph.GetShortestPathDijkstra(n1, n5);

            path.ForEach(e => Console.WriteLine(e));

            Console.WriteLine("\nColoring the graph:");
            int[] colors = graph.Color();
            for (int i = 0; i < colors.Length; i++)
            {
                Console.WriteLine($"Node {graph.Nodes[i].Data}: {colors[i]}");
            }

            Console.WriteLine("\nDepth-First Search:");
            List <Node <int> > dfsNodes = graph.DFS();

            dfsNodes.ForEach(n => Console.WriteLine(n));

            Console.WriteLine("\nBreath-First Search:");
            List <Node <int> > bfsNodes = graph.BFS();

            bfsNodes.ForEach(n => Console.WriteLine(n));
        }
Пример #12
0
        static void Main(string[] args)
        {
            string prgrmChooser = Console.ReadLine();

            if (prgrmChooser == "a*")
            {
                Console.Clear();
                Graph <Vector2> graph = new Graph <Vector2>();
                string          file  = File.ReadAllText("AStarEnvironment.txt");
                Dictionary <Vector2, Vertex <Vector2> > vertices = new Dictionary <Vector2, Vertex <Vector2> >();
                Vector2 pos      = Vector2.Zero;
                Vector2 startPos = Vector2.Zero;
                Vector2 endPos   = Vector2.Zero;
                for (int i = 0; i < file.Length; i++)
                {
                    if (file[i] == ' ' || file[i] == 'S' || file[i] == 'E')
                    {
                        graph.Add(pos);
                        vertices.Add(pos, graph.Vertices[graph.Vertices.Count - 1]);
                        if (vertices.ContainsKey(new Vector2(pos.X - 1, pos.Y)))
                        {
                            graph.AddEdge(vertices[pos], vertices[new Vector2(pos.X - 1, pos.Y)]);
                        }
                        if (vertices.ContainsKey(new Vector2(pos.X, pos.Y - 1)))
                        {
                            graph.AddEdge(vertices[pos], vertices[new Vector2(pos.X, pos.Y - 1)]);
                        }
                        if (file[i] == 'S')
                        {
                            startPos = pos;
                        }
                        else if (file[i] == 'E')
                        {
                            endPos = pos;
                        }
                    }
                    else if (file[i] == '\n')
                    {
                        pos.Y++;
                        pos.X = -1;
                    }
                    pos.X++;
                }
                Console.WriteLine(file);
                Console.ReadLine();
                Stack <Vertex <Vector2> > path = graph.Pathfind(startPos, endPos, (Vertex <Vector2> a) => { return((endPos.X - a.Value.X) * (endPos.X - a.Value.X) + (endPos.Y - a.Value.Y) * (endPos.Y - a.Value.Y)); });
                while (path.Count > 0)
                {
                    Vector2 pos2 = path.Pop().Value;
                    Console.SetCursorPosition((int)pos2.X, (int)pos2.Y);
                    Console.Write('=');
                }
                Console.ReadKey();
            }
            else if (prgrmChooser == "graph")
            {
                bool        beenWarned   = false;
                int         radius       = 10;
                Graph <int> graph        = new Graph <int>();
                string      stuffToWrite = "";
                while (true)
                {
                    stuffToWrite = "";
                    string s = Console.ReadLine();
                    if (s[0] == 'i')
                    {
                        s = s.Remove(0, 1);
                        if (graph.Search(int.Parse(s)) == null)
                        {
                            graph.Add(int.Parse(s));
                        }
                        else if (!beenWarned)
                        {
                            Console.WriteLine("No repeats!");
                            beenWarned = true;
                            continue;
                        }
                        else
                        {
                            throw new Exception("I said no repeats!");
                        }
                    }
                    else if (s[0] == 'd')
                    {
                        s = s.Remove(0, 1);
                        graph.Remove(int.Parse(s));
                    }
                    else if (s[0] == 'e')
                    {
                        s = s.Remove(0, 1);
                        string[] vals = s.Split(';');
                        graph.AddEdge(int.Parse(vals[0]), int.Parse(vals[1]), vals.Length >= 3 ? vals[2] == "d" : false, vals.Length >= 4 ? double.Parse(vals[3]) : 1);
                    }
                    else if (s[0] == 'r')
                    {
                        s = s.Remove(0, 1);
                        string[] vals = s.Split(';');
                        graph.RemoveEdge(int.Parse(vals[0]), int.Parse(vals[1]), vals.Length >= 3 ? vals[2] == "u" : true);
                    }
                    else if (s[0] == 'R')
                    {
                        s      = s.Remove(0, 1);
                        radius = int.Parse(s);
                    }
                    else if (s[0] == 's')
                    {
                        s = s.Remove(0, 1);
                        if (s[0] == 'D')
                        {
                            s = s.Remove(0, 1);
                            Vertex <int> v = graph.Search(int.Parse(s), SearchType.DepthFirst);
                            if (v != null)
                            {
                                v.Color = ConsoleColor.Red;
                            }
                        }
                        else if (s[0] == 'B')
                        {
                            s = s.Remove(0, 1);
                            Vertex <int> v = graph.Search(int.Parse(s), SearchType.BreadthFirst);
                            if (v != null)
                            {
                                v.Color = ConsoleColor.Red;
                            }
                        }
                    }
                    else if (s[0] == 'g')
                    {
                        s = s.Remove(0, 1);
                        string[] param = s.Split(';');
                        int[]    vals  = UniqueRandom(int.Parse(param[0]), int.Parse(param[1]), int.Parse(param[2]));
                        for (int i = 0; i < vals.Length; i++)
                        {
                            graph.Add(vals[i]);
                        }
                        int[] vals2 = UniqueRandom(int.Parse(param[0]), int.Parse(param[1]), int.Parse(param[3]));
                        for (int i = 1; i < vals2.Length; i++)
                        {
                            graph.AddEdge(vals2[i - 1], vals2[i]);
                        }
                    }
                    else if (s[0] == 'P')
                    {
                        s = s.Remove(0, 1);
                        Func <Vertex <int>, double> a         = (Vertex <int> c) => { return(0); };
                        Func <Vertex <int>, double> heuristic = s[0] == 'D' ? a : (Vertex <int> b) => { return(0); };
                        graph.Pathfind(new Vertex <int>(), new Vertex <int>(), a);
                        s = s.Remove(0, 1);
                        string[] stringVals        = s.Split(';');
                        int[]    vals              = { int.Parse(stringVals[0]), int.Parse(stringVals[1]) };
                        Stack <Vertex <int> > path = graph.Pathfind(vals[0], vals[1]);
                        while (path.Count > 0)
                        {
                            stuffToWrite += path.Pop().Value.ToString() + (path.Count > 0 ? ", " : "");
                        }
                    }
                    else if (s[0] == 'p')
                    {
                        s = s.Remove(0, 1);
                        int id = int.Parse(s);
                        if (id == 1)
                        {
                            graph.Vertices = new List <Vertex <int> >();
                            for (int i = 0; i < 6; i++)
                            {
                                graph.Add(i);
                            }
                            graph.AddEdge(0, 1, true, 9);
                            graph.AddEdge(1, 2, true, 2);
                            graph.AddEdge(0, 3, true, 8);
                            graph.AddEdge(3, 4, true, 2);
                            graph.AddEdge(3, 5, true, 16);
                            graph.AddEdge(4, 5, true, 4);
                        }
                    }

                    Visualize(graph, radius);
                    Console.SetCursorPosition(0, 0);
                    Console.Write(stuffToWrite);
                }
            }
        }