利用修正单纯形法解线性规划问题_第1页
利用修正单纯形法解线性规划问题_第2页
利用修正单纯形法解线性规划问题_第3页
利用修正单纯形法解线性规划问题_第4页
利用修正单纯形法解线性规划问题_第5页
已阅读5页,还剩3页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

1、利用单纯形法解线性规化问题 动力工程系.车辆工程.王伟.20510009利用修正单纯形法解线性规划问题一 软件示意:二 代码说明:Dim A(1 To 3, 1 To 6) As Double '矩阵ADim a1(1 To 3) As Double '矩阵A的第一列向量Dim a2(1 To 3) As Double '矩阵A的第二列向量Dim a3(1 To 3) As Double '矩阵A的第三列向量Dim a4(1 To 3) As Double '矩阵A的第四列向量Dim a5(1 To 3) As Double '矩阵A的第五列向量

2、Dim a6(1 To 3) As Double '矩阵A的第六列向量Dim B_(1 To 3, 1 To 3) As Double '基矩阵B的逆矩阵Dim XB(1 To 3) As Double '基本可行解Dim b(1 To 3) As Double '右端向量bDim C(1 To 6) As Double '检验数Dim CB(1 To 3) As Double '基本可行解对应的检验数Dim (1 To 3) As Double '单纯形乘子矢量Dim r(1 To 6) As Double '检验矢量rDim

3、r_min As Double '检验矢量最小值Dim k_sign As Integer '检验矢量最小值对应的位置Dim Y(1 To 3, 0 To 6) As Double '矩阵yDim just_vector(1 To 3) As DoubleDim liji_min As Double '用于判断离基变量所用值Dim r_sign As Integer '用于记录离基变量对应的位置Dim main_yuan As Double '用于存放主元Dim Erk(1 To 3, 1 To 3) As DoubleDim Exchange_

4、B(1 To 3, 1 To 3) '在矩阵Erk与矩阵B_进行乘法运算时,作为矩阵B_的替换矩阵Dim Exchange_XB(1 To 3) '在矩阵Erk与XB_进行乘法运算时,作为XB_的替换矩阵Dim iterative_time As Integer '定义迭代的次数Dim XB_optimization(1 To 6) As Double '最优解Private Sub Command1_Click()'窗口1For iterative_time = 1 To 1000 '开始了迭代循环 Select Case k_sign Cas

5、e 1 If (r_sign - 3) = 3 Then CB(1) = C(2) '付值给基本可行解对应的检验数 CB(2) = C(3) CB(3) = C(6) XB_optimization(1) = 0 XB_optimization(2) = XB(1) XB_optimization(3) = XB(2) XB_optimization(4) = 0 XB_optimization(5) = 0 XB_optimization(6) = XB(3) End If Case 2 If (r_sign - 3) = 1 Then CB(1) = C(2) '付值给基本

6、可行解对应的检验数 CB(2) = C(5) CB(3) = C(6) XB_optimization(1) = 0 XB_optimization(2) = XB(1) XB_optimization(3) = 0 XB_optimization(4) = 0 XB_optimization(5) = XB(2) XB_optimization(6) = XB(3) End If Case 3 If (r_sign - 3) = 2 Then CB(1) = C(2) '付值给基本可行解对应的检验数 CB(2) = C(3) CB(3) = C(6) XB_optimization(

7、1) = 0 XB_optimization(2) = XB(1) XB_optimization(3) = XB(2) XB_optimization(4) = 0 XB_optimization(5) = 0 XB_optimization(6) = XB(3) End If End Select For i = 1 To 3 '计算单纯形乘子矢量 (i) = CB(1) * B_(1, i) + CB(2) * B_(2, i) + CB(3) * B_(3, i) Next i For j = 1 To 6 '计算检验矢量r r(j) = C(j) - (1) * A(

8、1, j) + (2) * A(2, j) + (3) * A(3, j) Next j r_min = r(1) '预先给定一个值 k_sign = 1 For i = 1 To 6 '找出最小检验值 If (r(i) < r_min) Then r_min = r(i) '最小检验值 k_sign = i '最小检验值所在位置,对应进基矢量位置 End If Next i If r_min < 0 Then For i = 1 To 3 '对应进基矢量所得的y值 Y(i, k_sign) = B_(i, 1) * A(1, k_sign)

9、 + B_(i, 2) * A(2, k_sign) + B_(i, 3) * A(3, k_sign) Next i For i = 1 To 3 '确定离基变量 If Y(i, k_sign) <> 0 Then just_vector(i) = Y(i, 0) / Y(i, k_sign) End If Next i For i = 1 To 3 If (just_vector(i) > 0 Then liji_min = just_vector(i) '预先给定一个值 Exit For End If Next i r_sign = 4 For i =

