Ejemplo n.º 1
0
        /*
         * ContainsBothNodes method works the same as the ContainsNode method, except it receives two nodes when called and
         * both must be present in the arc for the method to return true.
         */
        public bool ContainsBothNodes(Node node1, Node node2)
        {
            //System.Console.WriteLine("\nIn ContainsBothNodes()");

            //System.Console.WriteLine("Leaving ContainsBothNodes()\n");

            return (_nodesInArc.Contains(node1) && _nodesInArc.Contains(node2));
        }
Ejemplo n.º 2
0
        /*************************
         *  CONSTRUCTOR(S)
         *************************/
        /*
         * Arc method constructs an instance of the Arc class--receiving two nodes, adding them to a hashSet,
         * and setting the cost of the arc instance to a default value of 0.
         *
         * Method is called by the Graph class through its AddArc method.
         */
        public Arc(Node node1, Node node2)
        {
            _nodesInArc = new HashSet<Node>();

            _cost = 0;

            _nodesInArc.Add(node1);

            _nodesInArc.Add(node2);

            _arcName = node1.Name + "<-->" + node2.Name;
        }
Ejemplo n.º 3
0
        private int _yCoordinate; // Also used by Master Graph

        #endregion Fields

        #region Constructors

        /*************************
         *  CONSTRUCTOR(S)
         *************************/
        /*
         * GraphBuilder constructs an instance of the GraphBuilder class.
         */
        public GraphBuilder()
        {
            //System.Console.WriteLine("\nIn GraphBuilder()");

            _currentGraph = new Graph();

            _xCoordinate = 0;

            _yCoordinate = 0;

            _alreadyIssuedCoordinates = new List<string>();

            _currentNode = new Node();

            _previousNode = new Node();

            _directionTraveled = "none";

            _nodeNamesList = new List<string> {"A", "B", "C", "D", "E",
                                               "F", "G", "H", "I", "J",
                                               "K", "L", "M", "N", "O",
                                               "P", "Q", "R", "S", "T",
                                               "U", "V", "W", "X", "Y",};

            _nodeNamesListCounter = 0;

            _descriptionsOfNodesUsedInCurrentRun = new List<string>();

            _directionsTraveledInCurrentRun = new List<string>();

            _masterGraph = new Graph();

            _masterGraphAlreadyIssuedCoordinates = new List<string>();

            _masterGraphNodeNamesListCounter = 0;

            _masterGraphTargetNode = new Node();

            _masterGraphTargetNodeXCoordinate = 0;

            _masterGraphTargetNodeYCoordinate = 0;

            //System.Console.WriteLine("Leaving GraphBuilder()\n");
        }
        /*************************
         *  CONSTRUCTOR(S)
         *************************/
        /*
         * GraphNavigatorIntermediate constructor takes a graph, starting node, and orientation ("north", "east", "south", or "west")
         * with that node, setting up the frame work in which an agent class will recieve information about it navigation options
         * within the graph and traverse the graph.
         */
        public GraphNavigatorIntermediate(Graph graph, Node startingNode, string startingOrientation)
        {
            //System.Console.WriteLine("\nIn GraphNavigatorIntermediate()");

            if (!graph.ContainsNode(startingNode.Name))
            {
                System.Console.WriteLine("Error; Graph does not contain specified starting node");

                return;
            }

            _graphBeingNavigated = graph;

            _currentNode = startingNode;

            _orientation = startingOrientation;

            //System.Console.WriteLine("Leaving GraphNavigatorIntermediate()\n");
        }
Ejemplo n.º 5
0
        /*
         * 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");
        }
Ejemplo n.º 6
0
        /*
         * GetNode returns the node that has the same specified name
         */
        public Node GetNode(string nodeName)
        {
            //System.Console.WriteLine("\nIn GetNode()");

            Node blankNode = new Node();

            foreach (Node node in _nodes)
            {
                if (node.Name.Equals(nodeName))
                {
                    System.Console.WriteLine("Node found");

                    //System.Console.WriteLine("Leaving GetNode()\n");

                    return node;
                }
            }

            System.Console.WriteLine("Node NOT found; Return default/blank node");

            //System.Console.WriteLine("Leaving GetNode()\n");

            return blankNode;
        }
