A linear inverse blending problem
A manufacturer produces a feeding mix for pet animals.
The feed mix contains two nutritive ingredients and one ingredient (filler) to provide bulk.
One kg of feed mix must contain a minimum quantity of each of four nutrients as below:
The ingredients have the following nutrient values and cost
The problem is to find the composition of the feeding mix that minimises the production costs subject to the constraints above.
Stated otherwise: what is the optimal amount of ingredients in one kg of feeding mix?
Mathematically this can be estimated by solving a linear programming problem:
Cost (to be minimised) is given by:
equality ensures that the sum of the three fractions equals 1:
1 = x_1+x_2+x_3
inequalities enforce the nutritional constraints:
and so on
The solution is Ingredient1 (x1) = 0.5909, Ingredient2 (x2)=0.1364 and Filler (x3)=0.2727.
A list with matrix
G and vector
H that contain the inequality
conditions and with vector
Cost, defining the cost function.
G or names of
Cost are the names of the
ingredients, rownames of
G and names of
H are the nutrients.
Karline Soetaert <firstname.lastname@example.org>.
linp to solve a linear programming problem.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
# Generate the equality condition (sum of ingredients = 1) E <- rep(1, 3) F <- 1 G <- Blending$G H <- Blending$H # add positivity requirement G <- rbind(G, diag(3)) H <- c(H, rep(0, 3)) # 1. Solve the model with linear programming res <- linp(E = t(E), F = F, G = G, H = H, Cost = Blending$Cost) # show results print(c(res$X, Cost = res$solutionNorm)) dotchart(x = as.vector(res$X), labels = colnames(G), main = "Optimal blending with ranges", sub = "using linp and xranges", pch = 16, xlim = c(0, 1)) # 2. Possible ranges of the three ingredients (xr <- xranges(E, F, G, H)) segments(xr[,1], 1:ncol(G), xr[,2], 1:ncol(G)) legend ("topright", pch = c(16, NA), lty = c(NA, 1), legend = c("Minimal cost", "range")) # 3. Random sample of the three ingredients # The inequality that all x > 0 has to be added! xs <- xsample(E = E, F = F, G = G, H = H)$X pairs(xs, main = "Blending, 3000 solutions with xsample") # Cost associated to these random samples Costs <- as.vector(varsample(xs, EqA = Blending$Cost)) hist(Costs) legend("topright", c("Optimal solution", format(res$solutionNorm, digits = 3)))