Changeset 2924


Ignore:
Timestamp:
03/04/10 04:52:28 (12 years ago)
Author:
swagner
Message:

Operator architecture refactoring (#95)

  • implemented reviewers' comments on version r2917.
Location:
trunk/sources
Files:
3 added
36 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab 3.3.sln

    r2914 r2924  
    5959    {1849A92E-DCFC-4E05-BB0A-D7B7A3DAFCFB} = {1849A92E-DCFC-4E05-BB0A-D7B7A3DAFCFB}
    6060    {0E27A536-1C4A-4624-A65E-DC4F4F23E3E1} = {0E27A536-1C4A-4624-A65E-DC4F4F23E3E1}
     61    {446C4F3D-1A12-465A-9128-97D0F47140C9} = {446C4F3D-1A12-465A-9128-97D0F47140C9}
    6162    {678E2145-8152-4E19-9646-07D439D00301} = {678E2145-8152-4E19-9646-07D439D00301}
    6263    {BB994448-2B21-4564-BB2E-38D8FFF8CF18} = {BB994448-2B21-4564-BB2E-38D8FFF8CF18}
  • trunk/sources/HeuristicLab.Algorithms.SGA/3.3/SGA.cs

    r2917 r2924  
    5252      get { return (ConstrainedValueParameter<ICrossover>)Parameters["Crossover"]; }
    5353    }
    54     private ConstrainedValueParameter<IManipulator> MutatorParameter {
    55       get { return (ConstrainedValueParameter<IManipulator>)Parameters["Mutator"]; }
     54    private OptionalConstrainedValueParameter<IManipulator> MutatorParameter {
     55      get { return (OptionalConstrainedValueParameter<IManipulator>)Parameters["Mutator"]; }
    5656    }
    5757    private ValueParameter<IntData> ElitesParameter {
     
    7575      Parameters.Add(new ConstrainedValueParameter<ICrossover>("Crossover", "The operator used to cross solutions."));
    7676      Parameters.Add(new ValueParameter<DoubleData>("MutationProbability", "The probability that the mutation operator is applied on a solution.", new DoubleData(0.05)));
    77       Parameters.Add(new ConstrainedValueParameter<IManipulator>("Mutator", "The operator used to mutate solutions."));
     77      Parameters.Add(new OptionalConstrainedValueParameter<IManipulator>("Mutator", "The operator used to mutate solutions."));
    7878      Parameters.Add(new ValueParameter<IntData>("Elites", "The numer of elite solutions which are kept in each generation.", new IntData(1)));
    7979      Parameters.Add(new ValueParameter<IntData>("MaximumGenerations", "The maximum number of generations which should be processed.", new IntData(1000)));
  • trunk/sources/HeuristicLab.Algorithms.SGA/3.3/SGAOperator.cs

    r2908 r2924  
    9797      #region Create operator graph
    9898      VariableCreator variableCreator = new VariableCreator();
    99       ResultsCollector resultsCollector1 = new ResultsCollector();
     99      ResultsCollector resultsCollector = new ResultsCollector();
    100100      SubScopesSorter subScopesSorter1 = new SubScopesSorter();
    101101      Placeholder selector = new Placeholder();
     
    116116      Comparator comparator = new Comparator();
    117117      BestAverageWorstQualityCalculator bestAverageWorstQualityCalculator = new BestAverageWorstQualityCalculator();
    118       ResultsCollector resultsCollector2 = new ResultsCollector();
    119118      DataTableValuesCollector dataTableValuesCollector = new DataTableValuesCollector();
    120119      ConditionalBranch conditionalBranch = new ConditionalBranch();
     
    122121      OperatorGraph.InitialOperator = variableCreator;
    123122
     123      variableCreator.CollectedValues.Add(new ValueParameter<IntData>("Generations", new IntData(0)));
     124      variableCreator.CollectedValues.Add(new ValueParameter<DoubleData>("Best Quality", new DoubleData(0)));
     125      variableCreator.CollectedValues.Add(new ValueParameter<DoubleData>("Average Quality", new DoubleData(0)));
     126      variableCreator.CollectedValues.Add(new ValueParameter<DoubleData>("Worst Quality", new DoubleData(0)));
    124127      variableCreator.CollectedValues.Add(new ValueParameter<DataTable>("Qualities", new DataTable("Qualities")));
    125       variableCreator.Successor = resultsCollector1;
    126 
    127       LookupParameter<DataTable> qualities = new LookupParameter<DataTable>("Qualities");
    128       qualities.ActualName = "Qualities";
    129       resultsCollector1.CollectedValues.Add(qualities);
    130       resultsCollector1.ResultsParameter.ActualName = "Results";
    131       resultsCollector1.Successor = subScopesSorter1;
     128      variableCreator.Successor = resultsCollector;
     129
     130      resultsCollector.CollectedValues.Add(new LookupParameter<IntData>("Generations"));
     131      resultsCollector.CollectedValues.Add(new LookupParameter<DoubleData>("Best Quality"));
     132      resultsCollector.CollectedValues.Add(new LookupParameter<DoubleData>("Average Quality"));
     133      resultsCollector.CollectedValues.Add(new LookupParameter<DoubleData>("Worst Quality"));
     134      resultsCollector.CollectedValues.Add(new LookupParameter<DataTable>("Qualities"));
     135      resultsCollector.ResultsParameter.ActualName = "Results";
     136      resultsCollector.Successor = subScopesSorter1;
    132137
    133138      subScopesSorter1.DescendingParameter.ActualName = "Maximization";
     
    196201      comparator.Successor = bestAverageWorstQualityCalculator;
    197202
    198       bestAverageWorstQualityCalculator.AverageQualityParameter.ActualName = "AverageQuality";
    199       bestAverageWorstQualityCalculator.BestQualityParameter.ActualName = "BestQuality";
     203      bestAverageWorstQualityCalculator.AverageQualityParameter.ActualName = "Average Quality";
     204      bestAverageWorstQualityCalculator.BestQualityParameter.ActualName = "Best Quality";
    200205      bestAverageWorstQualityCalculator.MaximizationParameter.ActualName = "Maximization";
    201206      bestAverageWorstQualityCalculator.QualityParameter.ActualName = "Quality";
    202       bestAverageWorstQualityCalculator.WorstQualityParameter.ActualName = "WorstQuality";
     207      bestAverageWorstQualityCalculator.WorstQualityParameter.ActualName = "Worst Quality";
    203208      bestAverageWorstQualityCalculator.Successor = dataTableValuesCollector;
    204209
    205       LookupParameter<DoubleData> bestQuality = new LookupParameter<DoubleData>("BestQuality");
    206       bestQuality.ActualName = "BestQuality";
    207       dataTableValuesCollector.CollectedValues.Add(bestQuality);
    208       LookupParameter<DoubleData> averageQuality = new LookupParameter<DoubleData>("AverageQuality");
    209       averageQuality.ActualName = "AverageQuality";
    210       dataTableValuesCollector.CollectedValues.Add(averageQuality);
    211       LookupParameter<DoubleData> worstQuality = new LookupParameter<DoubleData>("WorstQuality");
    212       worstQuality.ActualName = "WorstQuality";
    213       dataTableValuesCollector.CollectedValues.Add(worstQuality);
     210      dataTableValuesCollector.CollectedValues.Add(new LookupParameter<DoubleData>("Best Quality"));
     211      dataTableValuesCollector.CollectedValues.Add(new LookupParameter<DoubleData>("Average Quality"));
     212      dataTableValuesCollector.CollectedValues.Add(new LookupParameter<DoubleData>("Worst Quality"));
    214213      dataTableValuesCollector.DataTableParameter.ActualName = "Qualities";
    215       dataTableValuesCollector.Successor = resultsCollector2;
    216 
    217       bestQuality = new LookupParameter<DoubleData>("BestQuality");
    218       bestQuality.ActualName = "BestQuality";
    219       resultsCollector2.CollectedValues.Add(bestQuality);
    220       averageQuality = new LookupParameter<DoubleData>("AverageQuality");
    221       averageQuality.ActualName = "AverageQuality";
    222       resultsCollector2.CollectedValues.Add(averageQuality);
    223       worstQuality = new LookupParameter<DoubleData>("WorstQuality");
    224       worstQuality.ActualName = "WorstQuality";
    225       resultsCollector2.CollectedValues.Add(worstQuality);
    226       resultsCollector2.ResultsParameter.ActualName = "Results";
    227       resultsCollector2.Successor = conditionalBranch;
     214      dataTableValuesCollector.Successor = conditionalBranch;
    228215
    229216      conditionalBranch.ConditionParameter.ActualName = "Terminate";
  • trunk/sources/HeuristicLab.Analysis/3.3/BestAverageWorstQualityCalculator.cs

    r2891 r2924  
    7676          max = temp;
    7777        }
    78         BestQualityParameter.ActualValue = new DoubleData(max);
    79         AverageQualityParameter.ActualValue = new DoubleData(sum / qualities.Length);
    80         WorstQualityParameter.ActualValue = new DoubleData(min);
     78
     79        DoubleData best = BestQualityParameter.ActualValue;
     80        if (best == null) BestQualityParameter.ActualValue = new DoubleData(max);
     81        else best.Value = max;
     82        DoubleData average = AverageQualityParameter.ActualValue;
     83        if (average == null) AverageQualityParameter.ActualValue = new DoubleData(sum / qualities.Length);
     84        else average.Value = sum / qualities.Length;
     85        DoubleData worst = WorstQualityParameter.ActualValue;
     86        if (worst == null) WorstQualityParameter.ActualValue = new DoubleData(min);
     87        else worst.Value = min;
    8188      }
    8289      return base.Apply();
  • trunk/sources/HeuristicLab.Core.Views/3.3/CreateParameterDialog.Designer.cs

    r2796 r2924  
    162162                  | System.Windows.Forms.AnchorStyles.Left)
    163163                  | System.Windows.Forms.AnchorStyles.Right)));
    164       this.parameterTypeSelector.Caption = "Available &Parameters";
     164      this.parameterTypeSelector.Caption = "Available Parameters";
    165165      this.parameterTypeSelector.Location = new System.Drawing.Point(12, 12);
    166166      this.parameterTypeSelector.Name = "parameterTypeSelector";
  • trunk/sources/HeuristicLab.Core.Views/3.3/ItemArrayView.Designer.cs

    r2796 r2924  
    158158      this.detailsGroupBox.TabIndex = 0;
    159159      this.detailsGroupBox.TabStop = false;
    160       this.detailsGroupBox.Text = "&Details";
     160      this.detailsGroupBox.Text = "Details";
    161161      //
    162162      // viewHost
     
    180180      this.itemsGroupBox.TabIndex = 0;
    181181      this.itemsGroupBox.TabStop = false;
    182       this.itemsGroupBox.Text = "&Items";
     182      this.itemsGroupBox.Text = "Items";
    183183      //
    184184      // ItemArrayView
  • trunk/sources/HeuristicLab.Core.Views/3.3/ItemCollectionView.Designer.cs

    r2796 r2924  
    185185      this.detailsGroupBox.TabIndex = 0;
    186186      this.detailsGroupBox.TabStop = false;
    187       this.detailsGroupBox.Text = "&Details";
     187      this.detailsGroupBox.Text = "Details";
    188188      //
    189189      // viewHost
     
    207207      this.itemsGroupBox.TabIndex = 0;
    208208      this.itemsGroupBox.TabStop = false;
    209       this.itemsGroupBox.Text = "&Items";
     209      this.itemsGroupBox.Text = "Items";
    210210      //
    211211      // ItemCollectionView
  • trunk/sources/HeuristicLab.Core.Views/3.3/ItemCollectionView.cs

    r2917 r2924  
    122122      if (!listViewItem.Text.Equals(listViewItem.Tag.ToString())) {
    123123        listViewItem.Text = listViewItem.Tag.ToString();
    124         itemsListView.Sort();
    125124      }
    126125    }
  • trunk/sources/HeuristicLab.Core.Views/3.3/ItemListView.Designer.cs

    r2796 r2924  
    183183      this.detailsGroupBox.TabIndex = 0;
    184184      this.detailsGroupBox.TabStop = false;
    185       this.detailsGroupBox.Text = "&Details";
     185      this.detailsGroupBox.Text = "Details";
    186186      //
    187187      // viewHost
     
    205205      this.itemsGroupBox.TabIndex = 0;
    206206      this.itemsGroupBox.TabStop = false;
    207       this.itemsGroupBox.Text = "&Items";
     207      this.itemsGroupBox.Text = "Items";
    208208      //
    209209      // ItemListView
  • trunk/sources/HeuristicLab.Core.Views/3.3/OperatorCollectionView.cs

    r2917 r2924  
    1616      InitializeComponent();
    1717      Caption = "Operator Collection";
    18       itemsGroupBox.Text = "&Operators";
     18      itemsGroupBox.Text = "Operators";
    1919    }
    2020    /// <summary>
     
    3232      if (typeSelectorDialog == null) {
    3333        typeSelectorDialog = new TypeSelectorDialog();
    34         typeSelectorDialog.TypeSelector.Caption = "&Available Operators";
     34        typeSelectorDialog.TypeSelector.Caption = "Available Operators";
    3535        typeSelectorDialog.TypeSelector.Configure(typeof(IOperator), false, false);
    3636      }
  • trunk/sources/HeuristicLab.Core.Views/3.3/OperatorGraphView.Designer.cs

    r2801 r2924  
    118118      this.graphGroupBox.TabIndex = 0;
    119119      this.graphGroupBox.TabStop = false;
    120       this.graphGroupBox.Text = "Operator &Graph";
     120      this.graphGroupBox.Text = "Operator Graph";
    121121      //
    122122      // viewHost
  • trunk/sources/HeuristicLab.Core.Views/3.3/OperatorListView.cs

    r2917 r2924  
    1616      InitializeComponent();
    1717      Caption = "Operator List";
    18       itemsGroupBox.Text = "&Operators";
     18      itemsGroupBox.Text = "Operators";
    1919    }
    2020    /// <summary>
     
    3232      if (typeSelectorDialog == null) {
    3333        typeSelectorDialog = new TypeSelectorDialog();
    34         typeSelectorDialog.TypeSelector.Caption = "&Available Operators";
     34        typeSelectorDialog.TypeSelector.Caption = "Available Operators";
    3535        typeSelectorDialog.TypeSelector.Configure(typeof(IOperator), false, false);
    3636      }
  • trunk/sources/HeuristicLab.Core.Views/3.3/OperatorSetView.cs

    r2917 r2924  
    1616      InitializeComponent();
    1717      Caption = "Operator Set";
    18       itemsGroupBox.Text = "&Operators";
     18      itemsGroupBox.Text = "Operators";
    1919    }
    2020    /// <summary>
     
    3232      if (typeSelectorDialog == null) {
    3333        typeSelectorDialog = new TypeSelectorDialog();
    34         typeSelectorDialog.TypeSelector.Caption = "&Available Operators";
     34        typeSelectorDialog.TypeSelector.Caption = "Available Operators";
    3535        typeSelectorDialog.TypeSelector.Configure(typeof(IOperator), false, false);
    3636      }
  • trunk/sources/HeuristicLab.Core.Views/3.3/OperatorsSidebar.Designer.cs

    r2790 r2924  
    5050      // typeSelector
    5151      //
    52       this.typeSelector.Caption = "&Available Operators";
     52      this.typeSelector.Caption = "Available Operators";
    5353      this.typeSelector.Dock = System.Windows.Forms.DockStyle.Fill;
    5454      this.typeSelector.Location = new System.Drawing.Point(0, 0);
  • trunk/sources/HeuristicLab.Core.Views/3.3/ParameterCollectionView.cs

    r2917 r2924  
    3737      InitializeComponent();
    3838      Caption = "ParameterCollection";
    39       itemsGroupBox.Text = "&Parameters";
     39      itemsGroupBox.Text = "Parameters";
    4040    }
    4141    /// <summary>
  • trunk/sources/HeuristicLab.Core.Views/3.3/ScopeListView.cs

    r2917 r2924  
    1313      InitializeComponent();
    1414      Caption = "ScopeList";
    15       itemsGroupBox.Text = "&Scopes";
     15      itemsGroupBox.Text = "Scopes";
    1616    }
    1717    /// <summary>
  • trunk/sources/HeuristicLab.Core.Views/3.3/ScopeView.Designer.cs

    r2790 r2924  
    104104      this.scopesGroupBox.TabIndex = 0;
    105105      this.scopesGroupBox.TabStop = false;
    106       this.scopesGroupBox.Text = "&Scopes";
     106      this.scopesGroupBox.Text = "Scopes";
    107107      //
    108108      // variableCollectionView
  • trunk/sources/HeuristicLab.Core.Views/3.3/TypeSelector.Designer.cs

    r2790 r2924  
    8989      this.typesGroupBox.TabIndex = 0;
    9090      this.typesGroupBox.TabStop = false;
    91       this.typesGroupBox.Text = "&Available Types";
     91      this.typesGroupBox.Text = "Available Types";
    9292      //
    9393      // splitContainer
  • trunk/sources/HeuristicLab.Core.Views/3.3/TypeSelectorDialog.Designer.cs

    r2790 r2924  
    7575                  | System.Windows.Forms.AnchorStyles.Left)
    7676                  | System.Windows.Forms.AnchorStyles.Right)));
    77       this.typeSelector.Caption = "&Available Types";
     77      this.typeSelector.Caption = "Available Types";
    7878      this.typeSelector.Location = new System.Drawing.Point(12, 12);
    7979      this.typeSelector.Name = "typeSelector";
  • trunk/sources/HeuristicLab.Core.Views/3.3/TypeSelectorDialog.cs

    r2818 r2924  
    5151    public TypeSelectorDialog() {
    5252      InitializeComponent();
     53      okButton.Enabled = typeSelector.SelectedType != null;
    5354    }
    5455
  • trunk/sources/HeuristicLab.Core.Views/3.3/ValueParameterCollectionView.cs

    r2917 r2924  
    3737      InitializeComponent();
    3838      Caption = "ValueParameterCollection";
    39       itemsGroupBox.Text = "&Parameters";
     39      itemsGroupBox.Text = "Parameters";
    4040    }
    4141    /// <summary>
  • trunk/sources/HeuristicLab.Core.Views/3.3/VariableCollectionView.cs

    r2917 r2924  
    1313      InitializeComponent();
    1414      Caption = "VariableCollection";
    15       itemsGroupBox.Text = "&Variables";
     15      itemsGroupBox.Text = "Variables";
    1616    }
    1717    /// <summary>
  • trunk/sources/HeuristicLab.Core.Views/3.3/VariableView.Designer.cs

    r2917 r2924  
    100100      this.valueGroupBox.TabIndex = 7;
    101101      this.valueGroupBox.TabStop = false;
    102       this.valueGroupBox.Text = "&Value:";
     102      this.valueGroupBox.Text = "Value";
    103103      //
    104104      // valuePanel
  • trunk/sources/HeuristicLab.Optimization/3.3/EngineAlgorithm.cs

    r2917 r2924  
    9696    protected EngineAlgorithm()
    9797      : base() {
    98       globalScope = new Scope();
     98      globalScope = new Scope("Global Scope");
    9999      globalScope.Variables.Add(new Variable("Results", new VariableCollection()));
    100100      OperatorGraph = new OperatorGraph();
     
    103103    protected EngineAlgorithm(string name)
    104104      : base(name) {
    105       globalScope = new Scope();
     105      globalScope = new Scope("Global Scope");
    106106      globalScope.Variables.Add(new Variable("Results", new VariableCollection()));
    107107      OperatorGraph = new OperatorGraph();
     
    110110    protected EngineAlgorithm(string name, ParameterCollection parameters)
    111111      : base(name, parameters) {
    112       globalScope = new Scope();
     112      globalScope = new Scope("Global Scope");
    113113      globalScope.Variables.Add(new Variable("Results", new VariableCollection()));
    114114      OperatorGraph = new OperatorGraph();
     
    117117    protected EngineAlgorithm(string name, string description)
    118118      : base(name, description) {
    119       globalScope = new Scope();
     119      globalScope = new Scope("Global Scope");
    120120      globalScope.Variables.Add(new Variable("Results", new VariableCollection()));
    121121      OperatorGraph = new OperatorGraph();
     
    124124    protected EngineAlgorithm(string name, string description, ParameterCollection parameters)
    125125      : base(name, description, parameters) {
    126       globalScope = new Scope();
     126      globalScope = new Scope("Global Scope");
    127127      globalScope.Variables.Add(new Variable("Results", new VariableCollection()));
    128128      OperatorGraph = new OperatorGraph();
  • trunk/sources/HeuristicLab.Parameters.Views/3.3/ConstrainedValueParameterView.Designer.cs

    r2917 r2924  
    8585      this.valueGroupBox.TabIndex = 6;
    8686      this.valueGroupBox.TabStop = false;
    87       this.valueGroupBox.Text = "&Value:";
     87      this.valueGroupBox.Text = "Value";
    8888      //
    8989      // viewHost
     
    135135    #endregion
    136136
    137     private System.Windows.Forms.GroupBox valueGroupBox;
    138     private HeuristicLab.Core.Views.ViewHost viewHost;
    139     private System.Windows.Forms.ComboBox valueComboBox;
     137    protected System.Windows.Forms.GroupBox valueGroupBox;
     138    protected HeuristicLab.Core.Views.ViewHost viewHost;
     139    protected System.Windows.Forms.ComboBox valueComboBox;
    140140  }
    141141}
  • trunk/sources/HeuristicLab.Parameters.Views/3.3/ConstrainedValueParameterView.cs

    r2917 r2924  
    2121
    2222using System;
    23 using System.Collections.Generic;
     23using System.Linq;
    2424using HeuristicLab.Collections;
    2525using HeuristicLab.Core;
     
    3333  [View("ConstrainedValueParameter View")]
    3434  [Content(typeof(ConstrainedValueParameter<>), true)]
    35   public sealed partial class ConstrainedValueParameterView<T> : ParameterView where T : class, IItem {
    36     private List<T> valueComboBoxItems;
    37 
     35  public partial class ConstrainedValueParameterView<T> : ParameterView where T : class, IItem {
    3836    /// <summary>
    3937    /// Gets or sets the variable to represent visually.
     
    5250      InitializeComponent();
    5351      Caption = "ConstrainedValueParameter";
    54       valueComboBoxItems = new List<T>();
    5552    }
    5653    /// <summary>
     
    104101
    105102    private void FillValueComboBox() {
    106       valueComboBoxItems.Clear();
    107       valueComboBoxItems.Add(null);
     103      valueComboBox.SelectedIndexChanged -= new EventHandler(valueComboBox_SelectedIndexChanged);
     104      valueComboBox.DataSource = null;
    108105      if (Content != null) {
    109         foreach (T item in Content.ValidValues)
    110           valueComboBoxItems.Add(item);
     106        valueComboBox.DataSource = Content.ValidValues.ToList();
     107        valueComboBox.Enabled = valueComboBox.Items.Count > 0;
     108        valueComboBox.SelectedItem = Content.Value;
    111109      }
    112       valueComboBox.Items.Clear();
    113       foreach (T item in valueComboBoxItems)
    114         valueComboBox.Items.Add(item == null ? "-" : item.ToString());
    115       if (Content != null) valueComboBox.SelectedIndex = valueComboBoxItems.IndexOf(Content.Value);
     110      valueComboBox.SelectedIndexChanged += new EventHandler(valueComboBox_SelectedIndexChanged);
    116111    }
    117112
     
    121116        Invoke(new EventHandler(Content_ValueChanged), sender, e);
    122117      else {
    123         valueComboBox.SelectedIndex = valueComboBoxItems.IndexOf(Content.Value);
     118        valueComboBox.SelectedItem = Content.Value;
    124119        viewHost.Content = Content.Value;
    125120      }
     
    128123      if (InvokeRequired)
    129124        Invoke(new CollectionItemsChangedEventHandler<T>(ValidValues_ItemsAdded), sender, e);
    130       else {
    131         foreach (T item in e.Items) {
    132           valueComboBoxItems.Add(item);
    133           valueComboBox.Items.Add(item == null ? "-" : item.ToString());
    134         }
    135       }
     125      else
     126        FillValueComboBox();
    136127    }
    137128    private void ValidValues_ItemsRemoved(object sender, CollectionItemsChangedEventArgs<T> e) {
    138129      if (InvokeRequired)
    139130        Invoke(new CollectionItemsChangedEventHandler<T>(ValidValues_ItemsRemoved), sender, e);
    140       else {
    141         foreach (T item in e.Items) {
    142           int index = valueComboBoxItems.IndexOf(item);
    143           valueComboBoxItems.RemoveAt(index);
    144           valueComboBox.Items.RemoveAt(index);
    145         }
    146       }
     131      else
     132        FillValueComboBox();
    147133    }
    148134    private void ValidValues_CollectionReset(object sender, CollectionItemsChangedEventArgs<T> e) {
     
    155141
    156142    private void valueComboBox_SelectedIndexChanged(object sender, EventArgs e) {
    157       Content.Value = valueComboBoxItems[valueComboBox.SelectedIndex];
     143      Content.Value = (T)valueComboBox.SelectedItem;
    158144    }
    159145  }
  • trunk/sources/HeuristicLab.Parameters.Views/3.3/HeuristicLab.Parameters.Views-3.3.csproj

    r2900 r2924  
    9191    <Compile Include="ConstrainedValueParameterView.Designer.cs">
    9292      <DependentUpon>ConstrainedValueParameterView.cs</DependentUpon>
     93    </Compile>
     94    <Compile Include="OptionalConstrainedValueParameterView.cs">
     95      <SubType>UserControl</SubType>
     96    </Compile>
     97    <Compile Include="OptionalConstrainedValueParameterView.Designer.cs">
     98      <DependentUpon>OptionalConstrainedValueParameterView.cs</DependentUpon>
    9399    </Compile>
    94100    <Compile Include="OptionalValueParameterView.cs">
  • trunk/sources/HeuristicLab.Parameters.Views/3.3/OptionalValueParameterView.Designer.cs

    r2917 r2924  
    9090      this.valueGroupBox.TabIndex = 6;
    9191      this.valueGroupBox.TabStop = false;
    92       this.valueGroupBox.Text = "&Value:";
     92      this.valueGroupBox.Text = "Value";
    9393      //
    9494      // valuePanel
  • trunk/sources/HeuristicLab.Parameters.Views/3.3/ValueLookupParameterView.Designer.cs

    r2917 r2924  
    100100      this.valueGroupBox.TabIndex = 8;
    101101      this.valueGroupBox.TabStop = false;
    102       this.valueGroupBox.Text = "&Value:";
     102      this.valueGroupBox.Text = "Value";
    103103      //
    104104      // valuePanel
  • trunk/sources/HeuristicLab.Parameters.Views/3.3/ValueParameterView.Designer.cs

    r2917 r2924  
    8585      this.valueGroupBox.TabIndex = 6;
    8686      this.valueGroupBox.TabStop = false;
    87       this.valueGroupBox.Text = "&Value:";
     87      this.valueGroupBox.Text = "Value";
    8888      //
    8989      // valuePanel
  • trunk/sources/HeuristicLab.Parameters/3.3/ConstrainedValueParameter.cs

    r2852 r2924  
    2121
    2222using System;
    23 using HeuristicLab.Common;
     23using System.Linq;
     24using HeuristicLab.Collections;
    2425using HeuristicLab.Core;
    2526using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
     
    2728namespace HeuristicLab.Parameters {
    2829  /// <summary>
    29   /// A parameter whose value has to be chosen from a set of valid values which is defined it the parameter itself.
     30  /// A parameter whose value has to be chosen from a set of valid values.
    3031  /// </summary>
    31   [Item("ConstrainedValueParameter<T>", "A parameter whose value has to be chosen from a set of valid values which is defined it the parameter itself.")]
    32   public sealed class ConstrainedValueParameter<T> : Parameter, IValueParameter<T> where T : class, IItem {
    33     private ItemSet<T> validValues;
    34     [Storable]
    35     public ItemSet<T> ValidValues {
    36       get { return validValues; }
    37       private set {
    38         DeregisterValidValuesEvents();
    39         validValues = value;
    40         RegisterValidValuesEvents();
     32  [Item("ConstrainedValueParameter<T>", "A parameter whose value has to be chosen from a set of valid values.")]
     33  [EmptyStorableClass]
     34  public class ConstrainedValueParameter<T> : OptionalConstrainedValueParameter<T> where T : class, IItem {
     35    public override T Value {
     36      get { return base.Value; }
     37      set {
     38        if ((value == null) && (ValidValues.Count > 0)) throw new ArgumentNullException();
     39        base.Value = value;
    4140      }
    4241    }
    4342
    44     private T value;
    45     [Storable]
    46     public T Value {
    47       get { return this.value; }
    48       set {
    49         if (value != this.value) {
    50           if ((value != null) && !validValues.Contains(value)) throw new ArgumentException("Invalid value.");
    51           this.value = value;
    52           OnValueChanged();
    53         }
    54       }
     43    public ConstrainedValueParameter() : base() { }
     44    public ConstrainedValueParameter(string name) : base(name) { }
     45    public ConstrainedValueParameter(string name, ItemSet<T> validValues) : base(name, validValues) { }
     46    public ConstrainedValueParameter(string name, ItemSet<T> validValues, T value) : base(name, validValues, value) { }
     47    public ConstrainedValueParameter(string name, string description) : base(name, description) { }
     48    public ConstrainedValueParameter(string name, string description, ItemSet<T> validValues) : base(name, description, validValues) { }
     49    public ConstrainedValueParameter(string name, string description, ItemSet<T> validValues, T value) : base(name, description, validValues, value) { }
     50
     51    protected override void validValues_ItemsAdded(object sender, CollectionItemsChangedEventArgs<T> e) {
     52      if (Value == null) Value = ValidValues.First();
    5553    }
    56     IItem IValueParameter.Value {
    57       get { return Value; }
    58       set {
    59         T val = value as T;
    60         if ((value != null) && (val == null))
    61           throw new InvalidOperationException(
    62             string.Format("Type mismatch. Value is not a \"{0}\".",
    63                           typeof(T).GetPrettyName())
    64           );
    65         Value = val;
    66       }
     54    protected override void ValidValues_ItemsRemoved(object sender, CollectionItemsChangedEventArgs<T> e) {
     55      if ((Value != null) && !ValidValues.Contains(Value)) Value = ValidValues.FirstOrDefault();
    6756    }
    68 
    69     public ConstrainedValueParameter()
    70       : base("Anonymous", typeof(T)) {
    71       ValidValues = new ItemSet<T>();
    72     }
    73     public ConstrainedValueParameter(string name)
    74       : base(name, typeof(T)) {
    75       ValidValues = new ItemSet<T>();
    76     }
    77     public ConstrainedValueParameter(string name, ItemSet<T> validValues)
    78       : base(name, typeof(T)) {
    79       ValidValues = validValues;
    80     }
    81     public ConstrainedValueParameter(string name, ItemSet<T> validValues, T value)
    82       : base(name, typeof(T)) {
    83       ValidValues = validValues;
    84       Value = value;
    85     }
    86     public ConstrainedValueParameter(string name, string description)
    87       : base(name, description, typeof(T)) {
    88       ValidValues = new ItemSet<T>();
    89     }
    90     public ConstrainedValueParameter(string name, string description, ItemSet<T> validValues)
    91       : base(name, description, typeof(T)) {
    92       ValidValues = validValues;
    93     }
    94     public ConstrainedValueParameter(string name, string description, ItemSet<T> validValues, T value)
    95       : base(name, description, typeof(T)) {
    96       ValidValues = validValues;
    97       Value = value;
    98     }
    99 
    100     public override IDeepCloneable Clone(Cloner cloner) {
    101       ConstrainedValueParameter<T> clone = (ConstrainedValueParameter<T>)base.Clone(cloner);
    102       clone.ValidValues = (ItemSet<T>)cloner.Clone(validValues);
    103       clone.Value = (T)cloner.Clone(value);
    104       return clone;
    105     }
    106 
    107     public override string ToString() {
    108       return string.Format("{0}: {1} ({2})", Name, Value != null ? Value.ToString() : "null", DataType.GetPrettyName());
    109     }
    110 
    111     protected override IItem GetActualValue() {
    112       return Value;
    113     }
    114     protected override void SetActualValue(IItem value) {
    115       ((IValueParameter)this).Value = value;
    116     }
    117 
    118     public event EventHandler ValueChanged;
    119     private void OnValueChanged() {
    120       if (ValueChanged != null)
    121         ValueChanged(this, EventArgs.Empty);
    122       OnChanged();
    123     }
    124 
    125     private void RegisterValidValuesEvents() {
    126       if (validValues != null) {
    127         validValues.ItemsRemoved += new HeuristicLab.Collections.CollectionItemsChangedEventHandler<T>(ValidValues_ItemsRemoved);
    128         validValues.CollectionReset += new HeuristicLab.Collections.CollectionItemsChangedEventHandler<T>(ValidValues_CollectionReset);
    129         validValues.Changed += new ChangedEventHandler(ValidValues_Changed);
    130       }
    131     }
    132     private void DeregisterValidValuesEvents() {
    133       if (validValues != null) {
    134         validValues.ItemsRemoved -= new HeuristicLab.Collections.CollectionItemsChangedEventHandler<T>(ValidValues_ItemsRemoved);
    135         validValues.CollectionReset -= new HeuristicLab.Collections.CollectionItemsChangedEventHandler<T>(ValidValues_CollectionReset);
    136         validValues.Changed -= new ChangedEventHandler(ValidValues_Changed);
    137       }
    138     }
    139 
    140     private void ValidValues_ItemsRemoved(object sender, HeuristicLab.Collections.CollectionItemsChangedEventArgs<T> e) {
    141       if ((Value != null) && !validValues.Contains(Value)) Value = null;
    142     }
    143     private void ValidValues_CollectionReset(object sender, HeuristicLab.Collections.CollectionItemsChangedEventArgs<T> e) {
    144       if ((Value != null) && !validValues.Contains(Value)) Value = null;
    145     }
    146     private void ValidValues_Changed(object sender, ChangedEventArgs e) {
    147       OnChanged(e);
     57    protected override void ValidValues_CollectionReset(object sender, CollectionItemsChangedEventArgs<T> e) {
     58      if ((Value != null) && !ValidValues.Contains(Value)) Value = ValidValues.FirstOrDefault();
    14859    }
    14960  }
  • trunk/sources/HeuristicLab.Parameters/3.3/HeuristicLab.Parameters-3.3.csproj

    r2900 r2924  
    8585    <None Include="HeuristicLabParametersPlugin.cs.frame" />
    8686    <Compile Include="ConstrainedValueParameter.cs" />
     87    <Compile Include="OptionalConstrainedValueParameter.cs" />
    8788    <Compile Include="ValueParameter.cs" />
    8889    <Compile Include="LookupParameter.cs" />
  • trunk/sources/HeuristicLab.Parameters/3.3/OptionalValueParameter.cs

    r2891 r2924  
    3333    private T value;
    3434    [Storable]
    35     public T Value {
     35    public virtual T Value {
    3636      get { return this.value; }
    3737      set {
  • trunk/sources/HeuristicLab.Parameters/3.3/ValueParameter.cs

    r2891 r2924  
    3030  /// </summary>
    3131  [Item("ValueParameter<T>", "A parameter whose value is defined it the parameter itself.")]
    32   public sealed class ValueParameter<T> : Parameter, IValueParameter<T> where T : class, IItem {
    33     private T value;
    34     [Storable]
    35     public T Value {
    36       get { return this.value; }
     32  [EmptyStorableClass]
     33  public class ValueParameter<T> : OptionalValueParameter<T> where T : class, IItem {
     34    public override T Value {
     35      get { return base.Value; }
    3736      set {
    3837        if (value == null) throw new ArgumentNullException();
    39         if (value != this.value) {
    40           if (this.value != null) this.value.Changed -= new ChangedEventHandler(Value_Changed);
    41           this.value = value;
    42           this.value.Changed += new ChangedEventHandler(Value_Changed);
    43           OnValueChanged();
    44         }
    45       }
    46     }
    47     IItem IValueParameter.Value {
    48       get { return Value; }
    49       set {
    50         if (value == null) throw new ArgumentNullException();
    51         T val = value as T;
    52         if (val == null)
    53           throw new InvalidOperationException(
    54             string.Format("Type mismatch. Value is not a \"{0}\".",
    55                           typeof(T).GetPrettyName())
    56           );
    57         Value = val;
     38        base.Value = value;
    5839      }
    5940    }
    6041
    61     private ValueParameter()
    62       : base("Anonymous", typeof(T)) {
    63     }
    64     public ValueParameter(string name, T value)
    65       : base(name, typeof(T)) {
    66       Value = value;
    67     }
    68     public ValueParameter(string name, string description, T value)
    69       : base(name, description, typeof(T)) {
    70       Value = value;
    71     }
     42    private ValueParameter() : base() { }
     43    public ValueParameter(string name, T value) : base(name, value) { }
     44    public ValueParameter(string name, string description, T value) : base(name, description, value) { }
    7245
    7346    public override IDeepCloneable Clone(Cloner cloner) {
    74       ValueParameter<T> clone = new ValueParameter<T>(name, description, value);
     47      ValueParameter<T> clone = new ValueParameter<T>(name, description, Value);
    7548      cloner.RegisterClonedObject(this, clone);
    76       clone.Value = (T)cloner.Clone(value);
     49      clone.Value = (T)cloner.Clone(Value);
    7750      return clone;
    78     }
    79 
    80     public override string ToString() {
    81       return string.Format("{0}: {1} ({2})", Name, Value.ToString(), DataType.GetPrettyName());
    82     }
    83 
    84     protected override IItem GetActualValue() {
    85       return Value;
    86     }
    87     protected override void SetActualValue(IItem value) {
    88       ((IValueParameter)this).Value = value;
    89     }
    90 
    91     public event EventHandler ValueChanged;
    92     private void OnValueChanged() {
    93       if (ValueChanged != null)
    94         ValueChanged(this, EventArgs.Empty);
    95       OnChanged();
    96     }
    97     private void Value_Changed(object sender, ChangedEventArgs e) {
    98       OnChanged(e);
    9951    }
    10052  }
  • trunk/sources/HeuristicLab.Random/3.3/RandomCreator.cs

    r2834 r2924  
    2828namespace HeuristicLab.Operators {
    2929  /// <summary>
    30   /// An operator which creates a new pseudo random number generator.
     30  /// An operator which creates a new Mersenne Twister pseudo random number generator.
    3131  /// </summary>
    32   [Item("RandomCreator", "An operator which creates a new pseudo random number generator.")]
     32  [Item("RandomCreator", "An operator which creates a new Mersenne Twister pseudo random number generator.")]
    3333  [EmptyStorableClass]
    3434  [Creatable("Test")]
  • trunk/sources/HeuristicLab.SequentialEngine/3.3/SequentialEngine.cs

    r2851 r2924  
    3030  /// </summary>
    3131  [EmptyStorableClass]
    32   [Creatable("Engines")]
    3332  [Item("Sequential Engine", "Engine for sequential execution of algorithms.")]
    3433  public class SequentialEngine : Engine {
Note: See TracChangeset for help on using the changeset viewer.