Free cookie consent management tool by TermsFeed Policy Generator

Changeset 2890


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

Operator architecture refactoring (#95)

  • worked on algorithms, problems and parameters
Location:
trunk/sources
Files:
10 edited
1 moved

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  }
  • trunk/sources/HeuristicLab.Algorithms.SGA/3.3/SGAOperator.cs

    r2884 r2890  
    2525using HeuristicLab.Operators;
    2626using HeuristicLab.Parameters;
    27 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    2827using HeuristicLab.Selection;
    2928
  • trunk/sources/HeuristicLab.Operators/3.3/Comparator.cs

    r2834 r2890  
    4040      get { return (ValueLookupParameter<IItem>)Parameters["RightSide"]; }
    4141    }
    42     private ValueParameter<ComparisonData> ComparisonParameter {
    43       get { return (ValueParameter<ComparisonData>)Parameters["Comparison"]; }
     42    private OptionalValueParameter<ComparisonData> ComparisonParameter {
     43      get { return (OptionalValueParameter<ComparisonData>)Parameters["Comparison"]; }
    4444    }
    4545    public LookupParameter<BoolData> ResultParameter {
     
    5555      Parameters.Add(new LookupParameter<IItem>("LeftSide", "The left side of the comparison."));
    5656      Parameters.Add(new ValueLookupParameter<IItem>("RightSide", "The right side of the comparison."));
    57       Parameters.Add(new ValueParameter<ComparisonData>("Comparison", "The type of comparison.", new ComparisonData()));
     57      Parameters.Add(new OptionalValueParameter<ComparisonData>("Comparison", "The type of comparison.", new ComparisonData()));
    5858      Parameters.Add(new LookupParameter<BoolData>("Result", "The result of the comparison."));
    5959    }
  • trunk/sources/HeuristicLab.Operators/3.3/SubScopesRemover.cs

    r2834 r2890  
    3333  [Creatable("Test")]
    3434  public sealed class SubScopesRemover : SingleSuccessorOperator {
    35     private ValueParameter<BoolData> RemoveAllSubScopesParameter {
    36       get { return (ValueParameter<BoolData>)Parameters["RemoveAllSubScopes"]; }
     35    private OptionalValueParameter<BoolData> RemoveAllSubScopesParameter {
     36      get { return (OptionalValueParameter<BoolData>)Parameters["RemoveAllSubScopes"]; }
    3737    }
    3838    public ValueLookupParameter<IntData> SubScopeIndexParameter {
     
    5353    public SubScopesRemover()
    5454      : base() {
    55       Parameters.Add(new ValueParameter<BoolData>("RemoveAllSubScopes", "True if all sub-scopes of the current scope should be removed, otherwise false.", new BoolData(true)));
     55      Parameters.Add(new OptionalValueParameter<BoolData>("RemoveAllSubScopes", "True if all sub-scopes of the current scope should be removed, otherwise false.", new BoolData(true)));
    5656      Parameters.Add(new ValueLookupParameter<IntData>("SubScopeIndex", "The index of the sub-scope which should be removed. This parameter is ignored, if RemoveAllSubScopes is true."));
    5757      Parameters.Add(new ScopeParameter("CurrentScope", "The current scope from which one or all sub-scopes should be removed."));
  • trunk/sources/HeuristicLab.Parameters.Views/3.3/ValueParameterView.cs

    r2870 r2890  
    3030  /// The visual representation of a <see cref="Parameter"/>.
    3131  /// </summary>
    32   [Content(typeof(ValueParameter<>), true)]
     32  [Content(typeof(OptionalValueParameter<>), true)]
    3333  [Content(typeof(IValueParameter<>), false)]
    3434  public partial class ValueParameterView<T> : ParameterView where T : class, IItem {
  • trunk/sources/HeuristicLab.Parameters/3.3/HeuristicLab.Parameters-3.3.csproj

    r2852 r2890  
    6969    <Compile Include="ConstrainedValueParameter.cs" />
    7070    <Compile Include="LookupParameter.cs" />
     71    <Compile Include="OptionalValueParameter.cs" />
    7172    <Compile Include="SubScopesLookupParameter.cs" />
    7273    <Compile Include="ValueLookupParameter.cs" />
    73     <Compile Include="ValueParameter.cs" />
    7474    <Compile Include="ScopeParameter.cs" />
    7575    <Compile Include="HeuristicLabParametersPlugin.cs" />
  • trunk/sources/HeuristicLab.Parameters/3.3/OperatorParameter.cs

    r2818 r2890  
    3030  [EmptyStorableClass]
    3131  [Creatable("Test")]
    32   public class OperatorParameter : ValueParameter<IOperator> {
     32  public class OperatorParameter : OptionalValueParameter<IOperator> {
    3333    public OperatorParameter()
    3434      : base("Anonymous") {
  • trunk/sources/HeuristicLab.Parameters/3.3/OptionalValueParameter.cs

    r2889 r2890  
    2727namespace HeuristicLab.Parameters {
    2828  /// <summary>
    29   /// A parameter whose value is defined it the parameter itself.
     29  /// A parameter whose value is defined it the parameter itself. The value of the parameter can be null, if the parameter is not set.
    3030  /// </summary>
    31   [Item("ValueParameter<T>", "A parameter whose value is defined it the parameter itself.")]
    32   public class ValueParameter<T> : Parameter, IValueParameter<T> where T : class, IItem {
     31  [Item("OptionalValueParameter<T>", "A parameter whose value is defined it the parameter itself. The value of the parameter can be null, if the parameter is not set.")]
     32  public class OptionalValueParameter<T> : Parameter, IValueParameter<T> where T : class, IItem {
    3333    private T value;
    3434    [Storable]
     
    5757    }
    5858
    59     public ValueParameter()
     59    public OptionalValueParameter()
    6060      : base("Anonymous", typeof(T)) {
    6161    }
    62     public ValueParameter(string name)
     62    public OptionalValueParameter(string name)
    6363      : base(name, typeof(T)) {
    6464    }
    65     public ValueParameter(string name, T value)
     65    public OptionalValueParameter(string name, T value)
    6666      : base(name, typeof(T)) {
    6767      Value = value;
    6868    }
    69     public ValueParameter(string name, string description)
     69    public OptionalValueParameter(string name, string description)
    7070      : base(name, description, typeof(T)) {
    7171    }
    72     public ValueParameter(string name, string description, T value)
     72    public OptionalValueParameter(string name, string description, T value)
    7373      : base(name, description, typeof(T)) {
    7474      Value = value;
     
    7676
    7777    public override IDeepCloneable Clone(Cloner cloner) {
    78       ValueParameter<T> clone = (ValueParameter<T>)base.Clone(cloner);
     78      OptionalValueParameter<T> clone = (OptionalValueParameter<T>)base.Clone(cloner);
    7979      clone.Value = (T)cloner.Clone(value);
    8080      return clone;
  • trunk/sources/HeuristicLab.Problems.TSP/3.3/TSP.cs

    r2883 r2890  
    7575    public TSP()
    7676      : base() {
    77       ValueParameter<BoolData> maximizationParameter = new ValueParameter<BoolData>("Maximization", "Set to false as the Traveling Salesman Problem is a minimization problem.", new BoolData(false));
    78       maximizationParameter.ValueChanged += new EventHandler(MaximizationParameter_ValueChanged);
    79       Parameters.Add(maximizationParameter);
     77      Parameters.Add(new OptionalValueParameter<BoolData>("Maximization", "Set to false as the Traveling Salesman Problem is a minimization problem.", new BoolData(false)));
     78      Parameters.Add(new OptionalValueParameter<DoubleMatrixData>("Coordinates", "The x- and y-Coordinates of the cities.", new DoubleMatrixData(0, 0)));
     79      Parameters.Add(new OptionalValueParameter<IPermutationCreator>("SolutionCreator", "The operator which should be used to create new TSP solutions."));
     80      Parameters.Add(new OptionalValueParameter<ITSPEvaluator>("Evaluator", "The operator which should be used to evaluate TSP solutions."));
     81      Parameters.Add(new OptionalValueParameter<DoubleData>("BestKnownQuality", "The quality of the best known solution of this TSP instance."));
    8082
    81       Parameters.Add(new ValueParameter<DoubleMatrixData>("Coordinates", "The x- and y-Coordinates of the cities.", new DoubleMatrixData(0, 0)));
    82 
    83       ValueParameter<IPermutationCreator> solutionCreatorParameter = new ValueParameter<IPermutationCreator>("SolutionCreator", "The operator which should be used to create new TSP solutions.");
    84       solutionCreatorParameter.ValueChanged += new EventHandler(SolutionCreatorParameter_ValueChanged);
    85       Parameters.Add(solutionCreatorParameter);
    86 
    87       ValueParameter<ITSPEvaluator> evaluatorParameter = new ValueParameter<ITSPEvaluator>("Evaluator", "The operator which should be used to evaluate TSP solutions.");
    88       evaluatorParameter.ValueChanged += new EventHandler(EvaluatorParameter_ValueChanged);
    89       Parameters.Add(evaluatorParameter);
    90 
    91       Parameters.Add(new ValueParameter<DoubleData>("BestKnownQuality", "The quality of the best known solution of this TSP instance."));
     83      MaximizationParameter.ValueChanged += new EventHandler(MaximizationParameter_ValueChanged);
     84      SolutionCreatorParameter.ValueChanged += new EventHandler(SolutionCreatorParameter_ValueChanged);
     85      EvaluatorParameter.ValueChanged += new EventHandler(EvaluatorParameter_ValueChanged);
    9286
    9387      RandomPermutationCreator creator = new RandomPermutationCreator();
     
    10195      EvaluatorParameter.Value = evaluator;
    10296
    103       var ops = ApplicationManager.Manager.GetInstances<IPermutationOperator>().ToList();
    104       ops.ForEach(x => {
    105         IPermutationCrossover y = x as IPermutationCrossover;
    106         if (y != null) {
    107           y.ParentsParameter.ActualName = creator.PermutationParameter.ActualName;
    108           y.ChildParameter.ActualName = creator.PermutationParameter.ActualName;
    109         }
    110       });
    111       ops.ForEach(x => {
    112         IPermutationManipulator y = x as IPermutationManipulator;
    113         if (y != null)
    114           y.PermutationParameter.ActualName = creator.PermutationParameter.ActualName;
    115       });
     97      var ops = ApplicationManager.Manager.GetInstances<IPermutationOperator>();
     98      foreach (IPermutationCrossover op in ops.OfType<IPermutationCrossover>()) {
     99        op.ParentsParameter.ActualName = creator.PermutationParameter.ActualName;
     100        op.ChildParameter.ActualName = creator.PermutationParameter.ActualName;
     101      }
     102      foreach (IPermutationManipulator op in ops.OfType<IPermutationManipulator>()) {
     103        op.PermutationParameter.ActualName = creator.PermutationParameter.ActualName;
     104      }
    116105      operators = new OperatorSet(ops.Cast<IOperator>());
    117106    }
  • trunk/sources/HeuristicLab.Selection/3.3/ProportionalSelector.cs

    r2830 r2890  
    3636  [Creatable("Test")]
    3737  public sealed class ProportionalSelector : StochasticSingleObjectiveSelector {
    38     private ValueParameter<BoolData> WindowingParameter {
    39       get { return (ValueParameter<BoolData>)Parameters["Windowing"]; }
     38    private OptionalValueParameter<BoolData> WindowingParameter {
     39      get { return (OptionalValueParameter<BoolData>)Parameters["Windowing"]; }
    4040    }
    4141
     
    4747    public ProportionalSelector()
    4848      : base() {
    49       Parameters.Add(new ValueParameter<BoolData>("Windowing", "Apply windowing strategy (selection probability is proportional to the quality differences and not to the total quality).", new BoolData(true)));
     49      Parameters.Add(new OptionalValueParameter<BoolData>("Windowing", "Apply windowing strategy (selection probability is proportional to the quality differences and not to the total quality).", new BoolData(true)));
    5050      CopySelected.Value = true;
    5151    }
  • trunk/sources/HeuristicLab.Selection/3.3/Selector.cs

    r2882 r2890  
    3535  [EmptyStorableClass]
    3636  public abstract class Selector : SingleSuccessorOperator, ISelector {
    37     protected ValueParameter<BoolData> CopySelectedParameter {
    38       get { return (ValueParameter<BoolData>)Parameters["CopySelected"]; }
     37    protected OptionalValueParameter<BoolData> CopySelectedParameter {
     38      get { return (OptionalValueParameter<BoolData>)Parameters["CopySelected"]; }
    3939    }
    4040    public IValueLookupParameter<IntData> NumberOfSelectedSubScopesParameter {
     
    5555    protected Selector()
    5656      : base() {
    57       Parameters.Add(new ValueParameter<BoolData>("CopySelected", "True if the selected sub-scopes should be copied, otherwise false.", new BoolData(false)));
     57      Parameters.Add(new OptionalValueParameter<BoolData>("CopySelected", "True if the selected sub-scopes should be copied, otherwise false.", new BoolData(false)));
    5858      Parameters.Add(new ValueLookupParameter<IntData>("NumberOfSelectedSubScopes", "The number of sub-scopes which should be selected."));
    5959      Parameters.Add(new ScopeParameter("CurrentScope", "The current scope from which sub-scopes should be selected."));
Note: See TracChangeset for help on using the changeset viewer.