Optimization Technique Lecture Note
Optimization Technique Lecture Note
LECTURE NOTE
MATRIC NO:
FACULTY:
DEPT:
CLASS ID:
SUBMISSION DATE:
1
Chapter One
Optimization Techniques
1.1 Introduction
Optimization techniques are methods used to find the best possible solution or outcome for a given problem
within a defined set of constraints. These techniques are widely used in various fields such as engineering,
economics, operations research, and artificial intelligence. Optimization is the process of making something as
effective or functional as possible. Basic types include: Linear Optimization, Nonlinear Optimization, Integer
Optimization, Combinatorial Optimization, Stochastic Optimization and Multi-Objective Optimization.
Linear Optimization also referred to as Linear Programming (LP) is concerned with the following:
a. Objective Function: A linear function that needs to be maximized or minimized.
b. Constraints: A set of linear inequalities or equations.
c. Feasible Region: The set of all possible points that satisfy the constraints.
d. Simplex Method: An iterative method to find the optimal solution.
Nonlinear Optimization also referred to as Nonlinear Programming (NLP) is concerned with the following:
a. Objective Function: A nonlinear function.
b. Constraints: Can be linear or nonlinear.
c. Methods: - Gradient Descent, - Newton's Method, - Conjugate Gradient Method
Integer Optimization also referred to as Integer Programming (IP) is concerned with the following:
a. Definition: Optimization where some or all of the decision variables are restricted to integer values.
b. Methods: - Branch and Bound, - Cutting Planes
2
Chapter Two
Linear Optimization
2.1 Widespread Methodology
The methods of linear programming were originally developed between 1945 and 1955 by American
mathematicians to solve problems arising in industry and economic planning. Many such problems
involve constraints on the size of the workforce, the quantities of raw materials available, and the number
of machines available and so on. The problems that will be solved usually have two variables in them
and can be solved graphically, but problems occurring in industry have many more variables and have to
be solved by computer. For example, in oil refineries, problems arise with hundreds of variables and tens
of thousands of constraints. Another application is in determining the best diet for farm animals such as
pigs. In order to maximize the profit a pig farmer needs to ensure that the pigs are fed appropriate food
and sufficient quantities of it to produce lean meat. The pigs require a daily allocation of carbohydrate,
protein, amino acids, minerals and vitamins. Each involves various components. For example, the
mineral content includes calcium, phosphorus, salt, potassium, iron, magnesium, zinc, copper, manganese,
iodine, and selenium. All these dietary constituents should be present, in correct amounts. Undoubtedly
linear programming is one of the most widespread methods used to solve management and economic
problems, and has been applied in a wide variety of situations and contexts.
Example
A small firm builds two types of garden shed. Type A requires 2 hours of machine time and 5 hours of
craftsman time. Type B requires 3 hours of machine time and 5 hours of craftsman time.
Each day there are 30 hours of machine time available and 60 hours of craftsman time.
The profit on each type A shed is £60 and on each type B shed is £84. Formulate the appropriate linear
programming problem.
Solution
(a) Unknowns
Define
x = number of Type A sheds produced each day,
y = number of Type B sheds produced each day.
(b) Constraints
Machine time: 2 x + 3y ≤ 30
Craftsman time: 5x + 5y ≤ 60
and
x ≥ 0, y ≥ 0
(c) Profit
4
Symbol Name Symbol Example
We need to note that if, p < q, then p is some number that is strictly less than q. If p ≤ q, then it means that p is
some number that is either strictly less than q or is exactly equal to q. Likewise, the same applies to the
remaining two inequalities > (greater than) and ≥ (greater than or equal to).
Now, Let's say we have a linear inequality, 3x - 4 < 20. In this case LHS < RHS. We can see that the expression
on the left-hand side, that is, 3x - 4 is in fact lesser than the number on the right-hand side, which is 20. We can
represent this inequality pictorially on a weighing scale as:
Addition Rule of Linear Inequalities: As per the addition rule of linear inequalities, adding the same number to each
side of the inequality produces an equivalent inequality, that is the inequality symbol does not change.
If x > y, then x + a > y + a and if x < y, then x + a < y + a.
Subtraction Rule of Linear Inequalities: As per the subtraction rule of linear inequalities, subtracting the same
number from each side of the inequality produces an equivalent inequality, that is the inequality symbol does not
change. If x > y, then x − a > y − a and if x < y, then x − a < y − a.
Multiplication Rule of Linear Inequalities: As per the multiplication rule of linear inequalities, multiplication on both
sides of an inequality with a positive number always produces an equivalent inequality, that is the inequality
symbol does not change. If x > y and a > 0, then x × a > y × a and if x < y and a > 0, then x × a < y × a, Here,
× is used as the multiplication symbol. On the other hand, multiplication on both sides of the inequality with a
negative number does not produce an equivalent inequality unless we also reverse the direction of the inequality
symbol. If x > y and a < 0, then x × a < y × a and if x < y and a < 0, then x × a > y × a.
Division Rule of Linear Inequalities: As per the division rule of linear inequalities, division of both sides of an
inequality with a positive number produces an equivalent inequality, that is the inequality symbol does not
change. If x > y and a > 0, then (x/a) > (y/a) and if x < y and a > 0, then (x/a) < (y/a). On the other hand, the
division of both sides of an inequality with a negative number produces an equivalent inequality if the inequality
symbol is reversed. If x > y and a < 0, then (x/a) < (y/a) and if x < y and a < 0, then (x/a) > (y/a)
5
Chapter Three
Solving System of Linear Inequalities
3.1 Introduction
Solving linear inequalities in multi-step one variable is the same as solving multi-step linear equations; begin by
isolating the variable from the constants. As per the rules of inequalities, while we are solving multi-step linear
inequalities, it is important for us to not forget to reverse the inequality sign when multiplying or dividing with
negative numbers.
Step 1: Simplify the inequality on both sides - on LHS as well as RHS as per the rules of inequality.
Step 2: When the value is obtained, if the inequality is a strict inequality, the solution for x is less than or greater
than the value obtained as defined in the question. And, if the inequality is not a strict inequality, then the
solution for x is less than or equal to or greater than or equal to the value obtained as defined in the question.
Now, let's try solving linear inequalities with an example, to understand the concept. 2x + 3 > 7
To solve this linear inequality, we would follow the steps: 2x > 7 - 3 ⇒ 2x > 4 ⇒ x > 2
The solution to this inequality will be the set of all values of x for which this inequality x > 2 is satisfied, that is,
all real numbers strictly greater than 2.
6
Linear inequalities with one variable are plotted on a number line, as the output gives the solution of one
variable. Hence, graphing linear inequalities in one variable is done using a number line only. On the contrary,
linear inequalities with two variables are plotted on a two-dimensional x and y axis graph, as the output gives the
solution of two variables. Hence, graphing of two-variable linear inequalities is done using a graph.
Let's consider the below example. 4x > -3x + 21
The solution in this case is simple. 4x + 3x > 21 ⇒ 7x > 21 ⇒ x > 3
This can be plotted on a number line as:
Any point lying on the blue part of the number line will satisfy this inequality. Note that in this case, we have
drawn a hollow dot at point 3. This is to indicate that 3 is not a part of the solution set (this is because the given
inequality has a strict inequality). As per the solution obtained, the blue part of the number line satisfies the
inequality. Let's take another example of linear inequalities: 3x + 1 ≤ 7
We proceed as follows: 3x ≤ 7 - 1 ⇒ 3x ≤ 6 ⇒ x ≤ 2
We want to represent this solution set on a number line. Thus, we highlight that part of the number line lying to
the left of 2
We see that any number lying on the red part of the number line will satisfy this inequality and so it is a part of
the solution set for this inequality. Note that we have drawn a solid dot exactly at point 2. This is to indicate that
2 is also a part of the solution set.
7
inequalities in two variables represent the inequal relationship between two algebraic expressions which
includes two distinct variables. A linear inequality in two variables is formed when symbols other than equal
to, such as greater than or less than are used to relate two expressions, and two variables are involved.
Here are some examples of linear inequalities in two variables:
2x<3y+2
7x−2y>8
3x+4y+3≤2y−5
y+x≥0
The solution of a linear inequality in two variables, like Ax + By > C, is an ordered pair (x, y) that produces a
true statement when the values of x and y are substituted into the inequality. Solving linear inequalities is the
same as solving linear equations; the difference it holds is of inequality symbol. We solve linear inequalities in
the same way as linear equations.
Step 1: Simplify the inequality on both sides, on LHS as well as RHS as per the rules of inequality.
Step 2: Once the value is obtained, we have:
a. strict inequalities, in which the two sides of the inequalities cannot be equal to each other.
b. non-strict inequalities, in which the two sides of the inequalities can also be equal.
Linear inequalities in two variables have infinite sets or infinitely many ordered pair solutions.
These ordered pairs or the solution sets can be graphed in the appropriate half of a rectangular coordinate plane.
In order to graph inequalities with two variables,
1. Identify the type of inequality (greater than, less than, greater than or equal to, less than or equal to).
2. Graph the boundary line - a dashed (in case of strict inequality) or a solid line (in case of non-strict
inequalities).
3. Choose a test point, most probably (0, 0) or any other point which is not on the boundary.
4. Shade the region accordingly. If the test point solves the inequality, shade the region that contains
it. Otherwise, shade the opposite side of the boundary line.
5. Verify with more number of test points in and out of the region.
Example: Graph the linear equality 2x+3y>7
a. Plot the straight line corresponding to the linear equation 2x+3y=72x+3y=7.
b. Determine any two points (solutions) for this equation: two possible points on the graph can be taken
as A(−1,3),B(2,1)A(−1,3),B(2,1) and plot them on the graph.
c. Determine some specific solutions for the linear inequality 2x+3y>7, which can be as follows
(2,3),(3,1),(4.5,0),(0,3),(1.5,2)
d. Plot these five points on the same graph.
8
All the five points (corresponding to the five solutions) lie above the line.
a. Take any point which lies above the line. Its coordinates, say (x0,y0),(x0,y0),, will satisfy the inequality:
2x0+3y0>7
b. This means that the solution set for the inequality consists of all points lying above the line.
c. Put x = 0, y = 0, which gives 2(0) + 3(0) > 7, which further gives 0 > 7.This doesn't holds true for the
given inequality. So, shade the half plane which doesn't include the point (0, 0).
Example 1
Golden's mother hands over $7 to him for chocolates. She tells him to spend only $7 or less than that.
A milk chocolate costs $2 while a nuts chocolate costs $3. Let x be the number of milk chocolates and y be the
number of nuts chocolates. Form an inequality corresponding to the above situation and graph the inequality.
Solution
2x+3y≤72x+3y≤7will be the inequality corresponding to the above situation.
In this case, we will plot a solid line as boundary joining the points which satisfy the linear equation 2x+3y=7
For 2x+3y=7
x 2 5 -7
y 1 -1 7
For inequality2x+3y≤7
a. Determine some specific solutions for the linear inequality 2x+3y≤72x+3y≤7 which can be as
follows: (0,1),(−4,0),(1,0),(−5,1),(2,−1)
b. Plot these points. These will lie below the solid line.
Now, put x = 0, y = 0. This gives, 2(0) + 3(0) ≤ 7, which satisfies the inequality. So, shade the half plane in the
linear inequality graph below, which includes the point (0,0).
9
Example 2 Graph the solution set for y>−5x+2
Solution: y>−5x+2 is an inequality in slope intercept form; slope=-5, intercept=2. In this case, we will plot a
dashed line because of a less than or equal to equality, as boundary joining the points which satisfy the linear
equation y=−5x+2. For y=−5x+2
x 0 1 2 -1
y 2 -3 -8 7
For the inequality y>−5x+2
a. Determine some specific solutions for the linear inequality y>−5x+2y>−5x+2 which can be as
follows: (1,2),(3,−2),(4,3),(4,5),(3,6)(1,2),(3,−2),(4,3),(4,5),(3,6)
b. Plot these points. These will lie above the dotted line.
For y>−5x+2 put x=0, y=0. This gives 0>-5(0)+2, which further gives 0>2
This doesn't hold true for the given inequality. So, shade the half plane in the linear inequality graph below,
which doesn't includes the point (0,0).
10
Chapter Four
Solved Examples
Question 1. A company is involved in the production of two items (X and Y). The resources needed to
produce X and Y are twofold, namely machine time for automatic processing and craftsman time for hand
finishing. The table below gives the number of minutes required for each item:
Machine time Craftsman time
Item X 13 20
Y 19 29
The company has 40 hours of machine time available in the next working week but only 35 hours of craftsman
time. Machine time is costed at £10 per hour worked and craftsman time is costed at £2 per hour worked. Both
machine and craftsman idle times incur no costs. The revenue received for each item produced (all production is
sold) is £20 for X and £30 for Y. The company has a specific contract to produce 10 items of X per week for a
particular customer.
a. Formulate the problem of deciding how much to produce per week as a linear program.
b. Solve this linear program graphically.
11
Solution
Let
a. x be the number of items of X
b. y be the number of items of Y
then the LP is: maximize
a. 20x + 30y - 10(machine time worked) - 2(craftsman time worked)
subject to:
a. 13x + 19y <= 40(60) machine time
b. 20x + 29y <= 35(60) craftsman time
c. x >= 10 contract
d. x,y >= 0
so that the objective function becomes
maximise
a. 20x + 30y - 10(13x + 19y)/60 - 2(20x + 29y)/60
i.e. maximise
a. 17.1667x + 25.8667y
subject to:
a. 13x + 19y <= 2400
b. 20x + 29y <= 2100
c. x >= 10
d. x,y >= 0
It is plain from the diagram below that the maximum occurs at the intersection of x=10 and 20x + 29y <= 2100
Solving simultaneously, rather than by reading values off the graph, we have that x=10 and y=65.52 with the
value of the objective function being £1866.5
Question 2. A company manufactures two products (A and B) and the profit per unit sold is £3 and £5
respectively. Each product has to be assembled on a particular machine, each unit of product A taking 12
12
minutes of assembly time and each unit of product B 25 minutes of assembly time. The company estimates that
the machine used for assembly has an effective working week of only 30 hours (due to
maintenance/breakdown).
Technological constraints mean that for every five units of product A produced at least two units of product B
must be produced.
a. Formulate the problem of how much of each product to produce as a linear program.
b. Solve this linear program graphically.
c. The company has been offered the chance to hire an extra machine, thereby doubling the effective
assembly time available. What is the maximum amount you would be prepared to pay (per week) for the
hire of this machine and why?
Solution
Let
xA = number of units of A produced
xB = number of units of B produced
then the constraints are:
12xA + 25xB <= 30(60) (assembly time)
xB >= 2(xA/5)
i.e. xB - 0.4xA >= 0
i.e. 5xB >= 2xA (technological)
where xA, xB >= 0
and the objective is
maximise 3xA + 5xB
It is plain from the diagram below that the maximum occurs at the intersection of 12xA + 25xB = 1800 and xB -
0.4xA = 0
13
Solving simultaneously, rather than by reading values off the graph, we have that:
xA= (1800/22) = 81.8
xB= 0.4xA = 32.7
with the value of the objective function being £408.9
Doubling the assembly time available means that the assembly time constraint (currently 12xA + 25xB <= 1800)
becomes 12xA + 25xB <= 2(1800) This new constraint will be parallel to the existing assembly time constraint
so that the new optimal solution will lie at the intersection of 12xA + 25xB = 3600 and xB - 0.4xA = 0
i.e. at xA = (3600/22) = 163.6
xB= 0.4xA = 65.4
with the value of the objective function being £817.8
Hence we have made an additional profit of £(817.8-408.9) = £408.9 and this is the maximum amount we would
be prepared to pay for the hire of the machine for doubling the assembly time. This is because if we pay more
than this amount then we will reduce our maximum profit below the £408.9 we would have made without the
new machine.
Question 3. Solve
minimise
4a + 5b + 6c
subject to
a + b >= 11
a - b <= 5
c-a-b=0
14
7a >= 35 - 12b
a >= 0 b >= 0 c >= 0
Solution
To solve this LP we use the equation c-a-b=0 to put c=a+b (>= 0 as a >= 0 and b >= 0) and so the LP is
reduced to
minimise
4a + 5b + 6(a + b) = 10a + 11b
subject to
a + b >= 11
a - b <= 5
7a + 12b >= 35
a >= 0 b >= 0
From the diagram below the minimum occurs at the intersection of a - b = 5 and a + b = 11
i.e. a = 8 and b = 3 with c (= a + b) = 11 and the value of the objective function 10a + 11b = 80 + 33 = 113.
Question 5. A carpenter makes tables and chairs. Each table can be sold for a profit of £30 and each chair
for a profit of £10. The carpenter can afford to spend up to 40 hours per week working and takes six hours to
make a table and three hours to make a chair. Customer demand requires that he makes at least three times as
many chairs as tables. Tables take up four times as much storage space as chairs and there is room for at most
four tables each week.
Formulate this problem as a linear programming problem and solve it graphically.
Solution
Variables
Let
xT = number of tables made per week
xC = number of chairs made per week
Constraints
a. total work time
6xT + 3xC <= 40
a. customer demand
xC >= 3xT
a. storage space
16
(xC/4) + xT <= 4
a. all variables >= 0
Objective
maximise 30xT + 10xC
The graphical representation of the problem is given below and from that we have that the solution lies at the
intersection of
(xC/4) + xT = 4 and 6xT + 3xC = 40
Solving these two equations simultaneously we get xC = 10.667, xT = 1.333 and the corresponding profit =
£146.667
17
Chapter Five
Sample Python Programs
5.1 Introduction
A few Python project solution for solving linear optimization problems using the PuLP library are presented
here. The PuLP library is a popular tool for linear programming in Python.
Step 1: Install the PuLP Library. First, ensure you have the PuLP library installed. You can install it using pip:
pip install pulp
Step 2: Define the Linear Optimization Problems
We will solve two linear optimization problems as examples:
1. Maximization Problem (Graphical Method Example)
a. Objective: Maximize Z=3x1+
b. Constraints: x1+x2≤4
x1≤2
x2≤3
x1,x2≥0
2. Maximization Problem (Simplex Method Example)
a. Objective: Maximize Z=3x1+5x2
b. Constraints: x1+2x2≤8
3x1+2x2≤12
x1,x2≥0
# Decision variables
x1 = pulp.LpVariable('x1', lowBound=0, cat='Continuous')
x2 = pulp.LpVariable('x2', lowBound=0, cat='Continuous')
# Objective function
problem1 += 3 * x1 + 2 * x2, "Z"
# Constraints
problem1 += x1 + x2 <= 4
problem1 += x1 <= 2
problem1 += x2 <= 3
# Decision variables
x1 = pulp.LpVariable('x1', lowBound=0, cat='Continuous')
x2 = pulp.LpVariable('x2', lowBound=0, cat='Continuous')
# Objective function
problem2 += 3 * x1 + 5 * x2, "Z"
# Constraints
problem2 += x1 + 2 * x2 <= 8
problem2 += 3 * x1 + 2 * x2 <= 12
Solution:
# Import the PuLP library
import pulp
# Decision variables
x1 = pulp.LpVariable('x1', lowBound=0, cat='Continuous')
x2 = pulp.LpVariable('x2', lowBound=0, cat='Continuous')
# Objective function
Problem2 += 4 * x1 + 3 * x2, "Z"
# Constraints
Problem2 += 2 * x1 + x2 >= 8
Problem2 += x1 + x2 >= 6
20
Example 3: Resource Allocation Problem
Problem: A company produces two products, P1 and P2. Each product requires different amounts of two
resources, R1 and R2. The objective is to maximize profit.
1. Profit for P1: $5 per unit
2. Profit for P2: $4 per unit
3. Availability of R1: 20 units
4. Availability of R2: 40 units
5. P1 requires 2 units of R1 and 1 unit of R2
6. P2 requires 1 unit of R1 and 2 units of R2
Formulation: Maximize Z=5x1+4x2
Subject to:
2x1+x2≤20
x1+2x2≤40
x1,x2≥0
Solution:
# Create the problem variable to contain the problem data
problem4 = pulp.LpProblem("Maximize Profit", pulp.LpMaximize)
# Decision variables
x1 = pulp.LpVariable('P1', lowBound=0, cat='Continuous')
x2 = pulp.LpVariable('P2', lowBound=0, cat='Continuous')
# Objective function
problem4 += 5 * x1 + 4 * x2, "Profit"
# Constraints
problem4 += 2 * x1 + x2 <= 20
problem4 += x1 + 2 * x2 <= 40
Solution:
# Create the problem variable to contain the problem data
Problem4 = pulp.LpProblem("Minimize Cost", pulp.LpMinimize)
# Decision variables
x1 = pulp.LpVariable('F1', lowBound=0, cat='Continuous')
x2 = pulp.LpVariable('F2', lowBound=0, cat='Continuous')
# Objective function
Problem4 += 3 * x1 + 2 * x2, "Cost"
# Constraints
Problem4 += 2 * x1 + x2 >= 8
Problem4 += x1 + 2 * x2 >= 10
Problem4 += 3 * x1 + 2 * x2 >= 15
Solution:
# Create the problem variable to contain the problem data
Problem5 = pulp.LpProblem("Minimize Transportation Cost", pulp.LpMinimize)
# Decision variables
x11 = pulp.LpVariable('W1_to_S1', lowBound=0, cat='Continuous')
x12 = pulp.LpVariable('W1_to_S2', lowBound=0, cat='Continuous')
x13 = pulp.LpVariable('W1_to_S3', lowBound=0, cat='Continuous')
x21 = pulp.LpVariable('W2_to_S1', lowBound=0, cat='Continuous')
x22 = pulp.LpVariable('W2_to_S2', lowBound=0, cat='Continuous')
x23 = pulp.LpVariable('W2_to_S3', lowBound=0, cat='Continuous')
# Objective function
Problem5 += 2 * x11 + 3 * x12 + 1 * x13 + 4 * x21 + 2 * x22 + 5 * x23, "Transportation Cost"
# Constraints
Problem5 += x11 + x12 + x13 <= 30 # Supply at W1
Problem5 += x21 + x22 + x23 <= 20 # Supply at W2
Problem5 += x11 + x21 >= 10 # Demand at S1
Problem5 += x12 + x22 >= 20 # Demand at S2
Problem5 += x13 + x23 >= 20 # Demand at S3
23
5.3 Study Questions and Answers
Question 1: What is the feasible region in a linear programming problem?
Answer: The feasible region is the set of all possible points that satisfy all the constraints of a linear
programming problem. It is typically a convex polygon or polyhedron in the decision variable space.
Question 2: How do you determine the optimal solution using the graphical method?
Answer: To determine the optimal solution using the graphical method:
1. Plot the constraints on a graph.
2. Identify the feasible region.
3. Draw the objective function and move it parallel until the last point in the feasible region is touched.
4. The coordinates of this point give the optimal solution.
Question 3: What is a slack variable, and why is it used in the simplex method?
Answer: A slack variable is added to a less-than-or-equal-to constraint to convert it into an equality. It
represents the unused portion of the resource. In the simplex method, slack variables are used to transform
inequalities into equalities, allowing the problem to be solved using matrix operations.
Question 4: Explain the significance of the pivot operation in the simplex method.
Answer: The pivot operation in the simplex method is used to move from one vertex of the feasible region to
an adjacent vertex. It involves selecting an entering variable (which will increase) and a leaving variable (which
will decrease to zero), updating the tableau accordingly. This operation continues iteratively until no further
improvements can be made, leading to the optimal solution.
Question 5: What is the Traveling Salesman Problem (TSP) and which category of optimization does it fall
under?
Answer: The Traveling Salesman Problem (TSP) is a combinatorial optimization problem where the goal is to
find the shortest possible route that visits a set of cities and returns to the origin city. It falls under the category
of combinatorial optimization.
25