{"id":285,"date":"2026-11-13T12:36:56","date_gmt":"2026-11-13T04:36:56","guid":{"rendered":"https:\/\/hoho.live\/luda\/index.php\/2026\/11\/13\/how-the-simplex-algorithm-pivots-a-linear-program\/"},"modified":"2026-11-13T21:58:32","modified_gmt":"2026-11-13T13:58:32","slug":"how-the-simplex-algorithm-pivots-a-linear-program","status":"publish","type":"post","link":"https:\/\/hoho.live\/luda\/index.php\/2026\/11\/13\/how-the-simplex-algorithm-pivots-a-linear-program\/","title":{"rendered":"How the simplex algorithm pivots a linear program"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\"><strong>Short answer:<\/strong> The <strong>simplex algorithm<\/strong> solves a linear program by walking from one vertex of the feasible polyhedron to a better neighbor. A basic feasible solution is a vertex. A pivot swaps one basic variable for one nonbasic variable and updates the tableau. If no neighbor improves the objective, the current vertex is optimal. The method is finite if a cycling rule such as <strong>Bland&#8217;s rule<\/strong> is used, and it is not polynomial in the worst case. <strong>Klee and Minty<\/strong> built a polytope where a common pivot rule visits exponentially many vertices. Practical instances usually take far fewer pivots.<\/p>\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n<h4 class=\"wp-block-heading\"><strong>What the problem actually asks<\/strong><\/h4>\n\n<p class=\"wp-block-paragraph\">A linear objective over a polyhedron attains its optimum at a vertex, when a vertex optimum exists. Neighboring vertices differ by one basic column. The reduced costs tell which nonbasic variable would improve the objective if it entered. The leaving variable is the one that hits zero first as the entering variable grows, which keeps the solution feasible. That ratio test is the pivot.<\/p>\n\n\n<p class=\"wp-block-paragraph\">Degeneracy, a basic variable already zero, can make a pivot change the basis without moving the point. A careless rule can cycle forever among bases of the same vertex. Bland&#8217;s rule, smallest-index entering and leaving variables, forbids the cycle. It does not make the worst case polynomial.<\/p>\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n<h4 class=\"wp-block-heading\"><strong>What the algorithm guarantees<\/strong><\/h4>\n\n<p class=\"wp-block-paragraph\">With an anti-cycling rule, simplex terminates at an optimal vertex or reports that the problem is unbounded or infeasible, after a Phase I procedure has found a feasible start or proved there is none. Each pivot costs a matrix update. The number of pivots is exponential on some polytopes and modest on the problems the method is used for. Interior-point methods are polynomial and have a different practical profile. Extra memory is the tableau or a revised-simplex factorization of the basis.<\/p>\n\n\n<p class=\"wp-block-paragraph\">The algorithm assumes a linear objective and linear constraints. An integer restriction makes the problem integer programming, and a simplex optimum of the relaxation can be fractional. The fractional vertex is not then a feasible integer point.<\/p>\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n<h4 class=\"wp-block-heading\"><strong>The working steps<\/strong><\/h4>\n\n<ol class=\"wp-block-list\">\n<li>Put the program in equational form with nonnegative variables. Run a Phase I auxiliary problem if a feasible basis is not obvious.<\/li>\n<li>Compute reduced costs. If every reduced cost says the objective would not improve, stop. The basis is optimal.<\/li>\n<li>Otherwise choose an entering variable by the pivot rule. If its column has no positive entry in the constraint rows, the problem is unbounded.<\/li>\n<li>Choose the leaving variable by the minimum nonnegative ratio of the right-hand side to that column. Update the basis.<\/li>\n<li>Use Bland&#8217;s rule or another anti-cycling rule if degenerate pivots are possible. Repeat until the stopping test fires.<\/li>\n<\/ol>\n\n\n<p class=\"wp-block-paragraph\">Finite termination with Bland&#8217;s rule is not a polynomial-time claim. The Klee-Minty cube is the counterexample to that leap. Interior-point algorithms are the polynomial alternative. A fractional solution is optimal for the linear program and may be useless for an integer program built from the same inequalities.<\/p>\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n<h4 class=\"wp-block-heading\"><strong>Approaches that look simpler and fail<\/strong><\/h4>\n\n<figure class=\"wp-block-table\">\n<table>\n<thead>\n<tr>\n<th>Approach<\/th>\n<th>Why it fails when a degenerate pivot is assumed to make progress<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>Claim every pivot strictly improves the objective<\/td>\n<td>A degenerate pivot can change the basis and leave the point fixed. Without an anti-cycling rule the same bases can repeat forever.<\/td>\n<\/tr>\n<tr>\n<td>Claim a polynomial pivot count because each pivot is polynomial work<\/td>\n<td>The work per pivot is polynomial and the number of pivots is not, on the known worst-case polytopes.<\/td>\n<\/tr>\n<tr>\n<td>Round a fractional basic solution and call it an integer optimum<\/td>\n<td>The linear optimum need not be near a feasible integer point. Integer feasibility is a different problem.<\/td>\n<\/tr>\n<tr>\n<td>Skip Phase I and start from a basis that violates the constraints<\/td>\n<td>The ratio test preserves feasibility only when the start was feasible. An infeasible start needs the auxiliary problem.<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/figure>\n\n\n<p class=\"wp-block-paragraph\">A polynomial-time linear programming algorithm is an interior-point method. An integer restriction needs branch and bound or another integer solver, which may call simplex on relaxations. Simplex is the vertex-walking algorithm.<\/p>\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n<h4 class=\"wp-block-heading\"><strong>A working example<\/strong><\/h4>\n\n<p class=\"wp-block-paragraph\">This Python fragment pivots a feasible tableau. The entering column is the lowest index with a negative objective coefficient, and the leaving row is the smallest ratio, with the lowest basic index on a tie. Maximizing x + y subject to x + y \u2264 2 and x \u2264 1 yields <code>2<\/code>.<\/p>\n\n<pre><code class=\"language-python\"># columns: x, y, s1, s2, rhs. Last row is -z for a maximization problem.\ntableau = [\n    [1.0, 1.0, 1.0, 0.0, 2.0],\n    [1.0, 0.0, 0.0, 1.0, 1.0],\n    [-1.0, -1.0, 0.0, 0.0, 0.0],\n]\nbasis = [2, 3]\nwhile True:\n    entering = next((j for j in range(4) if tableau[-1][j] &lt; -1e-12), None)\n    if entering is None:\n        break\n    leave = None\n    best = None\n    for i in range(2):\n        coeff = tableau[i][entering]\n        if coeff &lt;= 1e-12:\n            continue\n        ratio = tableau[i][-1] \/ coeff\n        if best is None or ratio &lt; best - 1e-12 or (abs(ratio - best) &lt;= 1e-12 and basis[i] &lt; basis[leave]):\n            best = ratio\n            leave = i\n    if leave is None:\n        raise RuntimeError(&quot;unbounded&quot;)\n    pivot = tableau[leave][entering]\n    tableau[leave] = [value \/ pivot for value in tableau[leave]]\n    for i in range(3):\n        if i == leave:\n            continue\n        factor = tableau[i][entering]\n        tableau[i] = [tableau[i][j] - factor * tableau[leave][j] for j in range(5)]\n    basis[leave] = entering\nobjective = tableau[-1][-1]\nassert abs(objective - 2) &lt; 1e-9\nprint(int(round(objective)))\n<\/code><\/pre>\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n<h4 class=\"wp-block-heading\"><strong>Where it is used<\/strong><\/h4>\n\n<p class=\"wp-block-paragraph\">The simplex algorithm is the pivot method inside linear-programming solvers such as <strong>HiGHS<\/strong>, <strong>CPLEX<\/strong>, and <strong>Gurobi<\/strong>, next to interior-point methods. Airline schedules, supply chains, and blending problems are linear programs. A shortest path is a tiny special case, not a reason to call a general solver.<\/p>\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n<h4 class=\"wp-block-heading\"><strong>When you can drop this algorithm<\/strong><\/h4>\n\n<p class=\"wp-block-paragraph\">Drop a pivot rule with no anti-cycling protection on a degenerate program. Use Bland&#8217;s rule or a modern solver&#8217;s rule. Keep simplex for linear programs, and do not treat its worst-case path as a typical running time.<\/p>\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n<h4 class=\"wp-block-heading\"><strong>Why this stays published<\/strong><\/h4>\n\n<p class=\"wp-block-paragraph\">We publish this so a search for the simplex algorithm returns the pivot, Bland&#8217;s rule against cycling, and the exponential worst case. <strong>The simplex algorithm walks improving vertices of a linear program and, with an anti-cycling rule, terminates, even though some pivot rules take exponentially many steps on some polytopes.<\/strong><\/p>\n\n\n<p class=\"wp-block-paragraph\">\u672c\u6587\u7531 HoHo \u8207 AI \u5354\u4f5c\u6574\u7406\uff0c\u6700\u5f8c\u66f4\u65b0\u65bc 2026 \u5e74 11 \u6708 13 \u65e5\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Short answer: The simplex algorithm solves a linear program by walking from one vertex of the feasible polyhedron to a better neighbor. A basic feasible solution is a vertex. A pivot swaps one basic variable for one nonbasic variable and updates the tableau. If no neighbor improves the objective,&hellip;<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[30,54],"tags":[],"class_list":["post-285","post","type-post","status-publish","format-standard","hentry","category-algorithms","category-optimization"],"_links":{"self":[{"href":"https:\/\/hoho.live\/luda\/index.php\/wp-json\/wp\/v2\/posts\/285","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/hoho.live\/luda\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/hoho.live\/luda\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/hoho.live\/luda\/index.php\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/hoho.live\/luda\/index.php\/wp-json\/wp\/v2\/comments?post=285"}],"version-history":[{"count":2,"href":"https:\/\/hoho.live\/luda\/index.php\/wp-json\/wp\/v2\/posts\/285\/revisions"}],"predecessor-version":[{"id":684,"href":"https:\/\/hoho.live\/luda\/index.php\/wp-json\/wp\/v2\/posts\/285\/revisions\/684"}],"wp:attachment":[{"href":"https:\/\/hoho.live\/luda\/index.php\/wp-json\/wp\/v2\/media?parent=285"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/hoho.live\/luda\/index.php\/wp-json\/wp\/v2\/categories?post=285"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/hoho.live\/luda\/index.php\/wp-json\/wp\/v2\/tags?post=285"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}