Maximise profits with the given constraints.
Maximise total profit using decision variables X1 = volume of apple juice, X2 = volume of orange juice |
Profit = 11X1 + 12X2 |
---|---|
Budget Constraint | 0.1X1 + 0.2X2 ≤ 12 |
Space Constraint | 1.1X1 + 1.2X2 ≤ 34 |
Contract Constraint 1 | X1 ≥ 5 |
Contract Constraint 2 | X2 ≥ 5 |
Non-negativity Constraint 1 | X1 ≥ 0 |
Non-negativity Constraint 2 | X2 ≥ 0 |
# Functions
library(lpSolve)
- Run the linear optimisation model.
# Define parameters
objective.fn <- c(11, 22)
const.mat <- (matrix(
c(0.1, 0.2,
1.1, 1.2,
1, 0,
0, 1), # R assumes non-negativity, so the non-negativity constraint does not need to be specified
ncol = 2, # Number of decision variables
byrow = TRUE))
const.dir <- c("<=","<=",">=",">=")
const.rhs <- c(12,34,5,5)
# Run the model
lp.solution <- lp("max", objective.fn, const.mat, const.dir, const.rhs,
compute.sens = TRUE)
lp.solution
lp.solution$solution
- If required, obtain shadow prices.
lp.solution$duals
- If required, conduct sensitivity analysis.
lp.solution$sens.coef.to # Upper bounds to the coefficients
lp.solution$sens.coef.from # Lower bounds to the coefficients
Minimise costs with the given constraints.
Minimise total cost using decision variables X1 = volume of apple juice, X2 = volume of orange juice |
Cost = 11X1 + 12X2 |
---|---|
Budget Constraint | 0.1X1 + 0.2X2 ≤ 12 |
Space Constraint | 1.1X1 + 1.2X2 ≤ 34 |
Contract Constraint 1 | X1 ≥ 5 |
Contract Constraint 2 | X2 ≥ 5 |
Non-negativity Constraint 1 | X1 ≥ 0 |
Non-negativity Constraint 2 | X2 ≥ 0 |
# Functions
library(lpSolve)
- Run the linear optimisation model.
objective.fn <- c(11, 22)
const.mat <- (matrix(
c(0.1, 0.2,
1.1, 1.2,
1, 0,
0, 1), # R assumes non-negativity, so the non-negativity constraint does not need to be specified
ncol = 2, # Number of decision variables
byrow = TRUE))
const.dir <- c("<=","<=",">=",">=")
const.rhs <- c(12,34,5,5)
lp.solution <- lp("min", objective.fn, const.mat, const.dir, const.rhs,
compute.sens = TRUE)
lp.solution
lp.solution$solution
- If required, obtain shadow prices.
lp.solution$duals
- If required, conduct sensitivity analysis.
lp.solution$sens.coef.to # Upper bounds to the coefficients
lp.solution$sens.coef.from # Lower bounds to the coefficients