Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

1. Objective: Class Template and STL A) The code sample provided will feature tw

ID: 3835508 • Letter: 1

Question

1. Objective: Class Template and STL

A) The code sample provided will feature two classes E1 and E2, and their base class EBase. Two additional classes provided, C1 and C2, will wrap a STL container (already a template) and also have additional methods, which capture some workflow as a template.  C1 and C2 will store E1 and E2 types of objects in their respective STL stores. We observe that the code in C1 and C2 is identical, and only the type on which they operate is different – either E1 or E2. It is therefore a good candidate for a class template. Your assignment will be to write a class CT as a template that replaces C1 and C2.   [ same number of lines of code as in C1 or C2]

Summary and take away: The purpose is to arrive at a template class that captures a sample workflow in a given problem domain and can operate on multiple data types. It will be designed as a wrapper around a STL container, which already is a template, where multiple data types can be plugged in, such as E1 or E2. A general constraint for a template, however, is that the types are indeed pluggable, that is: they will have all the features (methods and operators, natural ones or overloaded), needed for the template logic to run properly. We can have those checks enforced by having an EBase class capturing all those common methods and operators. In addition, the class hierarchy will enable polymorphic overridden methods, so our high level workflow can be customized, depending on which type, E1 or E2, is plugged in.

Notice, that at the end of day, only a templated CT will be needed. It will capture the high level process flow as its algorithm, but also offer specialized logic through polymorphism. This sophisticated set up becomes a design pattern.

B) Then, in main, stand up the instances CT1 and CT2 of type CT, holding E1 and E2 types respectively. [ 2 lines of code]

2.

Objective: Generic Algorithms

A) This part will add an additional method to both C1 and C2, and also to CT. The method will wrap one of the Generic Algorithms, find or search - the signature will be provided, or can be looked up at cplusplus.com. As you recall, Generic Algorithms rely on the Iterator concept, but often only implicitly by making use of being() and end() methods attached to the container they operate on. [3-5 lines of code to write in C1 and C2]

B) Add a matching method to CT class template [3-5 lines of code in CT]

C) The success of the Generic Algorithm find depends on what operation being present in the objects held in the container? What about search?

D) Extra credit: Write code for this operation. (Hint: this code can live in the base class EBase)

Please put the code with the respective question. Thank you!

Explanation / Answer

utilizing System;
utilizing GAF;
utilizing GAF.Operators;
namespace BinaryF6
{
inward class Program
{
private static void Main(string[] args)
{
const twofold crossoverProbability = 0.65;
const twofold mutationProbability = 0.08;
const int elitismPercentage = 5;
/make the populace
var populace = new Population(100, 44, false, false);
/make the hereditary administrators
var first class = new Elite(elitismPercentage);
var hybrid = new Crossover(crossoverProbability, genuine)
{
CrossoverType = CrossoverType.SinglePoint
};
var transformation = new BinaryMutate(mutationProbability, genuine);
/make the GA itself
var ga = new GeneticAlgorithm(population, EvaluateFitness);
/subscribe to the GAs Generation Complete occasion
ga.OnGenerationComplete += ga_OnGenerationComplete;
/add the administrators to the ga procedure pipeline
ga.Operators.Add(elite);
ga.Operators.Add(crossover);
ga.Operators.Add(mutation);
/run the GA
ga.Run(TerminateAlgorithm);
}
}
}
The wellness capacity can be called anything besides ought to have this mark. This capacity just disentangles the chromosome, figures the double F6 and perceives how great the separate chromosome is before giving back its 'wellness'.
Stow away Shrink Copy Code
open static twofold EvaluateFitness(Chromosome chromosome)
{
twofold fitnessValue = - 1;
in the event that (chromosome != invalid)
{
/this is a range consistent that is utilized to keep the x/y go between - 100 and +100
var rangeConst = 200/(System.Math.Pow(2, chromosome.Count/2) - 1);
/get x and y from the arrangement
var x1 = Convert.ToInt32(chromosome.ToBinaryString(0, chromosome.Count/2), 2);
var y1 = Convert.ToInt32(chromosome.ToBinaryString
(chromosome.Count/2, chromosome.Count/2), 2);
/Adjust range to - 100 to +100
var x = (x1 * rangeConst) - 100;
var y = (y1 * rangeConst) - 100;
/utilizing parallel F6 for wellness.
var temp1 = System.Math.Sin(System.Math.Sqrt(x * x + y * y));
var temp2 = 1 + 0.001 * (x * x + y * y);
var result = 0.5 + (temp1 * temp1 - 0.5)/(temp2 * temp2);
fitnessValue = 1 - result;
}
else
{
/chromosome is invalid
toss new ArgumentNullException("chromosome",
"The predetermined Chromosome is null.");
}
return fitnessValue;
}