Ejemplo n.º 7
0
        /*
         * UpdateMasterGraph is used to add what was learned in the last run to the Master Graph.
         */
        private void UpdateMasterGraph()
        {
            //System.Console.WriteLine("\nIn UpdateMasterGraph()");

            List<string> reversedPathOfDirectionsTraveledInCurrentRun = new List<string>();

            System.Console.WriteLine("The path traveled in the last run was...");

            foreach (string direction in _directionsTraveledInCurrentRun)
            {
                System.Console.Write(direction + " -- ");

                reversedPathOfDirectionsTraveledInCurrentRun.Insert(0, Helper.GiveOppositeDirection(direction));
            }

            System.Console.WriteLine("AT TARGET NODE");

            System.Console.WriteLine("Reversing that path from the target node, the path is now...");

            foreach (string reversedDirection in reversedPathOfDirectionsTraveledInCurrentRun)
            {
                System.Console.Write(reversedDirection + " -- ");
            }

            System.Console.WriteLine("AT LAST RUN'S STARTING NODE");

            List<string> reversedListOfDescriptionsOfNodesUsedInCurrentRun = new List<string>();

            System.Console.WriteLine("The nodes used to get to the target node, in order, look as follows...");

            foreach (String nodeDescription in _descriptionsOfNodesUsedInCurrentRun)
            {
                System.Console.Write(nodeDescription + " -- ");

                reversedListOfDescriptionsOfNodesUsedInCurrentRun.Insert(0, nodeDescription);
            }

            System.Console.WriteLine("AT TARGET NODE");

            System.Console.WriteLine("That list of node descriptions reversed look as follows...");

            foreach (String nodeDescriptionFromReversedList in reversedListOfDescriptionsOfNodesUsedInCurrentRun)
            {
                System.Console.Write(nodeDescriptionFromReversedList + " -- ");
            }

            System.Console.WriteLine("AT LAST RUN'S STARTING NODE");

            if (_masterGraph.NumNodes() == 0)
            {
                _masterGraph = _currentGraph;

                _masterGraphTargetNode = _currentNode;

                _masterGraphTargetNode.IsTarget = true;

                _masterGraphTargetNodeXCoordinate = _xCoordinate;

                _masterGraphTargetNodeYCoordinate = _yCoordinate;

                _masterGraphAlreadyIssuedCoordinates = _alreadyIssuedCoordinates;

                _masterGraphNodeNamesListCounter = _nodeNamesListCounter;
            }
            else
            {
                _currentNode = _masterGraphTargetNode; // Not necessary; Simply explicative

                _xCoordinate = _masterGraphTargetNodeXCoordinate;

                _yCoordinate = _masterGraphTargetNodeYCoordinate;

                int backtrackingCounter = 0;

                while (backtrackingCounter < reversedPathOfDirectionsTraveledInCurrentRun.Count)
                {
                    string backtrackingDirectionTraveled = reversedPathOfDirectionsTraveledInCurrentRun.ElementAt(backtrackingCounter);

                    if (backtrackingDirectionTraveled.Equals("north"))
                    {
                        GoNorth();
                    }

                    if (backtrackingDirectionTraveled.Equals("east"))
                    {
                        GoEast();
                    }

                    if (backtrackingDirectionTraveled.Equals("south"))
                    {
                        GoSouth();
                    }

                    if (backtrackingDirectionTraveled.Equals("west"))
                    {
                        GoWest();
                    }

                    bool northArcOptionIsPresent = false;

                    bool eastArcOptionIsPresent = false;

                    bool southArcOptionIsPresent = false;

                    bool westArcOptionIsPresent = false;

                    if (reversedListOfDescriptionsOfNodesUsedInCurrentRun.ElementAt(backtrackingCounter + 1).Contains("N"))
                    {
                        northArcOptionIsPresent = true;
                    }

                    if (reversedListOfDescriptionsOfNodesUsedInCurrentRun.ElementAt(backtrackingCounter + 1).Contains("E"))
                    {
                        eastArcOptionIsPresent = true;
                    }

                    if (reversedListOfDescriptionsOfNodesUsedInCurrentRun.ElementAt(backtrackingCounter + 1).Contains("S"))
                    {
                        southArcOptionIsPresent = true;
                    }

                    if (reversedListOfDescriptionsOfNodesUsedInCurrentRun.ElementAt(backtrackingCounter + 1).Contains("W"))
                    {
                        westArcOptionIsPresent = true;
                    }

                    UpdateMasterGraphHelper(northArcOptionIsPresent, eastArcOptionIsPresent, southArcOptionIsPresent, westArcOptionIsPresent);

                    backtrackingCounter += 1;
                }
            }

            System.Console.WriteLine("The GraphBuilder's Master Graph is now setup as follows...");

            _masterGraph.ListNodes();

            _masterGraph.ListArcs();

            System.Console.WriteLine("The GraphBuilder's Master Graph target node is: " +
                                        _masterGraphTargetNode.Name + " [" + _masterGraphTargetNodeXCoordinate +
                                        "," + _masterGraphTargetNodeYCoordinate + "]");

            //System.Console.WriteLine("Leaving UpdateMasterGraph()\n");
        }
