Linear Programming
Mathwrist White Paper Series
Abstract
This document presents a technical overview of the Linear Programming (LP) feature in Mathwristโs C++ Numerical Programming Library (NPL). Two algorithms are implemented to solve LP problems. One is the classic Simplex method. The second one is an active-set based method with linear objective function.
1 Introduction
In canonical form, linear programming (LP) solves the following minimization problem with a linear objective function subject to linear constraints.
(1) |
To better support practical use, we actually formulate LP problems in a more general form,
(2) |
We shall refer as the cost vector, as general linear constraints and as simple bound (box) constraints respectively. Our implementation of both the Simplex method and the active-set method all take this general LP formulation at user interface level. Internally, the Simplex method needs convert this general form to the canonical form.
In the general form, let denote the index subset of general constraints that require equality to hold. Assume has full row rank. Clearly, the number of equality constraints should be less than . Otherwise the solution is purely determined by .
2 Simplex Method
The classic Simplex algorithm is derived from the canonical LP formulation. In this canonical form, all general constraints are equality constraints. We shall assume has full row rank. Let be the number of linear equality contraints and be the number of unknowns. Again, , otherwise we either donโt have a feasible solution, or the solution is just determined by the linear system .
Next, let be an index set of exact number of index elements, . Let denote the complement subset. A unknown variable that has index or is called a basic variable or non-basic variable respectively. We can shuffle the order of unknown variables and rewrite the linear equality constraints as
, where and are basic variables and non-basic variables. and are the constraint coefficient submatrix for and respectively. If we could find an index set such that is nonsingular and , we can then fix to obtaint a basic feasible solution.
The Fundamental Theorem of Linear Programming, i.e. [2] section 13.2, ensures that if the LP problem (1) has solutions, at least one of them is a basic point. Given an initial basic feasible point and the associated index set, Simplex method iteratively searches in the space of basic feasible points. At each iteration, it tests whether the optimality conditions are satisfied. If not, a non-basic index is identified as the โenter indexโ and a basic index is identified as the โquit indexโ. By increasing variable from zero and decreasing variable to 0, the objective function decreases yet maintaining all feasibility conditions, hence obtaining an improved basic feasible point.
2.1 Optimality Conditions
At the -th iteration, let denote the basic feasible point, the constraint coefficient matrix for basic variables and the constraint coefficient matrix for non-basic variable . Let and be cost vector relevant to and . The following conditions need hold in order for to be an optimal solution,
, where is the vector of Lagrange multipliers for strict equality conditions , is the vector of Lagrange multipliers for non-negative conditions where is exactly fixed at 0 currently.
We first solve a linear system to obtain
, and then
If all elements in are positive, the Simplex algorithm terminates and returns as the solution.
2.2 Pivoting and LU Update
When does not satisfy the optimality conditions, we have for some . Let be the -th column of matrix , which is the constraint coefficient vector for variable . It can be shown that there exists a feasible descent direction ,
, such that by moving along this direction,
-
1.
becomes positive and
-
2.
all other non-basic variables are fixed at 0 and
-
3.
equality condition is retained and
-
4.
objective function value decreases.
Also, by moving along , if all basic variable increase value, we declare the given LP problem is unbounded. Otherwise, such that the basic variable hits zero before any other basic varialbes. Now we have an โenter indexโ to join the basic index set and a โquit indexโ to join the non-basic index set . This is the pivoting operation. By the end of it, we have obtained a new basic feasible point . One can show that obtained by the pivoting operation also have full rank.
A crucial part of a Simplex implementation is to efficiently solve the linear system for some right hand side vector . At the first iteration, we have a LU decomposition on . Subsequently, is obtained by swapping columns and for quit and enter index and . The LU decomposition of can be economically obtained by updating and . Our implementation is based on the LU update algorithm [4] by J.J. Forrest and J. A. Tomlin.
2.3 Canonical Form Conversion
Given a LP problem descriped in the general form (2), we need to convert it to the canonical form (1). First of all, for an unknown variable with simple bound constraint , we can convert it to two equality constraints and by introducing slack and surplus variable and . Then becomes a free variable. All free variables can be further decomposed to positive part and negative part as . This approach effectively makes the augmented unknown space very large.
To implement an efficient algorithm, NPL actually only introduces slack and surplus variables to general inequality constraints. For unknowns with simple bound constraints, we construct the index set and such that the basic variables stay in their feasible region and non-basic variables are fixed at one of their bounds. When we test the optimality conditions, we need flip the sign of a Lagrange multiplier if the non-basic variable is fixed at its upper bound.
All general inequality constraints are splitted to a set of upper bounded constraints and a set of lower bounded constraints . By introducing slack and surplus variables, and , we construct a new set of linear equality constraints with respect to the augmented unknwns .
We shall refer this new set of linear constratins as . Note that by this construction, we have more unknowns than the linear equality constraints. The constraint specification is then converted to the Canonical form (1).
2.4 Initial Basic Feasible Point
To obtain an initial basic feasible point , we first enforce feasibility to simple bound constraints. If one unknown variable provided by the initial guess is outside of its simple bounds, we fix it at the nearest boundary. Secondly, we add artificial variables so that equality strictly holds for all linear constraints.
The initial basic index set containts all artificial variables and some of and . This gives us a diagonal matrix with diagonal elements being either 1 or -1. Lastly, we solve the following phase-I LP feasibility subproblem.
Clearly, when the Simplex method terminates at the end of this phase-I feasibility problem, we either declare that the original LP problem has no feasible solution if any artificial variable in is still positive, or have obtained an initial basic feasible point.
2.5 Selection of the Enter Index
When we test optimality conditions, likely there are multiple negative Lagrange multipliers in . There are different strategies in practice to choose the โenter indexโ from those negative elements. We use the โSteepest Edgeโ method outlined in [2], section 13.5. This strategy has the advantage of finding a search direction that tends to render large step moves.
3 Active-set Method
Active-set based methods can directly work on the general form (2) of a LP problem. Similar to the Simplex method, an active-set method also generates a sequence of feasible points. At each iteration, it partitions all linear constraints into two sets. One set is called โworking setโ, which includes the set of equality constraints and some inequality constraints that now have equality exactly holds for the current feasible point . The other set is the non-working set. Both working and non-working sets are feasible at .
Let and denote the index set of working and non-working general constraints respectively. The size of never exceeds . Let and be the corresponding working and non-working constraint coefficient matrix. At each iteration, the method computes a null space direction wrt such that moving along this direction does not change the value of . Hence we shall refer as a feasible direction.
By moving along a descent feasible direction , the objective function value will decrease. Non-working constraints will also change values, unless they are linearly dependent to . If contraint hits its bound along before any other non-working constraints, strict equality holds for constraint at its bound. It then becomes a working constraint and moves from to . Whenever the working set has exactly number of constraints, a vertex point is reached, which is a stationary point.
On the other hand, if we can move infinite step length along without hitting any non-working constraint, we can declare the LP problem has unbounded solution. This could happen when the rows of are just linear combinations of . In other words, there is redundancy in constraint specification.
At a vertex point, optimality conditions are tested on all inequality working constraints . If the Lagrange multiplier condition for working constraint is not satisfied, we can move along a negative Lagrange direction such that leaves from its bound and becomes strictly feasible. We also move index from to . It can be shown that such a direction is a descent direction. At each iteration, the algorithm repeats to udpate and move along a descent feasible direction until all optimality conditions are satisfied.
3.1 Simple Bound Constraints
The overall strategy of an active set method is to maintain a set of working constraints and search in a direction that retains the values of these working constraints. The same principle applies to simple bound constraints as well. Without loss of generality, assume all simple bounds are lower bounded constraints . At each iteration, if a variable is equal to its lower bound, it is considered as a fixed varialbe. A variable that stays stictly inside its feasible region is considered as a free variable.
Let and denote the set of fixed and free variables respectively. We could treat the simple bounds for as general inequality constraints with equality exactly being held currently. Therefore we can include as many fixed variables as possible in the current working set and arrange the working constraints in the following block structure,
, where the coefficient matrix of general working constraints is partitioned to and for fixed and free variables accordingly. The search direction is a change to those free variables. We just need bookkeep when a free variable hits its bounds and becomes a fixed variable, and when a fixed variable is removed from the working set and becomes free.
3.2 Null Space Direction
Assume there are number of general constraints in a working set . Let have a full QR factorization
The first columns of forms the range space of . The remaining columns of is the null space , . If we seek a null space direction of free variables for some , then . Moving along such a null space direction retains the feasibility with respect to the current working constraints.
To obtain a descent feasible direction, we simply choose being the projection of the negative gradient to the null space, . For LP problems, is the cost vector . So , where is the cost of free variables. Let denote the cost of fixed variables on the other hand.
3.3 Optimality Conditions
Including the fixed variables as working constraints, the stationary condition requires
Accordingly, we can solve
Next we test Lagrange multipliers and . For upper bounded constraints, the sign of Lagrange multipliers are flipped. If all are positive, the optimal solution is found. Otherwise either the general constraint or the fixed variable that has the most negative is selected to quit from the current working set or the set of fixed variables. It can be shown that the feasible direction wrt the updated working set is a descent direction.
3.4 QR Update
The active set method needs repeatedly solve the linear system for some right hand side vector . Given the QR factorization of , we solve
changes whenever a working constraint is added or removed from the working set or the set of free variables changes. An efficient QR factorization update scheme is implemented based on [3], section 5.2.4.
3.5 Initial Working Set and Feasible Point
The active set method also has a phase-I feasibility stage to find an initial feasible point and a subsequent optimality stage to solve the actual LP problem. A โcrash startโ strategy, [3] section 5.8.1, is implemented to seamlessly connect these two stages. By the end of solving the phase-I feasibility problem, we have not only obtained a pair of initial feasible point and initial working set, but also have all internal resources, i.e. QR factorization, ready to immediately start the the phase-II iterations.
Again, without loss of generality, assume all inequality constraints are lower bound constraints. We first construct a crash index set to include all equality constraints . Linear dependency is tested so that only independent constraints are added to . Next, given an initial guess and a โcrash radiusโ control parameter provided by a user, we compute the violation amount for all general constraints, and for simple bounds.
A violated constraint is added to if its violation amount is smaller than and it is independent to all existing constraints in . This procedure stops as soon as has constraints.
Next, we can fix all violated variables in to the corresponding simple bound values and obtain . Now let include all general constraints in and solve free variables from
At this point, we have obtained an initial working set and an initial point that is feasible to working general constraints . Of course, some of the non-working general constraints or simple bounds could still be violated. Conceptually, we introduce artificial variables and and solve a phase-I feasibility subproblem,
When the active set method terminates after its phase-I stage, if the objective function value is not zero, we declare the LP problem has no feasible solution. Otherwise, the solution and working set after phase-I is the starting point of phase-II.
4 Termination Control
Both the Simplex method and the active set method have a control parameter for the max number of iterations allowed. The algorithm always terminates after iterations. Further, there is an exception-throw control. Once enabled, the algorithm throws an exception after iterations. If disabled, it just reports the โhalf-wayโ solution found after iterations.
Both algorithms also have a โconvergence toleranceโ parameter that is used to check the Lagrange multipliers in optimality condition test. If the most negative Lagrange multiplier , the Lagrange multiplier condition is considered as satisfied.
In Simplex method, the number of basic variables is exactly equal to the number of equality constraints. So the basic feasible points generated by the algorithm are always vertex points. Stationary condition is automatically satisfied at a vertex point.
In the active set method, the number of working constraints usually is equal to the number of variables , hence a vertex point as well. However, it is possible that the cost vector for free variables happens to be 0 or a linear combination of at a non-vertex point. The active set method has a โstationary toleranceโ control parameter . When or , we consider the stationary condition is satisfied at a non-vertex point.
5 Summary
The active set method is a very powerful tool to handle LP and many other contrained optimization problems. It directly takes the general LP form (2) without having to introduce slack and artifical variables. When the number of general contraints is significantly greater than the number of unknowns , it has the advantage of working on a linear system that is no bigger than the number of free variables.
Simplex method simultaneously works on all linear constraints. Initially, we need convert the general form to canonical form (1) with slack and artifical variables. It is most suitable for the situation .
References
- [1] David G. Luenberger: Linear and Nonlinear Programming, 2nd edition, Springer 2003
- [2] Jorge Nocedal and Stephen J. Wright: Numerical Optimization, Springer, 1999
- [3] Philip E. Gill, Walter Murray and Margaret H. Wright: Practical Optimization, Academic Press, 1981
- [4] J.J. Forrest and J. A. Tomlin: Updated Triangular Factors of the Basis to Maintain Sparsity in the Product from Simplex Method, Mathematical Programming 2(1972) 263-278