linear_programs.tex 27 KB
Newer Older
1
\documentclass[12pt, a4paper]{article}
Niklas's avatar
Niklas committed
2
\usepackage[top=1cm,bottom=2cm,left=2.5cm,right=2.5cm]{geometry}
3
4
5
6
7
8
9
10
\usepackage[utf8]{inputenc}
\usepackage[english]{babel}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage{amsthm}
\usepackage{mathtools}
\usepackage{array}
Niklas's avatar
Niklas committed
11
12
13
\usepackage{booktabs}
\usepackage{multirow}
\usepackage[linesnumbered, ruled, vlined]{algorithm2e}
14
15
16
\usepackage{graphicx}
\usepackage{float}
\usepackage{tikz}
17
\usepackage{tikz-3dplot}
18
19
20
21
22
23
\usetikzlibrary{calc}
\usepackage{listings}
\usepackage{enumitem}
\usepackage{wrapfig}
%\usepackage{bbold}
\usepackage{bbm}
Niklas's avatar
Niklas committed
24
\usepackage{bm}
25
26
27
28
29
30
31
32
33
34
35
36
37
\usepackage[justification=centering]{caption}
\usetikzlibrary{arrows, automata, graphs, shapes, petri, decorations.pathmorphing}
\parindent = 0pt
\frenchspacing
\let\emptyset\varnothing
\let\epsilon\varepsilon
\let\rho\varrho
\let\theta\vartheta

% define environments
\theoremstyle{definition}
\newtheorem{definition}{Definition}
\newtheorem*{remark*}{Remark}
Niklas's avatar
Niklas committed
38
\newtheorem*{example*}{Example}
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57

\theoremstyle{plain}
\newtheorem{lemma}[definition]{Lemma}
\newtheorem{theorem}[definition]{Theorem}

\renewcommand{\labelenumi}{(\roman{enumi})}
\renewcommand{\labelenumi}{(\roman{enumi})}

\author{Niklas Rieken}
\title{Linear Programs}

\begin{document}
\maketitle

A \emph{linear program} (\emph{LP}) consists of \emph{variables} $x = (x_1, \ldots, x_n)$, an \emph{objective function} $z(x) = c^Tx$ with $c \in \mathbb{Q}^n$ that can either be maximized or minimized, and \emph{constraints} $a^T x \sim b$ with $a \in \mathbb{Q}^n, b \in \mathbb{Q}, \sim \in \{\leq, =, \geq\}$. An LP is in \emph{canonical form} if it is written as
\begin{align*}
	\text{maximize }	& c_1 x_1 + c_2 x_2 + \ldots + c_n x_n\\
	\text{subject to }	& a_{11} x_1 + a_{12} x_2 + \ldots + a_{1n} x_n	&&\leq b_1\\
						& a_{21} x_1 + a_{22} x_2 + \ldots + a_{2n} x_n &&\leq b_2\\
58
						& \quad\quad\quad\quad\quad\vdots & \\
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
						& a_{m1} x_1 + a_{m2} x_2 + \ldots + a_{mn} x_n &&\leq b_m\\
						& x_1, x_2,	\ldots, x_n							&&\geq 0
\end{align*}
or shorter
\begin{align*}
	\text{maximize }	& \sum_{j=1}^n c_j x_j\\
	\text{subject to }	& \sum_{j=1}^n a_{ij} x_j \leq b_i	& i \in \{1, \ldots, m\}\\
						& x_j \geq 0						& j \in \{1, \ldots, n\}
\end{align*}	
or even shorter
\begin{align*}
	\text{maximize }	& c^T x\\
	\text{subject to }	& Ax \leq b\\
						& x \geq 0.
\end{align*}
We call the $x_j$ ($j \in \{1, \ldots, n\}$) \emph{decision variables}, $c^T$ the \emph{objective function coefficients}, $A$ the \emph{coefficient matrix}, and $b$ the \emph{right hand side} of the LP. Moreover, we write $a_i^T$ for the coefficients of the $i$-th constraint. Note that every LP has an ''equivalent`` LP in canonical form:
\begin{itemize}
76
	\item $\min_x c^T x = \max_x -c^T x$,
77
78
79
80
81
82
83
84
85
86
	\item $a_i^T x \geq b_i$ iff $-a_i^T x \leq -b_i$,
	\item $a_i^T x = b_i$ iff $a_i^T x \leq b_i$ and $a_i^T x \geq b_i$,
	\item $x_j \leq 0$ iff $-x_j \geq 0$,
	\item $x_j$ unbounded: Replace $x_j = x_j^+ - x_j^-$ with $x_j^+, x_j^- \geq 0$. 
\end{itemize}

Every constraint (from an LP in canonical form) defines a \emph{halfspace} in $\mathbb{R}^n$ and its separating hyperplane has $a_i^T$ as its normal vector.
\begin{figure}[H]
	\centering
	\begin{tikzpicture}
