LINEAR PROGRAMMING
Linear programming is a method to achieve the best outcome (such as maximum profit or lowest cost) in a mathematical model whose requirements are represented by linear relationships . Linear programming is a special case of mathematical programming (also known as mathematical optimization).
More formally, linear programming is a technique for the optimization of a linear objective function , subject to linear equality and linear equality constraints. Its feasible region is a convex polytope, which is a set defined as the intersection of finitely many half spaces, each of which is defined by a linear inequality. Its objective function is a real-valued affine(linear)function defined on this polyhedron.
A linear programming algorithm finds a point in the polytope where this function has the smallest (or largest) value if such a point exists.
The main objective of linear programming is to maximize or minimize the numerical value. It consists of Linear functions which are subjected to the constraints in the form of linear equations or in the form of inequalities.
My name's Happy khatun. I am a student of city university. This blog is the easiest way to learn python programming in Bangladesh. This course is conducted in City University by our most honorable teacher Nuruzzaman Faruqui.
In this blog you will find every single line explanation of python code. Here every person can gather knowledge about python programming. Also one will be overcome of his fear regarding python programming.
Here is a proper discussion about linear programming
problem statement:
suppose there are few examples:
- Two machines, X₁ and X₂.
- X₁ costs $50/hour to run, X₂ costs $80/hour to run. The goal is to minimize cost.
- This can be formalized as a cost function: 50x₁ + 80x₂.
- X₁ requires 5 units of labor per hour.
- X₂ requires 2 units of labor per hour.
- Total of 20 units of labor to spend.
- This can be formalized as a constraint: 5x₁ + 2x₂ ≤ 20.
- X₁ produces 10 units of output per hour.
- X₂ produces 12 units of output per hour.
- The company needs 90 units of output.
- This is another constraint.
- Literally, it can be rewritten as 10x₁ + 12x₂ ≥ 90.
- However, constraints need to be of the form (a₁x₁ + a₂x₂ + … + aₙxₙ ≤ b) or (a₁x₁ + a₂x₂ + … + aₙxₙ = b).
Therefore, we multiply by (-1) to get to an equivalent equation of the desired form: (-10x₁) + (-12x₂) ≤ -90.
Now let's have a look on python code regarding these examples
import scipy.optimize
# objective Function: 50x_1 + 80_2
# Constarint 1: 5x_1 + 2x_2 <= 20
# Constarint 2: -10x_1 + - 12x_2 <= -90
result = scipy.optimize.linprog(
[50,80], # cost function: 50x_1 + 80x_2
A_ub=[
[5,2],
[-10,-12]
], # Coefficients for inequalities
b_ub=[20,-90], # Constraints for inequalities:20 and -90
)
if result.successs:
print(f"x1: {round(result.x[0], 2)} hours")
print(f"x2: {round(result.x[1], 2)} hours")
else:
print("No solution")
Result:
Running this above code in pycharm we get following result
Linear programming and Optimization are used in various industries. The manufacturing and service industry uses linear programming on a regular basis.Linear programming (LP) is one of the simplest ways to perform optimization. It helps you solve some very complex optimization problems by making a few simplifying assumptions.
Applications of linear programming are everywhere around you. You use linear programming at personal and professional fronts. You are using linear programming when you are driving from home to work and want to take the shortest route. Or when you have a project delivery you make strategies to make your team work efficiently for on-time delivery.

No comments:
Post a Comment