10、1 To 3 '找出最小检验值 If (just_vector(i) <= liji_min) And (just_vector(i) > 0) Then liji_min = just_vector(i) '最小检验值 r_sign = i + 3 '最小检验值所在位置,对应进基矢量位置 End If Next i main_yuan = Y(r_sign - 3, k_sign) If main_yuan <> 0 Then Select Case (r_sign - 3) '计算矩阵Erk Case 1 Erk(1, 1) = 1

11、/ main_yuan Erk(2, 1) = -Y(2, k_sign) / main_yuan Erk(3, 1) = -Y(3, k_sign) / main_yuan For i = 2 To 3 For j = 1 To 3 Erk(j, i) = A(j, i + 3) Next j Next i Case 2 Erk(1, 2) = -Y(1, k_sign) / main_yuan Erk(2, 2) = 1 / main_yuan Erk(3, 2) = -Y(3, k_sign) / main_yuan For j = 1 To 3 Erk(j, 1) = A(j, 4)

12、Next j For j = 1 To 3 Erk(j, 3) = A(j, 6) Next j Case 3 Erk(1, 3) = -Y(1, k_sign) / main_yuan Erk(2, 3) = -Y(2, k_sign) / main_yuan Erk(3, 3) = 1 / main_yuan For i = 1 To 2 For j = 1 To 3 Erk(j, i) = A(j, i + 4) Next j Next i End Select End If For i = 1 To 3 '给矩阵Exchange_B(i, j)付值 For j = 1 To 3

13、 Exchange_B(i, j) = B_(i, j) Next j Next i For i = 1 To 3 '计算B的新可逆矩阵B_ For j = 1 To 3 B_(i, j) = Erk(i, 1) * Exchange_B(1, j) + Erk(i, 2) * Exchange_B(2, j) + Erk(i, 3) * Exchange_B(3, j) Next j Next i For i = 1 To 3 '给Exchange_XB(i)付值 Exchange_XB(i) = XB(i) Next i For i = 1 To 3 '计算基本可行

14、解 XB(i) = Erk(i, 1) * Exchange_XB(1) + Erk(i, 2) * Exchange_XB(2) + Erk(i, 3) * Exchange_XB(3) Y(i, 0) = XB(i) Next i Else MsgBox ("优化完毕!") Exit For End IfNext iterative_timeCommand2.Enabled = True '使能按钮Command3.Enabled = True '使能按钮Form1.Text1(1).Text = XB_optimization(1) '显示最优

15、解x1Form1.Text1(2).Text = XB_optimization(2) '显示最优解x2Form1.Text1(3).Text = XB_optimization(3) '显示最优解x3Form1.Text1(4).Text = XB_optimization(4) '显示最优解x4Form1.Text1(5).Text = XB_optimization(5) '显示最优解x5Form1.Text1(6).Text = XB_optimization(6) '显示最优解x6Form1.Text1(0).Text = C(1) * XB_

16、optimization(1) + C(2) * XB_optimization(2) + C(3) * XB_optimization(3) + C(4) * XB_optimization(4) + C(5) * XB_optimization(5) + C(6) * XB_optimization(6) '显示最优值ZForm1.Text1(7) = iterative_time - 1 '显示迭代次数End SubPrivate Sub Command2_Click()End '结束程序End SubPrivate Sub Command3_Click() Fo

17、rm1.Show '调用优化结果显示窗口End SubPrivate Sub Form_Load()Dim i, j As IntegerFor i = 1 To 3 '付值给系数矩阵A For j = 1 To 6 A(i, j) = Quotiety_A(j + 6 * (i - 1).Text '付值给系数矩阵A Next jNext iFor i = 1 To 6 '将矩阵A列分块(a1,a2,a3,a4,a5,a6) For j = 1 To 3 Select Case i Case 1 a1(j) = A(j, i) Case 2 a2(j) = A

18、(j, i) Case 3 a3(j) = A(j, i) Case 4 a4(j) = A(j, i) Case 5 a5(j) = A(j, i) Case 6 a6(j) = A(j, i) End Select Next jNext iFor i = 1 To 3 '付值给基矩阵B的逆矩阵B_ For j = 1 To 3 Select Case i Case 1 B_(j, i) = a4(j) Case 2 B_(j, i) = a5(j) Case 3 B_(j, i) = a6(j) End Select Next jNext iFor i = 1 To 6 '付值给检验数 Select Case i Case 1 C(1) = C_quotiety(0).Text Case 2 C(2) = C_quotiety(1).Text Case 3 C(3) = C_quotiety(2).Text Case 4 C(4) = C_quotiety(3).Text Case 5 C(5) = C_quotiety(4).Text Case 6 C(6) = C_quotiety(5).Text End SelectNext ib(1) = b_quotiety(0).Text '付值给右端向量bb

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论