Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
03/01/10 03:01:01 (15 years ago)
Author:
swagner
Message:

Operator architecture refactoring (#95)

  • worked on algorithms, problems and parameters
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Algorithms.SGA/3.3/SGA.cs

    r2884 r2890  
    4343    private SGAOperator sgaOperator;
    4444
    45     private ValueParameter<IntData> PopulationSizeParameter {
    46       get { return (ValueParameter<IntData>)Parameters["PopulationSize"]; }
     45    private OptionalValueParameter<IntData> PopulationSizeParameter {
     46      get { return (OptionalValueParameter<IntData>)Parameters["PopulationSize"]; }
    4747    }
    4848    private ConstrainedValueParameter<ISelector> SelectorParameter {
     
    5555      get { return (ConstrainedValueParameter<IManipulator>)Parameters["Mutator"]; }
    5656    }
    57     private ValueParameter<IntData> ElitesParameter {
    58       get { return (ValueParameter<IntData>)Parameters["Elites"]; }
     57    private OptionalValueParameter<IntData> ElitesParameter {
     58      get { return (OptionalValueParameter<IntData>)Parameters["Elites"]; }
    5959    }
    6060
     
    6969    public SGA()
    7070      : base() {
    71       Parameters.Add(new ValueParameter<IntData>("Seed", "The random seed used to initialize the new pseudo random number generator.", new IntData(0)));
    72       Parameters.Add(new ValueParameter<BoolData>("SetSeedRandomly", "True if the random seed should be set to a random value, otherwise false.", new BoolData(true)));
    73       Parameters.Add(new ValueParameter<IntData>("PopulationSize", "The size of the population of solutions.", new IntData(100)));
     71      Parameters.Add(new OptionalValueParameter<IntData>("Seed", "The random seed used to initialize the new pseudo random number generator.", new IntData(0)));
     72      Parameters.Add(new OptionalValueParameter<BoolData>("SetSeedRandomly", "True if the random seed should be set to a random value, otherwise false.", new BoolData(true)));
     73      Parameters.Add(new OptionalValueParameter<IntData>("PopulationSize", "The size of the population of solutions.", new IntData(100)));
    7474      Parameters.Add(new ConstrainedValueParameter<ISelector>("Selector", "The operator used to select solutions for reproduction."));
    7575      Parameters.Add(new ConstrainedValueParameter<ICrossover>("Crossover", "The operator used to cross solutions."));
    76       Parameters.Add(new ValueParameter<DoubleData>("MutationProbability", "The probability that the mutation operator is applied on a solution.", new DoubleData(0.05)));
     76      Parameters.Add(new OptionalValueParameter<DoubleData>("MutationProbability", "The probability that the mutation operator is applied on a solution.", new DoubleData(0.05)));
    7777      Parameters.Add(new ConstrainedValueParameter<IManipulator>("Mutator", "The operator used to mutate solutions."));
    78       Parameters.Add(new ValueParameter<IntData>("Elites", "The numer of elite solutions which are kept in each generation.", new IntData(1)));
    79       Parameters.Add(new ValueParameter<IntData>("MaximumGenerations", "The maximum number of generations which should be processed.", new IntData(1000)));
     78      Parameters.Add(new OptionalValueParameter<IntData>("Elites", "The numer of elite solutions which are kept in each generation.", new IntData(1)));
     79      Parameters.Add(new OptionalValueParameter<IntData>("MaximumGenerations", "The maximum number of generations which should be processed.", new IntData(1000)));
    8080
    8181      PopulationSizeParameter.ValueChanged += new EventHandler(PopulationSizeParameter_ValueChanged);
     
    109109
    110110      var selectors = ApplicationManager.Manager.GetInstances<ISelector>().Where(x => !(x is IMultiObjectiveSelector));
    111       selectors.Select(x => x.CopySelected = new BoolData(true));
    112       selectors.Select(x => x.NumberOfSelectedSubScopesParameter.Value = new IntData(2 * (PopulationSizeParameter.Value.Value - ElitesParameter.Value.Value)));
    113       selectors.OfType<IStochasticOperator>().Select(x => x.RandomParameter.ActualName = "Random");
    114       foreach (ISelector selector in selectors)
     111      foreach (ISelector selector in selectors) {
     112        selector.CopySelected = new BoolData(true);
     113        selector.NumberOfSelectedSubScopesParameter.Value = new IntData(2 * (PopulationSizeParameter.Value.Value - ElitesParameter.Value.Value));
     114        if (selector is IStochasticOperator) ((IStochasticOperator)selector).RandomParameter.ActualName = "Random";
    115115        SelectorParameter.ValidValues.Add(selector);
     116      }
    116117    }
    117118
     
    124125
    125126    private void ElitesParameter_ValueChanged(object sender, EventArgs e) {
    126       SelectorParameter.ValidValues.Select(x => x.NumberOfSelectedSubScopesParameter.Value = new IntData(2 * (PopulationSizeParameter.Value.Value - ElitesParameter.Value.Value)));
     127      foreach (ISelector selector in SelectorParameter.ValidValues)
     128        selector.NumberOfSelectedSubScopesParameter.Value = new IntData(2 * (PopulationSizeParameter.Value.Value - ElitesParameter.Value.Value));
    127129    }
    128130    private void PopulationSizeParameter_ValueChanged(object sender, EventArgs e) {
    129       SelectorParameter.ValidValues.Select(x => x.NumberOfSelectedSubScopesParameter.Value = new IntData(2 * (PopulationSizeParameter.Value.Value - ElitesParameter.Value.Value)));
     131      foreach (ISelector selector in SelectorParameter.ValidValues)
     132        selector.NumberOfSelectedSubScopesParameter.Value = new IntData(2 * (PopulationSizeParameter.Value.Value - ElitesParameter.Value.Value));
    130133    }
    131134
     
    142145      if (Problem.SolutionCreator is IStochasticOperator) ((IStochasticOperator)Problem.SolutionCreator).RandomParameter.ActualName = "Random";
    143146      if (Problem.Evaluator is IStochasticOperator) ((IStochasticOperator)Problem.Evaluator).RandomParameter.ActualName = "Random";
    144       Problem.Operators.OfType<IStochasticOperator>().Select(x => x.RandomParameter.ActualName = "Random");
     147      foreach (IStochasticOperator op in Problem.Operators.OfType<IStochasticOperator>())
     148        op.RandomParameter.ActualName = "Random";
    145149
    146150      populationCreator.SolutionCreatorParameter.Value = Problem.SolutionCreator;
     
    150154      sgaOperator.EvaluatorParameter.Value = Problem.Evaluator;
    151155
    152       SelectorParameter.ValidValues.OfType<ISingleObjectiveSelector>().Select(x => x.MaximizationParameter.Value = Problem.Maximization);
    153       SelectorParameter.ValidValues.OfType<ISingleObjectiveSelector>().Select(x => x.QualityParameter.ActualName = Problem.Evaluator.QualityParameter.ActualName);
     156      foreach (ISingleObjectiveSelector op in SelectorParameter.ValidValues.OfType<ISingleObjectiveSelector>()) {
     157        op.MaximizationParameter.Value = Problem.Maximization;
     158        op.QualityParameter.ActualName = Problem.Evaluator.QualityParameter.ActualName;
     159      }
    154160
    155161      CrossoverParameter.ValidValues.Clear();
     
    170176    protected override void Problem_EvaluatorChanged(object sender, EventArgs e) {
    171177      if (Problem.Evaluator is IStochasticOperator) ((IStochasticOperator)Problem.Evaluator).RandomParameter.ActualName = "Random";
    172       SelectorParameter.ValidValues.OfType<ISingleObjectiveSelector>().Select(x => x.QualityParameter.ActualName = Problem.Evaluator.QualityParameter.ActualName);
     178
     179      foreach (ISingleObjectiveSelector op in SelectorParameter.ValidValues.OfType<ISingleObjectiveSelector>()) {
     180        op.QualityParameter.ActualName = Problem.Evaluator.QualityParameter.ActualName;
     181      }
     182
    173183      populationCreator.EvaluatorParameter.Value = Problem.Evaluator;
    174184      sgaOperator.QualityParameter.ActualName = Problem.Evaluator.QualityParameter.ActualName;
     
    178188    private void Problem_MaximizationChanged(object sender, EventArgs e) {
    179189      sgaOperator.MaximizationParameter.Value = Problem.Maximization;
    180       SelectorParameter.ValidValues.OfType<ISingleObjectiveSelector>().Select(x => x.MaximizationParameter.Value = Problem.Maximization);
     190      foreach (ISingleObjectiveSelector op in SelectorParameter.ValidValues.OfType<ISingleObjectiveSelector>()) {
     191        op.MaximizationParameter.Value = Problem.Maximization;
     192      }
    181193    }
    182194  }
Note: See TracChangeset for help on using the changeset viewer.