Niklas Rieken's avatar
Niklas Rieken committed
87
88
		\draw[-] (0, 0) -- (3, -2) coordinate(p1) coordinate[pos=.75] (a);
		\draw[->,red,thick] (a) -- ($(a)!.5cm!90:(p1)$) node[pos=1.4]{\scriptsize$a_i^T$};
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
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
		\draw[white,fill=gray!20] (0, 0) -- (-.5, 0) -- (-.5, -2.5) -- (3, -2.5) -- (3, -2);

		\node (feas) at (.7, -1.7) {\scriptsize{''feasible``}};
		\node (infeas) at (2.3, -.3) {\scriptsize{''infeasible``}};
	\end{tikzpicture}
\end{figure}

We call the set of points that satisfy all constraints \emph{feasible region} $P \coloneqq \{x \in \mathbb{R}^n \mid Ax \leq b, x \geq 0\}$. $P$ is a \emph{polyhedron}, i.e. the intersection of finitely many halfspaces. If $P$ is bounded, it is called a \emph{polytope}.
\begin{figure}[H]
	\centering
	\begin{tikzpicture}
		\begin{scope}
			\path[fill=gray!20] (0, 0) coordinate(p1) -- ++(35:2.5) coordinate(p2) -- ++(-45:2.5) coordinate(p3) -- ++(-120:3.5) coordinate(p4) -- ++(150:3) coordinate(p5);
			\node at (barycentric cs:p1=1,p2=1,p3=1,p4=1,p5=1) {$P$};
			\foreach \X [count=\Y] in {2,...,6} {
				\ifnum\X=6
					\path (p\Y) -- (p1) coordinate[pos=-0.2](a\Y) coordinate[pos=1.2](a1) coordinate[pos=0.5](m1);
					\draw (a\Y) -- (a1);
					\draw[->,red,thick] (m1) -- ($(m1)!1.2cm!90:(p1)$) node[pos=1.2]{$a_{\Y}^T$};
				\else
					\path (p\Y) -- (p\X) coordinate[pos=-0.2](a\Y) coordinate[pos=1.2](a\X) coordinate[pos=0.5](m\X);
					\draw (a\Y) -- (a\X);
					\draw[->,red,thick] (m\X) -- ($(m\X)!1.2cm!90:(p\X)$) node[pos=1.25]{$a_{\Y}^T$};
				\fi
			}
			\node (bounded) at (1.5, -5) {\scriptsize{''bounded``}};
		\end{scope}
		\begin{scope}[shift={(6, 1)}]
			\path[fill=gray!20] (1, -1) coordinate(q1) -- (3, -4) coordinate(q2) -- (5, -4) coordinate(q3) -- (6, -1) coordinate(q4);
			\node at (barycentric cs:q1=1,q2=1,q3=1,q4=1) {$P$};
			\foreach \X [count=\Y] in {2, 3, 4} {
				\path (q\Y) -- (q\X) coordinate[pos=-.2](b\Y) coordinate[pos=1.2](b\X) coordinate[pos=.5](n\X);
				\draw (b\Y) -- (b\X);
				\draw[->,red,thick] (n\X) -- ($(n\X)!1.2cm!-90:(q\X)$) node[pos=1.25]{$a_{\Y}^T$};
			}
			\node (unbounded) at (4, -6) {\scriptsize{''unbounded``}};
		\end{scope}
	\end{tikzpicture}
\end{figure}

If the constraints contradict themselves (for instance, $x + y \leq 1$, $x \geq 2$, and $x, y \geq 0$), then $P = \emptyset$, a corresponsing LP is called \emph{infeasible}. Constraints might also be \emph{redundant}, i.e. a constraint can be omitted without increasing the polyhedron (for example, $x + y \geq 0$ and $x, y \geq 0$).
\begin{figure}[H]
	\centering
	\begin{tikzpicture}
		\begin{scope}
			\path (0, 0) coordinate(p1) -- (-3, -2) coordinate(p2) -- (1, -3) coordinate(p3);
			\path (p1) -- (p2) coordinate[pos=-.2](a1) coordinate[pos=1.2](a2) coordinate[pos=.3](m2);
			\draw (a1) -- (a2);
			\draw[->,red,thick] (m2) -- ($(m2)!.8cm!90:(p2)$);
			\path (p2) -- (p3) coordinate[pos=-.2](a2) coordinate[pos=1.2](a3) coordinate[pos=.5](m3);
			\draw (a2) -- (a3);
			\draw[->,red,thick] (m3) -- ($(m3)!.8cm!90:(p3)$);
			\path (p3) -- (p1) coordinate[pos=-.2](a3) coordinate[pos=1.2](a1) coordinate[pos=.4](m1);
			\draw (a3) -- (a1);
			\draw[->,red,thick] (m1) -- ($(m1)!.8cm!90:(p1)$);
			\node (infeasible) at (-.5, -3.5) {\scriptsize{''infeasible``}};
		\end{scope}
		\begin{scope}[shift={(4.5, 0)}]
			\path[fill=gray!20] (4, 1) coordinate(q1) -- (0, 0) coordinate(q2) -- (0, -2) coordinate(q3) -- (4, -3) coordinate(q4);
			\node at (barycentric cs:q1=1,q2=1,q3=1,q4=1) {$P$};
			\foreach \X [count=\Y] in {2, 3, 4} {
				\path (q\Y) -- (q\X) coordinate[pos=-.3](b\Y) coordinate[pos=1.3](b\X) coordinate[pos=.5](n\X);
				\draw (b\Y) -- (b\X);
				\draw[->,red,thick] (n\X) -- ($(n\X)!.8cm!-90:(q\X)$);
			}
			\draw (-.5, .5) -- (-.5, -2.5);
			\draw[->,red,thick] (-.5, -1.2) -- (-1.2, -1.2);
			\node (redundant) at (1.5, -3.5) {\scriptsize{''redundant``}};
		\end{scope}
	\end{tikzpicture}
