Monday, April 5, 2021

Optimization - Linear Programming

Introduction



Linear programming is used to optimize a linear objective function and a system of linear inequalities or equations. The limitations set on the objective function are called as constraints. The objective function represents the quantity which needs to be minimized or maximized. Linear programming's main objective is to optimize the objective function. Linear programming problems can be solved using multiple methods. The most common methods are simplex method, solving the problems using R or open solver, and graphical method. In this article, we will solve the linear programming problems using the graphical method.

In linear programming a constraint for sum of a variable can be shown as follows:

(a₁x₁ + a₂x₂ + … + aₙxₙ ≤ b) or (a₁x₁ + a₂x₂ + … + aₙxₙ = b).

Here, x_ is a variable with a1_co-efficient and b is resources.

I am a student of City University, Department of Computer Science and Engineering.  My name is Md Shakil khan, ID-163432065. This course is Artificial Intelligence conducted in City University by Nuruzzaman Faruqui. This is the Best Artificial Intelligence Course in BangladeshArtificial intelligence is a lucrative field with above-average job growth, but the industry remains competitive. Roles in this discipline are very niche, requiring both an advanced technical background and extensive hands-on experience.

Problem Statement



Linear programming likes a mathematic term. We have to solve below this linear programming.






Source Code



import scipy.optimize

# Objective Function: 50x_1 + 80x_2
# Constraint 1: 5x_1 + 2x_2 <= 20
# Constraint 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.success:
print(f"X1: {round(result.x[0], 2)} hours")
print(f"X2: {round(result.x[1], 2)} hours")
else:
print("No solution")



Result


After solving the mathematical term with coding , we will get this kind of result.






At first in coding in python, we import the scipy optimize library. Then we write the mathematical term in the result variable. For this, we use scipy optimize linprog. Then we set the success condition if success shows the result and if no then show no solution.

Conclusion


At first, we discuss Linear Programming. Then we discuss where it is used. Then we discuss an example of linear programming, after this, we write the code in python and discuss the code so that everyone can easily understand the code. That's why This is the Best AI Course in Bangladesh.





No comments:

Post a Comment

Optimization - Linear Programming

Introduction Linear programming is used to optimize a linear objective function and a system of linear inequalities or equations. The limita...