
# Scheduling Service
## Production / Work Order Scheduling
:::info
**Primary goal**: Scheduling the work orders optimally to increase the productivity and efficiency, reduce costs, deliver on time, and increase customer satisfaction.
:::
Please refer to this [document](https://advantecho365-my.sharepoint.com/:w:/g/personal/ashley_peng_advantech_com/EU0IcZWIsF5EtufunHf7u_gBbIeivaLkvESpWXAPfqhJ-A?e=GFHf4g) for input and output of the scheduling system.

### Database
Database design: https://dbdocs.io/itsjuliussin/Smart-Scheduling?view=relationships (password: **advantech**)

### API
There are 3 sides of interaction with Data AI backend: ERP interaction, Data AI User Interface interaction, and MES Interaction.
**For ERP interaction**
1. On the development stage, we will use a CSV data instead of calling the ERP API.
2. For the testing stage, we will call ERP API to get the data from ERP. And then we will convert the data format from ERP to our format (following the database structure).
3. For the future development, we could use DataFabric to integrate different ERP data structure to our data architecture.
**For MES interaction**
1. Not designed yet. For now, the output of the schedule is enough to be stored in the `schedule` table
**For Data AI UI interaction**
1. According to the UI design
## Air Compressor / Machine Scheduling
:::info
**Primary goal**: Alternating the machine operation to balance the machine depreciation, and controling the machine operation based on the requirements (tbd).
:::

:::warning
This project won't interact with scheduling algorithm inside AI service because the task is quiet simple and can be done in scheduling service.
:::
### API
There are 3 sides of interaction with Data AI backend: RTM interaction, Data AI User Interface interaction, and output/control interaction.
### Object Data Flow
- User will connect the air compressor and the other sensors to the modbus gateway.
- User will create a machine object on RTM and connect the sensor from modbus gateway to RTM.
- Data AI UI will read all the machine objects from the RTM and display it on Data AI UI.
- User will create a project and a model, and then add the machine object.
- Data AI UI will call the Data AI backend API with a request body that includes: machine ID, operating time, operating load, and other settings.
- Data AI backend will retrieve the necessary data from the RTM (using machine ID, please refer to PHM GraphQL query function or ifactorysdk), and create an machine operating schedule
- Machine operating schedule will be stored in the database and be used to control the machine operation (ON/OFF) (control function tbd)
# Scheduling Algorithm
## Production / Work Order Scheduling
Suggestion:
- Use genetic algorithm or other metaheuristics for optimization
- Define the constrains and rules for scheduling (using resource limitation, process sequence, etc.)
- Define the loss function (function to judge the efficiency of a schedule) using due/deliver date, order/start date, priority, etc.