1. Optmization of analitycaly defined function
As it was announced GPdotNET v2.0 has new optimization modul based on Genetic Algorithm. In fact you can perform two kind of optimization in GPdotNET.
1. Optimization of analytic defined function
2. Optimization of GPModel
In tihis tutorial it will be presented how you can optimize classic mathematic function. For example we need to optimize the following function:
, on interval ![[-1; 5]](https://s0.wp.com/latex.php?latex=%5B-1%3B+5%5D&bg=ffffff&fg=333333&s=0&c=20201002)
First lets see how this function looks like, and what is the optimum (maximum) of the function in defined interval. For this propose we are going to use WolframAlpha, great online mathematical tool. All you need to do in order to calculate optimum of our functionis just click the following link: http://www.wolframalpha.com/input/?i=maximize+x%5E3+-+6x%5E2+%2B+4x+%2B+12+inteval+-1%2C5
After we click on the link above internet explorer show the picture similar with below.
As we can see maximum value is depicted with red point, and corespond with Max(0.367; 12.7). If you dont belive just calculate
and put in to function to get
.
Now our problem is how to do that with GPdotNET v2.0.
Working with Analytic Function edito in GPdotNET
1. Open GPdotNET v2.0 and press “New” Button.
2. The following dialog box appears:

3. Every time you want to create a new Model you got this dialog to choose what kind of model you want to create. As you previously know you can create 4 diferent models, and the last one is going to be show now.
4. Choose Optimization of analytic function (the last one), and the following windows appears:

On this picture we have 3 different. 1: Area for drawing three structures, 2: command for manipulation of analytic function and 3: register of constants and variables. The combo box Function contain all available function in GPdotNET, so if you want to add one just choose from the combo box and press Add Fun button.
To define our function we need to analyze it and start inserting operation by operation. If we look the function we have 3 addition, 1 substract, 2 multiplication, cube and quadrat. So first we are going to insert 1 addition.
5. From Function Combo box choose +, and press Add Funbutton, the following picture is appear.

After we inser + function, GPdotNET is automatically added to child, because addition operation has two argument.
6. Now click on Left child node, and Add “-” function similar like picture below:

7. Also on the left leaf node Add X^3 as picture show.

8. Select left node and add “*” function like picture below.

9. Now we are going to add X1- independent variable. Press Left mouse button on leaf node below X^3 function. In Param Name enter “X1” and press Add Param button. Notice that X1 is inserted in to right ListView control as register of variables.
Rule for Entering variable: You can only add variables in the form of : X1, X2, x3 ,….. The following picture shows the result of adding variable.

10. Now select left empty node “o” and insert constant 6. It is the same procedure as inserting variable. Type 6 in parame name and oress Add Param button. The rest of the job is similar so the final result mus be similar like picure below:

11. When we finish with defining the function press Finish button, and registered variables and constants are transferred to Terminals need to make program.
Running optimization module in GPdotNET
12. After you press Finish button, select Optimize Model tab, and we are ready to star finding optimum value for our function. Before we press RUN button on the toolbar we need to define maximum and minimum values for variable X1. To do this:
13. Select X1 in listView located in Optimize Model panel, enter minimum and maximum value and then press updatebutton.Now Optimum panel is rey for running simulaton.

14- Now that we have all needed information to run program, press Optimize toolbar button. In few millisecond program is started and simulation begins. After some evolution best solution (optimum) ius found so you can stop the program if you want to by pressing STOP toolbar button.
The solution of our optimization shows below picture.It is very closed to previous one calculated by WolframAlpha.

15. Press Save toolbar button and save your work.
2. Optimization of GPModel v2.0
Optimization of GPModel begins after you find solution to yout model.
1. When you create new model, choose second option instead of first for Modelling and optimization.
2. How to perform modelling in GPdotNEt you can see in previous post.
3. After you finish modeling refer to ste 12. the procedure is the same. Definie maximum and minumu value of vaiables and press Optimize button.