1. 程式人生 > >線性規劃之單純形算法

線性規劃之單純形算法

線性規劃 單純形 sets sim ted ali gen lex move

首先給出轉動操作的偽代碼(摘自算法導論):

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"

線性規劃之單純形算法