CS-251 DESIGN & ANALYSIS OF ALGORITHMS
CREDIT HOURS: 3+0
SEMESTER SPRING 2025
COURSE INSTRUCTOR: DR. SAMRA KANWAL
[email protected] Military College of Signals
National University of Science and Technology (NUST)
Department of Computer Software Engineering
STEPS IN DEVELOPING A LINEAR PROGRAMMING
(LP) MODEL
1) Formulation
2) Solution
3) Interpretation and Sensitivity
Analysis
PROPERTIES OF LP MODELS
1) Seek to minimize or maximize
2) Include “constraints” or
limitations
3) There must be alternatives
available
4) All equations are linear
EXAMPLE LP MODEL FORMULATION:
THE PRODUCT MIX PROBLEM
Decision: How much to make of > 2
products?
Objective: Maximize profit
Constraints: Limited resources
EXAMPLE: FLAIR FURNITURE CO.
Two products: Chairs and Tables
Decision: How many of each to make
this month?
Objective: Maximize profit
FLAIR FURNITURE CO. DATA
Tables Chairs
(per table) (per chair)
Profit Hours
$7 $5
Contribution Available
Carpentry 3 hrs 4 hrs 2400
Painting 2 hrs 1 hr 1000
Other Limitations:
• Make no more than 450 chairs
• Make at least 100 tables
Decision Variables:
T = Num. of tables to make
C = Num. of chairs to make
Objective Function: Maximize
Profit
Maximize $7 T + $5 C
CONSTRAINTS:
◼Have 2400 hours of carpentry
time available
3 T + 4 C < 2400 (hours)
◼Have 1000 hours of painting
time available
2 T + 1 C < 1000 (hours)
More Constraints:
◼Make no more than 450 chairs
C < 450 (num. chairs)
◼Make at least 100 tables
T > 100 (num. tables)
Nonnegativity:
Cannot make a negative number of chairs or tables
T>0
C>0
MODEL SUMMARY
Max 7T + 5C (profit)
Subject to the constraints:
3T + 4C < 2400 (carpentry hrs)
2T + 1C < 1000 (painting hrs)
C < 450 (max # chairs)
T > 100 (min # tables)
T, C > 0 (nonnegativity)
GRAPHICAL SOLUTION
◼ Graphing an LP model helps provide
insight into LP models and their
solutions.
◼ While this can only be done in two
dimensions, the same properties apply
to all LP models and solutions.
C
Carpentry
Constraint Line
3T + 4C = 2400 Infeasible
600
> 2400 hrs
3T
Intercepts +4
C
=2
(T = 0, C = 600) 40
0
Feasible
(T = 800, C = 0) 0 < 2400 hrs
0 800 T
C
1000
Painting
Constraint Line
2T + 1C = 1000
2T
+
1C
600
=1
00
Intercepts
0
(T = 0, C = 1000)
(T = 500, C = 0)
0
0 500 800 T
C
1000
Max Chair Line
C = 450
600
Min Table Line
450
T = 100
Feasible
0 Region
0 100 500 800 T
C
7T
+5
Objective
C
Function Line
=$
4,
500
04
7T + 5C = Profit
0
7T
Optimal Point
+5
400 (T = 320, C =
C
360)
=$
7T
2,
300
+5
80
C
0
=$
2,
200
10
0
100
0 100 200 300 400 500 T
C
Additional New optimal point
Constraint 500 T = 300, C = 375
Need at least 75
more chairs than 400
T = 320
tables C = 360
C > T + 75 300 No longer
feasible
Or
200
C – T > 75
100
0 100 200 300 400 500 T
LP CHARACTERISTICS
◼ Feasible Region: The set of points that
satisfies all constraints
◼ Corner Point Property: An optimal
solution must lie at one or more corner
points
◼ Optimal Solution: The corner point
with the best objective function value
is optimal
SPECIAL SITUATION IN LP
1. Redundant Constraints - do not affect the
feasible region
Example: x < 10
x < 12
The second constraint is redundant because
it is less restrictive.
SPECIAL SITUATION IN LP
2. Infeasibility – when no feasible
solution exists (there is no feasible
region)
Example: x < 10
x > 15
SPECIAL SITUATION IN LP
3. Alternate Optimal Solutions –
when there is more than one
optimal solution
C
2T
Max 2T + 2C 10
+
2C
Subject to: All points on
=
20
T + C < 10 6 Red
T < 5 segment are
C< 6 optimal
T, C > 0
0
0 5 10 T
SPECIAL SITUATION IN LP
4. Unbounded Solutions – when
nothing prevents the solution
from becoming infinitely large
n
C it o on
c ti
Max 2T + 2C re u
Di sol
Subject to: 2 of
2T + 3C > 6
T, C > 0 1
0 1 23 T
USE CASE: CLASSIFYING EMAILS AS SPAM OR NOT
SPAM
◼We want to build a binary
classification model to
distinguish between spam and
non-spam emails based on
simple features.
CLASSES:
●Class +1: Non-spam emails
●Class -1: Spam emails
SIMPLEX ALGORITHM
◼
SIMPLEX METHOD
◼ Used for solving LP problems
◼ Put into the form of a table, and then a number
of mathematical steps are performed on the
table
◼ Moves from one extreme point on the solution
boundary to another until the best one is found,
and then it stops
◼ A lengthy and tedious process but computer
software programs are now used easily instead
◼ Programs do not provide an in-depth
understanding of how those solutions are
derived
2. WHY SIMPLEX ALGORITHM?
◼Graphical methods work only for
2 variables.
◼Simplex handles any number of
variables and constraints.
◼Efficient in practice.
3. KEY CONCEPTS
◼Feasible Region: Points that
satisfy constraints.
◼Basic Feasible Solution: Corner
point of the region.
◼Optimal Solution: BFS with max
or min value of objective
function.
4. GEOMETRIC INTUITION
◼Use 2-variable example.
◼Draw constraints.
◼Show vertex movement.
◼Each step improves objective
function.
5. SIMPLEX ALGORITHM STEPS
◼1. Convert to standard form.
◼2. Initialize basic feasible
solution.
◼3. Construct simplex tableau.
◼4. Check optimality.
◼5. Choose entering variable.
◼6. Choose leaving variable.
6. EXAMPLE PROBLEM
◼Maximize Z = 3x + 2y
◼Subject to:
◼x + y ≤ 4
◼x ≤ 2
◼y ≤ 3
◼x, y ≥ 0
7. CONVERT TO STANDARD FORM
Maximize Z = 3x + 2y
Subject to:
x + y + s1 = 4
x + s2 = 2
y + s3 = 3
x, y, s1, s2, s3 ≥ 0
Key column
8. INITIAL SIMPLEX TABLEAU
Basi x y s1 s2 s3 RHS Min
c Ratio
Varia =RH
ble S/ke
y
colu
mn
Z -3 -2 0 0 0 0 0
S1 1 1 1 0 0 4 4
S2 1 0 0 1 0 2 2
s3 0 1 0 0 1 3 inf
9. ITERATION 1
◼Entering: x (most negative in Z
row)
◼Leaving: s2 (min ratio 2/1)
◼Pivot on (s2, x), update tableau.
◼X: key element
◼Make key element 1 and then
with unity key element convert all
col to zero
Key column
8. FINAL SIMPLEX TABLEAU
Basi x y s1 s2 s3 RHS Min
c Ratio
Varia =RH
ble S/ke
y
colu
mn
Z 0 -2 0 3 0 6 -3
S1 0 1 1 -1 0 2 2
x 1 0 0 1 0 2 Inf
s3 0 1 0 0 1 3 3
11. ITERATION 2
◼Entering: y
◼Leaving: s1 (min ratio 2/1)
◼Pivot on (s1, y), update tableau.
Solution: x = 2, y = 2, Z =
8. FINAL SIMPLEX TABLEAU 10
Basi x y s1 s2 s3 RHS Min
c Ratio
Varia =RH
ble S/ke
y
colu
mn
Z 0 0 2 1 0 10
y 0 1 1 -1 0 2
x 1 0 0 1 0 2
s3 0 0 -1 1 1 1
13. TIME COMPLEXITY
◼Worst case: Exponential
◼Average case: Polynomial
MODEL
◼ Our maximization model
◼ Z = 40x1 + 50x2 + 0s1 + 0s2
Subject to
x1 + 2x2+ s1 = 40
4x1 + 3x2 + s2 =120
x 1, x 2 , s 1, s 2 ≥ 0