Beispiel #1
0
        /// <summary>
        /// Make decisions with the pending requests and order the elevators to move accordingly
        /// </summary>
        public override void HandleRequests()
        {
            // Match the closest elevator that is availible to the requests
            foreach (var request in this.Building.PendingRequests)
            {
                if (this.Elevators.OnTheWayRequests.Contains(request))
                {
                    // If the request has already been handled, continue
                    continue;
                }

                var availibleElevators = this.Elevators.Elevators.FindAll(elevator => (elevator.IsIdle || elevator.IsRelocating)).ToList();

                if (availibleElevators.Count() == 0)
                {
                    // If there are no more availible elevators, break
                    break;
                }

                // Add the waypoints to the elevator
                var closestElevator = ElevatorCollection.GetClosestElevator(availibleElevators, request.Source);

                // If the elevator was relocating, interrupt the relocation
                if (closestElevator.IsRelocating)
                {
                    closestElevator.CancelRelocation();
                }

                closestElevator.AddWaypoint(new ElevatorWaypoint(request.Source, WaypointType.PICK_UP, request.Destination));
                closestElevator.OnTheWayRequests.Add(request);
            }
        }
Beispiel #2
0
        public PredictiveRelocatorPluggin(ElevatorCollection elevators, SimulationConfiguration config)
        {
            this.Elevaotrs = elevators;

            this.RequestsDistribution = new uint[config.BuildingFloors];

            // Keep track of a rolling average of the past half an hour
            this.N = (config.TotalResidents * config.AverageRequestsPerResidentPerDay) / 48;

            this.RequestQueue = new Queue <Request>();
        }
        public ElevatorAI(Building building, ElevatorCollection elevators, SimulationConfiguration config)
        {
            this.Building  = building;
            this.Elevators = elevators;

            if (config.SmartRelocation)
            {
                this.Relocator = new PredictiveRelocatorPluggin(elevators, config);
            }
            else
            {
                this.Relocator = null;
            }
        }
Beispiel #4
0
        public Building(SimulationConfiguration config)
        {
            this.BuildingFloors   = config.BuildingFloors;
            this.ResidentPerFloor = config.ResidentsPerFloor;
            this.InterestPerFloor = config.InterestPerFloor;

            this.Elevators = new ElevatorCollection(config);

            this.ElevatorAI = ElevatorAIFactory.CreateElevatorAI(this, this.Elevators, config);

            this.RequestGenerator = RequestGeneratorFactory.CreateRequestGenerator(this, config);

            this.PendingRequests = new List <Request>();
        }
        public static ElevatorAI CreateElevatorAI(Building building, ElevatorCollection elevators, SimulationConfiguration config)
        {
            switch (config.AIType)
            {
            case "BENCHMARK":
                return(new BenchmarkAI(building, elevators, config));

            case "OPTIMIZED":
                return(new OptimizedAI(building, elevators, config));

            case "REGULAR":
                return(new RegularAI(building, elevators, config));

            default:
                throw new UnknownAIException("The Elevator AI: " + config.AIType + " is unknown.");
            }
        }
Beispiel #6
0
        public override void HandleRequests()
        {
            // Get all the requests that have not been handled yet
            var notHandledRequests = this.Building.PendingRequests.FindAll(request => !this.Elevators.OnTheWayRequests.Contains(request));

            foreach (var request in this.Building.PendingRequests)
            {
                if (this.Elevators.OnTheWayRequests.Contains(request))
                {
                    // If the request has already been handled, continue
                    continue;
                }

                var availibleElevators = this.Elevators.Elevators.FindAll(elevator => (elevator.IsIdle || elevator.IsRelocating)).ToList();

                if (availibleElevators.Count() == 0)
                {
                    var sameDirElevators = this.Elevators.Elevators.FindAll(elevator => (elevator.Direction == request.Direction && elevator.Direction == Direction.DOWN && request.Source < elevator.CurrentFloor && !elevator.OnTheWayRequests.Exists(r => r.Direction == Direction.UP)) ||
                                                                            (elevator.Direction == request.Direction && elevator.Direction == Direction.UP && request.Source > elevator.CurrentFloor && !elevator.OnTheWayRequests.Exists(r => r.Direction == Direction.DOWN)));

                    if (sameDirElevators.Count() == 0)
                    {
                        continue;
                    }

                    // Get the closest elevator
                    var closest = ElevatorCollection.GetClosestElevator(sameDirElevators, request.Source);
                    closest.AddWaypoint(new ElevatorWaypoint(request.Source, WaypointType.PICK_UP, request.Destination));
                    closest.OnTheWayRequests.Add(request);

                    continue;
                }

                // Add the waypoints to the elevator
                var closestElevator = ElevatorCollection.GetClosestElevator(availibleElevators, request.Source);

                // If the elevator was relocating, interrupt the relocation
                if (closestElevator.IsRelocating)
                {
                    closestElevator.CancelRelocation();
                }

                closestElevator.AddWaypoint(new ElevatorWaypoint(request.Source, WaypointType.PICK_UP, request.Destination));
                closestElevator.OnTheWayRequests.Add(request);
            }
        }
 public OptimizedAI(Building building, ElevatorCollection elevators, SimulationConfiguration config) : base(building, elevators, config)
 {
     this.SpeedPerTick = config.ElevatorSpeed;
     this.LoadingTime  = config.LoadingTime;
 }
Beispiel #8
0
 public RegularAI(Building building, ElevatorCollection elevators, SimulationConfiguration config) : base(building, elevators, config)
 {
 }