private void BuildHandle()
        {
            try
            {
                // Checks
                if (Floors.Count < 2)
                {
                    throw new Exception("The simulation model must have at least 2 floors");
                }
                if (Elevators.Count < 1)
                {
                    throw new Exception("The simulation model must have at least 1 elevator");
                }

                ElevatorSimModel simModel = m_model.BuildModel(Floors.ToList(), Elevators.ToList());
                simModel.Log += AddEventLog;

                m_model.LinkStatistics(Floors.Count, Elevators.Count);

                IsBuilded = true;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Error", MessageBoxButton.OK);
            }
        }
Example #2
0
        /// <summary>
        /// Find the nearest elevator from the requested floor lobby when a up/down button is pressed by a person
        /// </summary>
        /// <param name="floor">This is the floor number i.e. form which floor lobby the user is pressed the button. </param>
        /// <param name="elevators">All availabe elevators to the Elevator system.</param>
        /// <returns>Returns the nearest elevator.</returns>
        public static IDictionary <Elevator, int> GetElevatorTimeMap(int requestedFloorNo)
        {
            var elevatorTimeMap = new Dictionary <Elevator, int>();

            System.Threading.Tasks.Task task = System.Threading.Tasks.Task.Run(() => Elevators.ToList().ForEach(elevator =>
            {
                int t = Utility.FindTimeTaken(elevator, requestedFloorNo);
                elevatorTimeMap.Add(elevator, t);
            }));
            task.Wait();
            return(elevatorTimeMap);
        }