Maximise profits with the given constraints.
Maximise total profit using decision variables X1 = number of apples to sell, X2 = whether to sell one orange or not |
Profit = 11X1 + 12X2 |
---|---|
Budget Constraint | 0.1X1 + 0.2X2 ≤ 12 |
Space Constraint | 1.1X1 + 1.2X2 ≤ 34 |
Contract Constraint (X1) | X1 ≥ 5 |
Non-negativity Constraint (X1) | X1 ≥ 0 |
Non-negativity Constraint (X2) | X2 ≥ 0 |
Integer Constraint (X1) | X1 is an integer |
Binding Constraint (X2) | X2 is binary |
# Functions
library(lpSolve)
- Run the integer optimisation model.
# Define parameters
objective.fn <- c(11, 22)
const.mat <- (matrix(
c(0.1, 0.2,
1.1, 1.2,
1, 0), # 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)
# Run the model
lp.solution <- lp("max", objective.fn, const.mat, const.dir, const.rhs,
int.vec = 1, binary.vec = 2, # For other questions ----- eg int.vec = c(1,2,3) / all.int = TRUE
compute.sens = FALSE)
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 = number of apples to sell, X2 = whether to sell one orange or not |
Cost = 11X1 + 12X2 |
---|---|
Budget Constraint | 0.1X1 + 0.2X2 ≤ 12 |
Space Constraint | 1.1X1 + 1.2X2 ≤ 34 |
Contract Constraint (X1) | X1 ≥ 5 |
Non-negativity Constraint (X1) | X1 ≥ 0 |
Non-negativity Constraint (X2) | X2 ≥ 0 |
Integer Constraint (X1) | X1 is an integer |
Binding Constraint (X2) | X2 is binary |
# Functions
library(lpSolve)
- Run the integer optimisation model.
# Define parameters
objective.fn <- c(11, 22)
const.mat <- (matrix(
c(0.1, 0.2,
1.1, 1.2,
1, 0), # 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)
# Run the model
lp.solution <- lp("min", objective.fn, const.mat, const.dir, const.rhs,
int.vec = 1, binary.vec = 2, # For other questions ----- eg int.vec = c(1,2,3) / all.int = TRUE
compute.sens = FALSE)
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