Ejemplo n.º 8
0
        /*
         * 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");
        }
Ejemplo n.º 9
0
        /*
         * StartNewRun prepares the GraphBuilder to begin an new run by updating the Master Graph and reseting all Current Run Graph
         * variables to their start state.
         */
        public void StartNewRun()
        {
            //System.Console.WriteLine("\nIn StartNewRun()");

            UpdateMasterGraph();

            _currentGraph = new Graph();

            _xCoordinate = 0;

            _yCoordinate = 0;

            _alreadyIssuedCoordinates = new List<string>();

            _currentNode = new Node();

            _previousNode = new Node();

            _directionTraveled = "none";

            _nodeNamesListCounter = 0;

            _descriptionsOfNodesUsedInCurrentRun = new List<string>();

            _directionsTraveledInCurrentRun = new List<string>();

            //System.Console.WriteLine("Leaving StartNewRun()\n");
        }
Ejemplo n.º 10
0
        /*************************
         *  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");
        }
        /*
         * StartNewRun method sets the class's _currentNode variable to a random node in the graph.
         * That node will be used as the starting node for the next run of the graph, which will be initiated by the agent class.
         */
        void Intermediate.StartNewRun()
        {
            //System.Console.WriteLine("\nIn StartNewRun()");

            System.Console.WriteLine("Press c to choose the next run's starting node; Press any other key to have it choosen by random: ");

            string optionSelect = Console.ReadLine();

            if (optionSelect.Equals("c"))
            {
                System.Console.WriteLine("Enter the name of the node (A-Y): ");

                string selectedNodeAsString = Console.ReadLine();

                Char selectedNodeAsChar = Convert.ToChar(selectedNodeAsString[0]);

                while (selectedNodeAsChar < 'A' || selectedNodeAsChar > 'Y')
                {
                    System.Console.WriteLine("Node not recognized; Enter the name of the node (A-Y): ");

                    selectedNodeAsString = Console.ReadLine();

                    selectedNodeAsChar = Convert.ToChar(selectedNodeAsString[0]);
                }

                selectedNodeAsString = Convert.ToString(selectedNodeAsChar);

                _currentNode = _graphBeingNavigated.GetNode(selectedNodeAsString);
            }
            else
            {
                int randomNumber = Helper.RandomNumberBetweenRange(0, _graphBeingNavigated.NumNodes());

                Node randomStartingNode = _graphBeingNavigated.NodesSet.ElementAt(randomNumber);

                System.Console.WriteLine("There are " + _graphBeingNavigated.NumNodes() + " nodes in the graph\nNode number " +
                                      randomNumber + " was chosen\nIts name is " + randomStartingNode.Name);

                _currentNode = randomStartingNode;
            }

            //System.Console.WriteLine("Leaving StartNewRun()\n");
        }
