288. Simplex Method

288.0.0.1. Linear Algebra Review
𝑥+𝑦=52𝑥𝑦=4

Row View

Solution: Intersection of 𝑛 lines or (hyper)planes

Column View

Solution: Combination of LHS column vectors to form the RHS vector

𝑥[12]+𝑦[11]=[54]

A linear system is singular if there is no unique solution

288.0.0.2. Gaussian Elimination

Given a system 𝐴𝑥=𝑏, or augmented matrix [𝐴𝑏], use the following 3 rules:

To solve the system:

  1. Transform the augmented matrix into row echelon form (REF) using these operations:

    • The first nonzero entry (pivot) in each row is to the right of the pivot in the row above
    • All entries below a pivot are zero
    • Rows of all zeros (if any) are at the bottom
  2. Back-substitute starting from the last nonzero row to find the solution
Example

Non-singular Case

System of equations

2𝑦=41𝑥+1𝑦=3

Augmented matrix

[024113]

Swapping (𝑅1𝑅2)

[113024]

Scaling (12𝑅2𝑅2)

Row Echelon Form (REF)

[113012]

Replacement (𝑅1𝑅2𝑅1)

Reduced Row Echelon Form (RREF)

[101012]

Result

𝑥=1,𝑦=2
Example

Singular Case

System of equations

𝑥+𝑦=22𝑥+2𝑦=4

Augmented matrix

[112224]

Replacement (𝑅22𝑅1𝑅2)

[112000]

Infinitely many solutions E.g.

  • 𝑥=0,𝑦=2
  • 𝑥=1,𝑦=1
  • 𝑥=2,𝑦=0
  • etc.

Rows are linearly dependent

The coefficient matrix

𝐴=[1122]

𝐴 has determinant 0, so it’s not invertible

288.0.0.3. Inverse
𝐴1𝐴=𝐼𝐴𝐴1𝐴=𝐼

𝐴1 is unique

Finding 𝐴1: Gauss-Jordan Elimination

A square matrix is nonsingular iff it is invertible

[𝐴𝐼][𝐼𝐴1]
Example
𝐴=[1221][𝐴𝐼]=[12102101]

Replacement (𝑅22𝑅1𝑅2)

[12100321]

Scale (13𝑅2𝑅2)

[1210012313]

Replacement (𝑅12𝑅2𝑅1)

[101323012313]

Result

𝐴1=[13232313]
288.0.0.4. Linear Dependence and Independence

A set of 𝑚 𝑛-dimensional vectors 𝑥1,𝑥2,,𝑥𝑚 are linearly dependent if there exists a non-zero vector 𝑤𝑚 such that:

𝑤1𝑥1+𝑤2𝑥2++𝑤𝑚𝑥𝑚=0

That is, at least one of the vectors can be written as a linear combination of the others.

Example

Dependent

Let:

𝑥1=[12],𝑥2=[24]

Augmented:

[120240]

Elimination (𝑅22𝑅1𝑅2)

[120000]

Independent

Let:

𝑥1=[12],𝑥2=[31]

Augmented:

[130210]

Elimination (𝑅22𝑅1𝑅2)

[120050]

Back-substitute

  • 5𝑤2=0𝑤2=0
  • 𝑤1+3𝑤2=0𝑤1=0

Only solution is 𝑤1=𝑤2=0

In Gaussian elimination, a row of all zeros

  1. Homogeneous System (RHS = 0)
[120000]𝑥1+2𝑥2=00=0
  1. Inconsistent System (Nonzero RHS)
[123005]𝑥1+2𝑥2=30=5
288.0.0.5. Extreme Points

Given that 𝑥, 𝑥1, and 𝑥2 are points in the set 𝑆:

Formal Definition

For a set 𝑆𝑛, a point 𝑥 is an extreme point if there does not exist a three-tuple (𝑥1,𝑥2,𝜆) such that 𝑥1𝑆, 𝑥2𝑆, 𝜆(0,1), and

𝑥=𝜆𝑥1+(1𝜆)𝑥2

A point 𝑥 in set 𝑆𝑛 is extreme if it cannot be written as a strict convex combination of two different points 𝑥1,𝑥2𝑆.

Convex Combination

Let 𝑥1,𝑥2,,𝑥𝑘𝑛. A convex combination of these vectors is any point of the form:

𝑥=𝜆1𝑥1+𝜆2𝑥2++𝜆𝑘𝑥𝑘

where:

𝑥 lies strictly between 𝑥1 and 𝑥2 on the line segment connecting them, not equal to either one

288.0.0.6. Slack and Suplus

1. Slack

Unused capacity

Example

Given a constraint:

𝑥1+𝑥25

The total must not exceed 5. To convert this into an equation, we add a slack variable 𝑠0:

𝑥1+𝑥2+𝑠=5
  • If 𝑥1+𝑥2=3, then 𝑠=2
  • If 𝑥1+𝑥2=5, then 𝑠=0

2. Excess (surplus)

Excess above the required amount

Example

Given a constraint:

𝑥1+𝑥25

The total must be at least 5. To convert this into an equation, we subtract a excess variable 𝑠5:

𝑥1+𝑥2𝑒=5
  • If 𝑥1+𝑥2=7, then 𝑒=2
  • If 𝑥1+𝑥2=5, then 𝑒=0
Objective Function
Maxmax𝑧=𝑐𝑇𝑥
Min Max𝑧min𝑧=𝑐𝑇𝒙max𝑧=𝑐𝑇𝒙
Constraint Forms
Slack𝑎1𝑥1+𝑎2𝑥2𝑏𝑎1𝑥1+𝑎2𝑥2+𝑠=𝑏
Excess + Artificial𝑎1𝑥1+𝑎2𝑥2𝑏𝑎1𝑥1+𝑎2𝑥2𝑒+𝑎=𝑏
=Artificial𝑎1𝑥1+𝑎2𝑥2=𝑏𝑎1𝑥1+𝑎2𝑥2+𝑎=𝑏
Negative 𝑏Multiply by −1𝑎1𝑥1+𝑎2𝑥2𝑏𝑎1𝑥1𝑎2𝑥2𝑏
Variable Bounds
Non-negativity𝑥𝑖,𝑠𝑖,𝑎𝑖0𝑖
Lower Bound ≠ 0Substitution𝑥15𝑦1=𝑥15𝑥1=𝑦1+5𝑦10
Unrestricted VariablesReplace with difference𝑥𝑗unrestricted𝑥𝑗=𝑥𝑗𝑥𝑗𝑥𝑗,𝑥𝑗0
Variable Roles
Basic VariablesUsually non-zeroPart of the current solution (solved from the constraints)
Non-Basic VariablesAlways zeroTemporarily set to 0 so basic variables can be solved
Simplex

Selection:

  • Entering variable
  • Pivot column selection

For maximization problems:

  • Select the column with the most negative value in the objective row
  • This corresponds to the variable that will increase the objective function the most

For minimization problems:

  • Select the column with the most positive value in the objective row
  • This corresponds to the variable that will decrease the objective function the most

Selection:

  • Leaving variable
  • Pivot row
  1. Calculate ratios for each row (except the objective row)
  • For each row: 𝑏𝑖/𝑝𝑖
  • Only consider rows where the pivot column element 𝑝𝑖>0
  • Ignore rows where the pivot column element 𝑝𝑖0
  1. Select the minimum ratio:
  • The row with the smallest non-negative ratio becomes the pivot row
  • The basic variable in this row is the leaving variable (exits the basis)

