什么是MRP? MRP即物料需求计划,是现代ERP的基础和核心,它是指企业怎样才能在规定的时间,规定的地点,按照规定的数量得到真正需要的物料,换句话说,就是库存管理怎样才能符合生产计划的要求,这是物料需求计划所解决的。MRP起初出现在美国,并由美国生产与库存管理协会倡导而发展起来的。
MRP是一种以计算机为基础的编制生产与实行控制的系统,它不仅是一种新的计划管理方法,而且也是一种新的组织生产方式。MRP的出现和发展,引起了生产管理理论和实践的变革。MRP是根据总生产进度计划中规定的最终产品的交货日期,规定必须完成各项作业的时间,编制所有较低层次零部件的生产进度计划,对外计划各种零部件的采购时间与数量,对内确定生产部门应进行加工生产的时间和数量。一旦作业不能按计划完成时,MRP系统可以对采购和生产进度的时间和数量加以调整,使各项作业的优先顺序符合实际情况。
本算法的业务逻辑请参考此链接(ppt格式)
![](/Images/OutliningIndicators/None.gif)
using System;
using System.Collections;
namespace wf
![](/Images/OutliningIndicators/ExpandedBlockStart.gif)
![](/Images/OutliningIndicators/ContractedBlock.gif)
{
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
/**////主函数
public class Starer
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
public static void Main()
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
int[] Order=new int[20];
Order[8]=50;
Order[11]=50;
Order[13]=100;
VNode[] vnodes=new VNode[20];
VNode a=new VNode("a",1,10,Order);
VNode b=new VNode("b",2,20);
VNode c=new VNode("c",3,0);
VNode d=new VNode("d",1,100);
VNode e=new VNode("e",1,10);
VNode f=new VNode("f",1,50);
vnodes[0]=a;
vnodes[1]=b;
vnodes[2]=c;
vnodes[3]=d;
vnodes[4]=e;
vnodes[5]=f;
ArcNode ab=new ArcNode(a,b,1);
ArcNode ac=new ArcNode(a,c,1);
ArcNode bc=new ArcNode(b,c,2);
ArcNode bd=new ArcNode(b,d,2);
ArcNode ce=new ArcNode(c,e,1);
ArcNode cf=new ArcNode(c,f,1);
Graph MPS=new Graph(vnodes);
![](/Images/OutliningIndicators/InBlock.gif)
MPS.List();
Console.ReadLine();
![](/Images/OutliningIndicators/InBlock.gif)
}
}
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
/**////定义VNode,即图中的各个节点,如Alpha,B,C,D,等,包括提前期,现有库存等数据
public class VNode
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
string name;
int leadtime;
int onhand;
int[] order=new int[20];
int[] list=new int[20];
int indegree=0;
public ArcNode firstarc,trailarc;
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
public string Name
{get
{return name;}}
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
public int Leadtime
{get
{return leadtime;}}
public int Onhand
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
get
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{return onhand;}
set
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{onhand=value;}
}
public int[] Order
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
get
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{return order;}
set
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{order=value;}
}
public int[] List
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
get
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{return list;}
set
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{list=value;}
}
public int Indegree
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
get
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{return indegree;}
set
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{indegree=value;}
}
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
public ArcNode Firstarc
{get
{return firstarc;}}
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
public ArcNode Trailarc
{get
{return trailarc;}}
public VNode(string Name,int LeadTime,int OnHand)
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
name=Name;
firstarc=trailarc=null;
indegree=0;
leadtime=LeadTime;
onhand=OnHand;
}
public VNode(string Name,int LeadTime,int OnHand,int[] Order)
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
name=Name;
firstarc=trailarc=null;
indegree=0;
leadtime=LeadTime;
onhand=OnHand;
order=Order;
}
}
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
/**////定义ArcNode,代表物料清单图中的弧,data是组成的数量,例如:弧 Alpha--B 的权重为1,data就是1,同理 弧B--C 的data为2
public class ArcNode
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
VNode headvex,trailvex;
ArcNode nextarc;
int data;
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
public VNode Headvex
{get
{return headvex;}}
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
public VNode Trailvex
{get
{return trailvex;}}
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
public ArcNode Nextarc
{get
{return nextarc;}}
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
public int Data
{get
{return data;}}
public ArcNode(VNode Trail,VNode Head,int Data)
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
headvex=Head;
trailvex=Trail;
data=Data;
nextarc=null;
if(Trail.firstarc==null)
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
Trail.firstarc=this;
Trail.trailarc=this;
}
else
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
Trail.trailarc.nextarc=this;
Trail.trailarc=this;
}
Head.Indegree++;
}
}
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
/**////定义物料清单图
public class Graph
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
VNode [] vnodes;
int vexnum;
public Graph(VNode[] Vnodes)
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
for(int i=0;i<Vnodes.Length;i++)
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
if (Vnodes[i]!=null)
vexnum++;
}
vnodes=new VNode[vexnum];
for(int i=0;i<this.vexnum;i++)
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
vnodes[i]=Vnodes[i];
}
}
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
/**//*用拓补算法实现主生产计划的节点计算(此算法以拓补排序为基础)*/
public void List()
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
Stack stack=new Stack();
for(int i=0;i<this.vexnum;i++)
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
if(vnodes[i].Indegree==0)
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
stack.Push(vnodes[i]);
}
}
while(stack.Count!=0)
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
VNode node=(VNode)stack.Pop();
Console.WriteLine(node.Name);
for(int i=0;i<node.Order.Length;i++)
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
if(node.Order[i]!=0)
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
if((i-node.Leadtime)<=0)
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
Console.WriteLine("提前期不足!");
continue;
}
if((node.Order[i]-node.Onhand)<=0)
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
node.Onhand=node.Onhand-node.Order[i];
}
else
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
node.List[i-node.Leadtime]=node.Order[i]-node.Onhand;
node.Onhand=0;
Console.WriteLine("第"+(i-node.Leadtime)+"周需要"+node.List[i-node.Leadtime]);
}
}
}
for(ArcNode p=node.Firstarc;p!=null;p=p.Nextarc)
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
VNode k=p.Headvex;
for(int i=0;i<node.List.Length;i++)
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
k.Order[i]=node.List[i]*p.Data+k.Order[i];
}
k.Indegree--;
if(k.Indegree==0)
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
stack.Push(k);
}
}
}
}
![](/Images/OutliningIndicators/InBlock.gif)
}
}
本人初出茅庐,如果疑问,请多指教,一定会诚恳接受!