重心法选址

整理文档很辛苦,赏杯茶钱您下走!

免费阅读已结束,点击下载阅读编辑剩下 ...

阅读已结束,您可以下载文档离线阅读编辑

资源描述

2单设施重心法选址2.1实验目的掌握单设施重心法选址的原理,能够计算简单选址题目中待选设施的位置;掌握单设施重心选址的算法流程,能够设计类似题目的算法流程,并编写程序。2.2实验过程(1)单设施重心法选址的原理重心法选址模型示意图如图2-1所示。图2-1单设施重心法选址选址示意图求解目标:C-总成本最低其中:fi-序号为i的点的运输费率;Vi-序号为i的点的产量或者销量;di-序号为i的点到待选设施点的相对距离。待选设施位置的计算公式:其中:Xc-重心的X坐标;Yc-重心的Y坐标;Xi-第i个地点X坐标;Yi-第i个地点Y坐标;iiniidVfMinC1niiiiniiiiicdVfdxVfX11)/()/(niiiiniiiiicdVfdyVfY11)/()/()()(22yicixcddYdXiXY?(2)算法流程图,如图2-2所示。图2-2算法流程图2.3实验结果(1)单设施重心法选址程序参数设定及其求解界面如图2-3所示。图2-3单设施重心法选址程序参数设定及其求解界面初始化Xc=0,Yc=0JD=0.001赋值SumCOld=0SumCNew=0Sum1=0Sum2=0Sum3=0计算diSumCOldXc,YcDiSumCNew判断(SumCOld-SumCNew)=JD输出Xc,YcSumCNewj(跌代次数)停止j=j+1是否(2)参数设定及其求解界面变量声明部分(代码)PrivateSubCommand1_Click()IfText1.Text=ThenMsgBoxX-横坐标不允许为空Text1.SetFocusExitSubElseIfIsNumeric(Text1.Text)=FalseThenMsgBoxX-横坐标必须为数值型数据!Text1.Text=Text1.SetFocusExitSubEndIfIfText2.Text=ThenMsgBoxY-纵坐标不允许为空Text2.SetFocusExitSubElseIfIsNumeric(Text2.Text)=FalseThenMsgBoxY-纵坐标必须为数值型数据!Text2.Text=Text2.SetFocusExitSubEndIfIfText3.Text=ThenMsgBox产量或销量不允许为空Text3.SetFocusExitSubElseIfIsNumeric(Text3.Text)=FalseThenMsgBox产量或销量应为数值型数据!Text3.Text=Text3.SetFocusExitSubElseIfVal(Text3.Text)0ThenMsgBox产量或销量应为正数,否则无实际意义!Text3.Text=Text3.SetFocusExitSubEndIfIfText4.Text=ThenMsgBox运输费率不允许为空Text4.SetFocusExitSubElseIfIsNumeric(Text4.Text)=FalseThenMsgBox运输费率应为数值型数据!Text4.Text=Text4.SetFocusExitSubElseIfVal(Text4.Text)0ThenMsgBox运输费率应为正数,否则无实际意义!Text4.Text=Text4.SetFocusExitSubEndIfIfText5.Text=ThenMsgBoxX0-横坐标不允许为空Text5.SetFocusExitSubElseIfIsNumeric(Text5.Text)=FalseThenMsgBoxX0-横坐标必须为数值型数据!Text5.Text=Text5.SetFocusExitSubEndIfIfText6.Text=ThenMsgBoxY0-纵坐标不允许为空Text6.SetFocusExitSubElseIfIsNumeric(Text6.Text)=FalseThenMsgBoxY0-纵坐标必须为数值型数据!Text6.Text=Text6.SetFocusExitSubEndIfIfText7.Text=ThenMsgBox精度不允许为空Text7.SetFocusExitSubElseIfIsNumeric(Text7.Text)=FalseThenMsgBox精度应为数值型数据!Text7.Text=Text7.SetFocusExitSubElseIfVal(Text7.Text)0ThenMsgBox精度应为正数,否则无实际意义!Text7.Text=Text7.SetFocusExitSubEndIfFori=1ToList1.ListCountIfText1.Text=Val(List1.List(i-1))AndText2.Text=Val(List2.List(i-1))ThenMsgBox与第&i&输入坐标值相同,请重新输入Text1.Text=Text2.Text=Text3.Text=Text4.Text=Text1.SetFocusExitSubEndIfNextiList1.AddItemText1.TextList2.AddItemText2.TextList3.AddItemText3.TextList4.AddItemText4.TextText1.Text=Text2.Text=Text3.Text=Text4.Text=Text1.SetFocusIfList1.ListCount=2ThenCommand2.Enabled=TrueEndIfEndSubPrivateSubCommand2_Click()Xc=Val(Text5.Text)Yc=Val(Text6.Text)JD=Val(Text7.Text)DimSumCOAsDoubleDimSumCNAsDoubleDimSum1AsDoubleDimSum2AsDoubleDimSum3AsDoubleForj=1To10000SumCO=0SumCN=0Sum1=0Sum2=0Sum3=0Fori=1ToList1.ListCountdi=Sqr((Xc-Val(List1.List(i-1)))^2+(Yc-Val(List2.List(i-1)))^2)'距离公式SumCO=SumCO+Val(List3.List(i-1))*Val(List4.List(i-1))*diSum1=Sum1+(Val(List1.List(i-1))*Val(List3.List(i-1))*Val(List4.List(i-1)))/diSum2=Sum2+(Val(List2.List(i-1))*Val(List3.List(i-1))*Val(List4.List(i-1)))/diSum3=Sum3+(Val(List3.List(i-1))*Val(List4.List(i-1)))/diNextiXc=Sum1/Sum3Yc=Sum2/Sum3Fori=1ToList1.ListCountdi=Sqr((Xc-Val(List1.List(i-1)))^2+(Yc-Val(List2.List(i-1)))^2)SumCN=SumCN+Val(List3.List(i-1))*Val(List4.List(i-1))*diNextiIf(SumCO-SumCN)=JDThenText8.Text=XcText9.Text=YcText10.Text=SumCNText11.Text=jExitForEndIfNextjEndSubPrivateSubList1_Click()Fori=1ToList1.ListCountIfList1.Selected(i-1)=TrueThenh=InputBox(请输入要改的参数:,参数修正)IfhAndIsNumeric(h)=TrueThenList1.List(i-1)=hElse:MsgBox输入的数据必须为数值型数据EndIfEndIfNextiEndSubPrivateSubList2_Click()Fori=1ToList2.ListCountIfList2.Selected(i-1)=TrueThenh=InputBox(请输入要改的参数:,参数修正)IfhAndIsNumeric(h)=TrueThenList2.List(i-1)=hElse:MsgBox输入的数据必须为数值型数据EndIfEndIfNextiEndSubPrivateSubList3_Click()Fori=1ToList3.ListCountIfList3.Selected(i-1)=TrueThenh=InputBox(请输入要改的参数:,参数修正)IfhAndIsNumeric(h)=TrueAndVal(h)0ThenList3.List(i-1)=hElse:MsgBox输入的数据必须为数值型数据EndIfEndIfNextiEndSubPrivateSubList4_Click()Fori=1ToList4.ListCountIfList4.Selected(i-1)=TrueThenh=InputBox(请输入要改的参数:,参数修正)IfhAndIsNumeric(h)=TrueAndVal(h)0ThenList4.List(i-1)=hElse:MsgBox输入的数据必须为数值型数据EndIfEndIfNextiEndSub(3)单设施重心法选址程序求解结果如图2-4所示。图2-4单设施重心法选址程序求解结果

1 / 8
下载文档,编辑使用

©2015-2020 m.777doc.com 三七文档.

备案号:鲁ICP备2024069028号-1 客服联系 QQ:2149211541

×
保存成功