,

Example
max𝑧=3𝑥1+2𝑥2𝑠.𝑡.𝑥1+𝑥24𝑥12𝑥23𝑥1,𝑥20

Step 1: Convert to Standard Form

max𝑧=3𝑥1+2𝑥2𝑠.𝑡.𝑥1+𝑥2+𝑠1=4𝑥1+𝑠2=2𝑥2+𝑠3=3𝑥1,𝑥2,𝑠1,𝑠2,𝑠30

Objective

𝑧3𝑥12𝑥2=0

Step 2: Initial Tableau

Basis𝑥1𝑥2𝑠1𝑠2𝑠3𝑏
𝑠1111004
𝑠2100102
𝑠3010013
𝑧−3−20000
  • Basic Variables: 𝑠1=4, 𝑠2=2, 𝑠3=3
  • Non-basic variables: 𝑥1=0, 𝑥2=0

    • 𝑉0=(0,0)
    • Objective: 𝑧=3𝑥1+2𝑥2=3(0)+2(0)=0

Step 3: Choose entering variable

  • Look at the bottom row (𝑧):

    • Coefficients of 𝑥1=3, 𝑥2=2
  • Most negative: 𝑥1 Enter the basis
Basis𝑥1𝑥2𝑠1𝑠2𝑠3𝑏
𝑠1111004
𝑠2100102
𝑠3010013
𝑧−3−20000

Step 4: Determine leaving variable

Look at ratios of 𝑏/𝑥1:

Basis𝑥1𝑥2𝑠1𝑠2𝑠3𝑏𝑏/𝑥1
𝑠11110044/1=4
𝑠21001022/1=2
𝑠30100133/0=
𝑧−3−20000
  • Minimum Ratio

    • 𝑠2 leaves, 𝑥1 enters
Basis𝑥1𝑥2𝑠1𝑠2𝑠3𝑏
𝑠1111004
𝑥1100102
𝑠3010013
𝑧−3−20300

Step 5: Pivot on row 2, column 𝑥1

Now eliminate 𝑥1 from other rows:

Basis𝑥1𝑥2𝑠1𝑠2𝑠3𝑏
𝑠1111004
𝑥1100102
𝑠3010013
𝑧−3−20300

𝑅𝑠1𝑅𝑠1𝑅𝑥1

Basis𝑥1𝑥2𝑠1𝑠2𝑠3𝑏
𝑠1111004
𝑥1100102
𝑠3010013
𝑧−3−20300
𝑅𝑠1𝑅𝑠1𝑅𝑥1𝑥1:11=0𝑥2:10=1𝑠1:10=1𝑠2:01=1𝑠3:00=0𝑏:42=2

Update 𝑅𝑠1

Basis𝑥1𝑥2𝑠1𝑠2𝑠3𝑏
𝑠1011−102
𝑥1100102
𝑠3010013
𝑧−3−20300

𝑅𝑧𝑅𝑧3𝑅𝑥1

Basis𝑥1𝑥2𝑠1𝑠2𝑠3𝑏
𝑠1011−102
𝑥1100102
𝑠3010013
𝑧−3−20300
𝑅𝑧𝑅𝑧3𝑅𝑥1𝑥1:3+3(1)=0𝑥2:2+3(0)=2𝑠1:0+3(0)=0𝑠2:0+3(1)=3𝑠3:0+3(0)=0𝑏:0+3(2)=6

Update 𝑅𝑧

Basis𝑥1𝑥2𝑠1𝑠2𝑠3𝑏
𝑠1011−102
𝑥1100102
𝑠3010013
𝑧0−20306
  • Basic Variables: 𝑥1=2, 𝑠1=2, 𝑠3=3
  • Non-basic variables: 𝑥2=0

    • 𝑉1=(2,0)
    • Objective: 𝑧=3𝑥1+2𝑥2=3(2)+2(0)=6
Basis𝑥1𝑥2𝑠1𝑠2𝑠3𝑏
𝑠1011−102
𝑥1100102
𝑠3010013
𝑧0−20306

Step 3: Choose entering variable

  • Look at the bottom row (𝑧):

    • Coefficients of 𝑥2=2
  • Most negative: 𝑥2 Enter the basis
Basis𝑥1𝑥2𝑠1𝑠2𝑠3𝑏
𝑠1011−102
𝑥1100102
𝑠3010013
𝑧0−20306

Step 4: Determine leaving variable

Look at ratios of 𝑏/𝑥2:

Basis𝑥1𝑥2𝑠1𝑠2𝑠3𝑏𝑏/𝑥2
𝑠1011−1022/1=2
𝑥11001022/0=
𝑠30100133/1=3
𝑧0−20306
  • 𝑠1 leaves, 𝑥2 enters
Basis𝑥1𝑥2𝑠1𝑠2𝑠3𝑏
𝑥2011−102
𝑥1100102
𝑠3010013
𝑧0−20306

Step 5: Pivot on row 1, column 𝑥2

Basis𝑥1𝑥2𝑠1𝑠2𝑠3𝑏
𝑥2011−102
𝑥1100102
𝑠3010013
𝑧0−20306

Now eliminate 𝑥2 from other rows:

Basis𝑥1𝑥2𝑠1𝑠2𝑠3𝑏
𝑥2011−102
𝑥1100102
𝑠3010013
𝑧0−20306

𝑅𝑠3𝑅𝑠3𝑅𝑥2

Basis𝑥1𝑥2𝑠1𝑠2𝑠3𝑏
𝑥2011−102
𝑥1100102
𝑠3010013
𝑧0−20306
𝑅𝑠3𝑅𝑠3𝑅𝑥2𝑥1:00=0𝑥2:11=0𝑠1:01=1𝑠2:0(1)=1𝑠3:10=1𝑏:32=1
Basis𝑥1𝑥2𝑠1𝑠2𝑠3𝑏
𝑥2011−102
𝑥1100102
𝑠300−1111
𝑧0−20306

𝑅𝑧=𝑅𝑧(2)𝑅𝑥2=𝑅𝑧+2𝑅𝑥2

Basis𝑥1𝑥2𝑠1𝑠2𝑠3𝑏
𝑥2011−102
𝑥1100102
𝑠300−1111
𝑧0−20306
𝑅𝑧=𝑅𝑧+2𝑅𝑥2𝑥1:0+2(0)=0𝑥2:2+2(1)=0𝑠1:0+2(1)=2𝑠2:3+2(1)=1𝑠3:0+2(0)=0𝑏:6+2(2)=10
Basis𝑥1𝑥2𝑠1𝑠2𝑠3𝑏
𝑥2011−102
𝑥1100102
𝑠300−1111
𝑧0021010
  • Basic Variables: 𝑥1=2, 𝑥2=2, 𝑠3=1
  • Non-basic variables: 𝑠1=0, 𝑠2=0

    • 𝑉2=(2,2)
    • Objective: 𝑧=3𝑥1+2𝑥2=3(2)+2(2)=10
Example

Problem

min𝑧=𝑥1+2𝑥2𝑠.𝑡.𝑥1+𝑥21(slack)2𝑥1𝑥22(surplus + artificial)𝑥1+3𝑥21(negative𝑏)𝑥1𝑥2=1(artificial)𝑥10𝑥2(unrestricted)

