[3824] | 1 | #region License Information
|
---|
| 2 | /* HeuristicLab
|
---|
[17207] | 3 | * Copyright (C) Heuristic and Evolutionary Algorithms Laboratory (HEAL)
|
---|
[3824] | 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 |
|
---|
| 22 | using System;
|
---|
[5750] | 23 | using System.Linq;
|
---|
[3824] | 24 | using System.Windows.Forms;
|
---|
[6233] | 25 | using HeuristicLab.Collections;
|
---|
| 26 | using HeuristicLab.Core;
|
---|
| 27 | using HeuristicLab.Core.Views;
|
---|
| 28 | using HeuristicLab.Data;
|
---|
[4068] | 29 | using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Views;
|
---|
[3824] | 30 | using HeuristicLab.MainForm;
|
---|
| 31 |
|
---|
[5693] | 32 |
|
---|
| 33 | namespace HeuristicLab.Problems.DataAnalysis.Symbolic.Views {
|
---|
[3824] | 34 | [View("Variable View")]
|
---|
[14826] | 35 | [Content(typeof(VariableBase), true)]
|
---|
[3824] | 36 | public partial class VariableView : SymbolView {
|
---|
[5750] | 37 | private CheckedItemCollectionView<StringValue> variableNamesView;
|
---|
| 38 |
|
---|
[14826] | 39 | public new VariableBase Content {
|
---|
| 40 | get { return (VariableBase)base.Content; }
|
---|
[3824] | 41 | set { base.Content = value; }
|
---|
| 42 | }
|
---|
| 43 |
|
---|
| 44 | public VariableView() {
|
---|
| 45 | InitializeComponent();
|
---|
[5750] | 46 | variableNamesView = new CheckedItemCollectionView<StringValue>();
|
---|
| 47 | variableNamesView.Dock = DockStyle.Fill;
|
---|
| 48 | variableNamesTabPage.Controls.Add(variableNamesView);
|
---|
| 49 | variableNamesView.Content = new CheckedItemCollection<StringValue>();
|
---|
| 50 |
|
---|
| 51 | RegisterVariableNamesViewContentEvents();
|
---|
[3824] | 52 | }
|
---|
| 53 |
|
---|
[5750] | 54 | private void RegisterVariableNamesViewContentEvents() {
|
---|
[8103] | 55 | variableNamesView.Content.ItemsAdded += new CollectionItemsChangedEventHandler<StringValue>(VariableNames_Changed);
|
---|
[11346] | 56 | variableNamesView.Content.ItemsRemoved += new CollectionItemsChangedEventHandler<StringValue>(VariableNames_Removed);
|
---|
[8103] | 57 | variableNamesView.Content.CheckedItemsChanged += new CollectionItemsChangedEventHandler<StringValue>(VariableNames_Changed);
|
---|
| 58 | variableNamesView.Content.CollectionReset += new CollectionItemsChangedEventHandler<StringValue>(VariableNames_Changed);
|
---|
[6598] | 59 | foreach (var variable in variableNamesView.Content) {
|
---|
[8103] | 60 | variable.ValueChanged += new EventHandler(Variable_ValueChanged);
|
---|
[6598] | 61 | }
|
---|
[5750] | 62 | }
|
---|
| 63 |
|
---|
[6599] | 64 |
|
---|
[5750] | 65 | private void DeregisterVariableNamesViewContentEvents() {
|
---|
[8103] | 66 | variableNamesView.Content.ItemsAdded -= new CollectionItemsChangedEventHandler<StringValue>(VariableNames_Changed);
|
---|
[11346] | 67 | variableNamesView.Content.ItemsRemoved -= new CollectionItemsChangedEventHandler<StringValue>(VariableNames_Removed);
|
---|
[8103] | 68 | variableNamesView.Content.CheckedItemsChanged -= new CollectionItemsChangedEventHandler<StringValue>(VariableNames_Changed);
|
---|
| 69 | variableNamesView.Content.CollectionReset -= new CollectionItemsChangedEventHandler<StringValue>(VariableNames_Changed);
|
---|
[6598] | 70 | foreach (var variable in variableNamesView.Content) {
|
---|
[8103] | 71 | variable.ValueChanged -= new EventHandler(Variable_ValueChanged);
|
---|
[6598] | 72 | }
|
---|
[5750] | 73 | }
|
---|
| 74 |
|
---|
| 75 |
|
---|
[3824] | 76 | protected override void RegisterContentEvents() {
|
---|
| 77 | base.RegisterContentEvents();
|
---|
| 78 | Content.Changed += new EventHandler(Content_Changed);
|
---|
| 79 | }
|
---|
| 80 |
|
---|
| 81 | protected override void DeregisterContentEvents() {
|
---|
| 82 | base.DeregisterContentEvents();
|
---|
| 83 | Content.Changed -= new EventHandler(Content_Changed);
|
---|
| 84 | }
|
---|
| 85 |
|
---|
| 86 | protected override void OnContentChanged() {
|
---|
| 87 | base.OnContentChanged();
|
---|
| 88 | UpdateControl();
|
---|
| 89 | }
|
---|
| 90 |
|
---|
[3904] | 91 | protected override void SetEnabledStateOfControls() {
|
---|
| 92 | base.SetEnabledStateOfControls();
|
---|
[8476] | 93 | enabledCheckBox.Enabled = Content != null && Content.VariableNames.Any() && !Locked && !ReadOnly;
|
---|
[5326] | 94 | weightInitializationMuTextBox.Enabled = Content != null;
|
---|
| 95 | weightInitializationMuTextBox.ReadOnly = ReadOnly;
|
---|
| 96 | weightInitializationSigmaTextBox.Enabled = Content != null;
|
---|
| 97 | weightInitializationSigmaTextBox.ReadOnly = ReadOnly;
|
---|
| 98 | additiveWeightChangeSigmaTextBox.Enabled = Content != null;
|
---|
| 99 | additiveWeightChangeSigmaTextBox.ReadOnly = ReadOnly;
|
---|
| 100 | multiplicativeWeightChangeSigmaTextBox.Enabled = Content != null;
|
---|
[6599] | 101 | multiplicativeWeightChangeSigmaTextBox.ReadOnly = ReadOnly;
|
---|
[14826] | 102 | varChangeProbTextBox.Enabled = Content != null;
|
---|
| 103 | varChangeProbTextBox.ReadOnly = ReadOnly;
|
---|
[3824] | 104 | }
|
---|
| 105 |
|
---|
| 106 | #region content event handlers
|
---|
| 107 | private void Content_Changed(object sender, EventArgs e) {
|
---|
| 108 | UpdateControl();
|
---|
| 109 | }
|
---|
| 110 | #endregion
|
---|
| 111 |
|
---|
| 112 | #region control event handlers
|
---|
[8103] | 113 | private void VariableNames_Changed(object sender, CollectionItemsChangedEventArgs<StringValue> e) {
|
---|
| 114 | foreach (var newVar in e.Items)
|
---|
| 115 | newVar.ValueChanged += new EventHandler(Variable_ValueChanged);
|
---|
| 116 | foreach (var oldVar in e.OldItems)
|
---|
| 117 | oldVar.ValueChanged -= new EventHandler(Variable_ValueChanged);
|
---|
[6598] | 118 | UpdateContent();
|
---|
[6599] | 119 | }
|
---|
[6598] | 120 |
|
---|
[11346] | 121 | private void VariableNames_Removed(object sender, CollectionItemsChangedEventArgs<StringValue> e) {
|
---|
| 122 | foreach (var newVar in e.Items)
|
---|
| 123 | newVar.ValueChanged -= new EventHandler(Variable_ValueChanged);
|
---|
| 124 | UpdateContent();
|
---|
| 125 | }
|
---|
| 126 |
|
---|
[8103] | 127 | private void Variable_ValueChanged(object sender, EventArgs e) {
|
---|
[6598] | 128 | UpdateContent();
|
---|
| 129 | }
|
---|
| 130 |
|
---|
| 131 | private void UpdateContent() {
|
---|
[5750] | 132 | if (Content != null) {
|
---|
[8936] | 133 | Content.Fixed = true;
|
---|
[6803] | 134 | DeregisterContentEvents();
|
---|
[11679] | 135 | Content.VariableNames = variableNamesView.Content.CheckedItems.Select(x => x.Value);
|
---|
| 136 | Content.AllVariableNames = variableNamesView.Content.Select(x => x.Value);
|
---|
[6803] | 137 | RegisterContentEvents();
|
---|
[5750] | 138 | }
|
---|
| 139 | }
|
---|
| 140 |
|
---|
[8103] | 141 | private void WeightMuTextBox_TextChanged(object sender, EventArgs e) {
|
---|
[3824] | 142 | double nu;
|
---|
[5326] | 143 | if (double.TryParse(weightInitializationMuTextBox.Text, out nu)) {
|
---|
[4989] | 144 | Content.WeightMu = nu;
|
---|
[5326] | 145 | errorProvider.SetError(weightInitializationMuTextBox, string.Empty);
|
---|
[3824] | 146 | } else {
|
---|
[5326] | 147 | errorProvider.SetError(weightInitializationMuTextBox, "Invalid value");
|
---|
[3824] | 148 | }
|
---|
| 149 | }
|
---|
[8103] | 150 | private void WeightSigmaTextBox_TextChanged(object sender, EventArgs e) {
|
---|
[3824] | 151 | double sigma;
|
---|
[5326] | 152 | if (double.TryParse(weightInitializationSigmaTextBox.Text, out sigma) && sigma >= 0.0) {
|
---|
[3824] | 153 | Content.WeightSigma = sigma;
|
---|
[5326] | 154 | errorProvider.SetError(weightInitializationSigmaTextBox, string.Empty);
|
---|
[3824] | 155 | } else {
|
---|
[5326] | 156 | errorProvider.SetError(weightInitializationSigmaTextBox, "Invalid value");
|
---|
[3824] | 157 | }
|
---|
| 158 | }
|
---|
| 159 |
|
---|
[8103] | 160 | private void AdditiveWeightChangeSigmaTextBox_TextChanged(object sender, EventArgs e) {
|
---|
[5326] | 161 | double sigma;
|
---|
| 162 | if (double.TryParse(additiveWeightChangeSigmaTextBox.Text, out sigma) && sigma >= 0.0) {
|
---|
| 163 | Content.WeightManipulatorSigma = sigma;
|
---|
| 164 | errorProvider.SetError(additiveWeightChangeSigmaTextBox, string.Empty);
|
---|
[3824] | 165 | } else {
|
---|
[5326] | 166 | errorProvider.SetError(additiveWeightChangeSigmaTextBox, "Invalid value");
|
---|
[3824] | 167 | }
|
---|
| 168 | }
|
---|
[8103] | 169 | private void MultiplicativeWeightChangeSigmaTextBox_TextChanged(object sender, EventArgs e) {
|
---|
[3824] | 170 | double sigma;
|
---|
[5326] | 171 | if (double.TryParse(multiplicativeWeightChangeSigmaTextBox.Text, out sigma) && sigma >= 0.0) {
|
---|
| 172 | Content.MultiplicativeWeightManipulatorSigma = sigma;
|
---|
| 173 | errorProvider.SetError(multiplicativeWeightChangeSigmaTextBox, string.Empty);
|
---|
[3824] | 174 | } else {
|
---|
[5326] | 175 | errorProvider.SetError(multiplicativeWeightChangeSigmaTextBox, "Invalid value");
|
---|
[3824] | 176 | }
|
---|
| 177 | }
|
---|
[14826] | 178 |
|
---|
| 179 | private void VarProbTextBox_TextChanged(object sender, EventArgs e) {
|
---|
| 180 | double prob;
|
---|
| 181 | if (double.TryParse(varChangeProbTextBox.Text, out prob) && prob >= 0.0 && prob <= 1.0) {
|
---|
| 182 | Content.VariableChangeProbability = prob;
|
---|
| 183 | errorProvider.SetError(varChangeProbTextBox, string.Empty);
|
---|
| 184 | } else {
|
---|
| 185 | errorProvider.SetError(varChangeProbTextBox, "Invalid value");
|
---|
| 186 | }
|
---|
| 187 | }
|
---|
[3824] | 188 | #endregion
|
---|
| 189 |
|
---|
| 190 | #region helpers
|
---|
| 191 | private void UpdateControl() {
|
---|
| 192 | if (Content == null) {
|
---|
[5326] | 193 | weightInitializationMuTextBox.Text = string.Empty;
|
---|
| 194 | weightInitializationSigmaTextBox.Text = string.Empty;
|
---|
| 195 | additiveWeightChangeSigmaTextBox.Text = string.Empty;
|
---|
| 196 | multiplicativeWeightChangeSigmaTextBox.Text = string.Empty;
|
---|
[14826] | 197 | varChangeProbTextBox.Text = string.Empty;
|
---|
[5750] | 198 | // temporarily deregister to prevent circular calling of events
|
---|
| 199 | DeregisterVariableNamesViewContentEvents();
|
---|
| 200 | variableNamesView.Content.Clear();
|
---|
| 201 | RegisterVariableNamesViewContentEvents();
|
---|
[3824] | 202 | } else {
|
---|
[5750] | 203 | // temporarily deregister to prevent circular calling of events
|
---|
| 204 | DeregisterVariableNamesViewContentEvents();
|
---|
[8853] | 205 | variableNamesView.Content.Clear();
|
---|
| 206 | foreach (var variableName in Content.AllVariableNames) {
|
---|
| 207 | variableNamesView.Content.Add(new StringValue(variableName), Content.VariableNames.Contains(variableName));
|
---|
| 208 | }
|
---|
[5750] | 209 | RegisterVariableNamesViewContentEvents();
|
---|
| 210 |
|
---|
[5326] | 211 | weightInitializationMuTextBox.Text = Content.WeightMu.ToString();
|
---|
| 212 | weightInitializationSigmaTextBox.Text = Content.WeightSigma.ToString();
|
---|
| 213 | additiveWeightChangeSigmaTextBox.Text = Content.WeightManipulatorSigma.ToString();
|
---|
| 214 | multiplicativeWeightChangeSigmaTextBox.Text = Content.MultiplicativeWeightManipulatorSigma.ToString();
|
---|
[14826] | 215 | varChangeProbTextBox.Text = Content.VariableChangeProbability.ToString();
|
---|
[3824] | 216 | }
|
---|
| 217 | SetEnabledStateOfControls();
|
---|
| 218 | }
|
---|
| 219 | #endregion
|
---|
[14826] | 220 |
|
---|
[3824] | 221 | }
|
---|
| 222 | }
|
---|