\end{figure}

Polyhedra are \emph{convex}, i.e. they satisfy Jensen's inequality: For all $x, y \in P$ and all $\theta \in [0, 1]$, $(1-\theta)x + \theta y \in P$.
\begin{proof}
	Let $x, y \in P$ and $\theta \in [0, 1]$, then 
	$$
		(\underbrace{1-\theta}_{\geq 0})\underbrace{x}_{\geq 0} + \underbrace{\theta}_{\geq 0} \underbrace{y}_{\geq 0} \geq 0
	$$
	and moreover,
	\begin{align*}
		A((1-\theta)x + \theta y) &= (1-\theta)\underbrace{Ax}_{\leq b} + \theta \underbrace{Ay}_{\leq b}\\
		&\leq (1-\theta)b + \theta b\\
		&= b.\qedhere
	\end{align*}
\end{proof}

The \emph{dimension} $\dim P$ is the dimension of the smallest affine subspace containg $P$. If $P \subseteq \mathbb{R}^n$ with $\dim P = n$, then $P$ is called \emph{full dimensional}. 
For a given $x \in P$, a constraint $a_i^T x \leq b_i$ is called \emph{active} (or \emph{binding}) if $a_i^T x = b_i$.
A \emph{face} with respect to $H \subseteq \{1, \ldots, m\}$ is
$$
	F \coloneqq \{x \in P \mid a_i^T x \leq b_i \text{ active in } x, i \in H\}.
$$
181
\begin{figure}[H]
182
183
	\centering
	\begin{tikzpicture}
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
		\begin{scope}
			\path[fill=gray!20] (0, 0) coordinate(p1) -- ++(35:2.5) coordinate(p2) -- ++(-45:2.5) coordinate(p3) -- ++(-120:3.5) coordinate(p4) -- ++(150:3) coordinate(p5);
			\node at (barycentric cs:p1=1,p2=1,p3=1,p4=1,p5=1) {$P$};
			\foreach \X [count=\Y] in {2,...,6} {
				\ifnum\X=6
					\path (p\Y) -- (p1) coordinate[pos=-0.2](a\Y) coordinate[pos=1.2](a1) coordinate[pos=0.5](m1);
					\draw[red] (a\Y) -- (a1);
				\else
					\ifnum\X=5
						\path (p\Y) -- (p\X) coordinate[pos=-0.2](a\Y) coordinate[pos=1.2](a\X) coordinate[pos=0.5](m\X);
						\draw[red] (a\Y) -- (a\X);
						\node[red] at (p5) {$\bullet$};
					\else
						\path (p\Y) -- (p\X) coordinate[pos=-0.2](a\Y) coordinate[pos=1.2](a\X) coordinate[pos=0.5](m\X);
						\draw (a\Y) -- (a\X);
					\fi
				\fi
			}
			\node (vertex) at (1.5, -4.5) {\scriptsize{''vertex ($0$-dim)``}};
		\end{scope}
		\begin{scope}[shift={(5.5, 0)}]
			\path[fill=gray!20] (0, -1) coordinate(p1) -- (2, -3) coordinate(p2) -- (3, -1) coordinate(p3) -- (2, 1) coordinate(p4) -- (0, 1) coordinate(p5);
			\node at (barycentric cs:p1=1,p2=1,p3=1,p4=1,p5=1) {$P$};
			\foreach \X [count=\Y] in {2,...,6} {
				\ifnum\X=6
					\path (p\Y) -- (p1) coordinate[pos=-0.2](a\Y) coordinate[pos=1.2](a1) coordinate[pos=0.5](m1);
					\draw (a\Y) -- (a1);
				\else
					\ifnum\X=3
						\path (p\Y) -- (p\X) coordinate[pos=-0.2](a\Y) coordinate[pos=1.2](a\X) coordinate[pos=0.5](m\X);
						\draw[red,very thick] (a\Y) -- (a\X);
					\else
						\path (p\Y) -- (p\X) coordinate[pos=-0.2](a\Y) coordinate[pos=1.2](a\X) coordinate[pos=0.5](m\X);
						\draw (a\Y) -- (a\X);
					\fi
				\fi
			}
			\node (edge) at (1.5, -4.5) {\scriptsize{''edge ($1$-dim)``}};
		\end{scope}
		\begin{scope}[shift={(10, -1)},scale=4.3]
			\coordinate (A1) at (0,0);
			\coordinate (A2) at (0.6,0.2);
			\coordinate (A3) at (1,0);
			\coordinate (A4) at (0.4,-0.2);
			\coordinate (B1) at (0.5,0.5);
			\coordinate (B2) at (0.5,-0.5);
			\draw[fill=gray!20] (A1) -- (A4) -- (B1);
			\draw[fill=gray!20] (A1) -- (A4) -- (B2);
			\draw[fill=gray!20] (A4) -- (A3) -- (B2);
			\draw[fill=red!60] (A4) -- (A3) -- (B1);
			\draw[dashed] (A1) -- (A2) -- (A3);
			\draw[dashed] (B1) -- (A2) -- (B2);
			\draw (A4) -- (A1) -- (B1);
			\draw (A4) -- (B2);
			\draw (A3) -- (A4) -- (B1);
			\draw (B1) -- (A1) -- (B2) -- (A3) ;
			\draw[red,thick](A4) -- (A3) -- (B1) -- cycle;
			\node at (.3, -.05) {$P$};
		\end{scope}
			\node (facet) at (12, -4.5) {\scriptsize{''facet ($(n-1)$-dim)``}};
