/* * AddArc adds an arc between two nodes to the graph. */ public void AddArc(Node node1, string node1ConnectionOption, Node node2) { //System.Console.WriteLine("\nIn AddArc()"); if (ContainsArc(node1.Name + "<-->" + node2.Name)) { System.Console.WriteLine("An arc already exists between " + node1.Name + " and node " + node2.Name + "; Nothing done"); //System.Console.WriteLine("Leaving AddArc()\n"); return; } string node2ConnectionOption = Helper.GiveOppositeDirection(node1ConnectionOption); if (!(node1.NodeArcOptionIsOpen(node1ConnectionOption) && node2.NodeArcOptionIsOpen(node2ConnectionOption))) { if (!node2.NodeArcOptionIsOpen(node1ConnectionOption)) { System.Console.WriteLine("That arc option for node1 is not open; Nothing Done"); } else { System.Console.WriteLine("That arc option for node2 is not open; Nothing Done"); } //System.Console.WriteLine("Leaving AddArc()\n"); return; } node1.ConnectNodeToAnotherViaSpecifiedArcOption(node2, node1ConnectionOption); node2.ConnectNodeToAnotherViaSpecifiedArcOption(node1, node2ConnectionOption); Arc newArc = new Arc(node1, node2); _arcs.Add(newArc); //System.Console.WriteLine("Leaving AddArc()\n"); }
/* * GetArc returns the arc that has the same specified name */ public Arc GetArc(string arcName) { //System.Console.WriteLine("\nIn GetArc()"); Node node1 = new Node(); Node node2 = new Node(); Arc blankArc = new Arc(node1, node2); string reverseArcName = arcName.Substring(5, 1) + "<-->" + arcName.Substring(0, 1); System.Console.WriteLine("Looking for arc " + reverseArcName + ", as well as " + arcName); foreach (Arc arc in _arcs) { if (arc.Name.Equals(arcName) || arc.Name.Equals(reverseArcName)) { System.Console.WriteLine("Arc " + arc.Name + " found"); //System.Console.WriteLine("Leaving GetArc()\n"); return arc; } } System.Console.WriteLine("Arc NOT found; Return default/blank arc"); //System.Console.WriteLine("Leaving GetArc()\n"); return blankArc; }