Standard Form

Step 1: Handle Unrestricted Variable 𝑥2

Since 𝑥2 is unrestricted:

𝑥2=𝑥2𝑥2𝑥2,𝑥20

Rewrite the objective:

𝑧=𝑥1+2(𝑥2𝑥2)=𝑥1+2𝑥22𝑥2

Step 2: Slack Constraint ()

𝑥1+𝑥21

Rewrite with 𝑥2𝑥2:

𝑥1+(𝑥2𝑥2)1

Add slack variable:

𝑥1+𝑥2𝑥2+𝑠1=1𝑠10

Step 3: Surplus + Artificial Constraint ()

2𝑥1𝑥22

Rewrite with 𝑥2𝑥2:

2𝑥1(𝑥2𝑥2)22𝑥1𝑥2+𝑥22

Convert to equality by subtracting a surplus variable and adding an artificial variable:

2𝑥1𝑥2+𝑥2𝑠2+𝑎1=2𝑠2,𝑎10

Step 4: Negative RHS Constraint

𝑥1+3𝑥21

Rewrite with 𝑥2𝑥2:

𝑥1+3(𝑥2𝑥2)1𝑥1+3𝑥23𝑥21

Multiply both sides by 1 to get a positive RHS and flip inequality:

𝑥13𝑥2+3𝑥21

Convert to equality by subtracting a surplus variable and adding an artificial variable:

𝑥13𝑥2+3𝑥2𝑠3+𝑎2=1𝑠3,𝑎20

Step 5: Artificial Equality Constraint (=)

𝑥1𝑥2=1

Rewrite with 𝑥2𝑥2:

𝑥1(𝑥2𝑥2)=1𝑥1𝑥2+𝑥2=1

Add an artificial variable:

𝑥1𝑥2+𝑥2+𝑎3=1𝑎30

Final Standard Form

min𝑧=𝑥1+2𝑥22𝑥2𝑠.𝑡.𝑥1+𝑥2𝑥2+𝑠1=12𝑥1𝑥2+𝑥2𝑠2+𝑎1=2𝑥13𝑥2+3𝑥2𝑠3+𝑎2=1𝑥1𝑥2+𝑥2+𝑎3=1𝑥1,𝑥2,𝑥2,𝑠1,𝑠2,𝑠3,𝑎1,𝑎2,𝑎30

Phase I

Objective

min𝑤=𝑎1+𝑎2+𝑎3𝑠.𝑡.𝑥1+𝑥2𝑥2+𝑠1=1(slack)2𝑥1𝑥2+𝑥2𝑠2+𝑎1=2(surplus + artificial)𝑥13𝑥2+3𝑥2𝑠3+𝑎2=1(negative𝑏)𝑥1𝑥2+𝑥2+𝑎3=1(artificial)𝑥1,𝑥2,𝑥2,𝑠1,𝑠2,𝑠3,𝑎1,𝑎2,𝑎30(unrestricted)

Deriving Phase I Objective Row 𝑅𝑤

  1. Objective function before substitution
𝑤=𝑎1+𝑎2+𝑎3
  1. Express each artificial variable in terms of other variables from their constraints
  • 𝑅𝑎1
2𝑥1𝑥2+𝑥2𝑠2+𝑎1=2𝑎1=2𝑥1+𝑥2𝑥2+𝑠2+2
  • 𝑅𝑎2
𝑥13𝑥2+3𝑥2𝑠3+𝑎2=1𝑎2=𝑥1+3𝑥23𝑥2+𝑠3+1
  • 𝑅𝑎3
𝑥1𝑥2+𝑥2+𝑎3=1𝑎3=𝑥1+𝑥2𝑥2+1
  1. Substitute into 𝑤:
𝑤=𝑎1+𝑎2+𝑎3=(2𝑥1+𝑥2𝑥2+𝑠2+2)+(𝑥1+3𝑥23𝑥2+𝑠3+1)+(𝑥1+𝑥2𝑥2+1)=(2𝑥1𝑥1𝑥1)+(𝑥2+3𝑥2+𝑥2)+(𝑥23𝑥2𝑥2)+(𝑠2+𝑠3)+(2+1+1)=4𝑥1+5𝑥25𝑥2+𝑠2+𝑠3+4
  1. Rewrite as a constraint (bring all variables to the left):
𝑤+4𝑥15𝑥2+5𝑥2𝑠2𝑠3=4𝑤=4𝑥1+5𝑥25𝑥2+𝑠2+𝑠3+4

So in tableau row 𝑅𝑤:

Basis𝑥1𝑥2𝑥2𝑠1𝑠2𝑠3𝑎1𝑎2𝑎3𝑏
𝑠111−11000001
𝑎12−110−101002
𝑎21−3300−10101
𝑎31−110000011
𝑤4−550−1−10004

Perform First Pivot

1. Pivot Column

Look at the 𝑤 row (objective row) for the most negative coefficient:

Basis𝑥1𝑥2𝑥2𝑠1𝑠2𝑠3𝑎1𝑎2𝑎3𝑏
𝑠111−11000001
𝑎12−110−101002
𝑎21−3300−10101
𝑎31−110000011
𝑤4−550−1−10004

The most negative is 5 pivot column is 𝑥2

2. Ratio

  • Compute ratios (𝑏/𝑥2) for rows with positive pivot entries:
Basis𝑥1𝑥2𝑥2𝑠1𝑠2𝑠3𝑎1𝑎2𝑎3𝑏𝑏/𝑥2
𝑠111−110000011
𝑎12−110−101002
𝑎21−3300−10101
𝑎31−110000011
𝑤4−550−1−10004
  • Minimum ratio is 1, so we pivot on row 𝑠1:
Basis𝑥1𝑥2𝑥2𝑠1𝑠2𝑠3𝑎1𝑎2𝑎3𝑏𝑏/𝑥2
𝑠111−110000011
𝑎12−110−101002
𝑎21−3300−10101
𝑎31−110000011
𝑤4−550−1−10004

3. Pivot 𝑠1𝑥2

Basis𝑥1𝑥2𝑥2𝑠1𝑠2𝑠3𝑎1𝑎2𝑎3𝑏
𝑥211−11000001
𝑎12−110−101002
𝑎21−3300−10101
𝑎31−110000011
𝑤4−550−1−10004

4. Gauss-Jordan Elimination

Example

Step 3: Pivot 𝑎1𝑥1

Basis𝑥1𝑥2𝑥2𝑠1𝑠2𝑠3𝑎1𝑎2𝑎3𝑏
𝑠111−11000005
𝑥13−110−101004
𝑎21−2200−10106
𝑎31−110000012
𝑤−54−401100012

Gauss-Jordan Elimination

