# shift_schedule **Repository Path**: dualwind/shift_schedule ## Basic Information - **Project Name**: shift_schedule - **Description**: 一个基于 or-tools 的排班系统,采用线性规划方法,适用于小规模排班场景 - **Primary Language**: Python - **License**: Apache-2.0 - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 2 - **Forks**: 1 - **Created**: 2022-09-05 - **Last Updated**: 2024-05-08 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # shift_schedule 排班系统 一个基于 or-tools 的排班系统,采用线性规划方法,适用于小规模排班场景 ## 说明 ### 基本步骤 1. 下载发行版 2. 运行程序 3. ~~打开http://127.0.0.1:5000,~~设置参数 4. 生成模板,并在 user_data 中的`排班模板.xls`中填写固定排班和员工期望排班(在原始排班工作表中填入员工期望(字体颜色不是"自动")和已固定的排班(单元格不是"无填充颜色"或纯白色)) 5. 关闭`排班模板.xls`,点击开始排班,在`排班模板.xls`排班结果工作表中查看结果 ### 参数说明 - 初始数据 ```python num_employees = 8 # 员工数 num_weeks = 3 # 需要排班的周数 shifts = ['O', 'M', 'A', 'N'] #班种 # 注意,员工号,日期等均从0开始计数 # 在下面的例子中,0表示休息,3表示夜班,1表示上午班,2表示下午班 ``` - 预先固定的排班 ```python # Fixed assignment: (employee, shift, day). # 已固定的排班:(员工号,班种,日期) # 可以用来指定前几天的排班,或者员工已批准(已确定)的休假 # 注意,该数据将会包含在输出中 # This fixes the first 2 days of the schedule. fixed_assignments = [ (0, 0, 0), (1, 0, 0), (2, 1, 0), (3, 1, 0), (4, 2, 0), (5, 2, 0), (6, 2, 3), (7, 3, 0), (0, 1, 1), (1, 1, 1), (2, 2, 1), (3, 2, 1), (4, 2, 1), (5, 0, 1), (6, 0, 1), (7, 3, 1), ] ``` - 员工需求 ```python # Request: (employee, shift, day, weight) # 员工需求:(员工号,班种,日期,权重) # A negative weight indicates that the employee desire this assignment. # 负权重表示该员工希望该天排到该班种,而正权重则表示不希望当天是该班种 requests = [ # Employee 3 wants the first Saturday off. (3, 0, 5, -2), # Employee 5 wants a night shift on the second Thursday. (5, 3, 10, -2), # Employee 2 does not want a night shift on the first Friday. (2, 3, 4, 4) ] ``` - 连续上某班种的天数限制 ```python # Shift constraints on continuous sequence : # (shift, hard_min, soft_min, min_penalty, # soft_max, hard_max, max_penalty) # 连续上某班种的天数限制 # (班种,硬性限制_在周期内最少连续要上的班期天数,软性限制_最小值,超出软性限制最小值的罚值 # 软性限制_最大值, 硬性限制_最大值,超出软性限制最大值的罚值) # 如(3, 1, 2, 20, 3, 4, 5)表示夜班连续数必须在1到4之间,但是不在2到3之间的话视为不良方案 # (0, 1, 1, 0, 2, 2, 0)表示连续休息的数量必须在1到2之间 shift_constraints = [ # One or two consecutive days of rest, this is a hard constraint. (0, 1, 1, 0, 2, 2, 0), # betweem 2 and 3 consecutive days of night shifts, 1 and 4 are # possible but penalized. (3, 1, 2, 20, 3, 4, 5), ] ``` - 每周上某班种的天数限制 ```python # Weekly sum constraints on shifts days: # (shift, hard_min, soft_min, min_penalty, # soft_max, hard_max, max_penalty) # 每周上某班种的天数限制 # (0, 1, 2, 7, 2, 3, 4)表示一周必须休息1到3天,休息2天最好 # (3, 0, 1, 3, 4, 4, 0)表示一周最好有1天夜班,最多4天夜班 weekly_sum_constraints = [ # Constraints on rests per week. (0, 1, 2, 7, 2, 3, 4), # At least 1 night shift per week (penalized). At most 4 (hard). (3, 0, 1, 3, 4, 4, 0), ] ``` - [ ] 连续两天之间班种转换的罚值 ```python # Penalized transitions: # (previous_shift, next_shift, penalty (0 means forbidden)) # 连续两天之间班种转换的罚值: # (前一天的班种,后一天的班种,罚值(0表示禁止这种转换)) # (2, 3, 4)上完下午班第二天可以上夜班,但最好不要这样 # (3, 1, 0)禁止上完夜班第二天接着上早班 penalized_transitions = [ # Afternoon to night has a penalty of 4. (2, 3, 4), # Night to morning is forbidden. (3, 1, 0), ] ``` - 一周中各天各个班种需要的员工数 ```python # daily demands for work shifts (morning, afternon, night) for each day # of the week starting on Monday. # 一周中各天各个班种需要的员工数,休息不计算在内(第一个班种) weekly_cover_demands = [ (2, 3, 1), # Monday (2, 3, 1), # Tuesday (2, 2, 2), # Wednesday (2, 3, 1), # Thursday (2, 2, 2), # Friday (1, 2, 3), # Saturday (1, 3, 1), # Sunday ] ``` - [ ] 超过上条中规定数量的罚值(目前默认全为5) ```python # Penalty for exceeding the cover constraint per shift type. # 超过上条中规定数量的罚值 # (2, 2, 5)夜班罚值较多 excess_cover_penalties = (2, 2, 5) ``` ## 开发计划 - [ ] 保存多个配置 - [ ] 前端显示结果 - [ ] 更多参数项配置(详见参数说明) ## 参考与依赖 - [or-tools-Google's Operations Research tools](https://github.com/google/or-tools) - [Flask-The Python micro framework for building web applications.](https://github.com/pallets/flask) 源代码未提供以下JavaScript、CSS文件,开发模式请手动修改index.html文件头 - [Vue.js-渐进式JavaScript 框架](https://cn.vuejs.org/) - [Pico.css-Minimal CSS Framework for semantic HTML](https://picocss.com/) - [Axios-基于promise可以用于浏览器和node.js的网络请求库](https://www.axios-http.cn/docs/intro) - [or-tools 排班系统示例](https://github.com/google/or-tools/blob/master/examples/python/shift_scheduling_sat.py) - https://developers.google.com/optimization/scheduling/employee_scheduling#program