/* * UpdateMasterGraphHelper works similar to RecordAndConnectNode, but adds nodes to the Master Graph instead of the Current * Graph. */ public void UpdateMasterGraphHelper(bool northArcOption, bool eastArcOption, bool southArcOption, bool westArcOption) { //System.Console.WriteLine("\nIn UpdateMasterGraphHelper()"); _previousNode = _currentNode; if (_previousNode.WasSpecifiedArcOptionExplored(_directionTraveled) && _masterGraphAlreadyIssuedCoordinates.Contains("[" + _xCoordinate + "," + _yCoordinate + "]")) { System.Console.WriteLine("Have traveled to an already known node along an already known path"); int tempIndex = _masterGraphAlreadyIssuedCoordinates.IndexOf("[" + _xCoordinate + "," + _yCoordinate + "]"); _currentNode = _masterGraph.GetNode(_nodeNamesList.ElementAt(tempIndex)); } else if (_masterGraphAlreadyIssuedCoordinates.Contains("[" + _xCoordinate + "," + _yCoordinate + "]")) { System.Console.WriteLine("Have traveled to an already known node along a previously unknown path"); int tempIndex = _masterGraphAlreadyIssuedCoordinates.IndexOf("[" + _xCoordinate + "," + _yCoordinate + "]"); _currentNode = _masterGraph.GetNode(_nodeNamesList.ElementAt(tempIndex)); _previousNode.SpecifiedArcOptionWasExplored(_directionTraveled); _masterGraph.AddArc(_previousNode, _directionTraveled, _currentNode); _currentNode.SpecifiedArcOptionWasExplored(Helper.GiveOppositeDirection(_directionTraveled)); } else { System.Console.WriteLine("Have traveled to an unknown node"); _previousNode.SpecifiedArcOptionWasExplored(_directionTraveled); _currentNode = new Node(_nodeNamesList.ElementAt(_masterGraphNodeNamesListCounter), northArcOption, eastArcOption, southArcOption, westArcOption); _currentNode.SpecifiedArcOptionWasExplored(Helper.GiveOppositeDirection(_directionTraveled)); _currentNode.XCoordinate = _xCoordinate; _currentNode.YCoordinate = _yCoordinate; _masterGraphAlreadyIssuedCoordinates.Add("[" + _xCoordinate + "," + _yCoordinate + "]"); _masterGraph.AddNode(_currentNode); _masterGraph.AddArc(_previousNode, _directionTraveled, _currentNode); _masterGraphNodeNamesListCounter += 1; } //System.Console.WriteLine("Leaving UpdateMasterGraphHelper()\n"); }
/************************* * METHODS *************************/ /* * RecordAndConnectNode takes a description of the intersection/node the agent is currently at and if that intersection/node * has not already been visited by the agent, records it in the form node within a graph, attaching it via an arc to the * intersection/node the agent just traveled from. If the node is not new, but the arc the agent traversed to get to it was * up till then unexplored, the method will only add the arc between the two known nodes to the graph. If the node is not new * and the arc traversed to get there was already explored, the method will add nothing to the graph. */ public void RecordAndConnectNode(bool northArcOption, bool eastArcOption, bool southArcOption, bool westArcOption) { //System.Console.WriteLine("\nIn RecordAndConnectNode()"); if (_directionTraveled.Equals("none")) { System.Console.WriteLine("Setting up and adding first node to GraphBuilder's Current Run Graph"); _currentNode = new Node(_nodeNamesList.ElementAt(_nodeNamesListCounter), northArcOption, eastArcOption, southArcOption, westArcOption); _descriptionsOfNodesUsedInCurrentRun.Add(_currentNode.ArcOptions); _currentNode.XCoordinate = _xCoordinate; _currentNode.YCoordinate = _yCoordinate; _currentGraph.AddNode(_currentNode); _alreadyIssuedCoordinates.Add("[" + _xCoordinate + "," + _yCoordinate + "]"); _nodeNamesListCounter += 1; } else { _previousNode = _currentNode; if (_previousNode.WasSpecifiedArcOptionExplored(_directionTraveled) && _alreadyIssuedCoordinates.Contains("[" + _xCoordinate + "," + _yCoordinate + "]")) { System.Console.WriteLine("Have traveled to an already known node along an already known path"); int tempIndex = _alreadyIssuedCoordinates.IndexOf("[" + _xCoordinate + "," + _yCoordinate + "]"); _currentNode = _currentGraph.GetNode(_nodeNamesList.ElementAt(tempIndex)); _descriptionsOfNodesUsedInCurrentRun.Add(_currentNode.ArcOptions); } else if (_alreadyIssuedCoordinates.Contains("[" + _xCoordinate + "," + _yCoordinate + "]")) { System.Console.WriteLine("Have traveled to an already known node along a previously unknown path"); int tempIndex = _alreadyIssuedCoordinates.IndexOf("[" + _xCoordinate + "," + _yCoordinate + "]"); _currentNode = _currentGraph.GetNode(_nodeNamesList.ElementAt(tempIndex)); _descriptionsOfNodesUsedInCurrentRun.Add(_currentNode.ArcOptions); _previousNode.SpecifiedArcOptionWasExplored(_directionTraveled); _currentGraph.AddArc(_previousNode, _directionTraveled, _currentNode); _currentNode.SpecifiedArcOptionWasExplored(Helper.GiveOppositeDirection(_directionTraveled)); } else { System.Console.WriteLine("Have traveled to an unknown node"); _previousNode.SpecifiedArcOptionWasExplored(_directionTraveled); _currentNode = new Node(_nodeNamesList.ElementAt(_nodeNamesListCounter), northArcOption, eastArcOption, southArcOption, westArcOption); _currentNode.SpecifiedArcOptionWasExplored(Helper.GiveOppositeDirection(_directionTraveled)); _descriptionsOfNodesUsedInCurrentRun.Add(_currentNode.ArcOptions); _currentNode.XCoordinate = _xCoordinate; _currentNode.YCoordinate = _yCoordinate; _alreadyIssuedCoordinates.Add("[" + _xCoordinate + "," + _yCoordinate + "]"); _currentGraph.AddNode(_currentNode); _currentGraph.AddArc(_previousNode, _directionTraveled, _currentNode); _nodeNamesListCounter += 1; } } //System.Console.WriteLine("Leaving ()\n"); }