Adding new functions

Adding new functions is a very simple process comprised of only a few steps to follow. The steps are:

  1. Create a new function based upon the signatures shown as follows
  2. Add the new function name to the GetFitnessValue function
  3. Add the new function name to the user interface

Let's now cover these steps on by one. First, we will deal with the function signature itself. The function signature is as follows:

Public double xxxxxx(double[] data)
{
}

Here, xxxxxx is the name of the function that will be displayed in the UI, as you can see in the following:

Optimization Function Window

After this, you must update the GetFitnessValue function so that it knows how to relate what is displayed on the user interface to an actual function. Here is a sample of what that function looks like. We will in fill this information later in the Let's add a new function section:

internal double GetFitnessValue(double x, double y)
{
double[] data = new double[2];
data[0] = x;
data[1] = y;

The fitnessFunction text is what appears in the user interface:

if (fitnessFunction == "Sphere")
return Swarm_Round(SphereFunction(data));
else if (fitnessFunction == "FitnessTest")
return Swarm_Round(FitnessTestFunction(data));
else if (fitnessFunction == "MSphere")
return Swarm_Round(MSphereFunction(data));
}
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset