Beispiel #1
0
        static void Main(string[] args)
        {
            AVL_BST myTree = new AVL_BST(); // create AVL tree

            Console.WriteLine("Check if tree is empty:");
            Console.WriteLine(myTree.IsEmpty()); // should be true


            Sensor SensorNorth = new Sensor(0, "North"); // robot is heading toward north
            Sensor SensorWest  = new Sensor(0, "West");
            Sensor SensorEast  = new Sensor(1, "East");

            Sensor SensorSouth = new Sensor(0, "South");


            // initialize the system
            myTree.Initialize(SensorNorth.SensorTrigger(), SensorNorth.SensorLabel(), SensorWest.SensorTrigger(), SensorWest.SensorLabel(), SensorEast.SensorTrigger(), SensorEast.SensorLabel());

            Console.WriteLine("\n-------Initial System Configuration----------");

            myTree.PrintInOrder();    // print initial configuration



            //------------1st update
            Console.WriteLine("\nFirst update after hitting obstacle");
            SensorNorth.SensorUpdate(1);                                                     // obstacle in north direction. change north sensor trigger to 1

            myTree.RootUpdate(SensorNorth.SensorTrigger(), SensorNorth.SensorLabel());       // Due to obstacle, root value changes to 1

            myTree.UpdatedSensorAdd(SensorSouth.SensorTrigger(), SensorSouth.SensorLabel()); // system updates to possible obstacle free direction

            myTree.ClockSingleRot();                                                         // Single clockwise rotation


            Console.WriteLine("-----ClockWise Single Rotation----");
            myTree.PrintInOrder();

            // second update
            Console.WriteLine("\nSecond update after hitting obstacle");
            SensorWest.SensorUpdate(1);                                                    // obstacle in west direction. change west sensor trigger to 1

            SensorEast.SensorUpdate(0);                                                    // East sensor is now obstacle free.Hence, 0

            myTree.RootUpdate(SensorWest.SensorTrigger(), SensorWest.SensorLabel());       // Due to obstacle, root value changes to 1

            myTree.UpdatedSensorAdd(SensorEast.SensorTrigger(), SensorEast.SensorLabel()); // system updates to possible obstacle free direction

            myTree.ClockSingleRot();                                                       // Single clockwise rotation


            Console.WriteLine("-----ClockWise Single Rotation----");
            myTree.PrintInOrder();


            // 3rd update

            Console.WriteLine("\nThird update after hitting obstacle");
            SensorSouth.SensorUpdate(1);                                                     // obstacle in south direction. change south sensor trigger to 1

            SensorNorth.SensorUpdate(0);                                                     // North sensor is now 0

            myTree.RootUpdate(SensorSouth.SensorTrigger(), SensorSouth.SensorLabel());       // Due to obstacle, root value changes to 1

            myTree.UpdatedSensorAdd(SensorNorth.SensorTrigger(), SensorNorth.SensorLabel()); // system updates to possible obstacle free direction

            myTree.ClockSingleRot();                                                         // Single clockwise rotation


            Console.WriteLine("-----ClockWise Single Rotation----");
            myTree.PrintInOrder();



            Console.WriteLine("\nCheck if tree is empty:");
            Console.WriteLine(myTree.IsEmpty()); // should be false
        }
Beispiel #2
0
        static void Main(string[] args)
        {
            AVL_BST myTree = new AVL_BST(); // create AVL tree

            Console.WriteLine("Check if tree is empty:");
            Console.WriteLine(myTree.IsEmpty()); // should be true


            Sensor SensorNorth = new Sensor(0, "North"); // robot is heading toward north
            Sensor SensorWest  = new Sensor(0, "West");
            Sensor SensorEast  = new Sensor(1, "East");

            Sensor SensorSouth = new Sensor(0, "South");


            // initialize the system
            myTree.Initialize(SensorNorth.SensorTrigger(), SensorNorth.SensorLabel(), SensorWest.SensorTrigger(), SensorWest.SensorLabel(), SensorEast.SensorTrigger(), SensorEast.SensorLabel());

            Console.WriteLine("\n-------Initial System Configuration----------");

            myTree.PrintInOrder();    // print initial configuration



            //------------1st update
            Console.WriteLine("\nFirst update after hitting obstacle");
            SensorNorth.SensorUpdate(1);                                                     // obstacle in north direction. change north sensor trigger to 1

            myTree.RootUpdate(SensorNorth.SensorTrigger(), SensorNorth.SensorLabel());       // Due to obstacle, root value changes to 1

            myTree.UpdatedSensorAdd(SensorSouth.SensorTrigger(), SensorSouth.SensorLabel()); // system updates to possible obstacle free direction

            myTree.ClockSingleRot();                                                         // Single clockwise rotation


            Console.WriteLine("-----ClockWise Single Rotation----");
            myTree.PrintInOrder();

            // second update
            Console.WriteLine("\nSecond update after hitting obstacle");
            SensorWest.SensorUpdate(1);                                                    // obstacle in west direction. change west sensor trigger to 1

            SensorEast.SensorUpdate(0);                                                    // East sensor is now obstacle free.Hence, 0

            myTree.RootUpdate(SensorWest.SensorTrigger(), SensorWest.SensorLabel());       // Due to obstacle, root value changes to 1

            myTree.UpdatedSensorAdd(SensorEast.SensorTrigger(), SensorEast.SensorLabel()); // system updates to possible obstacle free direction

            myTree.ClockSingleRot();                                                       // Single clockwise rotation


            Console.WriteLine("-----ClockWise Single Rotation----");
            myTree.PrintInOrder();


            // 3rd update

            Console.WriteLine("\nThird update after hitting obstacle");
            SensorSouth.SensorUpdate(1);                                                     // obstacle in south direction. change south sensor trigger to 1

            SensorNorth.SensorUpdate(0);                                                     // North sensor is now 0

            myTree.RootUpdate(SensorSouth.SensorTrigger(), SensorSouth.SensorLabel());       // Due to obstacle, root value changes to 1

            myTree.UpdatedSensorAdd(SensorNorth.SensorTrigger(), SensorNorth.SensorLabel()); // system updates to possible obstacle free direction

            myTree.ClockSingleRot();                                                         // Single clockwise rotation


            Console.WriteLine("-----ClockWise Single Rotation----");
            myTree.PrintInOrder();



            Console.WriteLine("\nCheck if tree is empty:");
            Console.WriteLine(myTree.IsEmpty()); // should be false


            /* A PseudoCode for Robot Navigation
             *
             *
             * System Initialization()
             *
             * while(true)
             * {
             *
             *     // Thread 1
             *
             *     SensorUpdate()      // Keep all
             *
             *     if(leftChild == 1) // Theres an obstacle on left
             *     {
             *
             *         LeftChild.Update() // Find a sensor with 0 value (clear path and put it in leftchild)
             *
             *
             *     }
             *
             *
             *     // Thread 2
             *
             *     RobotAction() // robot action class. Moving and Stoping
             *
             *     if(root == 1) // Obstacle in the moving direction
             *     {
             *
             *        AVLRotate()
             *
             *
             *     }
             *
             *
             *
             *
             *
             *
             *
             *
             *
             *
             * }
             *
             *
             *
             */
        }