Base class for one dimensional function optimizations.

Namespace:  AForge.Genetic
Assembly:  AForge.Genetic (in AForge.Genetic.dll) Version: 2.2.4.0 (2.2.4.0)

Syntax

C#
public abstract class OptimizationFunction1D : IFitnessFunction

Remarks

The class is aimed to be used for one dimensional function optimization problems. It implements all methods of IFitnessFunction interface and requires overriding only one method - OptimizationFunction(Double), which represents the function to optimize.

Note:The optimization function should be greater than 0 on the specified optimization range.

The class works only with binary chromosomes (BinaryChromosome).

Sample usage:

CopyC#
// define optimization function
public class UserFunction : OptimizationFunction1D
{
       public UserFunction( ) :
        base( new Range( 0, 255 ) ) { }

    public override double OptimizationFunction( double x )
       {
           return Math.Cos( x / 23 ) * Math.Sin( x / 50 ) + 2;
       }
}
...
// create genetic population
Population population = new Population( 40,
       new BinaryChromosome( 32 ),
       new UserFunction( ),
       new EliteSelection( ) );

while ( true )
{
       // run one epoch of the population
    population.RunEpoch( );
    // ...
}

Inheritance Hierarchy

System..::.Object
  AForge.Genetic..::.OptimizationFunction1D

See Also