public override bool EvaluateLogic() { var from = FirstChild.EvaluateLogic(); var to = SecondChild.EvaluateLogic(); return(from == to ? from : Random.NextBool()); }
public override double EvaluateNumber() { var from = FirstChild.EvaluateNumber(); var to = SecondChild.EvaluateNumber(); return(from + Random.NextDouble() * (to - from)); }
public override IEnumerable <IFormulaToken> Tokenize() { return(Enumerable.Repeat(CreateToken(), 1) .Concat(Enumerable.Repeat(FormulaTokenFactory.CreateParenthesisToken(true), 1)) .Concat(FirstChild == null ? FormulaTokenizer.EmptyChild : FirstChild.Tokenize()) .Concat(Enumerable.Repeat(FormulaTokenFactory.CreateParameterSeparatorToken(), 1)) .Concat(SecondChild == null ? FormulaTokenizer.EmptyChild : SecondChild.Tokenize()) .Concat(Enumerable.Repeat(FormulaTokenFactory.CreateParenthesisToken(false), 1))); }
public override Placement Clone() { return(new WindowPlacement { Position = Position, Size = Size, State = State, FirstChild = FirstChild?.Clone(), SecondChild = SecondChild?.Clone(), }); }
protected bool IsNumberT2L() { // TODO: meaningful (translated?) error message var t = FirstChild.IsNumber(); if (!SecondChild.IsNumber() == t) { throw new SemanticsErrorException(this, "Children are different"); } return(false); }
public static void test_multiple_child_classes() { FirstChild obj = new FirstChild(); Test.AssertEquals(1, obj.receivedValue); SecondChild obj2 = new SecondChild(); Test.AssertEquals(2, obj2.receivedValue); obj = new FirstChild(); Test.AssertEquals(1, obj.receivedValue); }
protected bool IsNumberN2N() { // TODO: meaningful (translated?) error message if (!FirstChild.IsNumber()) { throw new SemanticsErrorException(this, "First child must be number"); } if (!SecondChild.IsNumber()) { throw new SemanticsErrorException(this, "Second child must be number"); } return(true); }
public static void Execute() { //Employee partTime = new ParttimeEmployee("Athar"); //partTime.DisplayName(); //FulltimeEmployee fullTime = new FulltimeEmployee("Imam"); //fullTime.DisplayName(); BaseClass bc = new SecondChild(); Console.WriteLine("BaseClass bc = new SecondChild(): " + bc.GetMethod()); DerivedClass dc = new SecondChild(); Console.WriteLine("DerivedClass dc = new SecondChild(): " + dc.GetMethod()); SecondChild sc = new SecondChild(); Console.WriteLine("SecondChild sc = new SecondChild(): " + sc.GetMethod()); }
public override void Append(StringBuilder sb) { sb.Append(Serialize()); sb.Append("("); if (FirstChild == null) { sb.Append(FormulaSerializer.EmptyChild); } else { FirstChild.Append(sb); } sb.Append(", "); if (SecondChild == null) { sb.Append(FormulaSerializer.EmptyChild); } else { SecondChild.Append(sb); } sb.Append(")"); }
protected internal override XmlFormulaTree ToXmlObject2() { return(ToXml( firstChild: FirstChild == null ? null : FirstChild.ToXmlObject2(), secondChild: SecondChild == null ? null : SecondChild.ToXmlObject2())); }
public static Report Calculate( int n, List <int> a, List <int> b, int B, SelectionType selectionType, LocalOptimization optimization, int numberOfIterations = 10, int populationSize = 15) { if (numberOfIterations < 3) { numberOfIterations = 3; } NumberOfGenes = populationSize; RecordsForMax = new List <int>(); int iterationsForMax = 0, recordForMax = int.MinValue; CreatePopulation(n, a, b, B); do { switch (selectionType) { case SelectionType.Tournament: MakeTournamentSelectionForMax(); break; case SelectionType.FullyRandom: MakeFullyRandomSelection(); break; case SelectionType.PartlyRandom: MakeSelectionWithMaxAndRandom(); break; case SelectionType.OutBreeding: MakeOutBreedingSelection(); break; } FirstChild = Gene.Recombinate(FirstParent.Chromosomes, SecondParent.Chromosomes, n); SecondChild = Gene.Recombinate(FirstParent.Chromosomes, SecondParent.Chromosomes, n); FirstChild.Mutate(a, b); SecondChild.Mutate(a, b); FirstChild.Reanimate(a, b, B); SecondChild.Reanimate(a, b, B); switch (optimization) { case LocalOptimization.Optimize: FirstChild.OptimizeForMax(a, b, B); SecondChild.OptimizeForMax(a, b, B); break; } UpdatePopulationForMax(); if (recordForMax < Population[GetIndexOfMaxGen()].Fitness) { recordForMax = Population[GetIndexOfMaxGen()].Fitness; } RecordsForMax.Add(recordForMax); } while (!isReadyToStop(RecordsForMax, ++iterationsForMax, numberOfIterations)); CreatePopulation(n, a, b, B); RecordsForMin = new List <int>(); int recordForMin = int.MaxValue, iterationsForMin = 0; do { switch (selectionType) { case SelectionType.Tournament: MakeTournamentSelectionForMin(); break; case SelectionType.FullyRandom: MakeFullyRandomSelection(); break; case SelectionType.PartlyRandom: MakeSelectionWithMinAndRandom(); break; case SelectionType.OutBreeding: MakeOutBreedingSelection(); break; } FirstChild = Gene.Recombinate(FirstParent.Chromosomes, SecondParent.Chromosomes, n); SecondChild = Gene.Recombinate(FirstParent.Chromosomes, SecondParent.Chromosomes, n); FirstChild.Mutate(a, b); SecondChild.Mutate(a, b); FirstChild.Reanimate(a, b, B); SecondChild.Reanimate(a, b, B); switch (optimization) { case LocalOptimization.Optimize: FirstChild.OptimizeForMin(a, b, B); SecondChild.OptimizeForMin(a, b, B); break; } UpdatePopulationForMin(); if (recordForMin > Population[GetIndexOfMinGen()].Fitness) { recordForMin = Population[GetIndexOfMinGen()].Fitness; } RecordsForMin.Add(recordForMin); } while (!isReadyToStop(RecordsForMin, ++iterationsForMin, numberOfIterations)); return(new Report( (recordForMax, iterationsForMax, RecordsForMax), (recordForMin, iterationsForMin, RecordsForMin))); }
static void Main(string[] args) { SecondChild c = new SecondChild(); Console.ReadLine(); }
public override double EvaluateNumber() { return(Math.Max(FirstChild.EvaluateNumber(), SecondChild.EvaluateNumber())); }