How to Build a Python Appointment‑Based Elevator Control System
This article explains how to design and implement a Python‑driven appointment elevator system, covering platform setup, independent and group‑control architectures, core classes for people, floors, elevators, and buildings, and includes key code snippets and flow diagrams.
Hello, I'm 🌑 (the dark side of the moon). Today I introduce a Python‑based appointment elevator control system.
Design Platform
Windows 10
Python 3.8
Independent Elevator System Design
The core idea is to scan all floor requests, drive elevators to serve them, and handle overload or overcapacity. The following diagram illustrates the flow.
Key code for processing elevator requests:
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')PeopleRandom (Person Model)
Generates random person attributes such as current floor, weight, direction, and destination.
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()FloorsRandom (Random Floor Generator)
Creates passenger distribution for each floor within a given range.
class FloorsRandom:
"""
随机楼层生成,楼层随机人数生成。
"""
def __init__(self, floor_min: int, floor_max: int, people: int = 6):
"""...
"""Elevator
Defines elevator limits, direction, weight capacity, and passenger data.
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: up, 0: down
self.weight = 1000 # limit weight
self.persons = 12 # limit persons
self.person_data = pd.DataFrame(columns=['floor','weight','up','floor_go'])BuildingList
Represents a building with floor range and passenger data.
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')Group‑Control Elevator System Design
The group‑control system treats floor requests as tasks, distributes them among elevators, and periodically rescans until no pending requests remain, then switches elevators back to independent mode. This reduces waiting time and improves passenger comfort.
Task system flow diagram:
Each elevator execution flow diagram:
https://github.com/lk20200413/FunnyCodeRepository/tree/main/预约式电梯任务系统
Summary
The Python task‑based elevator system demonstrates how converting independent elevators into a coordinated group can be modeled with object‑oriented classes, simplified time handling, and multithreaded‑like task distribution, providing a foundation for more advanced scheduling algorithms.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
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!
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
