Skip to Content
Advanced Algorithm

4. Linear Programs

2019-09-04Original-language archivelegacy assets may be incomplete

Definition

  • Linear Programming Problem: the problem of either minimizing or maximizing a linear function subject to a finite set of linear constraints
    • feasible solution, feasible area, objective function, objective value, optimal solution, optimal objective value
  • unbounded: have a infinite objective value
  • infeasible: no feasible value
  • Equivalent: for each feasible solution x\overline{x} to LL with objective value zz, there is a corresponding feasible solution x\overline{x}' to LL' with objective value zz', and for each feasible solution x\overline{x}' to LL' with objective value zz', there is a corresponding feasible solution x\overline{x} to LL with objective value ́.

Standard Form

  • Maximize j=1ncjxj\sum_{j=1}^nc_jx_j
  • subject to j=1naijxjbi,xj0\sum_{j=1}^na_{ij}x_j\leq b_i, x_{j}\geq 0
  • Converting to Stand Form
    • Turn Minimize to Maximize
    • x=x1x2,x1>0,x2>0x=x_1-x_2,x_1>0,x_2>0
    • Turn equation to inequation
    • Turn \geq to \leq
  • (A,b,c)(A,b,c)
    • Maximize cTxc^Tx
    • subject to Axb,x0Ax\leq b,x\geq 0

Slack Form

  • Maximize j=1ncjxj\sum_{j=1}^nc_jx_j
  • subject to
    • xn+i=j=1ntjxj0x_{n+i}=\sum_{j=1}^nt_jx_j\geq0
    • xi0x_i\geq 0
  • basic variable: Left side of equation
  • nonbasic variable: Right side of equation
  • (N,B,A,b,c,v)(N,B,A,b,c,v)
    • Maximize cTx+vc^Tx+v
    • subject to
      • xi=bijNaijxj,iBx_i=b_i-\sum_{j\in N}a_{ij}x_j,i\in B
      • xi0,iNx_i\geq 0,i\in N

Simplex Algorithm

  • pivot: choose a nonbasic varible(entering variable) and a basic variable(leaving variable) and exchange their roles.
    • (N,B,A,b,c,v)(N^,B^,A^,b^,c^,v^)(N,B,A,b,c,v)\rightarrow (\hat{N},\hat{B},\hat{A},\hat{b},\hat{c},\hat{v})
  • at most (n+mm)\binom{n+m}{m} iterations, otherwise cycles
  • Bland's rule: choose smallest index then must terminate
//n: number of variable
//m: number of restriction
 
void pivot(int l, int e) {
    // Update leaving basic variable
    b[l] /= a[l][e];
    for (int j = 1; j <= n; j++)
        if (j != e) a[l][j] /= a[l][e];
    a[l][e] = 1 / a[l][e];
    // Update other basic variable
    for (int i = 1; i <= m; i++)
        if (i != l && fabs(a[i][e]) > 0) {
            b[i] -= a[i][e] * b[l];
            for (int j = 1; j <= n; j++)
                if (j != e) a[i][j] -= a[i][e] * a[l][j];
            a[i][e] = -a[i][e] * a[l][e];
        }
    // Update entering nonbasic variable
    ans += c[e] * b[l];
    for (int j = 1; j <= n; j++)
        if (j != e) c[j] -= c[e] * a[l][j];
    c[e] = -c[e] * a[l][e];
}
 
double simplex() {
    while (true) {
        int enter = 0, leave = 0;
        // Select enter variable
        for (enter = 1; enter <= n; ++enter)
            if (c[enter] > eps) break;
        if (enter == n + 1) return ans;
        // Select leave variable
        double mn = INF;
        for (int i = 1; i <= m; ++i)
            if (a[i][enter] > eps && mn > b[i] / a[i][enter]) {
                mn = b[i] / a[i][enter];
                leave = i;
            }
        if (mn == INF) return INF;
        pivot(leave, enter);
    }
}

Formulating Problems

  • Shortest Path
    • Maximize dtd_t
    • subject to dvdu+w(u,v),ds=0d_v\leq d_u+w(u,v),d_s=0
  • Maximum Flow
    • Maximize vVfsvvVfvs\sum_{v\in V}f_{sv}-\sum_{v\in V}f_{vs}
    • subject to fuvc(u,v),vVfvu=vVfuv,fuv0f_{uv}\leq c(u,v),\sum_{v\in V}f_{vu}=\sum_{v\in V}f_{uv},f_{uv}\geq 0
  • Minimum-cost Flow
    • Minimize (u,v)Ea(u,v)fuv\sum_{(u,v)\in E}a(u,v)f_{uv}
    • subject to fuvc(u,v),vVfvuvVfuv=0,fuv0,vVfsvvVfvs=df_{uv}\leq c(u,v), \sum_{v\in V}f_{vu}-\sum_{v\in V}f_{uv}=0,f_{uv}\geq 0,\sum_{v \in V}f_{sv}-\sum_{v\in V}f_{vs}=d
  • Multicommodity Flow
    • Minimize 00
    • subject to i=1kfiuvc(u,v),vVfiuvvVfivu=0,vVfisivvVfivsi=di,fiuv0\sum_{i=1}{k}f_{iuv}\leq c(u,v),\sum_{v\in V}f_{iuv}-\sum_{v\in V}f_{ivu} = 0,\sum_{v\in V}f_{is_iv}-\sum_{v\in V}f_{ivs_i}=d_i,f_{iuv}\geq 0
  • vertex cover