𝑅𝑥1=13𝑅𝑥1
Basis𝑥1𝑥2𝑥2𝑠1𝑠2𝑠3𝑎1𝑎2𝑎3𝑏
𝑠111−11000005
𝑥11−1/31/30−1/301/3004/3
𝑎21−2200−10106
𝑎31−110000012
𝑤−54−401100012
𝑅𝑎2=𝑅𝑎21𝑅𝑥1
Basis𝑥1𝑥2𝑥2𝑠1𝑠2𝑠3𝑎1𝑎2𝑎3𝑏
𝑠111−11000005
𝑥11−1/31/30−1/301/3004/3
𝑎20−5/35/301/3−1−1/31014/3
𝑎31−110000012
𝑤−54−401100012
𝑅𝑎3=𝑅𝑎31𝑅𝑥1
Basis𝑥1𝑥2𝑥2𝑠1𝑠2𝑠3𝑎1𝑎2𝑎3𝑏
𝑠111−11000005
𝑥11−1/31/30−1/301/3004/3
𝑎20−5/35/301/3−1−1/31014/3
𝑎30−2/32/301/30−1/3012/3
𝑤−54−401100012
𝑅𝑤=𝑅𝑤+5𝑅𝑥1
Basis𝑥1𝑥2𝑥2𝑠1𝑠2𝑠3𝑎1𝑎2𝑎3𝑏
𝑠111−11000005
𝑥11−1/31/30−1/301/3004/3
𝑎20−5/35/301/3−1−1/31014/3
𝑎30−2/32/301/300-1/3012/3
𝑤07/3−7/30−2/315/30056/3
𝑅𝑠1=𝑅𝑠11𝑅𝑥1
Basis𝑥1𝑥2𝑥2𝑠1𝑠2𝑠3𝑎1𝑎2𝑎3𝑏
𝑠104/3−4/311/30−1/30011/3
𝑥11−1/31/30−1/301/3004/3
𝑎20−5/35/301/3−1−1/31014/3
𝑎30−2/32/301/30−1/3012/3
𝑤07/3−7/30−2/315/30056/3

Step 3: Perform the Second Pivot

  1. Look at the 𝑤 row (objective row) for the most negative coefficient:
Basis𝑥1𝑥2𝑥2𝑠1𝑠2𝑠3𝑎1𝑎2𝑎3𝑏
𝑠104/3−4/311/30−1/30011/3
𝑥11−1/31/30−1/301/3004/3
𝑎20−5/35/301/3−1−1/31014/3
𝑎30−2/32/301/300-1/3012/3
𝑤07/3−7/30−2/315/30056/3
  • The most negative is 73 for 𝑥2

    • Pivot column is 𝑥2
  1. Ratio
  • Compute ratios (𝑏/𝑥2) for rows with positive pivot entries:
Basis𝑥1𝑥2𝑥2𝑠1𝑠2𝑠3𝑎1𝑎2𝑎3𝑏𝑏/𝑥2
𝑠104/3−4/311/30−1/30011/3
𝑥11−1/31/30−1/301/3004/343÷13=4
𝑎20−5/35/301/3−1−1/31014/3143÷53=2.8
𝑎30−2/32/301/300-1/3012/323÷23=1
𝑤07/3−7/30−2/315/30056/3
  • Minimum ratio is 1, so we pivot on row 𝑎3:
Basis𝑥1𝑥2𝑥2𝑠1𝑠2𝑠3𝑎1𝑎2𝑎3𝑏𝑏/𝑥2
𝑠104/3−4/311/30−1/30011/3
𝑥11−1/31/30−1/301/3004/343÷13=4
𝑎20−5/35/301/3−1−1/31014/3143÷53=2.8
𝑎30−2/32/301/300-1/3012/323÷23=1
𝑤07/3−7/30−2/315/30056/3

Step 4: Pivot 𝑎3𝑥2

Basis𝑥1𝑥2𝑥2𝑠1𝑠2𝑠3𝑎1𝑎2𝑎3𝑏
𝑠104/3−4/311/30−1/30011/3
𝑥11−1/31/30−1/301/3004/3
𝑎20−5/35/301/3−1−1/31014/3
𝑥20−2/32/301/30−1/3012/3
𝑤07/3−7/30−2/315/30056/3

Gauss-Jordan Elimination

𝑅𝑥2=𝑅𝑥2/(2/3)
Basis𝑥1𝑥2𝑥2𝑠1𝑠2𝑠3𝑎1𝑎2𝑎3𝑏
𝑠104/3−4/311/30−1/30011/3
𝑥11−1/31/30−1/301/3004/3
𝑎20−5/35/301/3−1−1/31014/3
𝑥20−1101/20−1/203/21
𝑤07/3−7/30−2/315/30056/3
𝑅𝑠1=𝑅𝑠1(43)𝑅𝑥2=𝑅𝑠1+43𝑅𝑥2
Basis𝑥1𝑥2𝑥2𝑠1𝑠2𝑠3𝑎1𝑎2𝑎3𝑏
𝑠1000110−1025
𝑥11−1/31/30−1/301/3004/3
𝑎20−5/35/301/3−1−1/31014/3
𝑥20−1101/20−1/203/21
𝑤07/3−7/30−2/315/30056/3
𝑅𝑥1=𝑅𝑥113𝑅𝑥2
Basis𝑥1𝑥2𝑥2𝑠1𝑠2𝑠3𝑎1𝑎2𝑎3𝑏
𝑠10000−1/201/20−1/21
𝑥11000−1/201/20−1/21
𝑎20−5/35/301/3−1−1/31014/3
𝑥20−1101/20−1/203/21
𝑤07/3−7/30−2/315/30056/3
𝑅𝑎2=𝑅𝑎253𝑅𝑥2
Basis𝑥1𝑥2𝑥2𝑠1𝑠2𝑠3𝑎1𝑎2𝑎3𝑏
𝑠10000−1/201/20−1/21
𝑥11000−1/201/20−1/21
𝑎20000−1/2−11/21−5/23
𝑥20−1101/20−1/203/21
𝑤07/3−7/30−2/315/30056/3
𝑅𝑤=𝑅𝑤(73)𝑅𝑥2=𝑅𝑤+73𝑅𝑥2
Basis𝑥1𝑥2𝑥2𝑠1𝑠2𝑠3𝑎1𝑎2𝑎3𝑏
𝑠10000−1/201/20−1/21
𝑥11000−1/201/20−1/21
𝑎20000−1/2−11/21−5/23
𝑥20−1101/20−1/203/21
𝑤00001/211/207/221

Step 5: Perform the Third Pivot

  1. Look at the 𝑤 row (objective row) for the most negative coefficient:
Basis𝑥1𝑥2𝑥2𝑠1𝑠2𝑠3𝑎1𝑎2𝑎3𝑏
𝑠10000−1/201/20−1/21
𝑥11000−1/201/20−1/21
𝑎20000−1/2−11/21−5/23
𝑥20−1101/20−1/203/21
𝑤0000−1/611/207/221
  • The most negative is 16 for 𝑠2

    • Pivot column is 𝑠2
  1. Ratio
  • Compute ratios (𝑏/𝑠2) for rows with positive pivot entries:
Basis𝑥1𝑥2𝑥2𝑠1𝑠2𝑠3𝑎1𝑎2𝑎3𝑏𝑏/𝑠2
𝑠10000−1/201/20−1/21
𝑥11000−1/201/20−1/21
𝑎20000−1/2−11/21−5/23
𝑥20−1101/20−1/203/212
𝑤0000−1/611/207/221

Two-Phase

max𝑧=2𝑥1+𝑥2𝑠.𝑡.𝑥1+𝑥22𝑥11𝑥1+𝑥25