244
245
246
247
248
	\end{tikzpicture}
\end{figure}

Every face itself is again a polyhedron. A point $x \in P$ is called \emph{feasible solution}, $x^\ast \in P$ such that $c^T x^\ast \geq c^T x$ for all $x \in P$ is called \emph{optimal solution} (provided that the objective function should be maximized), $c^T x^\ast$ is called \emph{optimum}.

Niklas's avatar
Niklas committed
249
\begin{theorem}[Fundamental Theorem of Linear Programming]
250
251
252
253
254
255
256
257
	For every LP exactly one of the following hold:
	\begin{enumerate}
		\item The LP is infeasible, i.e. $P = \emptyset$.
		\item The optimum is unbounded, i.e. for all $M > 0$, there exists $x \in P$ with $c^T x \geq M$.
		\item There exists a finite optimal solution.
	\end{enumerate}
	If the last case is true, then the optimal sollution is assumed at a vertex of $P$.
\end{theorem}
258
\begin{figure}[H]
259
260
	\centering
	\begin{tikzpicture}
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
		\begin{scope}[scale=.7]
			\path (0, 0) coordinate(p1) -- (-3, -2) coordinate(p2) -- (1, -3) coordinate(p3);
			\path (p1) -- (p2) coordinate[pos=-.2](a1) coordinate[pos=1.2](a2) coordinate[pos=.3](m2);
			\draw (a1) -- (a2);
			\path (p2) -- (p3) coordinate[pos=-.2](a2) coordinate[pos=1.2](a3) coordinate[pos=.5](m3);
			\draw (a2) -- (a3);
			\path (p3) -- (p1) coordinate[pos=-.2](a3) coordinate[pos=1.2](a1) coordinate[pos=.4](m1);
			\draw (a3) -- (a1);
			\path[draw,red] (-3, 0) coordinate(c1) -- (-2, -.5) coordinate(c2) coordinate[pos=.5](cm);
			\draw[red] (c1) -- (c2) node[pos=1.2] {$c$};
			\draw[red,thick,->] (cm) -- ($(cm)!.8cm!-90:(c2)$);
		\end{scope}
		\begin{scope}[shift={(2, 1)},scale=.7]
			\path[fill=gray!20] (1, -1) coordinate(q1) -- (3, -4) coordinate(q2) -- (5, -4) coordinate(q3) -- (6, -1) coordinate(q4);
			\node at (barycentric cs:q1=1,q2=1,q3=1,q4=1) {$P$};
			\foreach \X [count=\Y] in {2, 3, 4} {
				\path (q\Y) -- (q\X) coordinate[pos=-.2](b\Y) coordinate[pos=1.2](b\X) coordinate[pos=.5](n\X);
				\draw (b\Y) -- (b\X);
			}
			\path[draw,red] (2, 0) coordinate(c1) -- (3.5, -.3) coordinate(c2) coordinate[pos=.5](cm);
			\draw[red] (c1) -- (c2) node[pos=1.2] {$c$};
			\draw[red,thick,->] (cm) -- ($(cm)!.8cm!90:(c2)$);
		\end{scope}
		\begin{scope}[shift={(9, 0)},scale=.7]
			\path[fill=gray!20] (0, 0) coordinate(p1) -- ++(35:2.5) coordinate(p2) -- ++(-45:2.5) coordinate(p3) -- ++(-120:3.5) coordinate(p4) -- ++(150:3) coordinate(p5);
			\node at (barycentric cs:p1=1,p2=1,p3=1,p4=1,p5=1) {$P$};
			\foreach \X [count=\Y] in {2,...,6} {
				\ifnum\X=6
					\path (p\Y) -- (p1) coordinate[pos=-0.2](a\Y) coordinate[pos=1.2](a1) coordinate[pos=0.5](m1);
					\draw (a\Y) -- (a1);
				\else
					\path (p\Y) -- (p\X) coordinate[pos=-0.2](a\Y) coordinate[pos=1.2](a\X) coordinate[pos=0.5](m\X);
					\draw (a\Y) -- (a\X);
				\fi
			}
			\node at (p1) {\color{red}$\bullet$};
			\path[draw,red] (-1, .5) coordinate(c1) -- (0, 1.5) coordinate(c2) coordinate[pos=.5](cm);
			\draw[red] (c1) -- (c2) node[pos=1.2] {$c$};
			\draw[red,thick,->] (cm) -- ($(cm)!.8cm!90:(c2)$);
		\end{scope}
