Mrp算法的java代码实现
时间: 2023-10-12 10:16:56 浏览: 155
以下是一个简单的Java实现MRP算法的示例代码:
```java
import java.util.*;
public class MRPAlgorithm {
public static void main(String[] args) {
// 定义需求量矩阵(Demand Matrix)
int[][] demandMatrix = {{100, 150, 200}, {50, 75, 100}, {150, 200, 250}};
// 定义库存矩阵(Inventory Matrix)
int[][] inventoryMatrix = {{50, 25, 0}, {25, 10, 5}, {15, 10, 5}};
// 定义产出矩阵(Output Matrix)
int[][] outputMatrix = {{80, 100, 120}, {60, 80, 100}, {100, 120, 140}};
// 定义MRP对象
MRP mrp = new MRP(demandMatrix, inventoryMatrix, outputMatrix);
// 运行MRP算法
mrp.runMRP();
// 输出计划表
System.out.println("Material Requirements Planning (MRP) Report:");
System.out.println("Item\tPeriod 1\t\tPeriod 2\t\tPeriod 3");
for (int i = 0; i < mrp.getNumberOfItems(); i++) {
System.out.print((char) ('A' + i) + "\t");
for (int j = 0; j < 3; j++) {
System.out.print(mrp.getPlannedProduction(i, j) + "\t\t");
}
System.out.println();
}
}
}
class MRP {
private int[][] demandMatrix; // 需求量矩阵
private int[][] inventoryMatrix; // 库存矩阵
private int[][] outputMatrix; // 产出矩阵
private int numberOfItems; // 物料数量
private int numberOfPeriods; // 周期数量
private int[][] plannedProduction; // 计划生产量矩阵
public MRP(int[][] demandMatrix, int[][] inventoryMatrix, int[][] outputMatrix) {
this.demandMatrix = demandMatrix;
this.inventoryMatrix = inventoryMatrix;
this.outputMatrix = outputMatrix;
numberOfItems = demandMatrix.length;
numberOfPeriods = demandMatrix[0].length;
plannedProduction = new int[numberOfItems][numberOfPeriods];
}
public void runMRP() {
for (int i = 0; i < numberOfItems; i++) {
for (int j = 0; j < numberOfPeriods; j++) {
// 计算净需求量
int netDemand = demandMatrix[i][j] - inventoryMatrix[i][j];
// 如果净需求量小于等于0,则无需生产
if (netDemand <= 0) {
plannedProduction[i][j] = 0;
} else {
// 计算所需毛需求量
int grossDemand = netDemand;
// 计算所需总产出量
int totalOutput = 0;
for (int k = j; k < numberOfPeriods; k++) {
totalOutput += outputMatrix[i][k];
}
// 如果所需总产出量小于所需毛需求量,则需要增加生产计划
if (totalOutput < grossDemand) {
plannedProduction[i][j] = grossDemand - totalOutput;
}
}
}
}
}
public int getNumberOfItems() {
return numberOfItems;
}
public int getPlannedProduction(int itemIndex, int period) {
return plannedProduction[itemIndex][period];
}
}
```
该示例代码中定义了一个MRP类,其中包含了需求量矩阵、库存矩阵和产出矩阵等属性,以及计划生产量矩阵和运行MRP算法的方法。在main方法中,我们定义了一个需求量矩阵、库存矩阵和产出矩阵,然后创建MRP对象并运行MRP算法。最后,我们输出了计划表。
相关推荐
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)