Linear optimization using R, in this tutorial we are going to discuss the linear optimization problems in R.
Optimization is everything nowadays. We all have finite resources and time and we want to make the maximum profit out of that.
Companies want to makes maximum profits based on limited resources they have, yes optimization is the solution for that.
Data scientists can provide optimal solutions based on given constraints to achieve maximum profit.
To find the optimal solution for the problem given below.
Suppose a company wants to maximize the profit for two products A and B which are sold at $25 and $20 respectively.
There are 1800 resource units available every day and product A requires 20 units while B requires 12 units.
Both of these products require a production time of 4 minutes and the total available working hours are 8 in a day.
What should be the production quantity for each of the products to maximize profits?
In this case, the objective function in the problem will be
X1 is the units of product A produced
X2 is the units of product B produced
X1 and x2 are also called decision variables.
The constraints are resources and time in this case.
Let’s see how to resolve this problem in R
Linear optimization using R
Set the coefficients of the decision variables
Create constraint matrix
Define the constraints
RHS for the constraints
Optimal values for x1 and x2 are
The value of the objective function at an optimal point is
From the above output, we can see that the company should produce 45 units of product A and 75 units of product B to get sales of $2625, which is the maximum sales that the company can get given the constraints.