Ejemplo n.º 12
0
        /*
         * RemoveArc removes from the graph an arc between two nodes.
         */
        public void RemoveArc(Node node1, Node node2)
        {
            //System.Console.WriteLine("\nIn RemoveArc()");

            if (!ContainsArc(node1.Name + "<-->" + node2.Name))
            {
                System.Console.WriteLine("Arc not found in list of arcs; Nothing done");

                //System.Console.WriteLine("Leaving RemoveArc()\n");

                return;
            }

            // Remove actual connection between nodes

            if (node1.NodeConnectedViaNorthArcOption.Equals(node2))
            {
                node1.ResetSpecifiedArcOptionToDefault("north");

                node2.ResetSpecifiedArcOptionToDefault("south");
            }
            else if (node1.NodeConnectedViaEastArcOption.Equals(node2))
            {
                node1.ResetSpecifiedArcOptionToDefault("east");

                node2.ResetSpecifiedArcOptionToDefault("west");
            }
            else if (node1.NodeConnectedViaSouthArcOption.Equals(node2))
            {
                node1.ResetSpecifiedArcOptionToDefault("south");

                node2.ResetSpecifiedArcOptionToDefault("north");
            }
            else if (node1.NodeConnectedViaWestArcOption.Equals(node2))
            {
                node1.ResetSpecifiedArcOptionToDefault("west");

                node2.ResetSpecifiedArcOptionToDefault("east");
            }
            else
            {
                System.Console.WriteLine("Error; Connection between nodes not found");

                //System.Console.WriteLine("Leaving RemoveArc()\n");

                return;
            }

            // Remove arc from set

            string arcName1 = node1.Name + "<-->" + node2.Name;

            string arcName2 = node2.Name + "<-->" + node1.Name;

            System.Console.WriteLine("Looking for arc in set by name of " + arcName1 + " or " + arcName2);

            foreach (Arc arc in _arcs)
            {
                if (arc.Name.Equals(arcName1) || arc.Name.Equals(arcName2))
                {
                    System.Console.WriteLine("Arc " + arc.Name + " found in list of arcs and being removed");

                    _arcs.Remove(arc);

                    break;  // The list of arc has shrunk by one. If the foreach is not broken it will
                    // eventually attempt to access one more than the list's current size.
                }
            }

            //System.Console.WriteLine("Leaving RemoveArc()\n");
        }
Ejemplo n.º 13
0
        /*
         * 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;
        }
Ejemplo n.º 14
0
        public Node(string name, bool northArcOption, bool eastArcOption, bool southArcOption, bool westArcOption)
        {
            //System.Console.WriteLine("\nIn Node()");

            _name = name;

            _northArcOptionExists = northArcOption;

            _eastArcOptionExists = eastArcOption;

            _southArcOptionExists = southArcOption;

            _westArcOptionExists = westArcOption;

            _northArcOptionIsExplored = false;

            _eastArcOptionIsExplored = false;

            _southArcOtionIsExplored = false;

            _westArcOptionIsExplored = false;

            StringBuilder tempNodeDescription = new StringBuilder();

            if (northArcOption == true)
            {
                tempNodeDescription.Append("N");

                _nodeConnectedViaNorthArcOption = new Node();
            }

            if (eastArcOption == true)
            {
                tempNodeDescription.Append("E");

                _nodeConnectedViaEastArcOption = new Node();
            }

            if (southArcOption == true)
            {
                tempNodeDescription.Append("S");

                _nodeConnectedViaSouthArcOption = new Node();
            }

            if (westArcOption == true)
            {
                tempNodeDescription.Append("W");

                _nodeConnectedViaWestArcOption = new Node();
            }

            _arcOptions = tempNodeDescription.ToString();

            _isTarget = false;

            _cost = 0;

            _northArcOptionCost = 0;

            _eastArcOptionCost = 0;

            _southArcOptionCost = 0;

            _wesArcOptionCost = 0;

            _xCoordinate = 0;

            _yCoordinate = 0;

            //WriteDetailedDescriptionOfNodeToConsole();

            //System.Console.WriteLine("Leaving Node()\n");
        }
Ejemplo n.º 15
0
        /*
         * GetOtherNode method returns the node that is paired with the node the method receives.
         *
         * It should only be used after ContainsNode has returned true for the node being passed to the method.
         */
        public Node GetOtherNode(Node node)
        {
            //System.Console.WriteLine("\nIn GetOtherNode()");

            // Should only be used after checking that node is part of arc [i.e. ContainsNode(node) == true]

            if (_nodesInArc.First().Equals(node))
            {
                //System.Console.WriteLine("Leaving GetOtherNode()\n");

                return (_nodesInArc.Last());
            }

            //System.Console.WriteLine("Leaving GetOtherNode()\n");

            return (_nodesInArc.First());
        }
