Our Custom Problem

Now, create an object of the custom problem, as follows:

static Problem Problem = new CustomProblem();

The optimization settings should be as follows:

static readonly int NumRuns = 50;
static readonly int DimFactor = 4000;
static readonly int Dim = Problem.Dimensionality;
static readonly int NumIterations = DimFactor * Dim;

Create the optimizer object as follows:

static Optimizer Optimizer = new DE(Problem);

The control parameters for the optimizer should be as follows:

static readonly double[] Parameters = Optimizer.DefaultParameters;

Wrap the optimizer in a logger of result-statistics, as follows:

static readonly bool StatisticsOnlyFeasible = true;
static Statistics Statistics = new Statistics(Optimizer, StatisticsOnlyFeasible);

Wrap it again in the following repeater:

static Repeat Repeat = new RepeatSum(Statistics, NumRuns);
static void Main(string[] args)
{

Next, initialize the parallel random number generator, as follows:

Globals.Random = new RandomOps.MersenneTwister();

Then, set the maximum number of optimization iterations to perform with the following:

Problem.MaxIterations = NumIterations;

 Create a fitness trace for tracing the progress of optimization with the following code:

int NumMeanIntervals = 3000;
FitnessTrace fitnessTrace = new FitnessTraceMean(NumIterations, NumMeanIntervals);
FeasibleTrace feasibleTrace = new FeasibleTrace(NumIterations, NumMeanIntervals, fitnessTrace);

Then, assign the fitness trace to the optimizer as follows:

Optimizer.FitnessTrace = feasibleTrace;

Perform the optimizations as follows:

double fitness = Repeat.Fitness(Parameters);
if (Statistics.FeasibleFraction > 0)
{

Compute the result-statistics with the following line:

Statistics.Compute();

Output the best result, as well as result-statistics, with the following code:

Console.WriteLine("Best feasible solution found:", Color.Yellow);
Tools.PrintParameters(Problem, Statistics.BestParameters);
Console.WriteLine();
Console.WriteLine("Result Statistics:", Color.Yellow);
Console.WriteLine(" Feasible: {0} of solutions found.", Tools.FormatPercent(Statistics.FeasibleFraction), Color.Yellow);
Console.WriteLine(" Best Fitness: {0}", Tools.FormatNumber(Statistics.FitnessMin), Color.Yellow);
Console.WriteLine(" Worst: {0}", Tools.FormatNumber(Statistics.FitnessMax), Color.Yellow);
Console.WriteLine(" Mean: {0}", Tools.FormatNumber(Statistics.FitnessMean), Color.Yellow);
Console.WriteLine(" Std.Dev.: {0}", Tools.FormatNumber(Statistics.FitnessStdDev), Color.Yellow);
Console.WriteLine();
Console.WriteLine("Iterations used per run:", Color.Yellow);
Console.WriteLine(" Mean: {0}", Tools.FormatNumber(Statistics.IterationsMean), Color.Yellow);
}
else
{
Console.WriteLine("No feasible solutions found.", Color.Red);
}
}

When we run our program, it should look like the following screenshot:

The output result of our problem
..................Content has been hidden....................

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