Linear Programming

 Introduction: 

linear programming is a method of optimizing operations with some constraints. 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.

Today want to minimize a cost function i.e., c₁x₁ + c₂x₂ + … + cx. ere, each x₋ is a variable and it is associated with some cost c. A constraint that’s represented as a sum of variables that is either less than or equal to a value (a₁x₁ + a₂x₂ + … + axₙ<=b) or precisely equal to this value (a₁x₁ + a₂x₂ + … + axₙ=b).In this case, x₋ is a variable, and a₋ is some resource associated with it, and b is how many resources we can dedicate to this problem

This is an Artificial Intelligence course conducted in City Universit by Nuruzzaman Faruqui. This is the best course in Bangladesh. Because Sir explained all the necessary things to us well. The problem we are dealing with in the lab. First, sir gives us a very good idea of the problem by using many examples. After that sir explains about the solutions like how we can solve the problem, how they work. For that, we understand everything very easily.


Problem:

The problem is :

  1.  Two machines, X₁ and X₂.
  2.  X₁ costs $50/hour to run, X₂ costs $80/hour to run. The goal is to minimize cost. 
  3.  This can be formalized as a cost function: 50x₁ + 80x₂.
  4.  X₁ requires 5 units of labor per hour.
  5.  X₂ requires 2 units of labor per hour
  6. Total of 20 units of labor to spend. 
  7. This can be formalized as a constraint: 5x₁ + 2x₂ ≤ 20.
  8. X₁ produces 10 units of output per hour.
  9.  X₂ produces 12 units of output per hour.
  10. The company needs 90 units of output.
  11. This is another constraint.
  12. Literally, it can be rewritten as 10x₁ + 12x₂ ≥ 90
  13. However, constraints need to be of the form (a₁x₁ + a₂x₂ + … + ax = b)
  14. Therefore, we multiply by (-1) to get to an equivalent equation of the desired form: (-10x₁) + (-12x₂) ≤ -90.
This is the linear programming example we are implementing this problem by using the scipy library in python.

 Pseudocode :

import scipy.optimize
# Objective Function :50x_1 + 80x_2
# Constraint 1: 5x_1 + 2x_2 <=20
# Constraint 1: -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 : 

If everything is fine then we will get this type of result. 





Conclusion : 
First, we introduced the problem. After that, we explain the problem and how we can solve the problem. then we explain the algorithm after that we write the code and give comments that's why you can easily understand the code. I hope anyone can easily understand the code. we discuss the result. If anyone follows this article then he/she can easily understand everything, They can also do this very easily. 
we can say this is the only reflection of the way that Sir has taught us. So this is the best AI course in Bangladesh. 
 
You are free to copy the code from here or some other concluding remarks

No comments

Powered by Blogger.