Ejemplo n.º 16
0
        /*
         * ResetSpecifiedArcOptionToDefault method receives an arcOption and connects a placer-holder node to that option.
         *
         * The method is used by the Graph class when it uses its RemoveArc method.
         */
        public void ResetSpecifiedArcOptionToDefault(string arcOption)
        {
            //System.Console.WriteLine("\nIn ResetSpecifiedArcOptionToDefault()");

            Node defaultNode = new Node();

            if (arcOption == "north" || arcOption == "east" || arcOption == "south" || arcOption == "west")
            {
                ConnectNodeToAnotherViaSpecifiedArcOption(defaultNode, arcOption);
            }
            else
            {
                System.Console.WriteLine("Arc option not recognized; Nothing done");
            }

            //System.Console.WriteLine("Leaving ResetSpecifiedArcOptionToDefault()\n");
        }
Ejemplo n.º 17
0
        /*
         * NeighboringNodeToSpecifiedDirection returns the node which neighbors to the specified direction.
         */
        public Node NeighboringNodeToSpecifiedDirection(string arcOption)
        {
            //System.Console.WriteLine("In NeighboringNodeToSpecifiedDirection()\n");

            Node neighboringNode = new Node();

            if (arcOption.Equals("north"))
            {
                neighboringNode = _nodeConnectedViaNorthArcOption;
            }
            else if (arcOption.Equals("east"))
            {
                neighboringNode = _nodeConnectedViaEastArcOption;
            }
            else if (arcOption.Equals("south"))
            {
                neighboringNode = _nodeConnectedViaSouthArcOption;
            }
            else if (arcOption.Equals("west"))
            {
                neighboringNode = _nodeConnectedViaWestArcOption;
            }

            //System.Console.WriteLine("Leaving NeighboringNodeToSpecifiedDirection()\n");

            return neighboringNode;
        }