max𝑧=2𝑥1+𝑥2+0𝑒1+0𝑒2+0𝑠1𝑠.𝑡.𝑥1+𝑥2𝑒12𝑥1𝑒21𝑥1+𝑥2+𝑠15𝑧2𝑥1𝑥2=0
Basis𝑥1𝑥2𝑒1𝑒2𝑠1𝑏
???111002
???100101
𝑠1110015
𝑧−2−10000
min𝑤=0𝑥1+0𝑥2+0𝑒1+0𝑒2+0𝑠1𝑠.𝑡.𝑥1+𝑥2𝑒12𝑥1𝑒21𝑥1+𝑥2+𝑠15

Degeneracy

Degeneracy occurs when a basic variable takes the value zero in a basic feasible solution. This leads to ties in the minimum ratio test, which determines the leaving variable during a pivot.

Example

Problem

max𝑧=𝑥1+2𝑥2𝑠.𝑡.𝑥1+𝑥23𝑥2212𝑥1+𝑥22.5𝑥1,𝑥20

Standard Form

𝑧𝑥12𝑥2=0𝑥1+𝑥2+𝑠1=3𝑥2𝑠2=212𝑥1+𝑥2+𝑠3𝑥1,𝑥2,𝑠1,𝑠2,𝑠3>=0

Initialize Tableau

Basis𝑥1𝑥2𝑠1𝑠2𝑠3𝑏
𝑠1111003
𝑠2010102
𝑠31/210012.5
𝑤−1−10000
𝑥1=0𝑥2=0

Minimum Test

Basis𝑥1𝑥2𝑠1𝑠2𝑠3𝑏
𝑠1111003
𝑠2010102
𝑠31/210012.5
𝑤−1−10000

Ratio Test

Basis𝑥1𝑥2𝑠1𝑠2𝑠3𝑏
𝑠1111003
𝑠2010102
𝑠31/210012.5
𝑤−1−10000

Pivot

Basis𝑥1𝑥2𝑠1𝑠2𝑠3𝑏
𝑠1111003
𝑥2010102
𝑠31/210012.5
𝑤−1−10000

Gaussian Elimination

Basis𝑥1𝑥2𝑠1𝑠2𝑠3𝑏
𝑠1101−101
𝑥2010102
𝑠31/200−110.5
𝑤−100204
𝑥1=0𝑥2=2

Minimum Test

Basis𝑥1𝑥2𝑠1𝑠2𝑠3𝑏
𝑠1101−101
𝑥2010102
𝑠31/200−110.5
𝑤−100204

Ratio Test

Basis𝑥1𝑥2𝑠1𝑠2𝑠3𝑏
𝑠1101−101
𝑥2010102
𝑠31/200−110.5
𝑤−100204
11=10.50.5=1}Tie

Pivot

Basis𝑥1𝑥2𝑠1𝑠2𝑠3𝑏
𝑥1101−101
𝑥2010102
𝑠31/200−110.5
𝑤−100204

Gaussian Elimination

Basis𝑥1𝑥2𝑠1𝑠2𝑠3𝑏
𝑥1101−101
𝑠2010002
𝑠300−1/2−1/210
𝑤001105

If after elimination a basic variable has a value of 0, it indicates degeneracy.

Degeneracy comes from redundant constraints

Bland’s Rule: Choose the variable with the lowest index in the basis

  • 𝑥1 over 𝑥2
  • 𝑥2 over 𝑠1

Unbounded Solution

When identifying the entering variable, look at its column in the tableau. If all entries in that column (above the objective row) are 0, the problem is unbounded

Can’t perform ratio test no constraint limits the entering variable objective function increases without bound

Example

Problem

max𝑥1+𝑥2𝑠.𝑡.𝑥1𝑥21𝑥1,𝑥20

Standard Form

max𝑧𝑥1𝑥2=0𝑠.𝑡.𝑥12𝑥2+𝑠1=1𝑥1,𝑥2,𝑠10

Initialize Tableau

Basis𝑥1𝑥2𝑠1𝑏
𝑠11−111
𝑧−1−100

Minimum and Ratio Test

Basis𝑥1𝑥2𝑠1𝑏
𝑠11−111
𝑧−1−100

Pivot

Basis𝑥1𝑥2𝑠1𝑏
𝑥11−111
𝑧−1−100

Gaussian Elimination

Basis𝑥1𝑥2𝑠1𝑏
𝑥11−111
𝑧0−211

Minimum and Ratio Test

Basis𝑥1𝑥2𝑠1𝑏
𝑥11−111
𝑧0−211

Check for Optimality

Objective row has −2 for 𝑥2 → not optimal

Entering variable: 𝑥2 (most negative coefficient)

Unboundedness Detection

Looking at the 𝑥2 column:

Entry in constraint row: −1 (which is ≤ 0)

All entries in 𝑥2 column are ≤ 0

Conclusion: Cannot perform ratio test Problem is unbounded

Alternative Solutions

Example

Problem

max2𝑥1+4𝑥2𝑠.𝑡.𝑥1+𝑥2312𝑥1+𝑥22.5𝑥1,𝑥20

Standard Form

𝑧2𝑥1𝑥2=0𝑥1+𝑥2+𝑠1=312𝑥1+𝑥2+𝑠2=2.5𝑥1,𝑥2,𝑥30

Initialize Tableau

Basis𝑥1𝑥2𝑠1𝑠2𝑏
𝑠111103
𝑠21/21012.5
𝑧−2−4000

Minimum Test

Basis𝑥1𝑥2𝑠1𝑠2𝑏
𝑠111103
𝑠21/21012.5
𝑧−2−4000

Ratio Test

Basis𝑥1𝑥2𝑠1𝑠2𝑏
𝑠111103
𝑠21/21012.5
𝑧−2−4000

Pivot

Basis𝑥1𝑥2𝑠1𝑠2𝑏
𝑠111103
𝑥21/21012.5
𝑧−2−4000

Gaussian Elimination

Basis𝑥1𝑥2𝑠1𝑠2𝑏
𝑠11/201−10.5
𝑥21/21012.5
𝑧000410

In a maximization or minimization linear programming problem, if there is a 0 in the 𝑧 row (objective function row) of the final (optimal) simplex tableau in a non-basic column (i.e. a variable not currently in the solution), then there are multiple optimal solutions.

288.0.0.7. Standard Form
Example
2𝑥1+3𝑥242𝑥13𝑥24


Nonpositive

2𝑥1+3𝑥24,𝑥102𝑥1+3𝑥24,𝑥10

Free (Unrestricted)

2𝑥1+3𝑥26,𝑥1urs2𝑥12𝑥1+3𝑥24,𝑥1,𝑥10
288.0.0.8. Simplex Method
Example
max7𝑥1+6𝑥2𝑠.𝑡.2𝑥1+4𝑥2163𝑥1+2𝑥212𝑥1,𝑥20max7𝑥1+6𝑥2+0𝑠1+0𝑠2𝑠.𝑡.2𝑥1+4𝑥2+𝑠1=163𝑥1+2𝑥2+𝑠2=12


𝑥1𝑥2𝑠1𝑠2
Basis𝑐𝐵7600𝑏
𝑠10241016
𝑠20320112
𝑧𝑗0×2+0×3=00000
𝑐𝑗𝑧𝑗7600
𝑥1=0,𝑥2=0,𝑠1=16,𝑠2=12
𝑥1𝑥2𝑠1𝑠2
Basis𝑐𝐵7600𝑏Ratio
𝑠1024101616/2 = 8
𝑠2032011212/3 = 4
𝑧𝑗00000
𝑐𝑗𝑧𝑗7600
  1. Formulation

