Freefarm
      Hem
Kontakta oss
Dynamic optimization

Prologue

Picture this: You have a computer program that with fantastic accuracy can tell you what to feed your animals, both with respect to animal health and economy. So far this has been nothing but a dream, no computer program is better than the nutritional knowledge of the person using it. But perhaps that is going to change?!

Search functions

Take a look at this function:

f(x,y) = (y-x2)2 + (1-x)2

The picture below is a 3D-plot of the function.

The function is called Rosenbrock's banana function and is a classic function. Mathematicians use it to test search functions. The minimum of the function is in the point x=1, y=1 and the value is 0. Note that this is not a linear function.

Let's say that we are in a boat on a lake, looking for the deepest place. The depth of the lake is described by the banana function. Our tool is a long tape measure that we can sink down. How are we going to find the deepest place?

One way would be to divide the lake into a grid and measure in each intersection. However, if we did not make the grid fine enough, we risk missing the deepest point. Perhaps it would also take us to long. If we, in addition to that, add a third dimension like temperature as a function of f(x,y,z) where z is the depth of the lake, we would get an enormous amount of measuring points. Thus, this method seams to be inefficient

Another way would be to make continuous measurements along a strait line. At the deepest point we can make a new line 90 degrees from the first one, search along the new one, and repeat this until we find the deepest place. But, if there is two places fairly fare away from each other and not too much difference in depth, we might risk finding the second deepest place.

A third way would be to more or less randomly choose three points. The points would make a triangle. The corner of the triangle which is the deepest would probably point in the direction of the deepest place. By testing in that direction, and expand and shrink the triangle in a clever way, we should be able to rather quickly find the deepest place. This is exactly how the down-hill-simplex method works. It can be (and is) used for dynamic optimization.

The down-hill-simplex method is described in the literature, including suggestions of how to implement it in a computer program. I have used an example program from Numerical recipes as a base when working with dynamic optimization.

In the applet below (an applet is a small Java-program that runs on a home page) shows how the search function works as it step by step search for the minimum of the banana function. There is a delay built in the program so that we can follow what happens. When it reaches the minimum it makes a short pause, and then start over again.

If you can see this text, your web browser is not supporting Java. Pleas send an e-mail for help.

The figures at the top shows the value of the function f(x,y) where x and y represents the coordinates of each corner in the triangle. Finally the down-hill-simplex finds a point very near to 1,1 with the value of almost f(1,1)=0 (Note that computers write numbers close to zero as e.g. 1E-7 which corresponds to 0.00000001).

This example shows how to search for minimum in a non-linear function.

Dynamic systems

Filling a leaking bath tub is a dynamic system.

The bath tub is a system that is changing itself over time, that is it is a dynamic system. Depending on the in-flow and out-flow of water the water level will change.

In a similar way one can picture the rumen of an animal. The more of energy and protein the faster will the metabolism of micro organisms be. On the other hand, the faster the metabolism the more pH will decrease, which is inhibiting microbiological activity. In the same time, acids will flow out of the rumen, and perhaps equilibrium will be reached at some point.

Let's assume that we have the following totally fictitious dynamic system which should resemble a feeding animal. (Please ignore that this is a "corny" example, we are only going fore the principals of dynamic systems. Especially ignore that this system would be possible to treat with classic mathematic instead of numerical (computer based) methods.).

Feedstuff Nutrient A Nutrient B Price
Roughage 8 3 1
Grain 12 30 4

The animal requires 15 units of nutrient A and 25 of nutrient B. The animal absorbs 1% of the nutrients of the feed stuff per time unit. The uptake of nutrient B is positively correlated to the ratio roughage/grain. Flow-out of feedstuff from the gastro-intestinal tract follows the function e-0,1*t.

Uptake nutrient A: 0,01 * (x*8 + y*12)
Uptake nutrient B: (0.01 * (x*3 + y*30)) + 0,1*x/(x+y)
Flow out of feedstuff : e-0,1*t
x and y is than amount of roughage and grain in the gastro-intestinal tract.

No uptake is possible when there is less than 0.1 weight units left of the feed stuffs.

How much nutrients will the animal be able to absorb depending on the feed stuffs feed to the animal? The applet below illustrates this. You can test for yourself what happens if you alter the feed levels and click the OK-button. The graph is animated so that you can follow the dynamic system.

Black line = roughage
Blue line = grain
Red line = uptake nutrient A
Green line = uptake nutrient B

Please test the following settings and note the uptake of nutrient B:
Settings 1: roughage 5, grain 10
Settings 2: roughage 10, grain 10
Settings 3: roughage 5, grain 5
Settings 4: roughage 10, grain 5

When I tested this myself I got the following values of total uptake of nutrient B:
Settings 1: 34,2
Settings 2: 36,9
Increase : 2,7

Settings 3: 19,8
Settings 4: 22,8
Increase : 3

Note that the increase of 5 units of roughage did give a lager increase in uptake of nutrient B when the level of grain was 5 compared with 10.

Optimizing a dynamic system

By combining these two methods one can perform dynamic optimization.. This is of course very interesting for everyone interested in modern dynamic feeding standards for dairy cows. In a dynamic model it is not certain that the double level of grain will correspond to the double amount of nutrients absorbed. First all feedstuffs must be evaluated in relationship with all other ingredients in the ration. Only then can the total ration get a nutritional value. This means that ordinary linear methods used in e.g. Opti-kuckeliku will not work.

The key concept in dynamic optimization is to see the objective function built up by both the price and levels of different ingredients, and also the divergence of nutrient levels compared to the desired restrictions of nutrients for the animal. If a nutrient level is more or less than what we consider appropriate we add a large number to the objective function. This is how to do it:

  • Give the function a starting point (levels of feed stuffs).
  • Run the starting point through the dynamic model
  • Return the result from the model to the optimizer. Make sure the model adds a large number if some nutrient is more or less than what we want.
  • Let the optimizer decide the next point, and run it through the model again.
  • Repeat last step until the optimum is reached
The applet below is programmed to find the optimal levels of roughage and grain when the animal requires 15 units of nutrient A and 25 of nutrient B. You can if you like alter the desired values of nutrient A and B. The nutritional composition and price of roughage and grain is the same as in the example above. For demonstrational purposes the applets has a built-in delay so we can follow how the steps of the search algorithm towards optimum.

If one would like to use dynamic optimization for dairy cows and it should work under real farming conditions one would have to find out, understand and have access tot he following:

  • A proper model
  • Make sure the search function is robust
  • Make sure the programming implementation of the model is fast
  • Make a user friendly interface

I personally can't imagine any thing more fun and challenging than to answerer those questions! But seriously, why invest in dynamic optimization? The answer is that when using a liner model the result is always extreme. The user must always ask the question, can I feed this to my animals? Sometimes the calculated ration will be terrific, but the user will not dare to use it. Sometimes the result might me a disaster, but the user will not find out about before the animals do…

Dynamic optimization, on the other hand, might produce the strangest looking combinations of feedstuffs, but we can trust the results and safely feed the proposed ration to our animals and it also perhaps might be noticeable cheaper.

Written by Mattias Malmgren, date: 2003-08-26
Phone: +46 70 686 98 28
E-mail: mattias@freefarm.se