Simplex Method
Introduction
In algorithm competitions, the simplex method is often used to solve linear programming problems. However, since most linear programming problems encountered in algorithm competitions have more special structures and can often be transformed into network flow problems, the simplex method is not commonly used, and its efficiency is not as good as algorithms specifically designed for network flow problems.
Basic Concepts
Suppose we want to solve a linear programming problem in standard form with \( n \) decision variables and \( m+n \) constraints:
Assume that the system of linear equations determined by these \( m \) equality constraints has a solution, and \( A \) is full rank, so \( \operatorname{rank}A = m \le n \).
An Example
Before formally describing the steps of the simplex method, this section first examines a specific example to facilitate understanding.
Example
Consider the linear programming problem
By adding slack variables, we obtain its standard form:
Observing the equality constraints of this problem, they essentially express the variables \( x_4,x_5,x_6 \) in terms of the variables \( x_1,x_2,x_3 \). Rearranging the original problem slightly, we have
From this form, it is clear that by setting \( x_1=x_2=x_3=0 \), we obtain a feasible solution to the original problem:
Its corresponding objective value is \( z=0 \). For convenience, the variables set to zero, \( x_1,x_2,x_3 \), are called non-basic variables, and the remaining variables \( x_4,x_5,x_6 \) are called basic variables.
This feasible solution is obviously not optimal. By appropriately increasing the values of \( x_1,x_2,x_3 \) while keeping \( x_4,x_5,x_6 \) non-negative, the solution remains feasible. Moreover, since the coefficients of \( x_1,x_2,x_3 \) in the objective function are strictly negative, increasing their values will definitely reduce the objective function value. For example, we can choose to increase \( x_1 \). To reduce the objective function value as much as possible, we want to increase \( x_1 \) as much as possible. However, to ensure the solution remains feasible, we need to guarantee \( x_4,x_5,x_6\ge 0 \). Therefore, \( x_1 \) can be increased at most to
At this point, the feasible solution becomes
Since \( x_1 \) becomes a basic variable, to return to the initial situation (where three basic variables are expressed in terms of three non-basic variables), we need to choose a new non-basic variable. Since \( x_5,x_6 \) are both zero, we can choose either of them as the non-basic variable and set it to zero. Let's choose \( x_5 \) as the non-basic variable. Substituting
into the original problem, we can rewrite the problem as
This returns to the initial situation.
Continue observing the current objective function. The coefficient of the non-basic variable \( x_3 \) is still negative. Consider increasing the value of \( x_3 \). To ensure \( x_4,x_1,x_6\ge 0 \), variable \( x_3 \) can be increased at most to
Note that because the coefficient of \( x_3 \) in the expression for \( x_6 \) is positive, no matter how much we increase \( x_3 \), \( x_6 \) will not become negative. This is why there are only two terms in the braces this time. When \( x_3 \) increases to \( 10 \), both \( x_1 \) and \( x_4 \) become zero, so we can choose either of them as the new non-basic variable. Let's choose \( x_4 \). Substituting
into the above problem, the problem transforms to
By setting \( x_5=x_2=x_4=0 \), we can read the current feasible solution from this form:
and its corresponding objective value is \( z=-120 \).
Repeat the previous operation. Since the coefficient of \( x_2 \) is negative, we can increase its value; but to keep \( x_3,x_6 \) non-negative, it can only be increased to
Since the minimum in the braces appears in the expression for variable \( x_6 \), it will become zero when \( x_2=4 \). Substituting the expression
into the above problem, we can rewrite the original problem as
Still setting the non-basic variables \( x_5,x_6,x_4 \) to zero, we obtain the current feasible solution:
The corresponding objective value is \( z=-136 \).
Since all coefficients of the non-basic variables in the objective function are positive, we cannot continue the aforementioned process to improve the objective function. Therefore, the current feasible solution is the optimal solution. The algorithm terminates.
In this example, the algorithm starts from a feasible solution and continuously improves the objective function until no further improvement is possible. This is the basic idea of the simplex method.
Basic Feasible Solution
Since \( A \) is full rank, we can always select a subset \( B\subseteq\{1,2,\cdots,n\} \) of size \( m \) such that \( A_B \) is an invertible square matrix. Thus, we can express \( x_B \) in terms of the remaining variables \( x_N \):
Here, \( N=\{1,2,\cdots,n\}\setminus B \), matrices \( A_B,A_N \) are submatrices of \( A \) consisting of columns with indices \( i\in B \) and \( i\in N \) respectively, and vectors \( x_B,x_N \) are subvectors of \( x \) consisting of components with indices \( i\in B \) and \( i\in N \) respectively. If \( i\in B \), then \( x_i \) is called a basic variable; otherwise, it is called a non-basic variable. The set of all basic variables is called a basis, denoted in this article by the corresponding index set \( B \).
「Basis」
The name "basis" can be understood from a linear algebra perspective. Let the linear space spanned by all column vectors of \( A \) be \( V \). Then, the column vectors corresponding to basis \( B \) form a basis for the space \( V \).
In the expression for the basic variables \( x_B \), setting \( x_N=0 \) yields a solution to the system of equality constraints1:
A solution obtained in this way is called a basic solution of the linear programming problem. If it also satisfies all non-negativity constraints, i.e., \( x\ge 0 \), then it is also a feasible solution to the original problem, called a basic feasible solution (BFS). During the iteration of the simplex method, we need to always maintain the current solution as a basic feasible solution.
Pivoting
Each iteration of the simplex method is called a pivot. In terms of result, each pivot always removes an old basic variable and adds a new basic variable, thereby improving the objective function value.
「Pivot」
The name "pivot" can also be understood from a linear algebra perspective. As mentioned above, the column vectors corresponding to basis \( B \) form a basis for the space \( V \), which corresponds to a set of coordinate axes under the representation of that basis. Therefore, the pivoting process is the process of rotating a certain coordinate axis to a new position.
To determine which basic variable to add, we can express the objective function in terms of the non-basic variables:
Setting \( x_N=0 \) gives the objective value \( z=c_B^TA_B^{-1}b \) at the current basic feasible solution. The coefficient of the second term in the expression indicates the change in the objective function when \( x_N \) changes:
Note that \( c_B - A_B^T(A_B^{-1})^Tc_B = 0 \), so we can denote the vector
as the reduced cost of the linear programming problem at the feasible basic solution \( x \). A component \( \tilde c_i<0 \) indicates that increasing the value of variable \( x_i \) can improve the objective function of the original problem. Such a variable must be a non-basic variable; it is called the entering variable for this pivot. Because after pivoting, \( x_i \) will become a basic variable and will no longer be fixed at zero (though it may still equal zero).
After selecting the entering variable, we also need to choose the old basic variable to be removed. For this, we only need to determine which existing basic variable first becomes zero during the increase of \( x_i \). Substituting \( x_N=(x_i,x_{N\setminus\{i\}})=(x_i,0) \) into the expression for \( x_B \), we have
Therefore, the maximum amount \( x_i \) can be increased is
The variable that first becomes zero is the basic variable \( x_{B_j} \) corresponding to the index \( j \) that minimizes this expression. It is also the "bottleneck" in increasing \( x_i \)—continuing to increase \( x_i \) would make \( x_{B_j} \) negative. This variable is the leaving variable for this pivot. The method for determining the leaving variable is called the minimum ratio test.
Let the entering variable be \( x_i \) and the leaving variable be \( x_{i'} \). After pivoting, the basic variables become \( x_{B\setminus\{i\}\cup\{i'\}} \), and the non-basic variables become \( x_{N\setminus\{i'\}\cup\{i\}} \).
Termination Conditions
The simplex method is the process of starting from a basic feasible solution and continuously performing pivots. The discussion of pivoting in the previous section is not complete; it ignores some special cases. Some special cases correspond to algorithm termination, while others require additional handling.
First, an entering variable may not exist, i.e., \( \tilde c\ge 0 \). At this point, there is no way to further improve the optimal value, indicating that the current basic feasible solution is optimal, and the algorithm terminates. To prove this rigorously, we need to use the complementary slackness conditions. Let \( y=(A_B^{-1})^Tc_B \). Note that throughout the algorithm, we always maintain that \( x \) is a feasible solution and the complementary slackness condition holds, i.e.,
Therefore, as long as \( y \) is a feasible solution to the dual problem, i.e., \( A^Ty\le c \), we can conclude that \( x \) and \( y \) are optimal solutions to the primal and dual problems, respectively. This condition is exactly \( \tilde c\ge 0 \), meaning no entering variable exists.
「Shadow Price」
The vector \( y=(A_B^{-1})^Tc_B \) is often called the dual vector. When the basic feasible solution corresponding to \( B \) is the optimal solution to the primal problem, the vector \( y \) is the optimal solution to the dual problem. Therefore, when using the simplex method to solve the optimal solution of the primal problem, we also obtain the optimal solution to the dual problem. Since the vector \( y \) is the partial derivative of the current value with respect to the constraint constants, i.e.,
it is also called the shadow price.
Second, a leaving variable may not exist, i.e., \( A_B^{-1}A_i\le 0 \). In this case, there is no "bottleneck" in the pivoting process, meaning we can continuously improve the objective function by increasing \( x_i \) until it equals \( -\infty \). This indicates that the given linear programming problem is unbounded, and the algorithm terminates.
Finally, the choices of entering and leaving variables may not be unique. Inappropriate selection methods may lead to excessive pivoting or even cause the algorithm to cycle, preventing normal termination. Handling such situations is slightly more complex and requires applying some pivot rules to prevent cycling and reduce the number of pivots.
Simplex Tableau
To implement the pivoting process concretely, we only need to maintain the coefficient matrix of the linear programming problem after each pivot:
It corresponds to the linear programming problem:
The matrix \( \tilde T_B \) is called the condensed simplex tableau of the linear programming problem relative to basis \( B \). The top-left element \( (\tilde T_B)_{00} \) is the negative of the value of the current solution, the element in row \( 0 \) and column \( i \), \( (\tilde T_B)_{0i} \), is the reduced cost of the \( i \)-th non-basic variable \( x_{N_i} \), the element in row \( j \) and column \( 0 \), \( (\tilde T_B)_{j0} \), is the value of the \( j \)-th basic variable \( x_{B_j} \), and \( A_B^{-1}A_N \) is the coefficient matrix in the expression expressing the basic variables \( x_B \) in terms of the non-basic variables \( x_N \).
It is easy to see that all information needed for pivoting can be directly obtained from the condensed simplex tableau. Specifically, using the condensed simplex tableau, a single pivot includes the following operations:
- Select a column \( i=1,\cdots,n-m \) such that \( (\tilde T_B)_{0i}<0 \). If no such \( i \) exists, then the current solution is optimal, and the quantity \( -(\tilde T_B)_{00} \) is the optimal value.
- Select a row \( j=1,\cdots,m \) such that \( (\tilde T_B)_{ji}>0 \) and \( (\tilde T_B)_{j0}/(\tilde T_B)_{ji} \) is minimized. If no such \( j \) exists, then the original problem is unbounded.
- Let variable \( x_{N_i} \) enter the basis and variable \( x_{B_j} \) leave the basis, and update the simplex tableau.
Now, let's discuss specifically how to update the simplex tableau. Before updating, row \( j \) represents the equation
To update the simplex tableau, we need to express \( x_{N_i} \) in terms of \( x_{N\setminus\{N_i\}\cup\{B_j\}} \), i.e.:
Substituting this into the other equations, we obtain
Row \( 0 \) is similar, except the left side becomes \( -z \). Although the expressions look complex, in implementation, we only need two steps:
- Update row \( j \): let \( \alpha=(\tilde T_B)_{ji} \), then set the number in column \( i \) to \( 1 \), and then divide all numbers in the entire row by \( \alpha \);
- Update row \( j'\neq j \): let \( \beta=(\tilde T_B)_{j'i} \), then set the number in column \( j \) to \( 0 \), and then subtract \( \beta \) times row \( j \) from the entire row.
「Simplex Tableau」
The simplex tableau refers to the matrix
Compared to the condensed simplex tableau, it has \( m \) additional columns corresponding to the \( m \) basic variables; moreover, the column corresponding to the \( j \)-th basic variable is always \( e_j \), i.e., the vector with value \( 1 \) only in row \( j \) and \( 0 \) elsewhere. Since these columns do not provide extra information, when implementing the simplex method, these columns are often omitted, resulting in the condensed simplex tableau.
Using the simplex tableau makes it easier to understand the steps of updating the simplex tableau. Because all simplex tableaux \( T_B \) can be obtained by left-multiplying the same matrix \( T_0 \) by an invertible matrix \( L_B \) related to the basis, i.e.,
these simplex tableaux and \( T_0 \) can be transformed into each other through several elementary row operations. Therefore, when updating the simplex tableau, we only need to perform elementary row operations to make the column corresponding to the entering variable become \( e_j \). Translating this to the condensed simplex tableau gives the steps described above.
A reference implementation for updating the condensed simplex tableau is as follows:
Reference Implementation
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | |
From this implementation, we can see that the time complexity of a single simplex tableau update is \( O(mn) \). Later, when discussing pivot rules, we will explain that the complexity of determining the leaving and entering variables also does not exceed \( O(mn) \). Therefore, the time complexity of a single pivot is \( O(mn) \).
For better understanding, the detailed steps of the calculation using the condensed simplex tableau for the example discussed earlier are listed here.
Example (Continued)
Initially, the condensed simplex tableau is as follows:
According to the reduced costs in row \( 0 \), we can choose \( x_1,x_2,x_3 \) to enter. Let \( x_1 \) enter. Then, according to the minimum ratio test, we can choose \( x_5,x_6 \) to leave. Let \( x_5 \) leave. Correspondingly, update the condensed simplex tableau as follows:
According to the reduced costs in row \( 0 \), we can choose \( x_2,x_3 \) to enter. Let \( x_3 \) enter. Then, according to the minimum ratio test, we can choose \( x_4,x_1 \) to leave. Let \( x_4 \) leave. Correspondingly, update the condensed simplex tableau as follows:
According to the reduced costs in row \( 0 \), we can only choose \( x_2 \) to enter. Let \( x_2 \) enter. Then, according to the minimum ratio test, we can only choose \( x_6 \) to leave. Let \( x_6 \) leave. Using the aforementioned elementary row operations, update the simplex tableau as follows:
According to the reduced costs in row \( 0 \), there is no entering variable. Therefore, the current solution
is the optimal solution, and the optimal value (for the minimization problem) is \( -136 \).
Besides implementing the simplex method using the simplex tableau, we can also use the revised simplex method, which further improves the time and space complexity of the algorithm, reducing the complexity of a single update to \( O(m^2) \), which is particularly efficient when \( m\ll n \) or when \( A \) is a sparse matrix.
Geometric Background
This section introduces the geometric background of the simplex method.
The analysis of the feasible region of the linear programming problem
indicates:
- The optimal solution of a linear programming problem (if it exists) can always be chosen as a vertex of the feasible region \( \mathcal D \). Solving a linear programming problem reduces to finding the vertex solution with the optimal objective function value among all vertex solutions.
- The coordinates of each vertex can be obtained by solving the system of equations formed by the \( n \) binding constraints. For constraints in standard form, all \( m \) equality constraints are always binding; the remaining \( n-m \) binding constraints can only be chosen from the non-negativity constraints. Selecting these non-negativity constraints as binding constraints is equivalent to setting the corresponding decision variables \( x_N \) to \( 0 \); correspondingly, the system \( Ax = b \) reduces to a linear system \( A_Bx_B = b \) involving the remaining \( m \) decision variables \( x_B \). As long as \( A_B \) is invertible, we can solve for \( x_B = A_B^{-1}b \). This yields a solution \( (x_B,x_N)=(A_B^{-1}b,0) \); if \( x_B\ge 0 \), this is a vertex coordinate of \( \mathcal D \).
It is easy to see that the concept of a vertex solution is consistent with the basic feasible solution defined earlier. Therefore, as long as we find the optimal one among all basic feasible solutions, we obtain the optimal solution to the original problem. Although this greatly simplifies the problem, the number of vertices of the feasible region is exponential, making exhaustive search impractical.
To overcome this difficulty, we can consider moving along the edges of the feasible region, from one vertex to an adjacent vertex. Since adjacent vertices must lie on the same edge, they satisfy at least \( n-1 \) identical binding constraints. That is, the binding constraints corresponding to adjacent vertices can differ by exactly one. Therefore, for a basic feasible solution \( x \), replacing one of its basic variables with a non-basic variable yields an adjacent basic feasible solution \( x' \). This is exactly the pivoting operation.
Thus, the simplex method, starting from a basic feasible solution and continuously pivoting to improve the objective function, is essentially the process of moving from one vertex to adjacent vertices on the corresponding feasible region to improve the objective function.
Example (Continued)
In the example discussed in this article, the feasible region is a three-dimensional polyhedron with five vertices, as shown in the following figure:
The aforementioned solving process, from a geometric perspective, corresponds to the following path among the vertices of the polyhedron:
Implementation Details
Using the simplex tableau, we can already solve many linear programming problems. However, for the most general cases, there are still many details in the simplex method worth exploring in depth.
Slack Form
The method to convert a general-form linear programming problem to standard form has been discussed. However, to facilitate solving using the simplex method, we also need to ensure that the coefficient matrix \( A \) is full rank. Although the method of first converting to standard form and then eliminating linearly dependent constraints is feasible, for simplicity, the following strategy is usually adopted:
- Convert the linear programming problem to inequality form, i.e., the form \( \min\{c^Tx : Ax \le b,~ x \ge 0\} \);
- By adding slack variables \( s \), transform the problem to standard form: \( \min\{c^Tx : Ax + s = b,~ x\ge 0,~ s \ge 0\} \).
The advantage of this approach is that the resulting coefficient matrix \( (A,I) \) in standard form is always full rank, and there always exists a (not necessarily feasible) basic solution \( (x,s)=(0,b) \). This special standard form is also called the slack form.
Initial Basic Feasible Solution
The simplex method described earlier always assumes that a basic feasible solution is known. Sometimes, it is easy to find a basic feasible solution. For example, if \( b\ge 0 \) in the slack form above, then \( (x,s)=(0,b) \) is a basic feasible solution. This is the situation encountered in the numerical example earlier.
For the general case, the two-phase method can be used. In the two-phase method, we perform the simplex method twice. The first phase solves a feasibility linear programming problem to obtain a basic feasible solution for the original problem. The second phase starts from this basic feasible solution and applies the simplex method to solve the original problem.
Suppose we have a problem in standard form \( \min\{c^Tx : Ax = b \ge 0,~ x\ge 0\} \). In the first phase, we solve the problem
This is essentially a feasibility linear programming problem, where the newly added variables \( x_a \) are called artificial variables. It always has a basic feasible solution \( (x,x_a)=(0,b) \), so the simplex method can be applied directly. If the optimal value of this problem is strictly greater than \( 0 \), then there does not exist \( x\ge 0 \) such that \( Ax=b \), meaning the original problem is infeasible. If the optimal value of this problem equals \( 0 \), then in its optimal solution, the artificial variables must be zero. If some artificial variables are still basic variables, we can pivot them out through several pivots. Finally, when all artificial variables are non-basic variables, the basic solution obtained in the first phase can be used as the initial basic feasible solution for the second phase.
First-Phase Implementation Without Explicitly Introducing Artificial Variables
When implementing the first phase, it is not necessary to explicitly introduce artificial variables. For any initially chosen basis \( B \), we have
If \( (A_B^{-1}b)_j\ge 0 \), then no artificial variable is needed; otherwise, we need to additionally introduce an artificial variable \( x^{-}_{B_j} \), i.e.,
Let the index set \( L:=\{j:(A_B^{-1}b)_j<0\} \). Then the simplex tableau for the first phase is obtained by applying several elementary row transformations to the following simplex tableau:
Similar to simplifying the simplex tableau to the condensed simplex tableau, we can appropriately simplify it: (multiply row \( x_{B_{L}}^- \) by \( 1^T \) and add it to row \( 0 \), then omit the last three columns)
This is largely consistent with the normal condensed simplex tableau, except that the variables in the last row are marked with a negative sign, indicating that this row still contains artificial variables, meaning the original slack variables are still infeasible. Using this tableau, the pivoting process is as follows:
- If \( L=\varnothing \), the algorithm terminates.
- Otherwise, select an entering variable \( x_{N_i} \) based on the condition that the reduced cost in row \( 0 \) is negative. If none exists, then the original problem is infeasible, and the algorithm terminates.
-
Then select a leaving variable \( x_{B_j} \) based on column \( i \). Still use the minimum ratio test, but require that both the current feasible variables remain feasible and the current infeasible variables remain infeasible, i.e., select
\[ \arg\min_{j}\left\{\dfrac{(\tilde T_B)_{j0}}{(\tilde T_B)_{ji}}:(j\notin L\land(\tilde T_B)_{ji}>0)\lor(j\in L\land(\tilde T_B)_{ji}<0)\right\} \]as the row index of the leaving variable. If there are multiple such leaving variables, prioritize infeasible leaving variables.
-
Let \( x_{N_i} \) enter and \( x_{B_j} \) leave, and update the simplex tableau.
- If \( j\in L \), then remove \( j \) from \( L \) (i.e., remove the negative sign mark from that row), and add \( 1 \) to \( (\tilde T_B)_{0i} \).
The reason we can omit the columns corresponding to artificial variables is that if they are still basic variables, their corresponding columns are \( e_j \), which need not be recorded; and if they are no longer basic variables, they will not enter the basis again, so they also need not be recorded. When an artificial variable leaves the basis, it needs to be replaced by the corresponding non-artificial variable, which is the purpose of the last step in the above process.
A reference implementation is as follows:
Reference Implementation
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 | |
Before starting the first phase, an extra row is added to record the objective function of the first phase. When pivoting, pivot the entire tableau, including the objective function of the second phase. This way, when the first phase completes, the objective function of the second phase is also updated accordingly, and we can directly start the simplex method of the second phase.
The two-phase method can also be implemented with a single simplex method. By taking a sufficiently large positive number \( M \), we can directly solve the problem
to obtain the optimal solution to the original problem. In implementation, \( M \) is not assigned a specific numerical value but is treated as an unknown sufficiently large positive number during operations. This method is called the big \( M \) method.
The Practical Efficiency of the Naive Algorithm is Exponential
Since the slack form always has an initial basic solution, though not necessarily feasible, a simple idea to find an initial basic feasible solution is to start from an infeasible basic solution and repeatedly use pivoting operations to pivot out infeasible basic variables, selecting non-basic variables corresponding to columns with negative numbers in the same row to enter, until all basic variables are non-negative. A reference implementation is as follows:
Reference Implementation
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 | |
Although this is simple, compared to the two-phase method, it lacks an objective function describing the degree of infeasibility of the current basis, so there is no clear direction for improvement. Actual tests show that compared to the two-phase method or the big \( M \) method, which typically require \( O(m) \) pivots, this naive algorithm usually requires \( O(2^m) \) pivots, and when \( n,m \) are large, it easily falls into cycles. Although the constant in the number of pivots for the naive algorithm is small, it is only suitable for situations where \( n,m<50 \).
Pivot Rules
When pivoting, if there are multiple possible entering or leaving variables, pivot rules are needed to decide which variable to enter or leave. Using the simplex tableau, all rules discussed in this section can find entering and leaving variables in \( O(mn) \) time, so the time complexity of a single pivot remains \( O(mn) \).
The choice of entering variable often determines the number of pivots before algorithm termination. Common rules include:
- Choose the first entering variable found;
- Choose the entering variable with the smallest index; (part of Bland's rule)
- Choose the entering variable with the largest absolute reduced cost (i.e., \( |c_i| \)); (Dantzig's rule)
- Choose the entering variable that yields the largest improvement in the objective function per pivot (i.e., \( |c_i|\theta_i \));
- Choose the entering variable corresponding to the steepest edge, i.e., the one that yields the largest improvement in the objective function per unit length moved along the edge (i.e., \( |c_i|/\|A_B^{-1}A_i\| \));
- Randomly choose an entering variable.
In practice, the steepest edge rule is the most efficient2. It is generally believed that appropriate pivot rules can obtain the optimal solution for most problems in roughly \( 2m \) pivots. However, for all currently known pivot rules, there exist specially constructed examples3 that can force the number of pivots to be exponential. This is precisely why the simplex method performs quite well in practice but has exponential worst-case theoretical complexity.
The choice of leaving variable often determines whether the algorithm will cycle. If there are multiple basic feasible solutions with the same optimal value, the algorithm may cycle among these basic feasible solutions. Such situations are not common, so many simplex method implementations do not specify a rule for selecting the leaving variable. There are two common rules to avoid cycling:
- Bland's rule: Always choose the entering and leaving variables with the smallest indices.
-
Lexicographic rule: Always choose the row index \( j \) corresponding to the leaving variable \( x_{B_j} \) such that \( (A_B^{-1}A_i)_j>0 \) and
\[ \left(\dfrac{(A_B^{-1}b)_j}{(A_B^{-1}A_i)_j},\dfrac{(A_B^{-1})_{j1}}{(A_B^{-1}A_i)_j},\cdots,\dfrac{(A_B^{-1})_{jm}}{(A_B^{-1}A_i)_j}\right) \]is lexicographically smallest. The choice of entering variable is not important.
Note that if the linear programming problem is in slack form, these quantities can be directly found from the simplex tableau \( T_B \) in the form described earlier; otherwise, after finding an initial basic solution (not necessarily feasible), we can use the coefficients of the columns corresponding to the basic variables in these initial bases (keeping the order fixed) as the coefficients of \( A_B^{-1} \).
Bland's rule is very inefficient because the rule itself uses the same method for selecting entering and leaving variables, which easily causes the same variable to repeatedly enter and leave the basis. Comparatively, the lexicographic rule is more practical. The lexicographic rule is equivalent to perturbing the parameters of the linear programming problem slightly4, ensuring that there are no basic feasible solutions with the same optimal value, thus eliminating the possibility of cycling.
Reference Implementation
This section provides a reference implementation of a two-phase simplex method based on the condensed simplex tableau.
Luogu P13337【Template】Linear Programming
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 | |
Example Problems
「NOI2008」Volunteer Recruitment
A total of \( n \) days of activities require volunteer recruitment, where at least \( b_i \) volunteers are needed on day \( i \). There are \( m \) types of volunteers, where the \( j \)-th type can serve during the continuous interval \( [l_j,r_j] \), and the unit recruitment cost is \( c_i \). Find the optimal recruitment plan to minimize the cost of recruiting volunteers.
Solution
Let \( x_j \) be the number of volunteers of type \( j \) recruited. Then, we can formulate the linear programming problem as
where the coefficients
The original problem does not have an obvious initial feasible solution. Therefore, consider its dual problem:
By adding slack variables, it is easy to obtain an initial feasible solution, allowing us to skip the first phase and solve directly using the simplex method. According to duality theory, the solution obtained is the solution to the original problem.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 | |
Exercises
- Luogu P13337【Template】Linear Programming
- UOJ#179. Linear Programming
- Luogu P4232 Hide-and-Seek Beyond Unconsciousness
- Codeforces 1430 G. Yet Another DAG Problem
- AtCoder Beginner Contest 231 H - Minimum Coloring
References
- Linear Programming Simplex Method【Detailed Explanation + Diagram】
- 2016 National Training Team Papers
- Introduction to Algorithms
- Matoušek, Jiří, and Bernd Gärtner. Understanding and using linear programming. Vol. 1. Berlin: Springer, 2007.
- Inayatullah, Syed, Nasir Touheed, and Muhammad Imtiaz. "A streamlined artificial variable free version of simplex method." PloS one 10, no. 3 (2015): e0116156.
- Floudas, Christodoulos A., and Panos M. Pardalos, eds. Encyclopedia of optimization. Springer Science & Business Media, 2008.
-
In principle, since all vectors are column vectors by default, \( (x_B,x_N) \) should be written as \( (x_B^T,x_N^T)^T \). But to simplify notation, all similar cases in this article are directly written as \( (x_B,x_N) \), omitting the transpose symbol. ↩
-
Test results can be found in Forrest, John J., and Donald Goldfarb. "Steepest-edge simplex algorithms for linear programming." Mathematical programming 57, no. 1 (1992): 341-374. ↩
-
A classic counterexample can be found in Klee, Victor, and George J. Minty. "How good is the simplex algorithm." Inequalities 3, no. 3 (1972): 159-175. ↩
-
Detailed explanation can be found in this lecture note. ↩
本页面最近更新:,更新历史
发现错误?想一起完善? 在 GitHub 上编辑此页!
本页面贡献者:OI-wiki
本页面的全部内容在 CC BY-SA 4.0 和 SATA 协议之条款下提供,附加条款亦可能应用