Ejemplo n.º 18
0
        /*************************
         *  METHODS
         *************************/
        /*
         * ConnectNodeToAnotherViaSpecifiedArcOption method receives a reference to a neighboring node that will be connected to
         * the node invoking the method, along with the arcOption through which that neighboring node will be connected.
         *
         * The method is used by the Graph class when it uses its AddArc method.
         */
        public void ConnectNodeToAnotherViaSpecifiedArcOption(Node connectedNode, String arcOption)
        {
            //System.Console.WriteLine("\nIn UpdateNodeConnectedViaSpecifiedArcOption()");

            if (this.Equals(connectedNode))
            {
                System.Console.WriteLine("Node " + _name + " cannot be connected with itself; Nothing done");
            }
            else if (arcOption.Equals("north"))
            {
                if (_northArcOptionExists == true)
                {
                    _nodeConnectedViaNorthArcOption = connectedNode;

                    System.Console.WriteLine("Node " + _name + "'s north arc option now connects with node " + connectedNode._name);
                }
                else
                {
                    System.Console.WriteLine("Node " + _name + " does not have a north arc option; Nothing done");
                }
            }
            else if (arcOption.Equals("east"))
            {
                if (_eastArcOptionExists == true)
                {
                    _nodeConnectedViaEastArcOption = connectedNode;

                    System.Console.WriteLine("Node " + _name + "'s east arc option now connects to node " + connectedNode._name);
                }
                else
                {
                    System.Console.WriteLine("Node " + _name + " does not have a east arc option; Nothing done");
                }
            }
            else if (arcOption.Equals("south"))
            {
                if (_southArcOptionExists == true)
                {
                    _nodeConnectedViaSouthArcOption = connectedNode;

                    System.Console.WriteLine("Node " + _name + "'s south arc option now connects to node " + connectedNode._name);
                }
                else
                {
                    System.Console.WriteLine("Node " + _name + " does not have a south arc option; Nothing done");
                }
            }
            else if (arcOption.Equals("west"))
            {
                if (_westArcOptionExists == true)
                {
                    _nodeConnectedViaWestArcOption = connectedNode;

                    System.Console.WriteLine("Node " + _name + "'s west arc option now connects to node " + connectedNode._name);
                }
                else
                {
                    System.Console.WriteLine("Node " + _name + " does not have a west arc option; Nothing done");
                }
            }
            else
            {
                System.Console.WriteLine("Arc option not recognized; Nothing done");
            }

            //System.Console.WriteLine("Leaving UpdateNodeConnectedViaSpecifiedArcOption()\n");
        }
        /*
         * GoSouth method moves the agent's current position to the node located directly to the south.
         */
        void Intermediate.GoSouth()
        {
            //System.Console.WriteLine("\nIn GoSouth()");

            _currentNode = _currentNode.NodeConnectedViaSouthArcOption;

            _orientation = "south";

            //System.Console.WriteLine("Leaving GoSouth()\n");
        }
Ejemplo n.º 20
0
        /*************************
         *  METHODS
         *************************/
        /*
         * ContainsNode method receives a node and returns a bool--true if the node is present in the arc instance and
         * false if it is not.
         *
         * Method should always be called before calling the GetOtherNode method.
         */
        public bool ContainsNode(Node node)
        {
            //System.Console.WriteLine("\nIn ContainsNode()");

            //System.Console.WriteLine("Leaving ContainsNode()\n");

            return _nodesInArc.Contains(node);
        }
        /*
         * GoWest method moves the agent's current position to the node located directly to the west.
         */
        void Intermediate.GoWest()
        {
            //System.Console.WriteLine("\nIn GoWest()");

            _currentNode = _currentNode.NodeConnectedViaWestArcOption;

            _orientation = "west";

            //System.Console.WriteLine("Leaving GoWest()\n");
        }
