1、Rem 定义动态数组Dim a() As Single, c() As Single, b() As Single, cb() As SingleDim aa() As Single, cba() As Single, xcb() As Integer, xb() As IntegerDim m As Integer, n As Integer, l As Integer, k As Integer, cc As Integer, cm As Integer, ka As IntegerDim qq As Single, tt As Single, z As SinglePrivate Sub
2、 Command1_Click()Shown = Val(InputBox(请输入线性规划典范型方程变量的个数 N=?, 输入数据, 0)m = Val(InputBox(请输入线性规划典范型方程约束条件的个数 M=?, 输入数据, 0)Rem 给数组分配空间ReDim a(0 To m + 1, 0 To n + 2)ReDim aa(1 To m + 1, 1 To n + 2)ReDim c(n)ReDim b(m)ReDim cb(m)ReDim cba(n)ReDim xcb(n)ReDim xb(m)Rem 对线性规划约束方程增广矩阵A()进行归零计算For i = 0 To m
3、+ 1 For j = 0 To n + 2 a(i, j) = 0 Next jNext iRem 输入线性规划约束方程系数矩阵A()For i = 1 To m For j = 1 To n a(i, j) = Val(InputBox(请输入典范型方程约束条件矩阵的系数 a( & Str(i) & , & Str(j) & ):, 输入数据, 0) Next jNext iRem 输入线性规划约束方程右端常数B()For i = 1 To m b(i) = Val(InputBox(请输入典范型方程约束条件右端的常数 b( & Str(i) & ):, 输入数据, 0)Next iRem
4、 把右端常数写入增广矩阵A()中For i = 1 To m a(i, n + 1) = b(i)Next iRem 输入线性规划目标函数的系数C()For i = 1 To n c(i) = Val(InputBox(请输入典范型方程目标函数的系数 c( & Str(i) & ):, 输入数据, 0)Next iRem 把目标函数的系数写入增广矩阵A()中For i = 1 To n a(0, i) = c(i)Next iRem 输入线性规划单纯形初始表中基变量在目标函数中的系数CB()For i = 1 To m cb(i) = Val(InputBox(请输入线性规划单纯形初始表中基变
5、量在目标函数中的系数CB( & Str(i) & ):, 输入数据, 0)Next iRem 把基变量目标函数的系数写入增广矩阵A()中For i = 1 To m a(i, 0) = cb(i)Next iRem 记录基变量下标值For i = 1 To m xb(i) = Val(InputBox(请输入典范型方程第 & Str(i) & 行,基变量的下标:, 输入数据, 0)Next iRem 检验数的累积数归零并计算检验数For i = 1 To n cba(i) = 0Next iFor i = 1 To n For j = 1 To m cba(i) = cba(i) + a(j,
6、 0) * a(j, i) Next j a(m + 1, i) = a(0, i) - cba(i)Next iRem 计算目标函数值z = 0For i = 1 To m z = z + a(i, 0) * a(i, n + 1)Next ia(m + 1, n + 1) = zRem 打印增广矩阵A()For i = 0 To m + 1 For j = 0 To n + 2 Print a(i, j); Next j PrintNext iPrintRem 判断所有检验数是否都小于等于零cc = 0For i = 1 To n If a(m + 1, i) = 0 Then cc =
7、cc + 1 End IfNext iRem 统计检验数为零的个数cm = 0For i = 1 To n If a(m + 1, i) = 0 Then cm = cm + 1 End IfNext iPrint cc=; cc, cm=; cmRem 判断此单纯形表是否为最优单纯形表Do While cc qq Then qq = a(m + 1, i) l = i End If Next i Print Print l=; l, Rem 统计进基列上A(i,j)小于等于零的个数 ka = 0 For i = 1 To m If a(i, l) 0 Then a(i, n + 2) = a
8、(i, n + 1) / a(i, l) End If Next i tt = 10000 k = 0 For i = 1 To m If a(i, l) 0 And a(i, n + 2) tt Then tt = a(i, n + 2) k = i End If Next i Print k=; k Print Rem 进行初等行变换时,对临时数组归零计算 For i = 1 To m + 1 For j = 1 To n + 2 aa(i, j) = 0 Next j Next i Rem 确定枢轴元素,进行初等行变换 oo = a(k, l) For i = 1 To n + 1 aa
9、(k, i) = a(k, i) / oo Next i For i = 1 To m If i k Then For j = 1 To n + 1 aa(i, j) = a(i, j) + a(k, j) * (-a(i, l) Next j End If Next i Rem 把临时数组AA()的数据写到增广矩阵A()中去 For i = 1 To m + 1 For j = 1 To n + 2 a(i, j) = aa(i, j) Next j Next i a(k, 0) = a(0, l) xb(k) = l Rem 检验数的累积数归零并计算检验数 For i = 1 To n c
10、ba(i) = 0 Next i For i = 1 To n For j = 1 To m cba(i) = cba(i) + a(j, 0) * a(j, i) Next j a(m + 1, i) = a(0, i) - cba(i) Next i Rem 计算目标函数值 z = 0 For i = 1 To m z = z + a(i, 0) * a(i, n + 1) Next i a(m + 1, n + 1) = z Rem 判断所有检验数是否都小于等于零 cc = 0 For i = 1 To n If a(m + 1, i) m Then Print 本线性规划有多重最优解! Print 线性规划的最优值为: End IfEnd If Rem 打印线性规划的解和目标函数值For i = 1 To m Print X( & Str(xb(i) & )=; a(i, n + 1), Next iPrint 其它变量为零。Print Z=; a(m + 1, n + 1)Print Rem 打印增广矩阵A()For i = 0 To m + 1 For j = 0 To n + 2 Print a(i, j); Next j PrintNext iEnd Sub
版权声明:以上文章中所选用的图片及文字来源于网络以及用户投稿,由于未联系到知识产权人或未发现有关知识产权的登记,如有知识产权人并不愿意我们使用,如有侵权请立即联系:2622162128@qq.com ,我们立即下架或删除。
Copyright© 2022-2024 www.wodocx.com ,All Rights Reserved |陕ICP备19002583号-1
陕公网安备 61072602000132号 违法和不良信息举报:0916-4228922