Objective Function

𝑍=𝑐1𝑥1+𝑐2𝑥2++𝑐𝑛𝑥𝑛=𝑐𝑇𝑥

Constraints

𝑎11𝑥1+𝑎12𝑥2++𝑎1𝑛𝑥𝑛𝑏1𝑎21𝑥1+𝑎22𝑥2++𝑎2𝑛𝑥𝑛𝑏2𝑎𝑚1𝑥1+𝑎𝑚2𝑥2++𝑎𝑚𝑛𝑥𝑛=𝑏𝑚𝑥1,𝑥2,,𝑥𝑛0

Or,

𝐴𝑥,=,𝑏𝑥0
  1. Convert to Canonical Form

In slack variable form

𝑎11+𝑥1+𝑎12𝑥2++𝑎1𝑛𝑥𝑛+𝑠1=𝑏1𝑎21+𝑥1+𝑎22𝑥2++𝑎2𝑛𝑥𝑛+𝑠2=𝑏2𝑎𝑚1𝑥1+𝑎𝑚2𝑥2++𝑎𝑚𝑛𝑥𝑛+𝑠𝑚=𝑏𝑚𝑥1,𝑥2,,𝑥𝑛0𝑠1,𝑠2,,𝑠𝑚0

Or matrix notation,

max𝑧=𝑐𝑇𝑥𝑠.𝑡.𝐴𝑥+𝐼𝑠=𝑏𝑖𝑥0𝑠0
max𝑧=𝑐𝑇𝑥
=[𝑐1,𝑐2,,𝑐𝑛][𝑥1𝑥2𝑥𝑛]
𝐴𝑥+𝐼𝑠=𝑏
[𝑎11𝑎12𝑎1𝑛𝑎21𝑎22𝑎2𝑛𝑎𝑚1𝑎𝑚2𝑎𝑚𝑛][𝑥1𝑥2𝑥𝑛]+[100010001][𝑠1𝑠2𝑠𝑚]=[𝑏1𝑏2𝑏𝑚]
  1. Set up Simplex Tableau
𝑥1𝑥2𝑥𝑛𝑠1𝑠2𝑠𝑚RHS
Constraint 1𝑎11𝑎12𝑎1𝑛100𝑏1
Constraint 2𝑎21𝑎22𝑎2𝑛010𝑏2
Constraint 𝑛𝑎𝑚1𝑎𝑚2𝑎𝑚𝑛001𝑏𝑚
Objective Function𝑐1𝑐2𝑐𝑛0000
  1. Perform Pivot Operation

in the objective function row (this indicates which variable will enter the basis).

  1. Iterate

Repeat the pivot operations until there are no more negative coefficients in the objective function row, indicating that the current solution is optimal.

  1. Read the Solution

The final tableau will give the values of the variables at the optimal solution. The basic variables are the variables corresponding to the columns with the identity matrix in the final tableau, while non-basic variables are set to zero.

Example

Maximize:𝑍=3𝑥1+2𝑥2

s.t.

𝑥1+𝑥24

2𝑥1+𝑥25

𝑥1,𝑥20

1. Convert to Canonical Form

Introduce slack variables 𝑠1 and 𝑠2 to convert inequalities into equalities:

𝑥1+𝑥2+𝑠1=4

2𝑥1+𝑥2+𝑠2=5

𝑥1,𝑥2,𝑠1,𝑠20

Initialize Simplex Tableau

𝑥1𝑥2𝑠1𝑠2RHS
Constraint 111104
Constraint 221015
Objective Function−3−2000

2. Identify the Pivot Column

In the objective function row, the coefficients are [3,2,0,0]. The most negative coefficient is 3, which is in the 𝑥1 column. Therefore, 𝑥1 will enter the basis.

3. Identify the Pivot Row

Calculate the ratio of RHS to the pivot column’s coefficients (where the coefficients are positive):

  • For Row 1: 41=4 (pivot column coefficient is 1)

  • For Row 2: 52=2.5 (pivot column coefficient is 2)

The smallest ratio is 2.5, so Row 2 will be the pivot row. This means that 𝑠2 will leave the basis.

4. Pivot

Perform row operations to make the pivot element 1 and zero out other elements in the pivot column.

Pivot Element: The element at the intersection of Row 2 and 𝑥1 column is 2.

Steps:

  1. Make Pivot Element 1: Divide all elements in Row 2 by the pivot element (2):
New Row2=12×Old Row2=[1,0.5,0,0.5,2.5]
  1. Zero Out Pivot Column in Other Rows:
  • For Row 1: Subtract 1 times New Row 2 from Row 1:
New Row1=Old Row1[1,0.5,0,0.5,2.5]=[0,0.5,1,0.5,1.5]
  • For Objective Function: Add 3 times New Row 2 to the Objective Function row
New Objective Function=Old Objective Function+3×[1,0.5,0,0.5,2.5]=[0,0.5,0,1.5,7.5]

Updated Simplex Tableau

𝑥1𝑥2𝑠1𝑠2RHS
Constraint 100.51−0.51.5
Constraint 210.500.52.5
Objective Function0−0.501.57.5

288.0.1. Matrix Notation

max𝑐𝑇𝑥𝑠.𝑡.𝐴𝑥=𝑏𝑥0𝐴𝑚×𝑛𝑏𝑚×1𝑐𝑛×1𝑥𝑛×1max𝑐𝐵𝑇𝑥𝐵+𝑐𝑁𝑇𝑥𝑁𝑠.𝑡.𝐵𝑥𝐵+𝑁𝑥𝑁=𝑏𝑥𝐵,𝑥𝑁0𝑐𝑇=[𝑐𝐵𝑇,𝑐𝑁𝑇]𝐴=[𝐵,𝑁]

Where:

Example

Standard form:

max𝑥1𝑠.𝑡.2𝑥1𝑥2+𝑥3=42𝑥1+𝑥2+𝑥4=8𝑥2+𝑥3=3𝑥1,𝑥2,𝑥3,𝑥40𝑖=1,,5𝑐𝑇=[1,0,0,0,0]𝐴=[211002101001001]𝑏=[483]

Given 𝑥𝐵=(𝑥1,𝑥4,𝑥5) and 𝑥𝑁=(𝑥2,𝑥3):

𝑐𝐵𝑇=[1,0,0],𝑐𝑁𝑇=[0,0]𝐵=[200210001],𝑁=[111010]𝑏=[483]

Objective Function

1𝑥1+0𝑥2+0𝑥3+0𝑥4+0𝑥5=0𝑥𝐵𝑇𝑥𝑏+𝑥𝑁𝑇𝑥𝑁=0

Constraints

2𝑥11𝑥2+1𝑥3+0𝑥4+0𝑥5=42𝑥1+1𝑥2+0𝑥3+1𝑥4+0𝑥5=80𝑥1+1𝑥2+0𝑥3+0𝑥4+1𝑥5=3𝐴𝐵𝑥𝐵+𝐴𝑁𝑥𝑁=𝑏

Problem

max𝑐𝐵𝑇𝑥𝐵+𝑐𝑁𝑇𝑥𝑁𝑠.𝑡.𝐵𝑥𝐵+𝑁𝑥𝑁=𝑏𝑥𝐵,𝑥𝑁0

Rearange the the terms in the constrains:

max𝑐𝐵𝑇𝑥𝐵+𝑐𝑁𝑇𝑥𝑁𝑠.𝑡.𝑥𝐵=𝐵1(𝑏𝑁𝑥𝑁)𝑥𝐵,𝑥𝑁0

Replace 𝑥𝐵 in the objective function:

max𝑐𝐵𝑇[𝐵1(𝑏𝑁𝑥𝑁)]+𝑐𝑁𝑇𝑥𝑁𝑠.𝑡.𝑥𝐵=𝐵1(𝑏𝑁𝑥𝑁)𝑥𝐵,𝑥𝑁0

Rearrange the terms in the objectcive function:

max𝑐𝐵𝑇𝐵1𝑏(𝑐𝐵𝑇𝐵1𝑁𝑐𝑁𝑇)𝑥𝑁𝑠.𝑡.𝑥𝐵=𝐵1(𝑏𝑁𝑥𝑁)𝑥𝐵,𝑥𝑁0

The standard form LP becomes:

max𝑐𝐵𝑇𝐵1𝑏(𝑐𝐵𝑇𝐵1𝑁𝑐𝑁𝑇)𝑥𝑁𝑠.𝑡.𝑥𝐵=𝐵1(𝑏𝑁𝑥𝑁)𝑥𝐵,𝑥𝑁0

Rearrange the terms of the constrains:

max𝑐𝐵𝑇𝐵1𝑏(𝑐𝐵𝑇𝐵1𝑁𝑐𝑁𝑇)𝑥𝑁𝑠.𝑡.𝐼𝑥𝐵+𝐵1𝑁𝑥𝑁=𝐵1𝑏𝑥𝐵,𝑥𝑁0

Ignore the sign constraints and let 𝑧 be the objectctive value:

𝑧+(𝑐𝐵𝑇𝐵1𝑁𝑐𝑁𝑇)𝑥𝑁=𝑐𝐵𝑇𝐵1𝑏𝐼𝑥𝐵+𝐵1𝑁𝑥𝑁=𝐵1𝑏

The Simplex Tableau is:

0𝑐𝐵𝑇𝐵1𝑁𝑐𝑁𝑇𝑐𝐵𝑇𝐵1𝑏0
𝐼𝐵1𝑁𝑥𝑁𝐵1𝑏1,,𝑚
basicnon-basicRHS
Example

Step 1. Standard form

max𝑥1𝑠.𝑡.2𝑥1𝑥2+𝑥3=42𝑥1+𝑥2+𝑥4=8𝑥2+𝑥5=3


Matrix notation:

𝑐𝑇=[1,0,0,0,0],𝐴=[211002101001001],𝑏=[483]

Step 2. Initial Basis

𝐵=(𝑥1,𝑥4,𝑥5)𝑁=(𝑥2,𝑥3)𝐵=[200210001]𝑁=[111010]

Cost split:

𝑐𝐵𝑇=[1,0,0]𝑐𝑁𝑇=[0,0]

Compute inverse of 𝐵:

𝐵1=[1200110001]𝑥𝐵=𝐵1𝑏=[1200110001][483]=[243]

So the basic feasible solution (BFS) is:

𝑥=(𝑥1,𝑥2,𝑥3,𝑥4,𝑥5)=(2,0,0,4,3)𝑧=𝑐𝐵𝑇𝐵1𝑏=[1,0,0][243]=2

Step 3. Reduced costs and entering variable

𝑐̄𝑁𝑇=𝑐𝐵𝑇𝐵1𝑁𝑐𝑁𝑇=[100][1200110001][111010][00]=[1212]

Since 𝑐̄2=12<0, the entering variable is 𝑥2

Step 4. Direction, ratio test and leaving variable

For 𝑥𝐵=(𝑥1,𝑥4,𝑥5), we have:

𝑑=𝐵1𝑁2=[1200110001][111]=[1221]

Current basic solution:

𝑥𝐵=𝐴𝐵1𝑏=[243]

The minimum ratios test:

𝑥42=42=2𝑥51=31=3

Smallest ratio is 2𝑥4 leaves the basis

Step 5. Pivot to the new basis

𝐵=(𝑥1,𝑥2,𝑥5)𝑁=(𝑥3,𝑥4)𝐵=[211210010]𝑁=[100100]

Cost split:

𝑐𝐵𝑇=[1,0,0]𝑐𝑁𝑇=[0,0]

Compute inverse of 𝐵:

𝐵1=[12140121012121]𝑥𝐵=𝐵1𝑏=[12140121012121][483]=[321]=[𝑥1𝑥2𝑥5]

So the new basic feasible solution (BFS) is:

𝑥=(𝑥1,𝑥2,𝑥3,𝑥4,𝑥5)=(3,2,0,0,1)𝑧=𝑐𝐵𝑇𝑥𝐵=[1,0,0][321]=3

Step 6. Check optimality (reduced costs)

𝑐̄𝑁𝑇=𝑐𝐵𝑇𝐵1𝑁𝑐𝑁𝑇=[100][141401212012121][100100][00]=[1414]

No negative reduced costs optimal

𝑥=(3,2,0,0,1),𝑧=3
Example

Problem:

max2𝑥1+3𝑥2𝑠.𝑡.𝑥1+𝑥24𝑥1+2𝑥26


Standard form:

max2𝑥1+3𝑥2𝑠.𝑡.𝑥1+𝑥2+𝑠1=4𝑥1+2𝑥2+𝑠2=6


Let 𝑥𝐵=(𝑠1,𝑠2) and 𝑥𝑁=(𝑥1,𝑥2)

𝑐𝐵=[0,0]𝑐𝑁=[2,3]𝐴𝐵=[1001]𝐴𝑁=[1112]𝑏=[46]𝐴𝐵1=[1001]𝐴𝐵1𝐴𝑁=[1112]𝐴𝐵1𝑏=[46]𝑐𝐵𝑇𝐴𝐵1𝐴𝑁𝑐𝑁𝑇=[23]𝑐𝐵𝑇𝐴𝐵1𝑏=0
23000
11104
12016
basicnon-basicRHS

Let 𝑥𝐵=(𝑥1,𝑥2) and 𝑥𝑁=(𝑠1,𝑠2)

𝑐𝐵=[23]𝑐𝑁=[00]𝐴𝐵=[1112]𝐴𝑁=[1001]𝑏=[46]𝐴𝐵1=[2111]𝐴𝐵1𝐴𝑁=[2111]𝐴𝐵1𝑏=[22]𝑐𝐵𝑇𝐴𝐵1𝐴𝑁𝑐𝑁𝑇=[11]𝑐𝐵𝑇𝐴𝐵1𝑏=10
001110
10212
01112
basicnon-basicRHS
Example

Step 1. Canonical form

max𝑥1+3𝑥2𝑠.𝑡.𝑥1+𝑥23𝑥1+2𝑥283𝑥1+𝑥218


Step 2. Standard form

max𝑥1+3𝑥2𝑠.𝑡.𝑥1+𝑥2+𝑠1=3𝑥1+2𝑥2+𝑠2=83𝑥1+𝑥2+𝑠3=18


Matrix notation:

𝑐𝑇=[13000]𝐴=[111001201031001]𝑏=[3818]

Step 3. Initial Basis

