LP Simplex

对linear programming做一个复习note,第一部分从simplex 开始讲起
Recap of LP and BFS
简单的来说,由目标函数、线性约束组成的优化问题就是 Linear Programming, 形如:
Geometry of LP
每个LP的feasible region都可以表示为一个 polyhedron
Definition:
A polyhedron is a set that can be described in the form
where is an matrix and .
Standard Form of LP
通过添加slack variable,我们可以简单地把LP问题转化为如下的standard form:
Assumption:
A has linealy independent rows, or equivalently A has full row rank.
Basic Feasible Solution: We call a of the LP if and only if
- There exist indices such that the columns are linearly independent, and for
We call a if
-
For the standard LP polyhedron , the followings are equivalent:
- is an extreme point
- is a basic feasible solution
-
If there is a feasible solution, there is a basic feasible solution;
-
If there is an optimal solution, there is an optimal solution that is a basic feasible solution.
所以为了求解一个LP,我们有一个很直接的做法,遍历所有的BFS找到最优的解
Simplex Method
Simplex method 的roadmap:
- 找到任意一个BFS作为启动
- 找到一个BFS可能不是那么容易的,可能会涉及2-phase method
- 从1个BFS开始把1个顶点踢出basics 把另一个顶点换进basis(需确保这样使objective变好),几何上看我们在做的事情类似于沿着LP Polyhedron的某一条边,从一个顶点移动到另一个顶点
- 一直重复上述两步,直到没有相邻的BFS能带来更好的objective value
- 需确保不会陷入cycling(Bland' s Rule)
Simplex Method with Dictionary
考虑这样一个example:
Rewrite with Slack Variable
- 通过加入slack variable $\mathbf{w} $可以把不等式转化为等式
- $\mathbf{w} $需确保>0
第一个BFS很容易得到,我们直接把考虑为0,按约束条件求出来,就得到了第一个BFS,我们写成如下的dictionary表格的形式:

-
第一行是objective 行,这一行上的variable取0,不在basis里
-
余下几行(w1-w5)是basis行,他们都在basis里
观察objective行我们可以发现,前面的系数是正的,也就意味着如果能把 从0 increase 就可以提高obj value,那么最多能提高多少呢?
需要确保现在在basis里的variable 不会因为的提高而变为负数,观察余下几行我们会发现提高会导致w1-w5变化,那么一直到第一个w变为0我们就该停止提升x2 了,比较发现是最先变为0的。因此我们把变为非0(放入basis),变为0(移出basis)
注意在其他行内也要把w4 替换掉,底下几行只能出现非basis内的变量:

下一步做类似的处理,把前的系数仍然是正的,增加使得先到0

此时发现obj中所有的variable都是负数系数。我们得到了最优解!
Potential Pitfalls
我们之前的example规避了几个常见的麻烦:
- 我们找initial dictionary时,只需要把设为0,slack variable进入basis,但这是因为这样得到的slack variable都是非负的,如果时slack variable为0 那么就不是一个合法的BFS。
- 如果我们的iteration陷入一个cycling?
- 如果我们在找替换basis时发现所有的basis都不会到0反而会到正无穷?(unbounded)
Unboundedness Detection:
考虑这个dictionary:

我们可以无限制地提高,因此这是一个unbounded的问题
Initialization (2-phases)
2-phase method的思想:
添加slack 变为 ,但直接令得到的是 负数。我们再添加一个辅助变量: ,
此时,我们是能为这个constraint找到一个对应的basis variable 的,我们下面做一些操作把移出basis得到一个新的BFS(的一个BFS),这个BFS一定也是原问题的BFS。
怎么把移出basis呢?我们很巧妙的定义了一个新的优化问题(Phase-I problem)。
我们用一个例子展示这种思想。
原问题:
\begin{align*} \text{maximize} \quad & -x_0 \\ \text{subject to} \quad & -x_0 - 4x_1 - 2x_2 & \leq -8 \\ & -x_0 - 2x_1 & \leq -2 \\ & -x_0 + 3x_1 + 2x_2 & \leq 10 \\ & -x_0 - x_1 + 3x_2 & \leq 1 \\ & -x_0 - 3x_2 & \leq -2 \\ & x_0, x_1, x_2 & \geq 0. \end{align*}
Phase 1:
- Modify problem by subtracting a new variable, , from each constraint and
- replacing objective function with
\begin{align*} \text{maximize} \quad & -x_0 \\ \text{subject to} \quad & -x_0 - 4x_1 - 2x_2 & \leq -8 \\ & -x_0 - 2x_1 & \leq -2 \\ & -x_0 + 3x_1 + 2x_2 & \leq 10 \\ & -x_0 - x_1 + 3x_2 & \leq 1 \\ & -x_0 - 3x_2 & \leq -2 \\ & x_0, x_1, x_2 & \geq 0. \end{align*}
用Simplex method 解这个问题如果:
- Obj != 0 说明,原问题无解
- Obj=0,我们得到了一组解其中这组解一定是原问题的一个BFS
Phase 2:
用 Phase 1得到的BFS开始迭代
Cycling Detection
Theorem (Bland's Rule) If we use both the smallest index rule for choosing the entering basis and the exiting basis, then no cycle will occur in the simplex algorithm.
如果有多个variable 可以进入basis(在obj行上的系数为正)也可以离开basis(同时触0),一个确定的ordering规则可以保证不会出现cycling,最简单直接的就是用index作为order的顺序index。