正态分布在物料需求分配中的应用,附C#实现代码

本文介绍了一种根据生产计划跨度内不同月份物料需求量进行正态分布计算的方法,并提供了具体的算法实现步骤及示例代码。
业务需要:某生产项目物料需求量,根据生产计划跨度,在生产周期中,不同月份物料需求量正态分布。
什么叫正态分布:有个哥们描述的特别好,引用一下。 http://hi.baidu.com/snoopywang/blog/item/4d019b1602e6be51f3de3253.html
标准正态分布公式:
NormalDistribution.JPG
具体算法实现:(折叠了)
  
ContractedBlock.gif ExpandedBlockStart.gif
 1None.gifprivate void NormalDistribution(DateTime dRealTimeA, DateTime dRealTimeB, double douQuantity, double douK)
 2ExpandedBlockStart.gifContractedBlock.gif        dot.gif{
 3InBlock.gif            Hashtable has = new Hashtable();
 4InBlock.gif            //是否开始时间大于结束时间
 5InBlock.gif            if (dRealTimeA >= dRealTimeB)
 6InBlock.gif                return;
 7InBlock.gif
 8InBlock.gif            //节点的实际延续时间
 9InBlock.gif            int iDuration = DateDiff(dRealTimeB, dRealTimeA);
10InBlock.gif            //实物量正态分布加权总值
11InBlock.gif            double douQuantityDaySum = 0;
12InBlock.gif            double douQuantitySum = 0;
13InBlock.gif
14InBlock.gif            Hashtable hasPlanningMonth = new Hashtable();
15InBlock.gif            //算各月份天数            
16InBlock.gif            for (int i = 0; i < iDuration; i++)
17ExpandedSubBlockStart.gifContractedSubBlock.gif            dot.gif{
18InBlock.gif                double dNum1 = Convert.ToDouble(i);
19InBlock.gif                double dDuration = Convert.ToDouble(iDuration);
20InBlock.gif
21InBlock.gif                double dNum2 = dNum1 - dDuration / 2;
22InBlock.gif                double dNum3 = (-1 * dNum2) * (dNum2) * douK;
23InBlock.gif                double dNum4 = Math.Exp(dNum3);
24InBlock.gif                douQuantityDaySum += dNum4;
25InBlock.gif
26InBlock.gif                DateTime dPlanningDate = dRealTimeA.AddDays(i);
27InBlock.gif                string strMonth = dPlanningDate.ToString("yyyy"+ dPlanningDate.ToString("MM");
28InBlock.gif                if (!hasPlanningMonth.ContainsKey(strMonth))
29ExpandedSubBlockStart.gifContractedSubBlock.gif                dot.gif{
30InBlock.gif                    hasPlanningMonth.Add(strMonth, 1 * dNum4);
31ExpandedSubBlockEnd.gif                }

32InBlock.gif                else
33ExpandedSubBlockStart.gifContractedSubBlock.gif                dot.gif{
34InBlock.gif                    //新日期
35InBlock.gif                    double dDays = Convert.ToDouble(hasPlanningMonth[strMonth].ToString()) + 1 * dNum4;
36InBlock.gif                    hasPlanningMonth[strMonth] = dDays;
37ExpandedSubBlockEnd.gif                }

38ExpandedSubBlockEnd.gif            }

39InBlock.gif            int iMonthCount = 0;
40InBlock.gif
41InBlock.gif            foreach (object obj in hasPlanningMonth.Keys)
42ExpandedSubBlockStart.gifContractedSubBlock.gif            dot.gif{
43InBlock.gif                string strYear = obj.ToString().Substring(04);
44InBlock.gif                string strMonth = obj.ToString().Substring(42);
45InBlock.gif                //每天实物量
46InBlock.gif                double douDayQuantity = douQuantity / douQuantityDaySum;
47InBlock.gif                double dDays = Convert.ToDouble(hasPlanningMonth[obj.ToString()].ToString());
48InBlock.gif
49InBlock.gif                iMonthCount++;
50InBlock.gif                int intMonthQuantity = (int)System.Math.Floor(douDayQuantity * dDays);
51InBlock.gif                if (iMonthCount == hasPlanningMonth.Keys.Count)
52ExpandedSubBlockStart.gifContractedSubBlock.gif                dot.gif{
53InBlock.gif                    intMonthQuantity = Convert.ToInt32(douQuantity - douQuantitySum);
54ExpandedSubBlockEnd.gif                }

55InBlock.gif                else
56ExpandedSubBlockStart.gifContractedSubBlock.gif                dot.gif{
57InBlock.gif                    douQuantitySum += intMonthQuantity;
58ExpandedSubBlockEnd.gif                }

59InBlock.gif
60InBlock.gif                has.Add(strYear + strMonth, intMonthQuantity.ToString());                        
61ExpandedSubBlockEnd.gif            }

62InBlock.gif            listBox.Items.Clear();
63InBlock.gif            
64InBlock.gif            foreach (object obj in has.Keys)
65ExpandedSubBlockStart.gifContractedSubBlock.gif            dot.gif{
66InBlock.gif                listBox.Items.Add(obj.ToString() + "---" + has[obj.ToString()] + "\r\n");
67InBlock.gif                listBox.Sorted = true;
68ExpandedSubBlockEnd.gif            }

69ExpandedBlockEnd.gif        }

计算结果:
NormalDistributionResult.JPG
其它:为计算方便公式中的1/K,在编码过程中描术为K。

转载于:https://www.cnblogs.com/spymaster/archive/2006/12/21/598999.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值