Base problem

The following is the base class Problem that is used in every optimization:

public abstract class Problem
{
public Problem() : this(0, true)
{
}
public Problem(int maxIterations) : this(maxIterations, true)
{
}
public Problem(int maxIterations, bool requireFeasible)
{
MaxIterations = maxIterations;
RequireFeasible = requireFeasible;
}

The maximum number of optimization iterations to perform is as follows:

public int MaxIterations

The following command checks that the solution is feasible (that it satisfies constraints):

public bool RequireFeasible

Then, the name of the optimization problem is returned with the following command:

public abstract string Name

This includes an array with the names of the parameters, as follows:

public virtual string[] ParameterName => null;

To lower the search-space boundary, use the following command:

public abstract double[] LowerBound

To increase the upper search-space boundary, use the following command:

public abstract double[] UpperBound

The lower initialization boundary, if different from the search-space boundary, is denoted as follows:

public virtual double[] LowerInit => LowerBound;

The upper initialization boundary, if different from the search-space boundary, is denoted as follows:

public virtual double[] UpperInit => UpperBound;

The following command details the maximum (that is, the worst) fitness possible, as follows:

public virtual double MaxFitness => double.MaxValue;

The following command details the minimum (that is, the best) fitness possible. This is especially important if using meta-optimization where fitness is assumed to be non-negative; this should be roughly equivalent among all the problems we meta-optimize:

public abstract double MinFitness

The threshold for an acceptable fitness value is denoted as follows:


public virtual double AcceptableFitness => MinFitness;

To return the dimensionality of the problem, that is, the number of parameters in a candidate solution, use the following command:

public abstract int Dimensionality

The following line checks if the gradient has been implemented:

public virtual bool HasGradient => false;

The following command computes and returns fitness for the given parameters:

public virtual double Fitness(double[] parameters)
{
return Fitness(parameters, true);
}

The fitness evaluation is aborted preemptively if the fitness becomes higher (that is, worse) than fitnessLimit(), or if it is not possible for the fitness to improve, as follows:

public virtual double Fitness(double[] parameters, double fitnessLimit){
return Fitness(parameters);
}

We compute and return fitness for the given parameters. The fitness evaluation is aborted preemptively if feasibility of the new candidate solution is the same as or better than that of the old candidate solution—or if the fitness becomes higher (that is, worse) than fitnessLimit() and it is not possible for the fitness to improve, as follows:

public virtual double Fitness(double[] parameters, double fitnessLimit, bool oldFeasible, bool newFeasible)
{
return Tools.BetterFeasible(oldFeasible, newFeasible)? Fitness(parameters, fitnessLimit) : Fitness(parameters);
}

Compute and return fitness for the given parameters as follows:

public virtual double Fitness(double[] parameters, bool feasible)
{
return Fitness(parameters, MaxFitness, feasible, feasible);
}

Compute the gradient of the fitness-function with the following command relating to the computation time-complexity factor. For example, if fitness takes time O(n) to compute and gradient takes time O(n*n) to compute, then return n. </returns>:

public virtual int Gradient(double[] x, ref double[] v)
{
throw new NotImplementedException();
}

Enforce constraints and evaluate feasibility with the following command. If you do not wish to enforce constraints, you should make the call Feasible():

public virtual bool EnforceConstraints(ref double[] parameters)
{

By default, we bound the candidate solution to the search-space boundaries, as follows:

Tools.Bound(ref parameters, LowerBound, UpperBound);

Since we know that the candidate solution is now within bounds and this is all that is required for feasibility, we could just return true here. As shown in the following snippet, Feasible is called for educational purposes, as most optimizers call EnforceConstraints().

return Feasible(parameters);
}

Evaluate feasibility (constraint satisfaction) with the following code:

public virtual bool Feasible(double[] parameters)
{
return Tools.BetweenBounds(parameters, LowerBound, UpperBound);
}

The following is called at the beginning of an optimization run:

public virtual void BeginOptimizationRun()

The following is called at the end of an optimization run:

public virtual void EndOptimizationRun()

To return whether optimization is allowed to continue, use the following code:

public virtual bool Continue(int iterations, double fitness, bool feasible)
{
return (iterations < MaxIterations &&!(fitness <= AcceptableFitness && (!RequireFeasible || feasible)));
}
}
..................Content has been hidden....................

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