Skip to content

Commit

Permalink
Update (#26)
Browse files Browse the repository at this point in the history
* Update

* Update

* Update

* Update

* Update

* Update

* Update

* Update

---------

Co-authored-by: LongxingTan <tanlongxing888@163.com>
  • Loading branch information
yuetan1988 and LongxingTan committed Aug 9, 2023
1 parent 0036690 commit 7042313
Show file tree
Hide file tree
Showing 34 changed files with 1,018 additions and 329 deletions.
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ repos:
hooks:
- id: black
- repo: https://github.com/nbQA-dev/nbQA
rev: 1.3.1
rev: 1.2.3
hooks:
- id: nbqa-black
- id: nbqa-isort
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,13 @@

**[Documentation](https://python-lekin.readthedocs.io)** | **[Tutorials](https://python-lekin.readthedocs.io/en/latest/tutorials.html)** | **[Release Notes](https://python-lekin.readthedocs.io/en/latest/CHANGELOG.html)** | **[中文](https://github.com/LongxingTan/python-lekin/blob/master/README_zh_CN.md)**

**python-lekin** is a rapid-to-implement and easy-to-use Flexible Job Shop Scheduler Library, named after and inspired by [Lekin](https://web-static.stern.nyu.edu/om/software/lekin/). As a core function in **APS (advanced planning and scheduler)**, it helps manufacturers optimize the allocation of raw materials and production capacity optimally to balance demand and capacity.
**python-lekin** is a rapid-to-implement and easy-to-use Flexible Job Shop Scheduler Library, named after and inspired by [Lekin](https://web-static.stern.nyu.edu/om/software/lekin/). As a core function in **APS (advanced planning and scheduler)**, it helps manufacturers optimize the allocation of materials and production capacity optimally to balance demand and capacity.

- accelerate by
- Changeover Optimization
- Ready for demo, research and maybe production

# DRATFING- NOT FINISHED AND DON'T USE IT NOW!
# **DRAFTING- NOT FINISHED AND DON'T USE IT NOW!**

## Feature

Expand Down
15 changes: 9 additions & 6 deletions README_zh_CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,15 @@

**python-lekin**是一个APS智能排产调度工具,名字来源于[Lekin](https://web-static.stern.nyu.edu/om/software/lekin/)。在考虑实际约束的前提下,动态调整计划排程,高效响应客户订单承诺。

## 特征

- 支持工艺路线约束
- 支持产能约束
- 支持物料齐套约束
- 支持顺排、倒排等方法
- 支持遗传算法排产
- 支持强化学习排产

# **DRAFTING- NOT FINISHED AND DON'T USE IT NOW!**

## 快速入门

Expand All @@ -57,18 +59,19 @@ scheduler.solve(jobs, machines)

scheduler.draw()
```
### 数据解释
- Job
- Task
- Machine
- Route

## 示例
在实际APS系统开发中,

- 按工艺路线拆分工序
- 按BOM拆分物料

### 数据准备
- Job
- Task
- Machine
- Route

## 引用

```
Expand Down
7 changes: 7 additions & 0 deletions docs/source/application.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
Application
===========

基本概念
----------------
均衡生产:heijunka


数据
----------------

Expand Down Expand Up @@ -41,6 +46,8 @@ BOM: Bill Of Materials
·更新当前任务后续节点的最早开工时间,若当前任务为产品的最后一个工序则无须更新
8、判断所有任务是否均已完工,是则结束,否则返回步骤四。

解决冲突的过程,即是一个顺排的过程。把所有分布在该资源上的任务根据顺序进行顺排


可视化
------------
Expand Down
2 changes: 1 addition & 1 deletion docs/source/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ subject to:
Finite Capacity Planning

.. toctree::
:maxdepth: 5
:maxdepth: 2
:caption: Contents:

rules
Expand Down
1 change: 1 addition & 0 deletions docs/source/rules.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
Rules
============

分为rule-based、event-based、resource-based两种思路。

SPT最短加工时间
--------------------
Expand Down
49 changes: 0 additions & 49 deletions examples/basic_aps.py

This file was deleted.

129 changes: 129 additions & 0 deletions examples/data/k1.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
{
"itineraries": [
{
"itineraryName": "Itinerary 1",
"tasksList": [
{
"taskName": "Task 1",
"taskMachine": {
"machineName": "M1"
},
"taskDuration": 10.0
},
{
"taskName": "Task 2",
"taskMachine": {
"machineName": "M2"
},
"taskDuration": 5.0
},
{
"taskName": "Task 3",
"taskMachine": {
"machineName": "M3"
},
"taskDuration": 35.0
}
]
},
{
"itineraryName": "Itinerary 2",
"tasksList": [
{
"taskName": "Task 1",
"taskMachine": {
"machineName": "M2"
},
"taskDuration": 25.0
},
{
"taskName": "Task 2",
"taskMachine": {
"machineName": "M1"
},
"taskDuration": 5.0
},
{
"taskName": "Task 3",
"taskMachine": {
"machineName": "M3"
},
"taskDuration": 30.0
},
{
"taskName": "Task 4",
"taskMachine": {
"machineName": "M4"
},
"taskDuration": 15.0
}
]
},
{
"itineraryName": "Itinerary 3",
"tasksList": [
{
"taskName": "Task 1",
"taskMachine": {
"machineName": "M2"
},
"taskDuration": 5.0
},
{
"taskName": "Task 2",
"taskMachine": {
"machineName": "M4"
},
"taskDuration": 10.0
}
]
},
{
"itineraryName": "Itinerary 4",
"tasksList": [
{
"taskName": "Task 1",
"taskMachine": {
"machineName": "M2"
},
"taskDuration": 15.0
},
{
"taskName": "Task 2",
"taskMachine": {
"machineName": "M3"
},
"taskDuration": 10.0
},
{
"taskName": "Task 3",
"taskMachine": {
"machineName": "M4"
},
"taskDuration": 20.0
},
{
"taskName": "Task 4",
"taskMachine": {
"machineName": "M1"
},
"taskDuration": 10.0
}
]
}
],
"machines": [
{
"machineName": "M1"
},
{
"machineName": "M2"
},
{
"machineName": "M3"
},
{
"machineName": "M4"
}
]
}
90 changes: 90 additions & 0 deletions examples/rule_example1.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
import json

from lekin.dashboard.gantt import plot_gantt_chart
from lekin.lekin_struct import (
Job,
JobCollector,
Operation,
OperationCollector,
Resource,
ResourceCollector,
Route,
RouteCollector,
)
from lekin.solver.construction_heuristics import LPSTScheduler, SPTScheduler


def prepare_data(file_path="./data/k1.json"):
with open(file_path, "r", encoding="utf8") as file: # read file from path
data = json.loads(file.read())

job_collector = JobCollector()
# operation_collector = OperationCollector()
route_collector = RouteCollector()
resource_collector = ResourceCollector()

if list(data.keys()) == ["itineraries", "machines"]:
resources = data["machines"] # is first level structure is correct, then split
routes = data["itineraries"]

# parse the resource
for re in resources:
re_name = re["machineName"]
re_id = int(re_name.replace("M", ""))
resource = Resource(resource_id=re_id, resource_name=re_name)
resource_collector.add_resource_dict({re_id: resource})
print([i.resource_id for i in resource_collector.get_all_resources()])

# parse the job and route
for ro in routes:
# ro_name = ro["itineraryName"]
ro_id = int(ro["itineraryName"].replace("Itinerary ", ""))
route = Route(route_id=ro_id)
operations_sequence = []
for ta in ro["tasksList"]:
op_name = ta["taskName"]
op_id = ta["taskName"].replace("Task ", "")

op_pt = ta["taskDuration"]

op_tm = []
if isinstance(ta["taskMachine"], list):
for re in ta["taskMachine"]:
re_name = re["machineName"]
re_id = int(re_name.replace("M", ""))
op_tm.append(Resource(resource_id=re_id, resource_name=re_name))
else:
re_name = ta["taskMachine"]["machineName"]
re_id = int(re_name.replace("M", ""))
op_tm.append(Resource(resource_id=re_id, resource_name=re_name))

operations_sequence.append(
Operation(
operation_id=op_id,
operation_name=op_name,
quantity=1,
processing_time=op_pt,
parent_job_id=ro_id, # route defines job here
available_resource=op_tm,
)
)

route.operations_sequence = operations_sequence
route_collector.add_route(route)

job_collector.add_job(Job(job_id=ro_id, assigned_route_id=ro_id))

# print(resources)
print(routes)
pass
return job_collector, route_collector, resource_collector


def run_scheduling(job_collector, route_list, resource_collector):
scheduler = SPTScheduler()
scheduler.solve(job_collector, resource_collector, route_list)
return


if __name__ == "__main__":
prepare_data(file_path="./data/k1.json")
1 change: 0 additions & 1 deletion lekin/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
# from lekin.lekin_struct.operation import Operation
# from lekin.lekin_struct.route import Route
from lekin.scheduler import Scheduler
from lekin.solver.construction_heuristics import Rules
from lekin.solver.meta_heuristics import Heuristics

__all__ = ["Job", "Machine", "Route", "Operation", "Scheduler", "get_data"]
Expand Down
4 changes: 2 additions & 2 deletions lekin/lekin_struct/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"""

from lekin.lekin_struct.job import Job, JobCollector # 成品需求
from lekin.lekin_struct.operation import Operation # 工序
from lekin.lekin_struct.operation import Operation, OperationCollector # 工序
from lekin.lekin_struct.resource import Resource, ResourceCollector # 机器
from lekin.lekin_struct.route import Route
from lekin.lekin_struct.route import Route, RouteCollector
from lekin.lekin_struct.timeslot import TimeSlot

0 comments on commit 7042313

Please sign in to comment.