IND5001: Introduction to Industry 4.0 and Applications - 1R

Java Python IND5001: Introduction to Industry 4.0 and Applications - Assignment 1

Objective:

To simulate the production process shown in the specified video using Simul8 software and write a detailed report on the process. If you have not installed Simul8 software, please refer to Assignment 1 posted on CANVAS.

Steps:

1. Learn how to use Simul8

o Tutorials -https://www.simul8.com/support/help/doku.php?id=tutorials

o Videos -https://www.simul8.com/learn-to-simul8/getting-started-videos

2. Watch the Video:

o https://www.youtube.com/watch?v=eWHwpFAZdjk

o Watch the entire video to understand the production process. Take detailed notes on the key steps, resources, and flow of the process.

3. Identify Key Components:

o List all main components involved in the production process, including machinery, labor, materials, and other resources.

o Identify the stages of the production process and their sequence.

4. Create a Flowchart:

o Draw a flowchart of the production process, including all stages from raw materials to the final product.

o Clearly show the sequence of operations and the resources used at each stage.

5. Set Up Simul8:

o Open Simul8 and create a new simulation model.

o Define the entities, resources, and processes identified in your flowchart.

o Input parameters for each stage of the process, such as processing time, resource availability, and inter-arrival times.

6. Simulate the Process:

o Run the simulation in Simul8 and observe the flow of entities through the system and resource utilization.

o Make necessary adjustments to&n IND5001: Introduction to Industry 4.0 and Applications - Assignment 1R bsp;the simulation model to reflect the real- world process accurately.

7. Analyze the Results:

o Use Simul8’s analysis tools to collect data on key performance metrics   such as throughput, resource utilization, bottlenecks, and process time.

o Interpret the results to understand the efficiency of the production process.

8. Prepare a Report:

              o Write a detailed report summarizing your process and findings. Include:

An introduction to the production process

A description of each stage and the flowchart of the processes

The setup and parameters used in the Simul8 model

Analysis of the simulation results

Screenshots of the Simul8 model and results

o Discuss any challenges faced and how they were addressed.

o There is no need to submit the simulation file.

o Submit the report as a pdf

o There is no specific report format

Evaluation Criteria:

•    Understanding of the production process

• Accuracy and completeness of the simulation model

• Quality of the flowchart and report

•    Depth of analysis and interpretation of results

•    Quality of screenshots and clarity of explanations

Process Timing and Quantities:

1.  30s to unpack 1 unit of meat

2.  30s to cut up meat into chunks

3.  3min to grind 1 batch of meat

4.  15min to blend and season 4 batch of meat into 1 seasoned batch

5.  5min to fill a rack of sausage

6.  30min to steam a rack

7.  2min to shower to cool the meat

8.  1min to soak

9.  5min to peel 600 sausages

10. 1min to pack 10 sausages into 1 packet

11. 5min to freeze a batch of 20 packets

12. 1min to pack a box of 10 packets

13. Assume there is a 0         