minvVxvs.t.vexv1,eExv{0,1},vV\min \sum_{v\in V}x_v\newline s.t. \sum_{v\in e}x_v\geq 1,e\in E\newline x_v\in \{0,1\},v\in V

  • System of difference contraints
    • subject to: xixjckx_i-x_j\leq c_k (mm pairs)

Duality

  • Prime

mincTxs.t. Axbx0\min c^Tx\newline s.t.\ Ax\geq b\newline x\geq 0

  • Dual

maxbTys.t. yTAcTy0\max b^Ty\newline s.t.\ y^TA\leq c^T\newline y\geq 0

prime dual
maxc1x1++cnxn\max c_1x_1+\cdots+c_nx_n minb1y1++bmym\min b_1y_1+\cdots+b_my_m
aTxba^Tx\geq b yi0y_i\leq 0
aTx=ba^Tx=b -
aTxba^Tx\leq b yi0y_i\geq 0
- yi=0y_i=0
xi0x_i\geq 0 aTyca^Ty\geq c
xi0x_i\leq 0 aTyca^Ty\leq c
- aTy=ca^Ty=c
xi=0x_i=0 -
  • Weak Duality Theorem: \forall feasible primal solution xx and dual solution yy

yTbyTAxcTxy^Tb\leq y^TAx\leq c^Tx

  • Strong Duality Theorem: Primal LP has finite optimal solution xx^* iff dual LP has finite optimal solution yTb=cTxy^{*T}b=c^Tx^*
  • Complementary Slackness Condition: \forall feasible primal solution xx and dual solution yy, both xx and yy are optimal iff

i:Aix=biyi=0j:yTAj=cjxj=0\forall i:A_{i\cdot}x=b_i\vee y_i=0\newline \forall j:y^TA_{\cdot j}=c_j\vee x_j=0

  • Relaxed Complementary Slackness: \forall feasible primal solution xx and dual solution yy, for α,β1\alpha,\beta\geq 1

i:Aixαbiyi=0j:yTAj=cjβxj=0cTxαβbTyαβOPTIP\forall i:A_{i\cdot}x\leq \alpha b_i\vee y_i=0\newline \forall j:y^TA_{\cdot j}=\frac{c_j}{\beta}\vee x_j=0\newline \Rightarrow c^Tx\leq\alpha\beta b^Ty\leq\alpha\beta\text{OPT}_{\text{IP}}

  • Fundamental theorem of linear programming: Any linear program L, given in standard form, either:
    • has an optimal solution with a finite objective value
    • infeasible
    • unbounded

Primal-Dual Schema

  • The Primal-Dual Schema
    • Write down an LP-relaxation and its dual
    • Start with a primal infeasible solution xx and a dual feasible solution yy (usually x=0,y=0x=0,y=0)
    • Raise xx and yy until xx is feasible:
      • raise yy until some dual constrints gets tight yTAj=cjy^TA_{\cdot j}=c_j
      • raise xix_i (integrally) corresponding to the tight dual constraints
    • Show the complementary slackness conditions
      • i,Aixαbi\forall i, A_{i\cdot}x\leq\alpha b_i or yi=0y_i=0
      • j,yTAj=cj\forall j,y^TA_{\cdot j}=c_j or xj=0x_j=0
      • cTxαbTyαOPTc^Tx\leq\alpha b^Ty\leq\alpha\text{OPT}
  • Integrality Gap: supIOPT(I)OPTLP(I)\sup_I\frac{\text{OPT}(I)}{\text{OPT}_{\text{LP}}(I)}

Vertex Cover

  • Primal

minvVxvs.t. vexv1,eExv{0,1},vV\min \sum_{v\in V}x_v\newline s.t.\ \sum_{v\in e}x_v\geq 1,\forall e\in E\newline x_v\in\{0,1\},\forall v\in V

  • Dual

maxeEyes.t. evye1,vVye0,eE\max \sum_{e\in E}y_e\newline s.t.\ \sum_{e\owns v}y_e\leq 1,\forall v\in V\newline y_e\geq 0,\forall e\in E

  • Initially x=0,y=0x=0,y=0
  • Raise xx and yy until xx is feasible
    • pick an eEe\in E and raise yey_e to 1, set xv=1x_v=1 for vev\in e and delete all eve\owns v from EE
    • Find a maximal matching and return the set of matched vertices
  • Integrality Gap: 22

