private SubScopesSorter(SubScopesSorter original, Cloner cloner)
     : base(original, cloner)
 {
 }
    public CMAEvolutionStrategy()
      : base() {
      Parameters.Add(new FixedValueParameter<IntValue>(SeedName, "The random seed used to initialize the new pseudo random number generator.", new IntValue(0)));
      Parameters.Add(new FixedValueParameter<BoolValue>(SetSeedRandomlyName, "True if the random seed should be set to a random value, otherwise false.", new BoolValue(true)));
      Parameters.Add(new FixedValueParameter<IntValue>(PopulationSizeName, "λ (lambda) - the size of the offspring population.", new IntValue(20)));
      Parameters.Add(new FixedValueParameter<IntValue>(InitialIterationsName, "The number of iterations that should be performed with only axis parallel mutation.", new IntValue(0)));
      Parameters.Add(new FixedValueParameter<DoubleArray>(InitialSigmaName, "The initial sigma can be a single value or a value for each dimension. All values need to be > 0.", new DoubleArray(new[] { 0.5 })));
      Parameters.Add(new OptionalValueParameter<IntValue>(MuName, "Optional, the mu best offspring that should be considered for update of the new mean and strategy parameters. If not given it will be automatically calculated."));
      Parameters.Add(new ConstrainedValueParameter<ICMARecombinator>(CMARecombinatorName, "The operator used to calculate the new mean."));
      Parameters.Add(new ConstrainedValueParameter<ICMAManipulator>(CMAMutatorName, "The operator used to manipulate a point."));
      Parameters.Add(new ConstrainedValueParameter<ICMAInitializer>(CMAInitializerName, "The operator that initializes the covariance matrix and strategy parameters."));
      Parameters.Add(new ConstrainedValueParameter<ICMAUpdater>(CMAUpdaterName, "The operator that updates the covariance matrix and strategy parameters."));
      Parameters.Add(new ValueParameter<MultiAnalyzer>(AnalyzerName, "The operator used to analyze each generation.", new MultiAnalyzer()));
      Parameters.Add(new FixedValueParameter<IntValue>(MaximumGenerationsName, "The maximum number of generations which should be processed.", new IntValue(1000)));
      Parameters.Add(new FixedValueParameter<IntValue>(MaximumEvaluatedSolutionsName, "The maximum number of evaluated solutions that should be computed.", new IntValue(int.MaxValue)));
      Parameters.Add(new FixedValueParameter<DoubleValue>(TargetQualityName, "(stopFitness) Surpassing this quality value terminates the algorithm.", new DoubleValue(double.NaN)));
      Parameters.Add(new FixedValueParameter<DoubleValue>(MinimumQualityChangeName, "(stopTolFun) If the range of fitness values is less than a certain value the algorithm terminates (set to 0 or positive value to enable).", new DoubleValue(double.NaN)));
      Parameters.Add(new FixedValueParameter<DoubleValue>(MinimumQualityHistoryChangeName, "(stopTolFunHist) If the range of fitness values is less than a certain value for a certain time the algorithm terminates (set to 0 or positive to enable).", new DoubleValue(double.NaN)));
      Parameters.Add(new FixedValueParameter<DoubleValue>(MinimumStandardDeviationName, "(stopTolXFactor) If the standard deviation falls below a certain value the algorithm terminates (set to 0 or positive to enable).", new DoubleValue(double.NaN)));
      Parameters.Add(new FixedValueParameter<DoubleValue>(MaximumStandardDeviationChangeName, "(stopTolUpXFactor) If the standard deviation changes by a value larger than this parameter the algorithm stops (set to a value > 0 to enable).", new DoubleValue(double.NaN)));

      var randomCreator = new RandomCreator();
      var variableCreator = new VariableCreator();
      var resultsCollector = new ResultsCollector();
      var cmaInitializer = new Placeholder();
      solutionCreator = new Placeholder();
      var subScopesCreator = new SubScopesCreator();
      var ussp1 = new UniformSubScopesProcessor();
      populationSolutionCreator = new Placeholder();
      var cmaMutator = new Placeholder();
      var ussp2 = new UniformSubScopesProcessor();
      evaluator = new Placeholder();
      var subScopesCounter = new SubScopesCounter();
      sorter = new SubScopesSorter();
      var analyzer = new Placeholder();
      var cmaRecombinator = new Placeholder();
      var generationsCounter = new IntCounter();
      var cmaUpdater = new Placeholder();
      terminator = new Terminator();

      OperatorGraph.InitialOperator = randomCreator;

      randomCreator.RandomParameter.ActualName = "Random";
      randomCreator.SeedParameter.ActualName = SeedParameter.Name;
      randomCreator.SeedParameter.Value = null;
      randomCreator.SetSeedRandomlyParameter.ActualName = SetSeedRandomlyParameter.Name;
      randomCreator.SetSeedRandomlyParameter.Value = null;
      randomCreator.Successor = variableCreator;

      variableCreator.Name = "Initialize Variables";
      variableCreator.CollectedValues.Add(new ValueParameter<IntValue>("EvaluatedSolutions", new IntValue(0)));
      variableCreator.CollectedValues.Add(new ValueParameter<IntValue>("Generations", new IntValue(0)));
      variableCreator.Successor = resultsCollector;

      resultsCollector.CollectedValues.Add(new LookupParameter<IntValue>("EvaluatedSolutions"));
      resultsCollector.CollectedValues.Add(new LookupParameter<IntValue>("Generations"));
      resultsCollector.ResultsParameter.ActualName = "Results";
      resultsCollector.Successor = cmaInitializer;

      cmaInitializer.Name = "Initialize Strategy Parameters";
      cmaInitializer.OperatorParameter.ActualName = CMAInitializerParameter.Name;
      cmaInitializer.Successor = subScopesCreator;

      subScopesCreator.NumberOfSubScopesParameter.ActualName = PopulationSizeParameter.Name;
      subScopesCreator.Successor = ussp1;

      ussp1.Name = "Create population";
      ussp1.Parallel = new BoolValue(false);
      ussp1.Operator = populationSolutionCreator;
      ussp1.Successor = solutionCreator;

      populationSolutionCreator.Name = "Initialize arx";
      // populationSolutionCreator.OperatorParameter will be wired
      populationSolutionCreator.Successor = null;

      solutionCreator.Name = "Initialize xmean";
      // solutionCreator.OperatorParameter will be wired
      solutionCreator.Successor = cmaMutator;

      cmaMutator.Name = "Sample population";
      cmaMutator.OperatorParameter.ActualName = CMAMutatorParameter.Name;
      cmaMutator.Successor = ussp2;

      ussp2.Name = "Evaluate offspring";
      ussp2.Parallel = new BoolValue(true);
      ussp2.Operator = evaluator;
      ussp2.Successor = subScopesCounter;

      evaluator.Name = "Evaluator";
      // evaluator.OperatorParameter will be wired
      evaluator.Successor = null;

      subScopesCounter.Name = "Count EvaluatedSolutions";
      subScopesCounter.AccumulateParameter.Value = new BoolValue(true);
      subScopesCounter.ValueParameter.ActualName = "EvaluatedSolutions";
      subScopesCounter.Successor = sorter;

      // sorter.ValueParameter will be wired
      // sorter.DescendingParameter will be wired
      sorter.Successor = analyzer;

      analyzer.Name = "Analyzer";
      analyzer.OperatorParameter.ActualName = AnalyzerParameter.Name;
      analyzer.Successor = cmaRecombinator;

      cmaRecombinator.Name = "Create new xmean";
      cmaRecombinator.OperatorParameter.ActualName = CMARecombinatorParameter.Name;
      cmaRecombinator.Successor = generationsCounter;

      generationsCounter.Name = "Generations++";
      generationsCounter.IncrementParameter.Value = new IntValue(1);
      generationsCounter.ValueParameter.ActualName = "Generations";
      generationsCounter.Successor = cmaUpdater;

      cmaUpdater.Name = "Update distributions";
      cmaUpdater.OperatorParameter.ActualName = CMAUpdaterParameter.Name;
      cmaUpdater.Successor = terminator;

      terminator.Continue = cmaMutator;
      terminator.Terminate = null;

      qualityAnalyzer = new BestAverageWorstQualityAnalyzer();
      cmaAnalyzer = new CMAAnalyzer();

      InitializeOperators();
      RegisterEventHandlers();
      Parameterize();
    }
    private void Initialize() {
      #region Create parameters
      Parameters.Add(new ValueLookupParameter<IRandom>("Random", "A pseudo random number generator."));
      Parameters.Add(new ValueLookupParameter<BoolValue>("Maximization", "True if the problem is a maximization problem, otherwise false."));
      Parameters.Add(new LookupParameter<DoubleValue>("Quality", "The value which represents the quality of a solution."));
      Parameters.Add(new ValueLookupParameter<DoubleValue>("BestKnownQuality", "The best known quality value found so far."));
      Parameters.Add(new LookupParameter<DoubleValue>("MoveQuality", "The value which represents the quality of a move."));
      Parameters.Add(new LookupParameter<BoolValue>("MoveTabu", "The value that indicates if a move is tabu or not."));
      Parameters.Add(new ValueLookupParameter<IntValue>("MaximumIterations", "The maximum number of generations which should be processed."));
      Parameters.Add(new ValueLookupParameter<IntValue>("TabuTenure", "The length of the tabu list, and also means the number of iterations a move is kept tabu"));

      Parameters.Add(new ValueLookupParameter<IOperator>("MoveGenerator", "The operator that generates the moves."));
      Parameters.Add(new ValueLookupParameter<IOperator>("MoveMaker", "The operator that performs a move and updates the quality."));
      Parameters.Add(new ValueLookupParameter<IOperator>("MoveEvaluator", "The operator that evaluates a move."));
      Parameters.Add(new ValueLookupParameter<IOperator>("TabuChecker", "The operator that checks whether a move is tabu."));
      Parameters.Add(new ValueLookupParameter<IOperator>("TabuMaker", "The operator that declares a move tabu."));

      Parameters.Add(new ValueLookupParameter<IOperator>("Analyzer", "The operator used to analyze the solution and moves."));
      Parameters.Add(new ValueLookupParameter<VariableCollection>("Results", "The variable collection where results should be stored."));
      Parameters.Add(new LookupParameter<IntValue>("EvaluatedMoves", "The number of evaluated moves."));
      #endregion

      #region Create operators
      VariableCreator variableCreator = new VariableCreator();
      SubScopesProcessor subScopesProcessor0 = new SubScopesProcessor();
      Assigner bestQualityInitializer = new Assigner();
      Placeholder analyzer1 = new Placeholder();
      ResultsCollector resultsCollector1 = new ResultsCollector();
      SubScopesProcessor solutionProcessor = new SubScopesProcessor();
      Placeholder moveGenerator = new Placeholder();
      UniformSubScopesProcessor moveEvaluationProcessor = new UniformSubScopesProcessor();
      Placeholder moveEvaluator = new Placeholder();
      Placeholder tabuChecker = new Placeholder();
      SubScopesCounter subScopesCounter = new SubScopesCounter();
      SubScopesSorter moveQualitySorter = new SubScopesSorter();
      TabuSelector tabuSelector = new TabuSelector();
      ConditionalBranch emptyNeighborhoodBranch1 = new ConditionalBranch();
      SubScopesProcessor moveMakingProcessor = new SubScopesProcessor();
      UniformSubScopesProcessor selectedMoveMakingProcesor = new UniformSubScopesProcessor();
      Placeholder tabuMaker = new Placeholder();
      Placeholder moveMaker = new Placeholder();
      MergingReducer mergingReducer = new MergingReducer();
      Placeholder analyzer2 = new Placeholder();
      SubScopesRemover subScopesRemover = new SubScopesRemover();
      ConditionalBranch emptyNeighborhoodBranch2 = new ConditionalBranch();
      BestQualityMemorizer bestQualityUpdater = new BestQualityMemorizer();
      IntCounter iterationsCounter = new IntCounter();
      Comparator iterationsComparator = new Comparator();
      ConditionalBranch iterationsTermination = new ConditionalBranch();

      variableCreator.CollectedValues.Add(new ValueParameter<IntValue>("Iterations", new IntValue(0))); // Class TabuSearch expects this to be called Iterations
      variableCreator.CollectedValues.Add(new ValueParameter<BoolValue>("EmptyNeighborhood", new BoolValue(false)));
      variableCreator.CollectedValues.Add(new ValueParameter<ItemList<IItem>>("TabuList", new ItemList<IItem>()));
      variableCreator.CollectedValues.Add(new ValueParameter<VariableCollection>("Memories", new VariableCollection()));
      variableCreator.CollectedValues.Add(new ValueParameter<DoubleValue>("BestQuality", new DoubleValue(0)));

      bestQualityInitializer.Name = "Initialize BestQuality";
      bestQualityInitializer.LeftSideParameter.ActualName = "BestQuality";
      bestQualityInitializer.RightSideParameter.ActualName = QualityParameter.Name;

      analyzer1.Name = "Analyzer (placeholder)";
      analyzer1.OperatorParameter.ActualName = AnalyzerParameter.Name;

      resultsCollector1.CopyValue = new BoolValue(false);
      resultsCollector1.CollectedValues.Add(new LookupParameter<IntValue>("Iterations"));
      resultsCollector1.CollectedValues.Add(new LookupParameter<DoubleValue>("Best Quality", null, "BestQuality"));
      resultsCollector1.ResultsParameter.ActualName = ResultsParameter.Name;

      moveGenerator.Name = "MoveGenerator (placeholder)";
      moveGenerator.OperatorParameter.ActualName = MoveGeneratorParameter.Name;

      moveEvaluationProcessor.Parallel = new BoolValue(true);

      moveEvaluator.Name = "MoveEvaluator (placeholder)";
      moveEvaluator.OperatorParameter.ActualName = MoveEvaluatorParameter.Name;

      tabuChecker.Name = "TabuChecker (placeholder)";
      tabuChecker.OperatorParameter.ActualName = TabuCheckerParameter.Name;

      subScopesCounter.Name = "Increment EvaluatedMoves";
      subScopesCounter.ValueParameter.ActualName = EvaluatedMovesParameter.Name;

      moveQualitySorter.DescendingParameter.ActualName = MaximizationParameter.Name;
      moveQualitySorter.ValueParameter.ActualName = MoveQualityParameter.Name;

      tabuSelector.AspirationParameter.Value = new BoolValue(true);
      tabuSelector.BestQualityParameter.ActualName = "BestQuality";
      tabuSelector.CopySelected = new BoolValue(false);
      tabuSelector.EmptyNeighborhoodParameter.ActualName = "EmptyNeighborhood";
      tabuSelector.MaximizationParameter.ActualName = MaximizationParameter.Name;
      tabuSelector.MoveQualityParameter.ActualName = MoveQualityParameter.Name;
      tabuSelector.MoveTabuParameter.ActualName = MoveTabuParameter.Name;

      moveMakingProcessor.Name = "MoveMaking processor (UniformSubScopesProcessor)";

      emptyNeighborhoodBranch1.Name = "Neighborhood empty?";
      emptyNeighborhoodBranch1.ConditionParameter.ActualName = "EmptyNeighborhood";

      tabuMaker.Name = "TabuMaker (placeholder)";
      tabuMaker.OperatorParameter.ActualName = TabuMakerParameter.Name;

      moveMaker.Name = "MoveMaker (placeholder)";
      moveMaker.OperatorParameter.ActualName = MoveMakerParameter.Name;

      analyzer2.Name = "Analyzer (placeholder)";
      analyzer2.OperatorParameter.ActualName = AnalyzerParameter.Name;

      subScopesRemover.RemoveAllSubScopes = true;

      bestQualityUpdater.Name = "Update BestQuality";
      bestQualityUpdater.MaximizationParameter.ActualName = MaximizationParameter.Name;
      bestQualityUpdater.QualityParameter.ActualName = QualityParameter.Name;
      bestQualityUpdater.BestQualityParameter.ActualName = "BestQuality";

      iterationsCounter.Name = "Iterations Counter";
      iterationsCounter.Increment = new IntValue(1);
      iterationsCounter.ValueParameter.ActualName = "Iterations";

      iterationsComparator.Name = "Iterations >= MaximumIterations";
      iterationsComparator.Comparison = new Comparison(ComparisonType.GreaterOrEqual);
      iterationsComparator.LeftSideParameter.ActualName = "Iterations";
      iterationsComparator.RightSideParameter.ActualName = MaximumIterationsParameter.Name;
      iterationsComparator.ResultParameter.ActualName = "Terminate";

      emptyNeighborhoodBranch2.Name = "Neighborhood empty?";
      emptyNeighborhoodBranch2.ConditionParameter.ActualName = "EmptyNeighborhood";

      iterationsTermination.Name = "Iterations Termination Condition";
      iterationsTermination.ConditionParameter.ActualName = "Terminate";
      #endregion

      #region Create operator graph
      OperatorGraph.InitialOperator = variableCreator;
      variableCreator.Successor = subScopesProcessor0;
      subScopesProcessor0.Operators.Add(bestQualityInitializer);
      subScopesProcessor0.Successor = resultsCollector1;
      bestQualityInitializer.Successor = analyzer1;
      analyzer1.Successor = null;
      resultsCollector1.Successor = solutionProcessor;
      solutionProcessor.Operators.Add(moveGenerator);
      solutionProcessor.Successor = iterationsCounter;
      moveGenerator.Successor = moveEvaluationProcessor;
      moveEvaluationProcessor.Operator = moveEvaluator;
      moveEvaluationProcessor.Successor = subScopesCounter;
      moveEvaluator.Successor = tabuChecker;
      tabuChecker.Successor = null;
      subScopesCounter.Successor = moveQualitySorter;
      moveQualitySorter.Successor = tabuSelector;
      tabuSelector.Successor = emptyNeighborhoodBranch1;
      emptyNeighborhoodBranch1.FalseBranch = moveMakingProcessor;
      emptyNeighborhoodBranch1.TrueBranch = null;
      emptyNeighborhoodBranch1.Successor = subScopesRemover;
      moveMakingProcessor.Operators.Add(new EmptyOperator());
      moveMakingProcessor.Operators.Add(selectedMoveMakingProcesor);
      moveMakingProcessor.Successor = mergingReducer;
      selectedMoveMakingProcesor.Operator = tabuMaker;
      selectedMoveMakingProcesor.Successor = null;
      tabuMaker.Successor = moveMaker;
      moveMaker.Successor = null;
      mergingReducer.Successor = analyzer2;
      analyzer2.Successor = null;
      subScopesRemover.Successor = null;
      iterationsCounter.Successor = iterationsComparator;
      iterationsComparator.Successor = emptyNeighborhoodBranch2;
      emptyNeighborhoodBranch2.TrueBranch = null;
      emptyNeighborhoodBranch2.FalseBranch = iterationsTermination;
      emptyNeighborhoodBranch2.Successor = null;
      iterationsTermination.TrueBranch = null;
      iterationsTermination.FalseBranch = solutionProcessor;
      #endregion
    }
 private CMAEvolutionStrategy(CMAEvolutionStrategy original, Cloner cloner)
   : base(original, cloner) {
   qualityAnalyzer = cloner.Clone(original.qualityAnalyzer);
   cmaAnalyzer = cloner.Clone(original.cmaAnalyzer);
   solutionCreator = cloner.Clone(original.solutionCreator);
   populationSolutionCreator = cloner.Clone(original.populationSolutionCreator);
   evaluator = cloner.Clone(original.evaluator);
   sorter = cloner.Clone(original.sorter);
   terminator = cloner.Clone(original.terminator);
   RegisterEventHandlers();
 }
 private SubScopesSorter(SubScopesSorter original, Cloner cloner)
   : base(original, cloner) {
 }