301
302
303
304
305
306
	\end{tikzpicture}
\end{figure}

\begin{lemma}
	An $n$-dimensional polyhedron given by $m$ constraints has at most $\binom{m}{n}$ vertices, i.e. finitely many.
\end{lemma}
307
Thus, of all (usually infinitely many) feasible points, only finitely many are relevant. However, enumerating all those points and choosing the best solution (\emph{brute force}) is still very inefficient.
308
309

Idea for the Simplex algorithm: Move from vertex to vertex such that the objective value only increases (decreases, respectively, if objective is to minimize).
310
\begin{figure}[H]
311
312
	\centering
	\begin{tikzpicture}
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
		\path[fill=gray!20] (0, 0) coordinate(p1) -- ++(35:2.5) coordinate(p2) -- ++(-45:2.5) coordinate(p3) -- ++(-120:3.5) coordinate(p4) -- ++(150:3) coordinate(p5);
		\node at (barycentric cs:p1=1,p2=1,p3=1,p4=1,p5=1) {$P$};
		\foreach \X [count=\Y] in {2,...,6} {
			\ifnum\X=6
				\path (p\Y) -- (p1) coordinate[pos=-0.2](a\Y) coordinate[pos=1.2](a1) coordinate[pos=0.5](m1);
				\draw (a\Y) -- (a1);
			\else
				\path (p\Y) -- (p\X) coordinate[pos=-0.2](a\Y) coordinate[pos=1.2](a\X) coordinate[pos=0.5](m\X);
				\draw (a\Y) -- (a\X);
			\fi
		}
		\node[draw,red,circle] (S1) at (p4) {};
		\node[draw,red,circle] (S2) at (p5) {};
		\node[draw,red,circle] (S3) at (p1) {};
		\draw[-latex',red,thick] (S1) edge[bend right] (S2);
		\draw[-latex',red,thick] (S2) edge[bend right] (S3);
		\path[draw,red] (-1, .5) coordinate(c1) -- (0, 1.5) coordinate(c2) coordinate[pos=.5](cm);
		\draw[red] (c1) -- (c2) node[pos=1.2] {$c$};
		\draw[red,thick,->] (cm) -- ($(cm)!.8cm!90:(c2)$);
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
	\end{tikzpicture}
\end{figure}

We introduce \emph{slack variables} to fill gaps between constraints and corresponding right hand side.
$$
	y \coloneqq b - Ax, \quad y \geq 0. 
$$
This yields to \emph{standard form} for LPs:
\begin{align*}
	\text{minimize }	& c^T x				& \text{minimize }		& c^T x\\
	\text{subject to }	& Ax + y = b		& \text{subject to }	& Ax = b\\
						& x, y \geq 0		&						& x \geq 0
\end{align*}
where the LP on the right is obtained by setting $x_{n+i} = y_i$ for $i \in \{1, \ldots, m\}$ and we extend $c$ and $A$ in the obvious way.

The transformation from canonical form to standard form preserves dimension and vertices of the polyhedron.
348
349
\begin{figure}[H]
	\tdplotsetmaincoords{70}{45}
350
	\centering
Niklas's avatar
Niklas committed
351
	\begin{tikzpicture}[scale=3, >=latex']
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
		\begin{scope}[tdplot_main_coords]
			\path[fill=gray!20] (0, 0, 0) -- (1, 0, 0) -- (0, 1.2, 0);
			\draw[->] (0, 0, 0) -- (1.2, 0, 0) node[pos=1.1] {$x_1$};
			\draw[->] (0, 0, 0) -- (0, 1.5, 0) node[pos=1.07] {$x_2$};
			\node at (0, 0, 0) {$\bullet$};
			\node at (1, 0, 0) {$\bullet$};
			\node at (0, 1.2, 0) {$\bullet$};
			\draw[-] (1, 0, 0) -- (0, 1.2, 0);
		\end{scope}
			\node at (.45, -.7) {$P = \{x \in \mathbb{R}^2_+ \mid x_1 + x_2 \leq 1\}$}; 
		\begin{scope}[tdplot_main_coords, shift={(2, 1.6)}]
			\path[fill=gray!20] (1, 0, 0) -- (0, 1.2, 0) -- (0, 0, .8);
			\draw[->] (0, 0, 0) -- (1.2, 0, 0) node[pos=1.1] {$x_1$};
			\draw[->] (0, 0, 0) -- (0, 1.5, 0) node[pos=1.07] {$x_2$};
			\draw[->] (0, 0, 0) -- (0, 0, 1) node[pos=1.1] {$y_1$};
			\node at (0, 0, .8) {$\bullet$};
			\node at (1, 0, 0) {$\bullet$};
			\node at (0, 1.2, 0) {$\bullet$};
			\draw[-] (1, 0, 0) -- (0, 1.2, 0) -- (0, 0, .8) -- (1, 0, 0);
		\end{scope}
			\node at (3, -.7) {$P' = \{(x, y) \in \mathbb{R}^3_+ \mid x_1 + x_2 + y_1 = 1\}$}; 
373
374
375
376
	\end{tikzpicture}
\end{figure}

Note that the slack variable $y_i = 0$ iff the $i$-th constraint is active. % complementary slackness?
377
We can also interpret $x$ as slack variable, just note that $x_j = 0$ iff $x_j \geq 0$ active.
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397

Let $A_1, A_2, \ldots, A_n, A_{n+1}, \ldots, A_{n+m}$ be the columns of $A$ (the latter $m$ columns are unit vectors for slack varaiables). For $J \subseteq (1, \ldots, n+m)$, let $A_J$ denote the matrix consisting of columns $A_j$ with $j \in J$, e.g. for
$$
	A = \left(
		\begin{matrix}
			3 & 7 & 0 & -1 & 1 & 0\\
			-1 & -1 & -2 & 2 & 0 & 1
		\end{matrix}
	\right),
	\quad
	J = (5, 2)
	\implies 
	A_J = \left(
		\begin{matrix}
			1 & 7\\
			0 & -1
		\end{matrix}
	\right).
$$

398
A \emph{basis} $B = (B_1, \ldots, B_m) \subseteq (1, \ldots, n+m)$ is a subset of $m$ column indices such that the corresponding columns are linearly independent. $N = (1, \ldots, n+m) \setminus B$ is called \emph{non basis}. Variables $x_j$ with $j \in B$ are called \emph{basic variables}, and \emph{non-basic variables} if $i \in N$.
399
400
401
402
403
404
405
406
407
408
409
410
411
412

A vector $x \in \mathbb{Q}^{n+m}$ is a \emph{basic solution} to $Ax = b$, $x \geq 0$ if there is a basis $B$ such that
\begin{itemize}
	\item $A_B x_B = b$ (\emph{uniqueness}),
	\item $x_N = 0$ (\emph{at boundary}, \emph{vertex}).
\end{itemize}
If additionally $x_B \geq 0$ holds $x$ is called \emph{feasible basic solution}.

\begin{theorem}
	Every feasible basic solution corresponds to exactly one vertex of $P$.
\end{theorem}
Basic solution are also called \emph{extreme point solutions}.

We need $\dim P$ constraints to describe a vertex. The non-basic variables correspond to the active constraints.
413
\begin{figure}[H]
414
415
	\centering
	\begin{tikzpicture}
416
417
418
419
420
421
422
423
424
425
		\path[fill=gray!20] (0, 0) coordinate(p1) -- (2, 1) coordinate(p2) -- (4, 1) coordinate(p3) -- (6, 0) coordinate(p4) -- (5, -1) coordinate(p5);
		\foreach \X [count=\Y] in {2,...,5} {
			\path (p\Y) -- (p\X) coordinate[pos=-0.2](a\Y) coordinate[pos=1.2](a\X); 
			\ifnum\Y=4
				\draw (a\Y) -- node[below right]{\scriptsize$\Y$} (a\X);
			\else 
				\draw (a\Y) -- node[above] {\scriptsize$\Y$} (a\X);
			\fi
		}	
		\node[draw,circle,red,label={[align=left,red,shift={(1.5, 0)}]\scriptsize{At this vertex, the slack}\\[-.5em]\scriptsize{variables of constraint 2}\\[-.5em]\scriptsize{and 3 are $0$.}}] at (p3) {};
426
427
428
429
	\end{tikzpicture}
\end{figure}

Note that the basis in one vertex is not necessarily unique. We call those vertices \emph{degnerate}.
430
\begin{figure}[H]
431
	\centering
432
433
434
435
436
437
438
	\begin{tikzpicture}[scale=2]
		\path[fill=gray!20] (-.8, 0) -- (0, 0) -- (-.64, .64);
		\draw[-] (-1, 0) -- (1, 0) node[pos=1.05]{\scriptsize$1$};
		\draw[-] (-.8, .8) -- (.8, -.8) node[pos=1.05]{\scriptsize$2$};
		\draw[-] (0, 1) -- (0, -1) node[pos=1.05]{\scriptsize$3$};
		\draw[-] (.5, .75) -- (-.5, -.75) node[pos=1.05]{\scriptsize$4$};
		\node[align=left] at (3.5, 0) {Possible bases:\\$B = (1, 2), (1, 3), (1, 4), (2, 3), \ldots$};
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
	\end{tikzpicture}
\end{figure}

Given a standard form LP with $Ax = b$, $x \geq 0$ and basis $B$:
\begin{align*}
	& A_B x_B + A_N x_N &&= b\\
	\iff & x_B &&= \underbrace{A_B^{-1} b}_{\eqqcolon \bar{b}} - \underbrace{A_B^{-1} A_N}_{\eqqcolon \bar{A}_N} \underbrace{x_N}_{= 0}. 
\end{align*}
Using the objective function $z(x) = c^T x$:
\begin{align*}
	z(x) &= c^T x\\
	&= c_B^T x_B + c_N^T x_N\\
	&= c_B^T(A_B^{-1} b - A_B^{-1} A_N x_N) + c_N^T x_N\\
	&= c_B^T A_B^{-1} - c_B^T A_B^{-1} A_N x_N + c_N^T x_N\\
	&= \underbrace{c_B^T A_B^{-1} b}_{\eqqcolon \bar{z}} + (\underbrace{c_N^T - c_B^T A_B^{-1} A_N}_{\eqqcolon \bar{c}_N^T~\emph{''reduced cost``}}) \underbrace{x_N}_{= 0}.
\end{align*}
Optimality condition: Basis $B$ (and the corresponding vertex) optimal if reduced cost $\bar{c}_N^T \leq 0$. Intuitively, no non-basic variable can be increased without decreasing the value of $z$.

Niklas's avatar
Niklas committed
457
Otherwise we can find a non-basic variable that can ''improve`` the objective value. This means we deactivate a constraint (increasing its slack) and move to another vertex:
458
459
460
461
462
463
464
465
466
\begin{itemize}
	\item Initially: Vertex given by $B, N$.
	\item If there is a non-basic variable $x_s$, $s \in N$, with $\bar{c}_s > 0$, it is beneficial to increase $x_s$ (currently $x_s = 0$).
	\item Since $x_B = A_B^{-1} b - A_B^{-1} A_N x_N$, the values of basic-variables decrease if $A_B^{-1} A_s > 0$.
	\item The maximum value for $x_s$ is determined by ''the first`` basic variable which becomes $0$.
	\item If this never happens, i.e. $A_B^{-1} A_s \leq 0$, then $x_s$ can be arbitrarily  increased; in this case the objective value is unbounded.
\end{itemize}

The first basis: If $b \geq 0$, all slack variables are a feasible basis, i.e. $B = (n+1, \ldots, n+m)$, and hence, $A_B = A_B^{-1} = \mathbbm{1}_m$ and $\bar{A}_N = A_N$, $\bar{b} = b$. The first basic solution is then $x_{n+i} = b_i$ for $i \in \{1, \ldots, m\}$ and $x_1 = \ldots = x_n = 0$ (i.e. the origin). Since $c_B^T = 0$ (all slack), we have $\bar{c}_N^T = C_N^T$ and $\bar{z} = 0$. For calculation by hand, we can store all coefficients in a \emph{dictionary} (or \emph{tableau}):
Niklas's avatar
Niklas committed
467
468
\begin{table}[H]
	\def\arraystretch{1.3}
469
	\centering
Niklas's avatar
Niklas committed
470
471
	\begin{tabular}{c|cc|c|}
		\toprule
472
		\ & $\bar{c}_N^T$ & $0$ & $\bar{z}$\\
Niklas's avatar
Niklas committed
473
		\midrule
474
		$x_B$ & $\bar{A}_N$ & $\mathbbm{1}_m$ & $\bar{b}$\\
Niklas's avatar
Niklas committed
475
		\bottomrule
476
477
478
		\ & $x_N$ & $x_B$ & \
	\end{tabular}
\end{table}
Niklas's avatar
Niklas committed
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607

\begin{algorithm}
	\caption{Basic Simplex algorithm}
	\label{alg:simplex}
	Compute initial basic feasible solution.\\
	\While{Current basic solution not optimal} {
		Move to best adjacent basic solution.
	}
\end{algorithm}

In the following we demonstrate the Simplex method on a small example that captures the whole pivoting routines
\begin{example*}
	We consider the LP in canonical form
	\begin{align*}
		\text{maximize }	& 2 x_1 + x_2\\
		\text{subject to }	& 2x_1 - 3x_2 \leq 6\\
							& x_1 + x_2 \leq 4\\
							& x_1, x_2 \geq 0.
	\end{align*}
	The corresponding polytope is sketched in the next figure.
	\begin{figure}[H]
		\centering
		\begin{tikzpicture}
			\draw[->] (0, 0) -- (5, 0) node[below] {$x_2 \geq 0$};
			\draw[->] (0, 0) -- (0, 5) node[left] {$x_1 \geq 0$};
			\draw[-] (2.25, -.5) -- (4, 2/3) node[pos=1.1,right]{$2x_1-3x_2 \leq 6$};
			\draw[-] (-.5, 4.5) -- (4, 0) node[pos=.5, above right]{$x_1+x_2 \leq 4$};
		\end{tikzpicture}
	\end{figure}
	The corresponding LP in standard form is
	\begin{align*}
		\text{maximize }	& 2x_1 + x_2\\
		\text{subject to }	& 2x_1 - 3x_2 + x_3 = 6\\
							& x_1 + x_2 + x_4 = 4\\
							& x_1, x_2, x_3, x_4 \geq 0
	\end{align*}

	Since  $b = (6, 4) \geq (0, 0)$, we can choose the slack variables as basis, i.e. $B = (3, 4)$. Thus, the first basic solution is $(x_1, x_2, x_3, x_4) = (0, 0, 6, 4)$. From the standard form, we construct the initial simplex tableau.

	\begin{minipage}{.49\textwidth}
		\begin{table}[H]
			\centering
			\begin{tabular}{c|cccc|c|}
				\toprule
				\ & $2$ & $1$ & $0$ & $0$ & $0$\\
				\midrule
				$x_3$ & $\bm{2}$ & $-3$ & $1$ & $0$ & $6$\\
				$x_4$ & $1$ & $1$ & $0$ & $1$ & $4$\\
				\bottomrule
				\ & $x_1$ & $x_2$ & $x_3$ & $x_4$ & \
			\end{tabular}
		\end{table}
	\end{minipage}
	\begin{minipage}{.49\textwidth}
		\begin{figure}[H]
			\centering
			\begin{tikzpicture}[scale=.6]
				\draw[->] (0, 0) -- (5, 0);
				\draw[->] (0, 0) -- (0, 5);
				\draw[-] (2.25, -.5) -- (4, 2/3);
				\draw[-] (-.5, 4.5) -- (4, 0);
				\node[draw,circle,red,inner sep=2pt] at (0, 0) {};
			\end{tikzpicture}
		\end{figure}
	\end{minipage}


	As we can see the greatest improvement of $\bar{z}$ can be obtained by increasing $x_1$ to a positive value ($\bar{c}_1 = 2 > 1 = \bar{c}_2$). Since $x_B = \bar{b} - \bar{A}_1 x_1$, we have to decreas basic variables that have a positive value in $\bar{A}_1 = (2, 1)^T$ (i.e. all of them): Increasing $x_1$ by $1$ forces $x_3$ to decrease by $2$ and $x_4$ by $1$. We can only decrease $x_3, x_4$ until one of them falls to $0$, i.e. $x_1$ can only be increased to $\min \{\frac{6}{2}, \frac{4}{1}\} = 3$. Hence, in this case $x_3$ drops to $0$. Since $x_1$ becomes a basic variable, its column should become $(1, 0)^T$, so we do similar transformation as in the Gaussian eliminination with the $\bm{2}$ as pivot. Similarly, the reduced cost should become $0$.

	\begin{minipage}{.49\textwidth}
		\begin{table}[H]
			\centering
			\begin{tabular}{c|cccc|c|}
				\toprule
				\ & $0$ & $4$ & $-1$ & $0$ & $-6$\\
				\midrule
				$x_1$ & $1$ & $-\frac{3}{2}$ & $\frac{1}{2}$ & $0$ & $3$\\
				$x_4$ & $0$ & $\bm{\frac{5}{2}}$ & $-\frac{1}{2}$ & $1$ & $1$\\
				\bottomrule
				\ & $x_1$ & $x_2$ & $x_3$ & $x_4$ & \
			\end{tabular}
		\end{table}
	\end{minipage}
	\begin{minipage}{.49\textwidth}
		\begin{figure}[H]
			\centering
			\begin{tikzpicture}[scale=.6]
				\draw[->] (0, 0) -- (5, 0);
				\draw[->] (0, 0) -- (0, 5);
				\draw[-] (2.25, -.5) -- (4, 2/3);
				\draw[-] (-.5, 4.5) -- (4, 0);
				\node[draw,circle,red,inner sep=2pt] at (3, 0) {};
			\end{tikzpicture}
		\end{figure}
	\end{minipage}

	Note that by doing these Gaussian transformations we obtain $-6$ for $\bar{z}$, i.e. the wrong sign but we can live with this technical defect.
	The current solution now is $(3, 0, 0, 1)$ which can be improved by increasing $x_2$ since $\bar{c}_2 = 4 > 0$. Note that the second constraint is not binding yet, as its slack ist positive. However, the first constraint is binding (we designed it that way by decreasing its slack to $0$). Now we use $\bm{\frac{5}{2}}$ as pivot as it is the only positive entry in the $x_2$-column.
	
	\begin{minipage}{.49\textwidth}
		\begin{table}[H]
			\centering
			\begin{tabular}{c|cccc|c|}
				\toprule
				\ & $0$ & $0$ & $-\frac{1}{5}$ & $-\frac{8}{5}$ & $-7.4$\\
				\midrule
				$x_1$ & $1$ & $0$ & $\frac{1}{5}$ & $\frac{3}{5}$ & $\frac{18}{5}$\\
				$x_2$ & $0$ & $1$ & $-\frac{1}{5}$ & $\frac{2}{5}$ & $\frac{2}{5}$\\
				\bottomrule
				\ & $x_1$ & $x_2$ & $x_3$ & $x_4$ & \
			\end{tabular}
		\end{table}
	\end{minipage}
	\begin{minipage}{.49\textwidth}
		\begin{figure}[H]
			\centering
			\begin{tikzpicture}[scale=.6]
				\draw[->] (0, 0) -- (5, 0);
				\draw[->] (0, 0) -- (0, 5);
				\draw[-] (2.25, -.5) -- (4, 2/3);
				\draw[-] (-.5, 4.5) -- (4, 0);
				\node[draw,circle,red,inner sep=2pt] at (3.6, .4) {};
			\end{tikzpicture}
		\end{figure}
	\end{minipage}

	Note since $a_{12} = -\frac{3}{2} < 0$ in the previous tableau, by increasing $x_2$, we actually were able to increase $x_1$ further to $\frac{18}{5} = 3.6$ (observe the first constraint). 
	The reduced cost of any variable are now non-positive; hence, there is no suitable variable to increase and the current solution $(\frac{18}{5}, \frac{2}{5}, 0, 0)$ is optimal.
\end{example*}
608
\end{document}