Ejemplo n.º 22
0
        static void Main(string[] args)
        {
            System.Console.WriteLine("Would you like to traverse a graph or a maze? ");

            string userOption1 = System.Console.ReadLine();

            while (!(userOption1.Equals("graph") || userOption1.Equals("maze")))
            {
                System.Console.WriteLine("Input not recognized. Please enter \"graph\" or \"maze\".");

                userOption1 = System.Console.ReadLine();
            }

            Intermediate intermediate;

            if (userOption1.Equals("graph"))
            {
                System.Console.WriteLine("Graph option selected");

                Node node1 = new Node("A", false, false, true, false);
                Node node2 = new Node("B", false, true, false, false);
                Node node3 = new Node("C", false, true, true, true);
                Node node4 = new Node("D", false, false, false, true);
                Node node5 = new Node("E", false, false, true, false);
                Node node6 = new Node("F", true, false, true, false);
                Node node7 = new Node("G", false, true, true, false);
                Node node8 = new Node("H", true, true, true, true);
                Node node9 = new Node("I", false, false, true, true);
                Node node10 = new Node("J", true, false, true, false);
                Node node11 = new Node("K", true, true, true, false);
                Node node12 = new Node("L", true, false, true, true);
                Node node13 = new Node("M", true, false, false, false);
                Node node14 = new Node("N", true, true, true, false);
                Node node15 = new Node("O", true, false, true, true);
                Node node16 = new Node("P", true, false, true, false);
                Node node17 = new Node("Q", true, true, false, false);
                Node node18 = new Node("R", false, true, true, true);
                Node node19 = new Node("S", true, false, false, true);
                Node node20 = new Node("T", true, false, true, false);
                Node node21 = new Node("U", true, false, false, false);
                Node node22 = new Node("V", false, true, false, false);
                Node node23 = new Node("W", true, true, false, true);
                Node node24 = new Node("X", false, false, false, true);
                Node node25 = new Node("Y", true, false, false, false);

                node13.IsTarget = true;

                Graph graph1 = new Graph();

                graph1.AddNode(node1);
                graph1.AddNode(node2);
                graph1.AddNode(node3);
                graph1.AddNode(node4);
                graph1.AddNode(node5);
                graph1.AddNode(node6);
                graph1.AddNode(node7);
                graph1.AddNode(node8);
                graph1.AddNode(node9);
                graph1.AddNode(node10);
                graph1.AddNode(node11);
                graph1.AddNode(node12);
                graph1.AddNode(node13);
                graph1.AddNode(node14);
                graph1.AddNode(node15);
                graph1.AddNode(node16);
                graph1.AddNode(node17);
                graph1.AddNode(node18);
                graph1.AddNode(node19);
                graph1.AddNode(node20);
                graph1.AddNode(node21);
                graph1.AddNode(node22);
                graph1.AddNode(node23);
                graph1.AddNode(node24);
                graph1.AddNode(node25);

                graph1.AddArc(node1, "south", node6);

                graph1.AddArc(node2, "east", node3);

                graph1.AddArc(node3, "east", node4);
                graph1.AddArc(node3, "south", node8);

                graph1.AddArc(node5, "south", node10);

                graph1.AddArc(node6, "south", node11);

                graph1.AddArc(node7, "east", node8);
                graph1.AddArc(node7, "south", node12);

                graph1.AddArc(node8, "east", node9);
                graph1.AddArc(node8, "south", node13);

                graph1.AddArc(node9, "south", node14);

                graph1.AddArc(node10, "south", node15);

                graph1.AddArc(node11, "east", node12);
                graph1.AddArc(node11, "south", node16);

                graph1.AddArc(node12, "south", node17);

                graph1.AddArc(node14, "east", node15);
                graph1.AddArc(node14, "south", node19);

                graph1.AddArc(node15, "south", node20);

                graph1.AddArc(node16, "south", node21);

                graph1.AddArc(node17, "east", node18);

                graph1.AddArc(node18, "east", node19);
                graph1.AddArc(node18, "south", node23);

                graph1.AddArc(node20, "south", node25);

                graph1.AddArc(node22, "east", node23);

                graph1.AddArc(node23, "east", node24);

                /* List of nodes in graph should be:
                 *
                 *  A through Y (25 total)
                 *
                 * List of arcs in graph should be:
                 *
                 *  A<-->F
                 *  B<-->C
                 *  C<-->D
                 *  C<-->H
                 *  E<-->J
                 *  F<-->K
                 *  G<-->H
                 *  G<-->L
                 *  H<-->I
                 *  H<-->M
                 *  I<-->N
                 *  J<-->O
                 *  K<-->L
                 *  K<-->P
                 *  L<-->Q
                 *  N<-->O
                 *  N<-->S
                 *  O<-->T
                 *  P<-->U
                 *  Q<-->R
                 *  R<-->S
                 *  R<-->W
                 *  T<-->Y
                 *  V<-->W
                 *  W<-->X
                 *
                 * Graph structure looks like:
                 *
                 *  A   B---C---D   E
                 *  |       |       |
                 *  F   G---H---I   J
                 *  |   |   |   |   |
                 *  K---L   M   N---O
                 *  |   |       |   |
                 *  P   Q---R---S   T
                 *  |       |       |
                 *  U   V---W---X   Y
                 *
                 * Graph target node is:
                 *
                 *  M
                 *
                 */

                intermediate = new GraphNavigatorIntermediate(graph1, node1, "north");
            }
            else
            {
                System.Console.WriteLine("Maze option selected");

                // When maze option is ready, it will go here.

                System.Console.WriteLine("Enter the arc's lighter color reading:");

                double lighterColorReading = Convert.ToDouble(System.Console.ReadLine());

                System.Console.WriteLine("Enter the arc's darker color reading:");

                double darkerColorReading = Convert.ToDouble(System.Console.ReadLine());

                System.Console.WriteLine("Enter the arc's reading for white:");

                double whiteReading = Convert.ToDouble(System.Console.ReadLine());

                intermediate = new MazeNavigatorIntermediate(darkerColorReading, lighterColorReading, whiteReading, "north");
            }

            System.Console.WriteLine("Would you like to traverse the graph manually? [n/y]");

            string userOption2 = System.Console.ReadLine();

            while (!(userOption2.Equals("y") || userOption2.Equals("n")))
            {

                System.Console.WriteLine("Input not recognized. Please enter \"n\" or \"y\".");

                userOption2 = System.Console.ReadLine();
            }

            if (userOption2.Equals("y"))
            {

                System.Console.WriteLine("Manual option seleted");

                ManualAgent agent1 = new ManualAgent(intermediate);

                agent1.Traverse();
            }
            else {

                System.Console.WriteLine("Automatic option seleted");

                AutonomousAgent agent2 = new AutonomousAgent(intermediate);

                agent2.Traverse();

            }

            System.Console.WriteLine("------------------------");
            System.Console.WriteLine("- Press any key to end program");
            System.Console.WriteLine("------------------------\n\n");

            System.Console.ReadLine();
        }
