Пример #1
0
 private EldersSelector(EldersSelector original, Cloner cloner)
     : base(original, cloner)
 {
 }
        private CombinedOperator CreateEldersEmigrator()
        {
            var eldersEmigrator = new CombinedOperator()
            {
                Name = "Emigrate Elders"
            };
            var selectorProsessor    = new UniformSubScopesProcessor();
            var eldersSelector       = new EldersSelector();
            var shiftToRightMigrator = new UnidirectionalRingMigrator()
            {
                Name = "Shift elders to next layer"
            };
            var mergingProsessor             = new UniformSubScopesProcessor();
            var mergingReducer               = new MergingReducer();
            var subScopesCounter             = new SubScopesCounter();
            var reduceToPopulationSizeBranch = new ConditionalBranch()
            {
                Name = "ReduceToPopulationSize?"
            };
            var countCalculator = new ExpressionCalculator()
            {
                Name = "CurrentPopulationSize = Min(CurrentPopulationSize, PopulationSize)"
            };
            var bestSelector = new BestSelector();
            var rightReducer = new RightReducer();

            eldersEmigrator.OperatorGraph.InitialOperator = selectorProsessor;

            selectorProsessor.Operator  = eldersSelector;
            selectorProsessor.Successor = shiftToRightMigrator;

            eldersSelector.AgeParameter.ActualName            = AgeParameter.Name;
            eldersSelector.AgeLimitsParameter.ActualName      = AgeLimitsParameter.Name;
            eldersSelector.NumberOfLayersParameter.ActualName = NumberOfLayersParameter.Name;
            eldersSelector.LayerParameter.ActualName          = "Layer";
            eldersSelector.Successor = null;

            shiftToRightMigrator.ClockwiseMigrationParameter.Value = new BoolValue(true);
            shiftToRightMigrator.Successor = mergingProsessor;

            mergingProsessor.Operator = mergingReducer;

            mergingReducer.Successor = subScopesCounter;

            subScopesCounter.ValueParameter.ActualName = CurrentPopulationSizeParameter.Name;
            subScopesCounter.AccumulateParameter.Value = new BoolValue(false);
            subScopesCounter.Successor = reduceToPopulationSizeBranch;

            reduceToPopulationSizeBranch.ConditionParameter.ActualName = ReduceToPopulationSizeParameter.Name;
            reduceToPopulationSizeBranch.TrueBranch = countCalculator;

            countCalculator.CollectedValues.Add(new LookupParameter <IntValue>(PopulationSizeParameter.Name));
            countCalculator.CollectedValues.Add(new LookupParameter <IntValue>(CurrentPopulationSizeParameter.Name));
            countCalculator.ExpressionParameter.Value            = new StringValue("CurrentPopulationSize PopulationSize CurrentPopulationSize PopulationSize < if toint");
            countCalculator.ExpressionResultParameter.ActualName = CurrentPopulationSizeParameter.Name;
            countCalculator.Successor = bestSelector;

            bestSelector.NumberOfSelectedSubScopesParameter.ActualName = CurrentPopulationSizeParameter.Name;
            bestSelector.CopySelected = new BoolValue(false);
            bestSelector.Successor    = rightReducer;

            return(eldersEmigrator);
        }
    private CombinedOperator CreateEldersEmigrator() {
      var eldersEmigrator = new CombinedOperator() { Name = "Emigrate Elders" };
      var selectorProsessor = new UniformSubScopesProcessor();
      var eldersSelector = new EldersSelector();
      var shiftToRightMigrator = new UnidirectionalRingMigrator() { Name = "Shift elders to next layer" };
      var mergingProsessor = new UniformSubScopesProcessor();
      var mergingReducer = new MergingReducer();
      var subScopesCounter = new SubScopesCounter();
      var reduceToPopulationSizeBranch = new ConditionalBranch() { Name = "ReduceToPopulationSize?" };
      var countCalculator = new ExpressionCalculator() { Name = "CurrentPopulationSize = Min(CurrentPopulationSize, PopulationSize)" };
      var bestSelector = new BestSelector();
      var rightReducer = new RightReducer();

      eldersEmigrator.OperatorGraph.InitialOperator = selectorProsessor;

      selectorProsessor.Operator = eldersSelector;
      selectorProsessor.Successor = shiftToRightMigrator;

      eldersSelector.AgeParameter.ActualName = AgeParameter.Name;
      eldersSelector.AgeLimitsParameter.ActualName = AgeLimitsParameter.Name;
      eldersSelector.NumberOfLayersParameter.ActualName = NumberOfLayersParameter.Name;
      eldersSelector.LayerParameter.ActualName = "Layer";
      eldersSelector.Successor = null;

      shiftToRightMigrator.ClockwiseMigrationParameter.Value = new BoolValue(true);
      shiftToRightMigrator.Successor = mergingProsessor;

      mergingProsessor.Operator = mergingReducer;

      mergingReducer.Successor = subScopesCounter;

      subScopesCounter.ValueParameter.ActualName = CurrentPopulationSizeParameter.Name;
      subScopesCounter.AccumulateParameter.Value = new BoolValue(false);
      subScopesCounter.Successor = reduceToPopulationSizeBranch;

      reduceToPopulationSizeBranch.ConditionParameter.ActualName = ReduceToPopulationSizeParameter.Name;
      reduceToPopulationSizeBranch.TrueBranch = countCalculator;

      countCalculator.CollectedValues.Add(new LookupParameter<IntValue>(PopulationSizeParameter.Name));
      countCalculator.CollectedValues.Add(new LookupParameter<IntValue>(CurrentPopulationSizeParameter.Name));
      countCalculator.ExpressionParameter.Value = new StringValue("CurrentPopulationSize PopulationSize CurrentPopulationSize PopulationSize < if toint");
      countCalculator.ExpressionResultParameter.ActualName = CurrentPopulationSizeParameter.Name;
      countCalculator.Successor = bestSelector;

      bestSelector.NumberOfSelectedSubScopesParameter.ActualName = CurrentPopulationSizeParameter.Name;
      bestSelector.CopySelected = new BoolValue(false);
      bestSelector.Successor = rightReducer;

      return eldersEmigrator;
    }
Пример #4
0
 private EldersSelector(EldersSelector original, Cloner cloner)
   : base(original, cloner) { }