# Blending: A linear inverse blending problem In limSolve: Solving Linear Inverse Models

## Description

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 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(∑ {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.

## Usage

 `1` ```Blending ```

## Format

A list with matrix `G` and vector `H` that contain the inequality conditions and with vector `Cost`, defining the cost function.

Columnnames of `G` or names of `Cost` are the names of the ingredients, rownames of `G` and names of `H` are the nutrients.

## Author(s)

Karline Soetaert <[email protected]>.

`linp` to solve a linear programming problem.

## Examples

 ``` 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))) ```

### Example output

```Ingredient1 Ingredient2      Filler        Cost
0.5909091   0.1363636   0.2727273  31.8181818
min       max
Ingredient1 0.5 1.0000000
Ingredient2 0.0 0.5000000
Filler      0.0 0.2727273
Warning message:
In lsei(E = E, F = F, G = G, H = H) : No equalities - setting type = 2
```

limSolve documentation built on Aug. 14, 2017, 5:06 p.m.