𝐵=(𝑠1,𝑠2,𝑠3)𝑁=(𝑥2,𝑥2)𝐵=[100010001]𝑁=[111231]𝑐𝐵𝑇=[000]𝑐𝑁𝑇=[13]

Compute 𝐵1:

𝐵1=[100010001]

Compute basic feasible solution:

𝑥𝐵=𝐵1𝑏=[100010001][3818]=[3818]=[𝑠1𝑠2𝑠3]

Current basic feasible solution:

𝑥=(𝑥1,𝑥2,𝑠1,𝑠2,𝑠3)=(0,0,3,8,18)𝑧=𝑐𝐵𝑇𝐵1𝑏=𝑐𝐵𝑇𝑥𝐵=[000][3818]=0

Step 4. Reduced costs and entering variable

𝑐̄𝑁𝑇=𝑐𝐵𝑇𝐵1𝑁𝑐𝑁𝑇=[000][100010001][111231][13]=[13]

Since 𝑐̄1=1<0, the entering variable is 𝑥1

Step 5. Direction, ratio test and leaving variable

For 𝑥𝐵=(𝑠1,𝑠2,𝑠3), we have:

𝑑=𝐵1𝑁1=[100010001][113]=[113]

Current basic solution:

𝑥𝐵=𝐵1𝑏=[3818]

The minimum ratios test:

𝑠33=183=6

Smallest ratio is 3𝑠3 leaves the basis (only consider ratios where the corresponding 𝑑𝑖>0)

Step 6. Pivot to the new basis

𝐵=(𝑠1,𝑠2,𝑥1)𝑁=(𝑠3,𝑥2)𝐵=[101011003]𝑁=[010211]𝑐𝐵𝑇=[001]𝑐𝑁𝑇=[03]

Compute 𝐵1:

𝐵1=[100.33010.33000.33]

Compute basic feasible solution:

𝑥𝐵=𝐵1𝑏=[100.33010.33000.33][3818]=[8.9413.945.94]=[𝑠1𝑠2𝑥1]

Current basic feasible solution:

𝑥=(𝑥1,𝑥2,𝑠1,𝑠2,𝑠3)=(5.94,0,8.94,13.94,0)𝑧=𝑐𝐵𝑇𝑥𝐵=[001][8.9413.945.94]=5.94

Step 7. Reduced costs and entering variable

𝑐̄𝑁𝑇=𝑐𝐵𝑇𝐵1𝑁𝑐𝑁𝑇=[001][100.33010.33000.33][010211][03]=[0.332.67]

Since 𝑐̄2=−2.67<0, the entering variable is 𝑥2

Step 8. Direction, ratio test and leaving variable

For 𝑥𝐵=(𝑠1,𝑠2,𝑥1), we have:

𝑑=𝐵1𝑁2=[100.33010.33000.33][121]=[1.332.330.33]

Current basic solution:

𝑥𝐵=𝐵1𝑏=[8.9413.945.94]

The minimum ratios test:

𝑠11=8.941.33=6.75,𝑠22=13.942.33=6,𝑥11=5.940.33=18

Smallest ratio is 13.942𝑠2 leaves the basis (only consider ratios where the corresponding 𝑑𝑖>0)

Step 9. Pivot to the new basis

𝐵=(𝑠1,𝑥2,𝑥1)𝑁=(𝑠2,𝑠3)𝐵=[111021013]𝑁=[001101]𝑐𝐵𝑇=[031]𝑐𝑁𝑇=[00]

Compute 𝐵1:

𝐵1=[10.570.1400.430.1400.140.29]

Compute basic feasible solution:

𝑥𝐵=𝐵1𝑏=[10.570.1400.430.1400.140.29][3818]=[0.965.964.1]=[𝑠1𝑥2𝑥1]

Current basic feasible solution:

𝑥=(𝑥1,𝑥2,𝑠1,𝑠2,𝑠3)=(4,6,1,0,0)𝑧=𝑐𝐵𝑇𝑥𝐵=[031][0.965.964.1]=22
Nv = np.array(['x1', 'x2'])
Bv = np.array(['s1', 's2', 's3'])

A = np.array([
    [-1, 1, 1, 0, 0],
    [-1, 2, 0, 1, 0],
    [3, 1, 0, 0, 1],
])

c = np.array([1, 3, 0, 0, 0])

b = np.array([3, 8, 18])

cN = c[:2]
cB = c[2:]

N = A[:,:2]
B = A[:,2:]

print("Nv"), print(Nv)
print()
print("N"), print(N)
print()
print("cN"), print(cN)
print()
print("Bv"), print(Bv)
print()
print("B"), print(B)
print()
print("cB"), print(cB)
print()
print("b"), print(b)
print()

Binv = np.linalg.inv(B)
bfs = Binv @ b
z = cB @ bfs

print("B^(-1)"), print(Binv)
print()
print("BFS"), print(bfs)
print()
print("z"), print(z)
print()
reduced_cost = cB @ Binv @ N - cN

print("bar(c)_N^T"), print(reduced_cost)
print()

entering_var_index = 0

print("Entering var"), print(Nv[entering_var_index])
print()

d = Binv @ N[:,entering_var_index]
ratios = bfs / d

print(f"Ratios"), print(ratios)
print()

exiting_var_index = 2

print(f"Exiting variable"), print(Bv[exiting_var_index])
print()

B[:, exiting_var_index], N[:, entering_var_index] = N[:, entering_var_index].copy(), B[:, exiting_var_index].copy()
cB[exiting_var_index], cN[entering_var_index] = cN[entering_var_index].copy(), cB[exiting_var_index].copy()
Bv[exiting_var_index], Nv[entering_var_index] = Nv[entering_var_index].copy(), Bv[exiting_var_index].copy()

print("Nv"), print(Nv)
print()
print("N"), print(N)
print()
print("cN"), print(cN)
print()
print("Bv"), print(Bv)
print()
print("B"), print(B)
print()
print("cB"), print(cB)
print()

Binv = np.linalg.inv(B)
bfs = Binv @ b
z = cB @ bfs

print("B^(-1)"), print(Binv)
print()
print("BFS"), print(bfs)
print()
print("z"), print(z)
print()
reduced_cost = cB @ Binv @ N - cN

print("bar(c)_N^T"), print(reduced_cost)
print()

entering_var_index = 1

print("Entering var"), print(Nv[entering_var_index])
print()

d = Binv @ N[:,entering_var_index]
ratios = bfs / d

print(f"Ratios"), print(ratios)
print()

exiting_var_index = 1

print(f"Exiting variable"), print(Bv[exiting_var_index])
print()

B[:, exiting_var_index], N[:, entering_var_index] = N[:, entering_var_index].copy(), B[:, exiting_var_index].copy()
cB[exiting_var_index], cN[entering_var_index] = cN[entering_var_index].copy(), cB[exiting_var_index].copy()
Bv[exiting_var_index], Nv[entering_var_index] = Nv[entering_var_index].copy(), Bv[exiting_var_index].copy()

print("Nv"), print(Nv)
print()
print("N"), print(N)
print()
print("cN"), print(cN)
print()
print("Bv"), print(Bv)
print()
print("B"), print(B)
print()
print("cB"), print(cB)
print()

Binv = np.linalg.inv(B)
bfs = Binv @ b
z = cB @ bfs

print("B^(-1)"), print(Binv)
print()
print("BFS"), print(bfs)
print()
print("z"), print(z)
print()