/// <summary> /// Overloaded Constructor that iterates through a floor string and creates corresponding Elevator objects /// </summary> /// <param name="flr">pass in a string representing the floor</param> /// <param name="floorNumber">indicates the floor number</param> /// <param name="floorState">indicates the state or T Value that the floor belongs to in the Elevator System</param> public Floor(string flr, int floorNumber, int floorState) { floor = new ArrayList(); if (flr != null) { foreach (char c in flr) { Elevator elevator = new Elevator(c, floorNumber,floorState); this.floor.Add(elevator); } } }
/// <summary> /// Call this method to find out where a current elevator will be in the next State /// </summary> /// <param name="currentElevator"></param> /// <returns></returns> private Elevator FindNextElevator(Elevator currentElevator) { int nextStateOfCurrentElevator = currentElevator.floorState + 1; Elevator elevator = null; if (currentElevator != null && nextStateOfCurrentElevator <= ElevatorProgram.FinalTime) { //Get a list of all floors at the current state Hashtable allFloorsAtCurrentState = (Hashtable)ElevatorStates[nextStateOfCurrentElevator]; foreach (Floor f in allFloorsAtCurrentState.Values) { //Return the Elevator object as soon as you find it in the Current State elevator = f.IsElevatorOnFloor(currentElevator.elevatorName); if (elevator != null) { break; } } } return(elevator); }
/// <summary> /// Call this method to see if the current elevator is on the Final Floor at time T /// </summary> /// <param name="currentElevatorNode"></param> /// <returns></returns> private bool IsCurrentElevatorAFinalNode(Elevator currentElevatorNode) { if (currentElevatorNode.floorState == ElevatorProgram.FinalTime && currentElevatorNode.elevatorFloorNumber == ElevatorProgram.FinalFloor) { return true; } else { return false; } }
/// <summary> /// Recursive method to find all possible paths that the Starting Elevator can take until time T. /// </summary> /// <param name="parentNode"></param> /// <param name="currentElevator"></param> private void GetChildren(TreeNode parentNode, Elevator currentElevator) { Elevator nextElevator = null; //Get a list of all Elevators in the Current State ArrayList allElevatorsOnFloor = FindAllElevatorsForCurrentState(currentElevator); try { if (currentElevator.floorState <= ElevatorProgram.FinalTime) { foreach (Elevator elevator in allElevatorsOnFloor) { //Create a tree node object for all Elevators in the Current State TreeNode Node = new TreeNode(elevator.elevatorName.ToString()); Node.Tag = elevator; parentNode.Nodes.Add(Node); //Find the next State of the current Elevator and call this method recursively //to find all of its Child Nodes or possible path until time T nextElevator = FindNextElevator(elevator); if (nextElevator != null) { GetChildren(Node, nextElevator); } } } } catch (Exception) { } }
/// <summary> /// Call this method to find out where a current elevator will be in the next State /// </summary> /// <param name="currentElevator"></param> /// <returns></returns> private Elevator FindNextElevator(Elevator currentElevator) { int nextStateOfCurrentElevator = currentElevator.floorState + 1; Elevator elevator = null; if (currentElevator != null && nextStateOfCurrentElevator <= ElevatorProgram.FinalTime) { //Get a list of all floors at the current state Hashtable allFloorsAtCurrentState = (Hashtable)ElevatorStates[nextStateOfCurrentElevator]; foreach (Floor f in allFloorsAtCurrentState.Values) { //Return the Elevator object as soon as you find it in the Current State elevator = f.IsElevatorOnFloor(currentElevator.elevatorName); if (elevator != null) { break; } } } return elevator; }
/// <summary> /// Call this method to obtain a list of all Elevators in the Current State /// </summary> /// <param name="currentElevator"></param> /// <returns></returns> private ArrayList FindAllElevatorsForCurrentState(Elevator currentElevator) { //Get all Floors at State 1 Hashtable allFloorsAtCurrentState = (Hashtable)ElevatorStates[currentElevator.floorState]; ArrayList allElevatorsOnFloor = null; Floor currentFloor = null; foreach (Floor f in allFloorsAtCurrentState.Values) { //Find out which floor that the current elevator is on if (f.IsElevatorOnFloor(currentElevator.elevatorName) != null) { currentFloor = f; break; } } if (currentFloor != null) { //Get a list of all Elevators on the floor allElevatorsOnFloor = currentFloor.GetAllElevatorsOnFloor(); } return allElevatorsOnFloor; }