How to Build a Python Appointment‑Based Elevator Control System

This article walks through building a Python-based appointment elevator control system, covering platform setup, independent elevator design with detailed class implementations, a task‑oriented group‑control algorithm, and provides complete source code and diagrams for simulation and scheduling.

Python Crawling & Data Mining
Python Crawling & Data Mining
Python Crawling & Data Mining
How to Build a Python Appointment‑Based Elevator Control System

Design Platform

Windows 10

Python 3.8

Independent Elevator System Design

The group‑controlled elevator system fundamentally consists of independently operating elevators, so we first design an independent elevator system and illustrate its flow with a diagram.

We scan all floor requests in the building and drive elevators to fulfill passenger requests from the source floor to the target floor. Core code is shown below:

def take_elevator(self, elevator_data):
    """进电梯"""
    if not elevator_data:
        return elevator_data
    elevator_data = pd.DataFrame(elevator_data, dtype='int')
    data = elevator_data[elevator_data['up'] == self.up].copy()
    data2 = elevator_data[elevator_data['up'] != self.up].copy()
    while data['weight'].sum() > self.weight and not data.empty:  # 超重
        weight_max = data[data['weight'] == data['weight'].max()].index
        data2 = data2.append(data.loc[weight_max, :])
        data.drop(weight_max, inplace=True)
    while len(data) > self.persons and not data.empty:  # 超载
        weight_min = data[data['weight'] == data['weight'].min()].index
        data2 = data2.append(data.loc[weight_min, :])
        data.drop(weight_min, inplace=True)
    self.person_data = self.person_data.append(data)
    self.update_person_data(data, 'sub')
    return data2.to_dict(orient='records')

To better simulate real‑world elevator request handling, we create building, person model, elevator, and random person generation classes. When the number of passengers or total weight exceeds limits, the elevator skips loading passengers from the current floor.

Person Model Class

This class receives the current floor and floor range, then returns attributes of a person who will take the elevator.

class PeopleRandom:
    """
    构造随机人物模型
    返回各人物属性值,包含:所在楼层,体重,是否上楼,去往楼层
    """
    def __init__(self, floor: int, floors: tuple = (1, 30), people: int = 1):
        self.floor = floor
        self.floor_min, self.floor_max = floors
        self.people = people
        self.weight = self.set_weight()
        self.up = random.randint(0, 1)
        self.floor_go = self.go()

Random Floor Generation Class

This class takes a floor range and maximum number of people per floor, returning the passenger situation for all floors in the building.

class FloorsRandom:
    """
    随机楼层生成,楼层随机人数生成。
    """
    def __init__(self, floor_min: int, floor_max: int, people: int = 6):
        """
        输入的楼层是不存在0层,故而在floor_min进行加1后进行随机取数,如果小于等于0则减去1还原最低楼层。
        :param floor_min: 最低楼层
        :param floor_max: 最高楼层
        """

Elevator Class

The elevator model defines travel range, weight and passenger limits, direction, and passenger status.

class Elevator:
    """
    电梯模型:
    能够运行到的最低楼层,最高楼层及当前楼层
    """
    def __init__(self, floor_min, floor_max, floor: int = 1):
        self.floor = floor
        self.go_max = self.floor
        self.floor_min = floor_min
        self.floor_max = floor_max
        self.up = 1  # 1: 电梯上行,0:电梯下行
        self.weight = 1000  # 电梯限重
        self.persons = 12  # 电梯限制人员数量
        self.person_data = pd.DataFrame(columns=['floor', 'weight', 'up', 'floor_go'])

Building Class

The building model defines the floor range and passenger situation for each floor.

class BuildingList:
    """
    楼宇模型:
    最低楼层,最高楼层
    """
    def __init__(self, floor_min: int = -1, floor_max: int = 30):
        self.floor_min = floor_min
        self.floor_max = floor_max
        self.data = pd.DataFrame(columns=['floor', 'weight', 'up', 'floor_go'])
        self.set_data_all('simple')

To simplify computation, the model uses random person generation and assumes the elevator can transport all waiting passengers to their target floors across the building’s highest and lowest levels.

Design model code is open‑source:

https://github.com/lk20200413/FunnyCodeRepository/tree/main/预约式电梯任务系统

Group‑Control Elevator System Design

The group‑control design can effectively reduce passenger waiting time on each floor and improve comfort inside elevators.

In many residential buildings, elevators are independently controlled; pressing request buttons on each elevator can cause crowding and longer waits. The proposed "task system" treats floor requests as tasks, distributes them to elevators, rescans the building periodically, and switches elevators back to independent mode when no tasks remain.

Task system design flowchart:

Elevator execution flowchart:

The task system uses a distance‑first strategy. Detailed code is omitted for brevity; interested readers can obtain it from the repository above or contact the author for TaskSystem.py.

Summary

By designing a task‑based appointment elevator system in Python, we see that converting independent elevators into a coordinated group‑control system involves more than simply combining elevators; the design should prioritize time‑based operation, using multithreading to simulate concurrent elevator behavior. In this simplified version, floor‑skipping replaces detailed timing differences.

Any beautiful thing in the world is worth cherishing; we should not abandon our dreams because of present hardships.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

PythonBackend DevelopmentSystem Designtask schedulingElevator Simulation
Python Crawling & Data Mining
Written by

Python Crawling & Data Mining

Life's short, I code in Python. This channel shares Python web crawling, data mining, analysis, processing, visualization, automated testing, DevOps, big data, AI, cloud computing, machine learning tools, resources, news, technical articles, tutorial videos and learning materials. Join us!

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.