LIMBlending {LIM} | R Documentation |
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:
Nutrient | A | B | C | D | |
gram | 80 | 50 | 25 | 5 |
The ingredients have the following nutrient values and cost
(gram/kg) | A | B | C | D | Cost/kg | |
Ingredient 1 | 100 | 50 | 40 | 10 | 40 | |
Ingredient 2 | 200 | 150 | 10 | - | 60 | |
Filler | - | - | - | - | 0 |
The linear inverse models LIMBlending and LIMinputBlending are generated from the file Blending.input which can be found in subdirectory /examples/LinearProg of the packages directory
LIMBlending is generated by function Setup
LIMinputBlending is generated by function Read
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:
min(sum {Cost_i*x_i})
subject to
x_i>=0
Ex=f
Gx>=h
Where the Cost
(to be minimised) is given by:
x_1*40+x_2*60
The equality
ensures that the sum of the three fractions equals 1:
1 = x_1+x_2+x_3
And the inequalities
enforce the nutritional constraints:
100*x_1+200*x_2>80
50*x_1+150*x_2>50
and so on
The solution is Ingredient1 (x1) = 0.5909, Ingredient2 (x2)=0.1364 and Filler (x3)=0.2727.
LIMBlending LIMinputBlending
LIMBlending is of type lim
, which is a list of matrices, vectors, names and values that specify the linear inverse model problem.
see the return value of Setup
for more information about this list
LIMinputBlending is of type liminput
, see the return value of Read
for more information.
A more complete description of these structures is in vignette("LIM")
Karline Soetaert <k.soetaert@nioo.knaw.nl>
LIMTakapoto
, LIMEcoli
and many others
# 1. Solve the model with linear programming res <- Linp(LIMBlending,ispos=TRUE) # show results print(c(res$X,Cost = res$solutionNorm)) # 2. Possible ranges of the three ingredients (xr<-Xranges(LIMBlending,ispos=TRUE)) Nx <- LIMBlending$NUnknowns # plot dotchart(x=as.vector(res$X),xlim=range(xr),labels=LIMBlending$Unknowns, main="Optimal blending with ranges", sub="using linp and xranges",pch=16) segments(xr[,1],1:Nx,xr[,2],1:Nx) 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! blend <- LIMBlending blend$G <- rbind(blend$G,diag(3)) blend$H <- c(blend$H,rep(0,3)) xs <- Xsample(blend) pairs(xs,main="Blending, 3000 solutions with xsample")