你遇到的问题是: > ❓ 我在 `test1in.txt` 文件中写了 `1 2 3 4 5 6 7 8 9 10` 这 10 个数字, > 使用 `freopen` 重定向输入,但输出却是: > > ``` > num: 0 > sum: 0 > average: -nan(ind) > ``` 这个现象说明:**你的程序没有成功读取到任何数据**,导致计数为 0、总和为 0,平均值变成 `sum / num = 0 / 0` → **NaN(Not a Number)** --- ## ✅ 根本原因分析 `-nan(ind)` 是 IEEE 浮点标准中表示“无效操作”的结果,常见于: ```c double avg = 0.0 / 0.0; // → NaN ``` 所以问题出在: - `num == 0` → 没有读入任何有效数字 - 原因:`scanf` 或输入流失败了 --- ## 🔍 可能的原因与解决方案(逐条排查) ### ✅ 示例错误代码(典型问题) ```c #include <stdio.h> int main() { freopen("test1in.txt", "r", stdin); freopen("test1out.txt", "w", stdout); int num = 0; double sum = 0.0, x; while (scanf("%lf", &x) == 1) // 注意:%lf 用于 double { sum += x; num++; } printf(" num: %d\n", num); printf(" sum: %.2f\n", sum); printf("average: %.6f\n", sum / num); // 当 num=0 时 → NaN return 0; } ``` 如果上面代码输出 `num: 0`,说明 `while(scanf(...))` 根本没进循环! --- ## 🧩 常见原因及解决办法 --- ### ❌ 原因 1:文件名不匹配(大小写、路径、拼写) - 你的代码写的是 `"test1in.txt"`,但实际文件叫: - `test1In.txt` - `test1in.TXT` - `Test1in.txt` - 或者放在子目录里 📌 Windows 文件系统不区分大小写,但拼写必须完全一致。 ✅ 解决方法: 1. 确保文件就在 **可执行文件同目录下** 2. 在资源管理器中确认真实文件名(包括扩展名) - 查看 → “文件扩展名” 打勾 - 避免 `test1in.txt.txt` 的情况! 🔧 检查建议: ```c if (freopen("test1in.txt", "r", stdin) == NULL) { printf("❌ 错误:无法打开 test1in.txt!\n"); return 1; } ``` --- ### ❌ 原因 2:文件编码或格式问题(隐藏字符、换行符) 你在文本编辑器里看到的是 `1 2 3 ...`,但文件可能是: - UTF-8 with BOM - 包含不可见字符(如制表符、回车 `\r\n` 太长) - 数据不是用空格/换行分隔,而是逗号或其他符号 ✅ 解决方法: 用记事本打开 `test1in.txt`,另存为 ANSI 编码,并确保内容像这样: ``` 1 2 3 4 5 6 7 8 9 10 ``` 或者每行一个数也可以: ``` 1 2 3 ... 10 ``` 只要 `scanf("%lf", &x)` 能识别就行(它会自动跳过空白符) --- ### ❌ 原因 3:使用了错误的 `scanf` 格式符 如果你把 `double x;` 和 `%d` 混用,会导致解析失败。 | 变量类型 | 正确格式符 | |---------|------------| | `int x;` | `%d` | | `float x;` | `%f` | | `double x;` | `%lf` | ⚠️ 错误示例: ```c double x; scanf("%f", &x); // ❌ 应该是 %lf ``` 这会导致 `scanf` 无法正确读取 `double` 类型,返回值不是 1,循环不进入。 ✅ 正确写法: ```c double x; while (scanf("%lf", &x) == 1) { ... } ``` --- ### ❌ 原因 4:文件权限被锁定或防病毒软件拦截 有时 `.txt` 文件被其他程序(如 VS Code、记事本、杀毒软件)独占打开,导致 C 程序无法读取。 ✅ 解决方法: - 关闭所有编辑器 - 把文件复制到桌面再试 - 重启电脑(极端情况) --- ### ❌ 原因 5:未检查 `freopen` 是否成功(关键!) 这是最常见的疏忽! ```c freopen("test1in.txt", "r", stdin); // ❌ 没检查返回值 ``` 如果文件不存在,`stdin` 就会被设为 `NULL`,后续 `scanf` 返回 `-1` 或直接失败。 ✅ 必须检查: ```c if (freopen("test1in.txt", "r", stdin) == NULL) { printf("Error: Cannot open input file!\n"); return 1; } ``` --- ## ✅ 正确完整示例代码 ```c #define _CRT_SECURE_NO_WARNINGS #include <stdio.h> #include <stdlib.h> int main() { // 重定向输入 if (freopen("test1in.txt", "r", stdin) == NULL) { printf("❌ 错误:无法打开 test1in.txt,请检查文件是否存在!\n"); return 1; } // 重定向输出 if (freopen("test1out.txt", "w", stdout) == NULL) { printf("❌ 错误:无法创建 test1out.txt!\n"); return 1; } int num = 0; double sum = 0.0, x; // 循环读取每个数字 while (scanf("%lf", &x) == 1) { sum += x; num++; } // 输出统计结果 printf(" num: %d\n", num); printf(" sum: %.2f\n", sum); if (num > 0) printf("average: %.6f\n", sum / num); else printf("average: undefined\n"); // 避免除以零 return 0; } ``` --- ## ✅ 输出应为: ``` num: 10 sum: 55.00 average: 5.500000 ``` --- ## ✅ 排查清单(请对照检查) | 检查项 | 是否满足 | |--------|----------| | ✅ `test1in.txt` 和 `.exe` 在同一目录? | ☐ | | ✅ 文件真实名字是 `test1in.txt`(不是 `.txt.txt`)? | ☐ | | ✅ 内容是 `1 2 3 4 5 6 7 8 9 10` 或每行一个数? | ☐ | | ✅ 使用了 `scanf("%lf", &x)` 而不是 `%f`? | ☐ | | ✅ 检查了 `freopen` 返回值是否为 `NULL`? | ☐ | | ✅ 输出文件 `test1out.txt` 是否可写? | ☐ | --- ## ✅ 额外建议:调试技巧 ### 1. 先不用重定向,在控制台手动输入测试 ```c // 注释掉 freopen,手动输入测试 // freopen("test1in.txt", "r", stdin); printf("请输入几个数字(Ctrl+Z 结束):\n"); while (scanf("%lf", &x) == 1) { ... } ``` 看能否正常读取。如果手动可以,说明逻辑没问题,问题一定在文件路径或 `freopen`。 ### 2. 在程序开头打印当前工作目录 ```c system("cd"); // 显示当前路径 ``` 确认你运行程序的位置是否正确。 --- ## ✅ 总结 | 现象 | 原因 | 解决方案 | |------|------|-----------| | `num: 0`, `sum: 0`, `average: -nan(ind)` | 没读到任何数据 | 检查 `freopen` 成功与否 | | `scanf` 不进循环 | 文件打不开或格式错误 | 检查文件名、路径、格式符 | | 输出为空文件 | 输出重定向失败 | 检查 `freopen` 输出文件权限 | --- ### ❓相关问题
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值