Changeset 11952


Ignore:
Timestamp:
02/06/15 15:22:27 (7 years ago)
Author:
abeham
Message:

#2174:

  • Made encodingOperators hash set an ItemSet and private
  • Added a parameter that displays the operators of an encoding (fixedvalue showing a readonly version of the itemset)
  • Added protected methods to Encoding to add and remove operators
  • Adapted MultiEncodingView to derive from ParameterizedNamedItemView
  • Added name of MultiEncoding itself to list of forbidden names
Location:
branches/ProgrammableProblem
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • branches/ProgrammableProblem/HeuristicLab.Encodings.BinaryVectorEncoding/3.3/BinaryVectorEncoding.cs

    r11949 r11952  
    118118      ConfigureOperators(newOperators);
    119119      foreach (var @operator in newOperators)
    120         encodingOperators.Add(@operator);
     120        AddOperator(@operator);
    121121    }
    122122    #endregion
  • branches/ProgrammableProblem/HeuristicLab.Encodings.IntegerVectorEncoding/3.3/IntegerVectorEncoding.cs

    r11949 r11952  
    181181      ConfigureOperators(newOperators);
    182182      foreach (var @operator in newOperators)
    183         encodingOperators.Add(@operator);
     183        AddOperator(@operator);
    184184    }
    185185    #endregion
  • branches/ProgrammableProblem/HeuristicLab.Encodings.PermutationEncoding/3.3/PermutationEncoding.cs

    r11949 r11952  
    156156      ConfigureOperators(newOperators);
    157157      foreach (var @operator in newOperators)
    158         encodingOperators.Add(@operator);
     158        AddOperator(@operator);
    159159    }
    160160    #endregion
  • branches/ProgrammableProblem/HeuristicLab.Encodings.RealVectorEncoding/3.3/RealVectorEncoding.cs

    r11949 r11952  
    180180      ConfigureOperators(newOperators);
    181181      foreach (var @operator in newOperators)
    182         encodingOperators.Add(@operator);
     182        AddOperator(@operator);
    183183
    184184      foreach (var strategyVectorCreator in Operators.OfType<IRealVectorStdDevStrategyParameterCreator>())
  • branches/ProgrammableProblem/HeuristicLab.Optimization/3.3/BasicProblems/Encoding.cs

    r11949 r11952  
    2626using HeuristicLab.Core;
    2727using HeuristicLab.Optimization;
     28using HeuristicLab.Parameters;
    2829using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    2930
     
    3738    }
    3839
    39     protected HashSet<IOperator> encodingOperators = new HashSet<IOperator>(new TypeEqualityComparer<IOperator>());
     40    private ItemSet<IOperator> encodingOperators = new ItemSet<IOperator>(new TypeEqualityComparer<IOperator>());
    4041
    4142    [Storable(Name = "Operators")]
    4243    private IEnumerable<IOperator> StorableOperators {
    4344      get { return encodingOperators; }
    44       set { encodingOperators = new HashSet<IOperator>(value, new TypeEqualityComparer<IOperator>()); ; }
     45      set { encodingOperators = new ItemSet<IOperator>(value, new TypeEqualityComparer<IOperator>()); ; }
    4546    }
    4647
     
    5051        if (!value.OfType<T>().Any())
    5152          throw new ArgumentException("The provided operators contain no suitable solution creator");
    52         encodingOperators = new HashSet<IOperator>(value, new TypeEqualityComparer<IOperator>());
     53        encodingOperators.Clear();
     54        foreach (var op in value) encodingOperators.Add(op);
    5355
    5456        T newSolutionCreator = (T)encodingOperators.FirstOrDefault(o => o.GetType() == solutionCreator.GetType()) ??
     
    8587    protected Encoding(Encoding<T> original, Cloner cloner)
    8688      : base(original, cloner) {
    87       encodingOperators = new HashSet<IOperator>(original.Operators.Select(cloner.Clone), new TypeEqualityComparer<IOperator>());
     89      encodingOperators = cloner.Clone(original.encodingOperators);
    8890      solutionCreator = cloner.Clone(original.solutionCreator);
    8991    }
    90     protected Encoding(string name) : base(name) { }
     92    protected Encoding(string name)
     93      : base(name) {
     94      Parameters.Add(new FixedValueParameter<ReadOnlyItemSet<IOperator>>(name + ".Operators", "The operators that the encoding specifies.", encodingOperators.AsReadOnly()));
     95    }
    9196
    9297    public virtual Individual GetIndividual(IScope scope) {
    9398      return new SingleEncodingIndividual(this, scope);
     99    }
     100
     101    protected bool AddOperator(IOperator @operator) {
     102      return encodingOperators.Add(@operator);
     103    }
     104
     105    protected bool RemoveOperator(IOperator @operator) {
     106      return encodingOperators.Remove(@operator);
    94107    }
    95108
  • branches/ProgrammableProblem/HeuristicLab.Optimization/3.3/BasicProblems/MultiEncoding.cs

    r11949 r11952  
    5656
    5757      foreach (var @operator in ApplicationManager.Manager.GetInstances<IMultiEncodingOperator>())
    58         encodingOperators.Add(@operator);
     58        AddOperator(@operator);
    5959    }
    6060
  • branches/ProgrammableProblem/HeuristicLab.Problems.Programmable.Views/3.3/MultiEncodingView.Designer.cs

    r11892 r11952  
    4646    private void InitializeComponent() {
    4747      this.encodingsListView = new System.Windows.Forms.ListView();
     48      this.encodingNameColumnHeader = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
     49      this.encodingTypeColumnHeader = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
    4850      this.addEncodingButton = new System.Windows.Forms.Button();
    4951      this.removeEncodingButton = new System.Windows.Forms.Button();
    5052      this.splitContainer = new System.Windows.Forms.SplitContainer();
    51       this.encodingsGroupBox = new System.Windows.Forms.GroupBox();
    5253      this.encodingDetailsGroupBox = new System.Windows.Forms.GroupBox();
    5354      this.encodingDetailViewHost = new HeuristicLab.MainForm.WindowsForms.ViewHost();
    54       this.encodingNameColumnHeader = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
    55       this.encodingTypeColumnHeader = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
     55      this.encodingsGroupBox = new System.Windows.Forms.GroupBox();
     56      this.tabControl = new System.Windows.Forms.TabControl();
     57      this.encodingsTabPage = new System.Windows.Forms.TabPage();
     58      this.parametersTabPage = new System.Windows.Forms.TabPage();
    5659      ((System.ComponentModel.ISupportInitialize)(this.errorProvider)).BeginInit();
    5760      ((System.ComponentModel.ISupportInitialize)(this.splitContainer)).BeginInit();
     
    5962      this.splitContainer.Panel2.SuspendLayout();
    6063      this.splitContainer.SuspendLayout();
     64      this.encodingDetailsGroupBox.SuspendLayout();
    6165      this.encodingsGroupBox.SuspendLayout();
    62       this.encodingDetailsGroupBox.SuspendLayout();
     66      this.tabControl.SuspendLayout();
     67      this.encodingsTabPage.SuspendLayout();
    6368      this.SuspendLayout();
    6469      //
     
    8792      this.encodingsListView.Name = "encodingsListView";
    8893      this.encodingsListView.ShowGroups = false;
    89       this.encodingsListView.Size = new System.Drawing.Size(214, 416);
     94      this.encodingsListView.Size = new System.Drawing.Size(241, 384);
    9095      this.encodingsListView.TabIndex = 3;
    9196      this.encodingsListView.UseCompatibleStateImageBehavior = false;
    9297      this.encodingsListView.View = System.Windows.Forms.View.Details;
    9398      this.encodingsListView.SelectedIndexChanged += new System.EventHandler(this.encodingsListView_SelectedIndexChanged);
     99      //
     100      // encodingNameColumnHeader
     101      //
     102      this.encodingNameColumnHeader.Text = "Name";
     103      this.encodingNameColumnHeader.Width = 100;
     104      //
     105      // encodingTypeColumnHeader
     106      //
     107      this.encodingTypeColumnHeader.Text = "Type";
     108      this.encodingTypeColumnHeader.Width = 136;
    94109      //
    95110      // addEncodingButton
     
    116131      //
    117132      this.splitContainer.Dock = System.Windows.Forms.DockStyle.Fill;
     133      this.splitContainer.FixedPanel = System.Windows.Forms.FixedPanel.Panel1;
    118134      this.splitContainer.Location = new System.Drawing.Point(3, 16);
    119135      this.splitContainer.Name = "splitContainer";
     
    128144      //
    129145      this.splitContainer.Panel2.Controls.Add(this.encodingDetailsGroupBox);
    130       this.splitContainer.Size = new System.Drawing.Size(660, 452);
    131       this.splitContainer.SplitterDistance = 220;
     146      this.splitContainer.Size = new System.Drawing.Size(643, 420);
     147      this.splitContainer.SplitterDistance = 247;
    132148      this.splitContainer.TabIndex = 5;
    133       //
    134       // encodingsGroupBox
    135       //
    136       this.encodingsGroupBox.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
    137             | System.Windows.Forms.AnchorStyles.Left)
    138             | System.Windows.Forms.AnchorStyles.Right)));
    139       this.encodingsGroupBox.Controls.Add(this.splitContainer);
    140       this.encodingsGroupBox.Location = new System.Drawing.Point(0, 26);
    141       this.encodingsGroupBox.Name = "encodingsGroupBox";
    142       this.encodingsGroupBox.Size = new System.Drawing.Size(666, 471);
    143       this.encodingsGroupBox.TabIndex = 6;
    144       this.encodingsGroupBox.TabStop = false;
    145       this.encodingsGroupBox.Text = "Encodings";
    146149      //
    147150      // encodingDetailsGroupBox
     
    153156      this.encodingDetailsGroupBox.Location = new System.Drawing.Point(3, 27);
    154157      this.encodingDetailsGroupBox.Name = "encodingDetailsGroupBox";
    155       this.encodingDetailsGroupBox.Size = new System.Drawing.Size(430, 422);
     158      this.encodingDetailsGroupBox.Size = new System.Drawing.Size(386, 390);
    156159      this.encodingDetailsGroupBox.TabIndex = 1;
    157160      this.encodingDetailsGroupBox.TabStop = false;
     
    167170      this.encodingDetailViewHost.Name = "encodingDetailViewHost";
    168171      this.encodingDetailViewHost.ReadOnly = false;
    169       this.encodingDetailViewHost.Size = new System.Drawing.Size(424, 403);
     172      this.encodingDetailViewHost.Size = new System.Drawing.Size(380, 371);
    170173      this.encodingDetailViewHost.TabIndex = 0;
    171174      this.encodingDetailViewHost.ViewsLabelVisible = true;
    172175      this.encodingDetailViewHost.ViewType = null;
    173176      //
    174       // encodingNameColumnHeader
    175       //
    176       this.encodingNameColumnHeader.Text = "Name";
    177       this.encodingNameColumnHeader.Width = 80;
    178       //
    179       // encodingTypeColumnHeader
    180       //
    181       this.encodingTypeColumnHeader.Text = "Type";
    182       this.encodingTypeColumnHeader.Width = 120;
     177      // encodingsGroupBox
     178      //
     179      this.encodingsGroupBox.Controls.Add(this.splitContainer);
     180      this.encodingsGroupBox.Dock = System.Windows.Forms.DockStyle.Fill;
     181      this.encodingsGroupBox.Location = new System.Drawing.Point(3, 3);
     182      this.encodingsGroupBox.Name = "encodingsGroupBox";
     183      this.encodingsGroupBox.Size = new System.Drawing.Size(649, 439);
     184      this.encodingsGroupBox.TabIndex = 6;
     185      this.encodingsGroupBox.TabStop = false;
     186      this.encodingsGroupBox.Text = "Encodings";
     187      //
     188      // tabControl
     189      //
     190      this.tabControl.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
     191            | System.Windows.Forms.AnchorStyles.Left)
     192            | System.Windows.Forms.AnchorStyles.Right)));
     193      this.tabControl.Controls.Add(this.encodingsTabPage);
     194      this.tabControl.Controls.Add(this.parametersTabPage);
     195      this.tabControl.Location = new System.Drawing.Point(0, 26);
     196      this.tabControl.Name = "tabControl";
     197      this.tabControl.SelectedIndex = 0;
     198      this.tabControl.Size = new System.Drawing.Size(663, 471);
     199      this.tabControl.TabIndex = 7;
     200      //
     201      // encodingsTabPage
     202      //
     203      this.encodingsTabPage.Controls.Add(this.encodingsGroupBox);
     204      this.encodingsTabPage.Location = new System.Drawing.Point(4, 22);
     205      this.encodingsTabPage.Name = "encodingsTabPage";
     206      this.encodingsTabPage.Padding = new System.Windows.Forms.Padding(3);
     207      this.encodingsTabPage.Size = new System.Drawing.Size(655, 445);
     208      this.encodingsTabPage.TabIndex = 0;
     209      this.encodingsTabPage.Text = "Encodings";
     210      this.encodingsTabPage.UseVisualStyleBackColor = true;
     211      //
     212      // parametersTabPage
     213      //
     214      this.parametersTabPage.Location = new System.Drawing.Point(4, 22);
     215      this.parametersTabPage.Name = "parametersTabPage";
     216      this.parametersTabPage.Padding = new System.Windows.Forms.Padding(3);
     217      this.parametersTabPage.Size = new System.Drawing.Size(655, 445);
     218      this.parametersTabPage.TabIndex = 1;
     219      this.parametersTabPage.Text = "Parameters";
     220      this.parametersTabPage.UseVisualStyleBackColor = true;
    183221      //
    184222      // MultiEncodingView
    185223      //
    186224      this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Inherit;
    187       this.Controls.Add(this.encodingsGroupBox);
     225      this.Controls.Add(this.tabControl);
    188226      this.Name = "MultiEncodingView";
    189227      this.Size = new System.Drawing.Size(666, 497);
     228      this.Controls.SetChildIndex(this.parameterCollectionView, 0);
    190229      this.Controls.SetChildIndex(this.nameLabel, 0);
    191230      this.Controls.SetChildIndex(this.nameTextBox, 0);
    192231      this.Controls.SetChildIndex(this.infoLabel, 0);
    193       this.Controls.SetChildIndex(this.encodingsGroupBox, 0);
     232      this.Controls.SetChildIndex(this.tabControl, 0);
    194233      ((System.ComponentModel.ISupportInitialize)(this.errorProvider)).EndInit();
    195234      this.splitContainer.Panel1.ResumeLayout(false);
     
    197236      ((System.ComponentModel.ISupportInitialize)(this.splitContainer)).EndInit();
    198237      this.splitContainer.ResumeLayout(false);
     238      this.encodingDetailsGroupBox.ResumeLayout(false);
    199239      this.encodingsGroupBox.ResumeLayout(false);
    200       this.encodingDetailsGroupBox.ResumeLayout(false);
     240      this.tabControl.ResumeLayout(false);
     241      this.encodingsTabPage.ResumeLayout(false);
    201242      this.ResumeLayout(false);
    202243      this.PerformLayout();
     
    215256    private MainForm.WindowsForms.ViewHost encodingDetailViewHost;
    216257    private System.Windows.Forms.GroupBox encodingsGroupBox;
     258    private System.Windows.Forms.TabControl tabControl;
     259    private System.Windows.Forms.TabPage encodingsTabPage;
     260    private System.Windows.Forms.TabPage parametersTabPage;
    217261  }
    218262}
  • branches/ProgrammableProblem/HeuristicLab.Problems.Programmable.Views/3.3/MultiEncodingView.cs

    r11949 r11952  
    3333  [View("MultiEncoding View")]
    3434  [Content(typeof(MultiEncoding), IsDefaultView = true)]
    35   public sealed partial class MultiEncodingView : NamedItemView {
     35  public sealed partial class MultiEncodingView : ParameterizedNamedItemView {
    3636
    3737    public new MultiEncoding Content {
     
    4242    public MultiEncodingView() {
    4343      InitializeComponent();
     44      Controls.Remove(parameterCollectionView);
     45      parameterCollectionView.Dock = DockStyle.Fill;
     46      parametersTabPage.Controls.Add(parameterCollectionView);
    4447      addEncodingButton.Text = string.Empty;
    4548      addEncodingButton.Image = VSImageLibrary.Add;
     
    7780    private void addEncodingButton_Click(object sender, EventArgs e) {
    7881      using (var dialog = new CreateNewSingleEncodingDialog()) {
    79         dialog.ForbiddenNames = Content.Encodings.Select(x => x.Name);
     82        dialog.ForbiddenNames = Content.Encodings.Select(x => x.Name).Concat(new[] { Content.Name });
    8083        if (dialog.ShowDialog() == DialogResult.OK) {
    8184          IEncoding encoding;
    8285          try {
    8386            encoding = (IEncoding)Activator.CreateInstance(dialog.EncodingType, dialog.EncodingName);
    84           }
    85           catch (MissingMethodException mmex) {
    86             PluginInfrastructure.ErrorHandling.ShowErrorDialog(
    87               "The encoding must have a constructor that takes the name as a single string argument", mmex);
     87          } catch (MissingMethodException mmex) {
     88            PluginInfrastructure.ErrorHandling.ShowErrorDialog("The encoding must have a constructor that takes the name as a single string argument", mmex);
    8889            return;
    89           }
    90           catch (TargetInvocationException tiex) {
     90          } catch (TargetInvocationException tiex) {
    9191            PluginInfrastructure.ErrorHandling.ShowErrorDialog("The encoding could not be created due to an error in the constructor.", tiex);
    9292            return;
    93           }
    94           catch (MethodAccessException maex) {
     93          } catch (MethodAccessException maex) {
    9594            PluginInfrastructure.ErrorHandling.ShowErrorDialog("The encoding's string constructor is not public.", maex);
    9695            return;
Note: See TracChangeset for help on using the changeset viewer.