Ejemplo n.º 23
0
        /*
         * AddNode adds an instance of node to the graph.
         */
        public void AddNode(Node node)
        {
            //System.Console.WriteLine("\nIn AddNode()");

            if (ContainsNode(node.Name))
            {
                System.Console.WriteLine("A node by that name already exists in the graph; Nothing Done");

                //System.Console.WriteLine("Leaving AddNode()\n");

                return;
            }

            _nodes.Add(node);

            //System.Console.WriteLine("Leaving AddNode()\n");
        }
Ejemplo n.º 24
0
        /*
         * RemoveNode removes a instance of node from the graph.
         */
        public void RemoveNode(Node node)
        {
            //System.Console.WriteLine("\nIn RemoveNode()");

            if (!ContainsNode(node.Name))
            {
                System.Console.WriteLine("Node not found in list of nodes");

                //System.Console.WriteLine("Leaving RemoveNode()\n");

                return;
            }

            // Check which arcOptions a node has and if those options are connected to other nodes

            if (node.NorthArcOptionExists)
            {
                if (!node.NodeConnectedViaNorthArcOption.Name.Equals("Z"))
                {
                    System.Console.WriteLine("Removing arc connecting node " + node.Name + " to node " + node.NodeConnectedViaNorthArcOption.Name);

                    RemoveArc(node, node.NodeConnectedViaNorthArcOption);
                }
            }

            if (node.EastArcOptionExists)
            {
                if (!node.NodeConnectedViaEastArcOption.Name.Equals("Z"))
                {
                    System.Console.WriteLine("Removing arc connecting node " + node.Name + " to node to node " + node.NodeConnectedViaEastArcOption.Name);

                    RemoveArc(node, node.NodeConnectedViaEastArcOption);
                }
            }

            if (node.SouthArcOptionExists)
            {
                if (!node.NodeConnectedViaSouthArcOption.Name.Equals("Z"))
                {
                    System.Console.WriteLine("Removing arc connecting node " + node.Name + " to node " + node.NodeConnectedViaSouthArcOption.Name);

                    RemoveArc(node, node.NodeConnectedViaSouthArcOption);
                }
            }

            if (node.WestArcOptionExists)
            {
                if (!node.NodeConnectedViaWestArcOption.Name.Equals("Z"))
                {
                    System.Console.WriteLine("Removing arc connecting node " + node.Name + " to node " + node.NodeConnectedViaWestArcOption.Name);

                    RemoveArc(node, node.NodeConnectedViaWestArcOption);
                }
            }

            // Remove the node from the list of nodes

            _nodes.Remove(node);

            //System.Console.WriteLine("Leaving RemoveNode()\n");
        }