Free cookie consent management tool by TermsFeed Policy Generator

source: branches/HL-3.2-MonoMigration/HeuristicLab.StructureIdentification/GPOperatorLibraryEditor.cs @ 3747

Last change on this file since 3747 was 432, checked in by gkronber, 16 years ago
  • removed the button and methods for manual recalculation of min tree bounds introduced with r423 because it soon won't be needed anymore
  • GPOperatorGroup adds event-handlers to SubOperatorTypeConstraints on the operators added to the library to automatically update min tree size and height when any of them is changed.

(ticket #225)

File size: 5.3 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2008 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
4 *
5 * This file is part of HeuristicLab.
6 *
7 * HeuristicLab is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * HeuristicLab is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
19 */
20#endregion
21
22using System;
23using System.Collections.Generic;
24using System.ComponentModel;
25using System.Drawing;
26using System.Data;
27using System.Linq;
28using System.Text;
29using System.Windows.Forms;
30using HeuristicLab.Core;
31using System.Diagnostics;
32using HeuristicLab.Data;
33using HeuristicLab.Operators;
34using HeuristicLab.Random;
35using HeuristicLab.Functions;
36
37namespace HeuristicLab.StructureIdentification {
38  public partial class GPOperatorLibraryEditor : EditorBase {
39    public IOperatorLibrary OperatorLibrary {
40      get { return (IOperatorLibrary)Item; }
41      set { base.Item = value; }
42    }
43
44    public GPOperatorLibraryEditor(GPOperatorLibrary library)
45      : base() {
46      InitializeComponent();
47      OperatorLibrary = library;
48      operatorLibraryEditor.OperatorLibrary = library;
49
50      library.GPOperatorGroup.OperatorAdded += new EventHandler(GPOperatorLibraryView_OperatorAdded);
51      library.GPOperatorGroup.OperatorRemoved += new EventHandler(GPOperatorGroup_OperatorRemoved);
52
53      mutationVariableView.Enabled = false;
54      initVariableView.Enabled = false;
55
56      foreach(IOperator op in library.Group.Operators) {
57        if(op.GetVariable(FunctionBase.MANIPULATION) != null) {
58          ListViewItem item = new ListViewItem();
59          item.Text = op.Name;
60          item.Name = op.Name;
61          item.Tag = op;
62          mutationListView.Items.Add(item);
63        }
64        if(op.GetVariable(FunctionBase.INITIALIZATION) != null) {
65          ListViewItem item = new ListViewItem();
66          item.Name = op.Name;
67          item.Text = op.Name;
68          item.Tag = op;
69          initListView.Items.Add(item);
70        }
71      }
72    }
73
74
75    private void GPOperatorLibraryView_OperatorAdded(object sender, EventArgs e) {
76      IOperator op = ((OperatorEventArgs)e).op;
77      if(op.GetVariable(FunctionBase.MANIPULATION) != null) {
78        ListViewItem operatorMutationItem = new ListViewItem();
79        operatorMutationItem.Name = op.Name;
80        operatorMutationItem.Text = op.Name;
81        operatorMutationItem.Tag = op;
82        mutationListView.Items.Add(operatorMutationItem);
83      }
84
85      if(op.GetVariable(FunctionBase.INITIALIZATION) != null) {
86        ListViewItem operatorInitItem = new ListViewItem();
87        operatorInitItem.Name = op.Name;
88        operatorInitItem.Text = op.Name;
89        operatorInitItem.Tag = op;
90        initListView.Items.Add(operatorInitItem);
91      }
92
93      op.NameChanged += new EventHandler(op_NameChanged);
94      Refresh();
95    }
96
97    private void op_NameChanged(object sender, EventArgs e) {
98      IOperator srcOp = (IOperator)sender;
99      foreach(ListViewItem item in mutationListView.Items) {
100        if(item.Tag == srcOp) {
101          item.Name = srcOp.Name;
102          item.Text = srcOp.Name;
103          break;
104        }
105      }
106      foreach(ListViewItem item in initListView.Items) {
107        if(item.Tag == srcOp) {
108          item.Name = srcOp.Name;
109          item.Text = srcOp.Name;
110          break;
111        }
112      }
113    }
114
115
116    private void GPOperatorGroup_OperatorRemoved(object sender, EventArgs e) {
117      IOperator op = ((OperatorEventArgs)e).op;
118
119      foreach(ListViewItem item in mutationListView.Items) {
120        if(item.Tag == op) {
121          mutationListView.Items.Remove(item);
122          break;
123        }
124      }
125
126      foreach(ListViewItem item in initListView.Items) {
127        if(item.Tag == op) {
128          initListView.Items.Remove(item);
129          break;
130        }
131      }
132    }
133
134    private void mutationListView_SelectedIndexChanged(object sender, EventArgs e) {
135      if(mutationListView.SelectedItems.Count>0 && mutationListView.SelectedItems[0].Tag != null) {
136        IVariable variable = ((IOperator)mutationListView.SelectedItems[0].Tag).GetVariable(FunctionBase.MANIPULATION);
137        mutationVariableView.Enabled = true;
138        mutationVariableView.Variable = variable;
139      } else {
140        mutationVariableView.Enabled = false;
141      }
142    }
143
144    private void initListView_SelectedIndexChanged(object sender, EventArgs e) {
145      if(initListView.SelectedItems.Count>0 && initListView.SelectedItems[0].Tag != null) {
146        IVariable variable = ((IOperator)initListView.SelectedItems[0].Tag).GetVariable(FunctionBase.INITIALIZATION);
147        initVariableView.Enabled = true;
148        initVariableView.Variable = variable;
149      } else {
150        initVariableView.Enabled = false;
151      }
152    }
153  }
154}
Note: See TracBrowser for help on using the repository browser.