首页 > 编程语言 > 详细

线性规划之单纯形算法

时间:2019-03-13 11:55:50      阅读:146      评论:0      收藏:0      [点我收藏+]

首先给出转动操作的伪代码(摘自算法导论):

PIVOT

PIVOT\((N,B,A,b,c,v,l,e)\)
????let \(\hat{A}\) be a new \(m\times n\) matrix
????\(\hat{b}_{e}=b_l/a_{le}\)
????for each \(j\in N-\{e\}\)
????????\(\hat{a}_{ej}=a_{lj}/a_{le}\)
????\(\hat{a}_{el}=1/a_{le}\)
????for each \(i\in B-\{l\}\)
????????\(\hat{b}_i=b_i-a_{ie}\hat{b}_e\)
????????for each \(j\in N-\{e\}\)
????????????\(\hat{a}_{ij}=a_{ij}-a_{ie}\hat{a}_{ej}\)
????????\(\hat{a}_{il}=-a_{ie}\hat{a}_{el}\)
????\(\hat{v}=v+c_e\hat{b}_e\)
????for each \(j\in N-\{e\}\)
????????\(\hat{c}_j=c_j-c_e\hat{a}_{ej}\)
????\(\hat{c}_l=-c_e\hat{a}_{el}\)
????\(\hat{N}=N-\{e\}\cup \{l\}\)
????\(\hat{B}=B-\{l\}\cup \{e\}\)
????return\((\hat{N},\hat{B},\hat{A},\hat{b},\hat{c},\hat{v})\)

然后是单纯形主体:

SIMPLEX

SIMPLEX\((A,b,c)\)
????\((N,B,A,b,c,v)=\)INITIALIZE-SIMPLEX\((A,b,c)\)
????let \(\Delta\) be a new vector of length \(m\)
????while som index \(j\in N\) has \(c_j>0\)
????????choose an index \(e\in N\) for which \(c_e>0\)
????????for each index \(i\in B\)
????????????if \(a_{ie}>0\)
????????????????\(\Delta_i=b_i/a_{ie}\)
????????else
????????????\(\Delta_i=\infty\)
????????choose an index \(l\in B\) that minimizes \(\Delta_{l}\)
????????if \(\Delta_{l}=\infty\)
????????????return "unbounded"
????????else \((N,B,A,b,c,v)=\)PIVOT\((N,B,A,b,c,v,l,e)\)
????for \(i=1\) to \(n\)
????????if \(i\in B\)
????????????\(\overline{x}_i=b_i\)
????????else
????????????\(\overline{x}_i=0\)
????return \((\overline{x}_1,\overline{x}_2,\dots,\overline{x}_n)\)

最后是初始化可行解:

INITIALIZE-SIMPLE

INITIALIZE-SIMPLEX\((A,b,c)\)
????let \(k\) be the index of the minimum \(b_i\)
????if \(b_k\geqslant 0\)
????????return \((\{1,2,\dots,n\},\{n+1,n+2,\dots,n+m\},A,b,c,0)\)
????form \(L_{aux}\) by adding \(-x_0\) to the left-hand side of each constraint and setting the objective function to \(-x_0\)
????let \((N,B,A,b,c,v)\) be the resulting slack form for \(L_{aux}\)
????\(l=n+k\)
????\((N,B,A,b,c,v)=\)PIVOT\((N,B,A,b,c,v,l,0)\)
????iterate the while loop of lines 3-12 of SIMPLEX until an optimal solution to \(L_{aux}\) is found
????if the optimal solution to \(L_{aux}\) sets \(\overline{x}_0\) to 0
????????if \(\overline{x}_0\) is basic
????????????perform one (degenerate) pivot to make it nonbasic
????????from the final slack form of \(L_{aux}\),remove \(x_0\) from the constraints and restore the original objective function of \(L\),but replace each basic variable in this objective function by the right-hand side of its associated constraint
????????return the modified final slack form
????else return "infeasible"

线性规划之单纯形算法

原文:https://www.cnblogs.com/dummyummy/p/10521220.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!