Facility Location

  • Facility location NPH\in\text{NPH}
    • Instance
      • FF: Facilities
      • CC: clients
      • f:F[0,)f: F\rightarrow[0,\infty): Facility opening costs
      • c:F×C[0,)c: F\times C\rightarrow [0,\infty): Facility connecting cost
    • total cost: jCcϕ(j),j+iIfi\sum_{j\in C}c_{\phi(j),j}+\sum_{i\in I}f_i
    • Find IFI\subset F and ϕ:CI\phi:C\rightarrow I minimize total cost
  • Metric Facility Location: cϕ(j),j=dϕ(j)jc_{\phi(j),j}=d_{\phi(j)j}
    • triangle inequality: di1j1+di2j1+di2j2di1j2d_{i_1j_1}+d_{i_2j_1}+d_{i_2j_2}\geq d_{i_1j_2}
  • Primal

miniF,jCdijxij+iFfiyis.t. yixij0,iF,jCiFxij1,jCxij,yi{0,1},iF,jC\min \sum_{i\in F,j\in C}d_{ij}x_{ij}+\sum_{i\in F}f_iy_i\newline s.t.\ y_i-x_{ij}\geq0,\forall i\in F,j\in C\newline \sum_{i\in F}x_{ij}\geq 1,\forall j\in C\newline x_{ij},y_i\in\{0,1\},\forall i\in F,j\in C

  • Dual

maxjCαjs.t. αjβijdij,iF,jCjCβijfi,iFαj,βij0,iF,jC\max\sum_{j\in C}\alpha_j\newline s.t.\ \alpha_j-\beta_{ij}\leq d_{ij},\forall i\in F,j\in C\newline \sum_{j\in C}\beta_{ij}\leq f_i,\forall i\in F\newline \alpha_j,\beta_{ij}\geq 0,\forall i\in F,j\in C

  • Initially α=0,β=0\alpha=0,\beta=0
  • raise αj\alpha_j for all client jj simultaneously at a uniform continous rate
    • upon αj=dij\alpha_j=d_{ij} for a closed facility ii: edge (i,j)(i,j) is paid, fix βij=αjdij\beta_{ij}=\alpha_j-d_{ij}
    • upon jCβij=fi\sum_{j\in C}\beta_{ij}=f_i: tentatively open facility ii; all unconnected clients jj with paid edge (i,j)(i,j) to facility ii are declared connected to facility ii and stop raising αj\alpha_j
    • upon αj=dij\alpha_j=d_{ij} for an unconnected client jj and tentatively open facility ii: client jj is declared connected to facility ii and stop raising α\alpha
  • Integrality Gap: 33

LP Relaxation & Rounding

  • Represent problem as Integer Linear Program(ILP)
  • Relaxation: relax ILP to LP
  • Find the optimal fractional solution xx^* of LP
    • ellipsoid
    • interior-point
  • Rounding: round the solution to a feasible integral solution x^\hat x
  • Integrality Gap = supIOPT(I)OPTLP(I)\sup_I\frac{\text{OPT}(I)}{\text{OPT}_{\text{LP}}(I)}

Vertex Cover

Rounding

x^v={1xv0.50o.w.\hat x_v=\begin{cases}1&x_v^*\geq 0.5\newline 0&o.w.\end{cases}

Integrality Gap: 22

MAX-SAT

Random solution

P(Cj is satisfied)(12k)yjP(C_j\text{ is satisfied})\geq(1-2^{-k})y_j^*

12\frac{1}{2}-approximation

LP relaxation and randomized roudning

maxj=1myjs.t.iSj+xi+iSj(1xi)yjxi{0,1},yj{0,1}\max \sum_{j=1}^my_j\newline s.t. \sum_{i\in S_j^+}x_i+\sum_{i\in S_j^-}(1-x_i)\geq y_j\newline x_i\in\{0,1\},y_j\in\{0,1\}

Random Rounding

x^i={1w.p. xi0w.p. 1xi\hat x_i=\begin{cases}1& w.p.\ x_i^*\newline 0& w.p.\ 1-x_i^*\end{cases}

Analysis

P(Cj is satisfied)(1(11k)k)yj(11e)yjE[# of satisfied clauses](11e)OPTP(C_j\text{ is satisfied})\geq(1-(1-\frac{1}{k})^k)y_j^*\geq(1-\frac{1}{e})y_j^*\newline E[\text{\# of satisfied clauses}]\geq(1-\frac{1}{e})\text{OPT}

(11e)(1-\frac{1}{e})-approximation

Combination

average

Sample random solution, satisfy m1m_1 clauses
Randomized rounding LP-relaxation, satisfy m2m_2 clauses

E[max(m1,m2)]E[m1+m22]34OPTE[\max(m_1,m_2)]\geq E[\frac{m_1+m_2}{2}]\geq\frac{3}{4}\text{OPT}

Integrality gap: 34\frac{3}{4}
MAX-3SAT has a 78\frac{7}{8}-approximation algorithm by semidefinite programming and cannot have >78>\frac{7}{8}-approx unless NP=P