Free cookie consent management tool by TermsFeed Policy Generator

Changeset 6233


Ignore:
Timestamp:
05/19/11 13:52:12 (14 years ago)
Author:
mkommend
Message:

#1532:

  • Enabled renaming of symbols
  • Fixed cloning of grammers
  • Added readonly attribute in grammars to lock grammars during the algorithm run
  • Removed useless clone method in cloner
  • Changed CheckedItemCollectionViews to enable scrolling during the locked state
Location:
trunk/sources
Files:
22 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Common/3.3/Cloner.cs

    r5445 r6233  
    4141    /// <param name="item">The object which should be cloned.</param>
    4242    /// <returns>A clone of the given object.</returns>
    43     public IDeepCloneable Clone(IDeepCloneable obj) {
    44       if (obj == null) return null;
    45       IDeepCloneable clone;
    46       if (mapping.TryGetValue(obj, out clone))
    47         return clone;
    48       else
    49         return obj.Clone(this);
    50     }
    51     /// <summary>
    52     /// Creates a deep clone of a given deeply cloneable object.
    53     /// </summary>
    54     /// <param name="item">The object which should be cloned.</param>
    55     /// <returns>A clone of the given object.</returns>
    5643    public T Clone<T>(T obj) where T : class, IDeepCloneable {
    5744      if (obj == null) return null;
  • trunk/sources/HeuristicLab.Core.Views/3.3/CheckedItemCollectionView.cs

    r5445 r6233  
    2020#endregion
    2121
     22using System.Drawing;
    2223using System.Windows.Forms;
    2324using HeuristicLab.Collections;
     
    4950    }
    5051
     52    private Color backupColor = Color.Empty;
    5153    protected override void SetEnabledStateOfControls() {
     54      if (backupColor == Color.Empty) backupColor = base.itemsListView.BackColor;
    5255      base.SetEnabledStateOfControls();
    53       base.itemsListView.Enabled = !this.Locked;
     56      if (ReadOnly || Locked)
     57        base.itemsListView.BackColor = ListView.DefaultBackColor;
     58      else
     59        base.itemsListView.BackColor = backupColor;
    5460    }
    5561
     
    7076        bool check = e.NewValue == CheckState.Checked;
    7177        if (Content.ItemChecked(checkedItem) != check) {
    72           Content.SetItemCheckedState(checkedItem, check);
     78          if (!ReadOnly && !Locked) Content.SetItemCheckedState(checkedItem, check);
     79          else e.NewValue = e.CurrentValue;
    7380        }
    7481      }
  • trunk/sources/HeuristicLab.Core.Views/3.3/CheckedItemListView.cs

    r5445 r6233  
    2020#endregion
    2121
     22using System.Drawing;
    2223using System.Windows.Forms;
    2324using HeuristicLab.Collections;
     
    5152    }
    5253
     54    private Color backupColor = Color.Empty;
    5355    protected override void SetEnabledStateOfControls() {
     56      if(backupColor == Color.Empty) backupColor = base.itemsListView.BackColor;
    5457      base.SetEnabledStateOfControls();
    55       base.itemsListView.Enabled = !this.Locked;
     58      if (ReadOnly || Locked)
     59        base.itemsListView.BackColor = ListView.DefaultBackColor;
     60      else
     61        base.itemsListView.BackColor = backupColor;
    5662    }
    5763
     
    7278        bool check = e.NewValue == CheckState.Checked;
    7379        if (Content.ItemChecked(checkedItem) != check) {
    74           Content.SetItemCheckedState(checkedItem, check);
     80          if (!ReadOnly && !Locked) Content.SetItemCheckedState(checkedItem, check);
     81          else e.NewValue = e.CurrentValue;
    7582        }
    7683      }
  • trunk/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Views/3.4/SymbolView.cs

    r6109 r6233  
    2121
    2222using System;
     23using System.ComponentModel;
    2324using System.Windows.Forms;
    2425using HeuristicLab.Core.Views;
    2526using HeuristicLab.MainForm;
    2627using HeuristicLab.MainForm.WindowsForms;
    27 using System.ComponentModel;
    2828
    2929namespace HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Views {
     
    9191      if (double.TryParse(initialFrequencyTextBox.Text, out freq) && freq >= 0.0) {
    9292        Content.InitialFrequency = freq;
    93       } 
     93      }
    9494    }
    9595    #endregion
  • trunk/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Views/3.4/SymbolicExpressionGrammarView.cs

    r5809 r6233  
    3939    }
    4040
     41    public override bool ReadOnly {
     42      get {
     43        if ((Content != null) && Content.ReadOnly) return true;
     44        return base.ReadOnly;
     45      }
     46      set {
     47        if ((Content != null) && Content.ReadOnly) base.ReadOnly = true;
     48        else base.ReadOnly = value;
     49      }
     50    }
     51
    4152    public SymbolicExpressionGrammarView() {
    4253      InitializeComponent();
    4354      symbols = new CheckedItemList<ISymbol>();
    4455      symbols.CheckedItemsChanged += new CollectionItemsChangedEventHandler<IndexedItem<ISymbol>>(symbols_CheckedItemsChanged);
     56    }
     57
     58    protected override void RegisterContentEvents() {
     59      base.RegisterContentEvents();
     60      Content.ReadOnlyChanged += new EventHandler(Content_ReadOnlyChanged);
     61    }
     62    protected override void DeregisterContentEvents() {
     63      base.DeregisterContentEvents();
     64      Content.ReadOnlyChanged -= new EventHandler(Content_ReadOnlyChanged);
    4565    }
    4666
     
    5070    }
    5171
    52     protected override void SetEnabledStateOfControls() {
    53       base.SetEnabledStateOfControls();
    54       checkedItemListView.Enabled = Content != null;
    55       checkedItemListView.ReadOnly = ReadOnly;
     72    private void Content_ReadOnlyChanged(object sender, EventArgs e) {
     73      ReadOnly = Content.ReadOnly;
    5674    }
    5775
     
    6987      } else {
    7088        ClearSymbols();
    71         foreach (Symbol symbol in Content.Symbols) {
     89        foreach (ISymbol symbol in Content.Symbols) {
    7290          if (!(symbol is IReadOnlySymbol)) {
    7391            symbol.Changed += new EventHandler(symbol_Changed);
  • trunk/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/ArchitectureManipulators/SubroutineDuplicater.cs

    r5809 r6233  
    8383          subtree.Grammar.SetSubtreeCount(invokeSymbol, duplicatedDefunBranch.NumberOfArguments, duplicatedDefunBranch.NumberOfArguments);
    8484
    85           foreach (Symbol symbol in subtree.Grammar.Symbols) {
     85          foreach (ISymbol symbol in subtree.Grammar.Symbols) {
    8686            if (subtree.Grammar.IsAllowedChildSymbol(symbol, matchingInvokeSymbol))
    8787              subtree.Grammar.AddAllowedChildSymbol(symbol, invokeSymbol);
     
    9393          }
    9494
    95           foreach (Symbol symbol in subtree.Grammar.GetAllowedChildSymbols(matchingInvokeSymbol))
     95          foreach (ISymbol symbol in subtree.Grammar.GetAllowedChildSymbols(matchingInvokeSymbol))
    9696            if (symbol != invokeSymbol) //avoid duplicate entry invokesymbol / invokesymbol
    9797              subtree.Grammar.AddAllowedChildSymbol(invokeSymbol, symbol);
    9898          for (int i = 0; i < subtree.Grammar.GetMaximumSubtreeCount(matchingInvokeSymbol); i++) {
    99             foreach (Symbol symbol in subtree.Grammar.GetAllowedChildSymbols(matchingInvokeSymbol, i).Except(subtree.Grammar.GetAllowedChildSymbols(matchingInvokeSymbol)))
     99            foreach (ISymbol symbol in subtree.Grammar.GetAllowedChildSymbols(matchingInvokeSymbol, i).Except(subtree.Grammar.GetAllowedChildSymbols(matchingInvokeSymbol)))
    100100              subtree.Grammar.AddAllowedChildSymbol(invokeSymbol, symbol, i);
    101101          }
  • trunk/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/Creators/ProbabilisticTreeCreator.cs

    r6009 r6233  
    3838    private const string MaximumSymbolicExpressionTreeDepthParameterName = "MaximumSymbolicExpressionTreeDepth";
    3939    private const string SymbolicExpressionTreeGrammarParameterName = "SymbolicExpressionTreeGrammar";
     40    private const string ClonedSymbolicExpressionTreeGrammarParameterName = "ClonedSymbolicExpressionTreeGrammar";
    4041    #region Parameter Properties
    4142    public IValueLookupParameter<IntValue> MaximumSymbolicExpressionTreeLengthParameter {
     
    4748    public IValueLookupParameter<ISymbolicExpressionGrammar> SymbolicExpressionTreeGrammarParameter {
    4849      get { return (IValueLookupParameter<ISymbolicExpressionGrammar>)Parameters[SymbolicExpressionTreeGrammarParameterName]; }
     50    }
     51    public ILookupParameter<ISymbolicExpressionGrammar> ClonedSymbolicExpressionTreeGrammarParameter {
     52      get { return (ILookupParameter<ISymbolicExpressionGrammar>)Parameters[ClonedSymbolicExpressionTreeGrammarParameterName]; }
    4953    }
    5054    #endregion
     
    5761    }
    5862    public ISymbolicExpressionGrammar SymbolicExpressionTreeGrammar {
    59       get { return SymbolicExpressionTreeGrammarParameter.ActualValue; }
     63      get { return ClonedSymbolicExpressionTreeGrammarParameter.ActualValue; }
    6064    }
    6165    #endregion
     
    6973      Parameters.Add(new ValueLookupParameter<IntValue>(MaximumSymbolicExpressionTreeDepthParameterName, "The maximal depth of the symbolic expression tree (a tree with one node has depth = 0)."));
    7074      Parameters.Add(new ValueLookupParameter<ISymbolicExpressionGrammar>(SymbolicExpressionTreeGrammarParameterName, "The tree grammar that defines the correct syntax of symbolic expression trees that should be created."));
     75      Parameters.Add(new LookupParameter<ISymbolicExpressionGrammar>(ClonedSymbolicExpressionTreeGrammarParameterName, "An immutable clone of the concrete grammar that is actually used to create and manipulate trees."));
    7176    }
    7277
     
    7479      return new ProbabilisticTreeCreator(this, cloner);
    7580    }
     81    [StorableHook(HookType.AfterDeserialization)]
     82    private void AfterDeserialization() {
     83      if (!Parameters.ContainsKey(ClonedSymbolicExpressionTreeGrammarParameterName))
     84        Parameters.Add(new LookupParameter<ISymbolicExpressionGrammar>(ClonedSymbolicExpressionTreeGrammarParameterName, "An immutable clone of the concrete grammar that is actually used to create and manipulate trees."));
     85    }
     86
     87    public override IOperation Apply() {
     88      if (ClonedSymbolicExpressionTreeGrammarParameter.ActualValue == null) {
     89        SymbolicExpressionTreeGrammarParameter.ActualValue.ReadOnly = true;
     90        IScope globalScope = ExecutionContext.Scope;
     91        while (globalScope.Parent != null)
     92          globalScope = globalScope.Parent;
     93
     94        globalScope.Variables.Add(new Variable(ClonedSymbolicExpressionTreeGrammarParameterName, (ISymbolicExpressionGrammar)SymbolicExpressionTreeGrammarParameter.ActualValue.Clone()));
     95      }
     96      return base.Apply();
     97    }
    7698
    7799    protected override ISymbolicExpressionTree Create(IRandom random) {
    78100      return Create(random, SymbolicExpressionTreeGrammar, MaximumSymbolicExpressionTreeLength.Value, MaximumSymbolicExpressionTreeDepth.Value);
    79 
    80101    }
    81102
     
    165186                                select s)
    166187                               .ToList();
     188          if (allowedSymbols.Count == 0) return false;
    167189          var weights = allowedSymbols.Select(x => x.InitialFrequency).ToList();
    168190          var selectedSymbol = allowedSymbols.SelectRandom(weights, random);
  • trunk/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/Creators/SymbolicExpressionTreeCreator.cs

    r5809 r6233  
    2222using HeuristicLab.Common;
    2323using HeuristicLab.Core;
    24 using HeuristicLab.Data;
    2524using HeuristicLab.Parameters;
    2625using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
     
    5554    }
    5655
    57     public sealed override IOperation Apply() {
     56    public override IOperation Apply() {
    5857      SymbolicExpressionTree = Create(Random);
    5958      return base.Apply();
  • trunk/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/Interfaces/ISymbolicExpressionGrammar.cs

    r5809 r6233  
    2121
    2222
     23using System;
     24using HeuristicLab.Core;
    2325namespace HeuristicLab.Encodings.SymbolicExpressionTreeEncoding {
    24   public interface ISymbolicExpressionGrammar : ISymbolicExpressionGrammarBase {
     26  public interface ISymbolicExpressionGrammar : ISymbolicExpressionGrammarBase, IStatefulItem {
    2527    ISymbol ProgramRootSymbol { get; }
    2628    ISymbol StartSymbol { get; }
     
    3032    int MinimumFunctionArguments { get; set; }
    3133    int MaximumFunctionArguments { get; set; }
     34
     35    bool ReadOnly { get; set; }
     36    event EventHandler ReadOnlyChanged;
    3237  }
    3338}
  • trunk/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/SymbolicExpressionGrammar.cs

    r5809 r6233  
    2020#endregion
    2121
    22 using System.Linq;
     22using System;
    2323using HeuristicLab.Common;
     24using HeuristicLab.Core;
    2425using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    2526
     
    2829  public abstract class SymbolicExpressionGrammar : SymbolicExpressionGrammarBase, ISymbolicExpressionGrammar {
    2930    #region fields & properties
     31    [Storable(DefaultValue = false)]
     32    private bool readOnly;
     33    public bool ReadOnly {
     34      get { return readOnly; }
     35      set {
     36        if (readOnly != value) {
     37          readOnly = value;
     38          OnReadOnlyChanged();
     39        }
     40      }
     41    }
     42
    3043    [Storable]
    3144    private int minimumFunctionDefinitions;
     
    102115    protected SymbolicExpressionGrammar(SymbolicExpressionGrammar original, Cloner cloner)
    103116      : base(original, cloner) {
    104       programRootSymbol = (ProgramRootSymbol)cloner.Clone(original.programRootSymbol);
    105       startSymbol = (StartSymbol)cloner.Clone(original.StartSymbol);
    106       defunSymbol = (Defun)cloner.Clone(original.defunSymbol);
    107       symbols = original.symbols
    108         .ToDictionary(x => x.Key, y => (ISymbol)cloner.Clone(y.Value));
     117      programRootSymbol = cloner.Clone(original.programRootSymbol);
     118      startSymbol = cloner.Clone(original.StartSymbol);
     119      defunSymbol = cloner.Clone(original.defunSymbol);
     120
    109121      maximumFunctionArguments = original.maximumFunctionArguments;
    110122      minimumFunctionArguments = original.minimumFunctionArguments;
     
    140152      }
    141153    }
     154
     155    public event EventHandler ReadOnlyChanged;
     156    protected virtual void OnReadOnlyChanged() {
     157      var handler = ReadOnlyChanged;
     158      if (handler != null)
     159        handler(this, EventArgs.Empty);
     160    }
     161
     162    #region IStatefulItem
     163    void IStatefulItem.InitializeState() { }
     164    void IStatefulItem.ClearState() {
     165      ReadOnly = false;
     166    }
     167    #endregion
    142168  }
    143169}
  • trunk/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/SymbolicExpressionGrammarBase.cs

    r6009 r6233  
    8181      cachedMinExpressionDepth = new Dictionary<string, int>();
    8282    }
     83    [StorableHook(HookType.AfterDeserialization)]
     84    private void AfterDeserialization() {
     85      foreach (ISymbol symbol in symbols.Values)
     86        RegisterSymbolEvents(symbol);
     87    }
     88
    8389    protected SymbolicExpressionGrammarBase(SymbolicExpressionGrammarBase original, Cloner cloner)
    8490      : base(original, cloner) {
     
    8793      cachedMinExpressionDepth = new Dictionary<string, int>();
    8894
     95
     96      symbols = original.symbols.ToDictionary(x => x.Key, y => (ISymbol)cloner.Clone(y.Value));
    8997      symbolSubtreeCount = new Dictionary<string, Tuple<int, int>>(original.symbolSubtreeCount);
    90       symbols = new Dictionary<string, ISymbol>(original.symbols);
    9198
    9299      allowedChildSymbols = new Dictionary<string, List<string>>();
     
    97104      foreach (var element in original.allowedChildSymbolsPerIndex)
    98105        allowedChildSymbolsPerIndex.Add(element.Key, new List<string>(element.Value));
     106
     107      foreach (ISymbol symbol in symbols.Values)
     108        RegisterSymbolEvents(symbol);
    99109    }
    100110
     
    114124    protected void AddSymbol(ISymbol symbol) {
    115125      if (ContainsSymbol(symbol)) throw new ArgumentException("Symbol " + symbol + " is already defined.");
     126      RegisterSymbolEvents(symbol);
    116127      symbols.Add(symbol.Name, symbol);
    117128      symbolSubtreeCount.Add(symbol.Name, Tuple.Create(0, 0));
     129      ClearCaches();
     130    }
     131
     132    private void RegisterSymbolEvents(ISymbol symbol) {
     133      symbol.NameChanging += new EventHandler<CancelEventArgs<string>>(Symbol_NameChanging);
     134      symbol.NameChanged += new EventHandler(Symbol_NameChanged);
     135    }
     136    private void DeregisterSymbolEvents(ISymbol symbol) {
     137      symbol.NameChanging -= new EventHandler<CancelEventArgs<string>>(Symbol_NameChanging);
     138      symbol.NameChanged -= new EventHandler(Symbol_NameChanged);
     139    }
     140
     141    private void Symbol_NameChanging(object sender, CancelEventArgs<string> e) {
     142      if (symbols.ContainsKey(e.Value)) e.Cancel = true;
     143    }
     144    private void Symbol_NameChanged(object sender, EventArgs e) {
     145      ISymbol symbol = (ISymbol)sender;
     146      string oldName = symbols.Where(x => x.Value == symbol).First().Key;
     147      string newName = symbol.Name;
     148
     149      symbols.Remove(oldName);
     150      symbols.Add(newName, symbol);
     151
     152      var subtreeCount = symbolSubtreeCount[oldName];
     153      symbolSubtreeCount.Remove(oldName);
     154      symbolSubtreeCount.Add(newName, subtreeCount);
     155
     156      List<string> allowedChilds;
     157      if (allowedChildSymbols.TryGetValue(oldName, out allowedChilds)) {
     158        allowedChildSymbols.Remove(oldName);
     159        allowedChildSymbols.Add(newName, allowedChilds);
     160      }
     161
     162      for (int i = 0; i < GetMaximumSubtreeCount(symbol); i++) {
     163        if (allowedChildSymbolsPerIndex.TryGetValue(Tuple.Create(oldName, i), out allowedChilds)) {
     164          allowedChildSymbolsPerIndex.Remove(Tuple.Create(oldName, i));
     165          allowedChildSymbolsPerIndex.Add(Tuple.Create(newName, i), allowedChilds);
     166        }
     167      }
     168
     169      foreach (var parent in Symbols) {
     170        if (allowedChildSymbols.TryGetValue(parent.Name, out allowedChilds))
     171          if (allowedChilds.Remove(oldName))
     172            allowedChilds.Add(newName);
     173
     174        for (int i = 0; i < GetMaximumSubtreeCount(parent); i++) {
     175          if (allowedChildSymbolsPerIndex.TryGetValue(Tuple.Create(parent.Name, i), out allowedChilds))
     176            if (allowedChilds.Remove(oldName)) allowedChilds.Add(newName);
     177        }
     178      }
     179
    118180      ClearCaches();
    119181    }
     
    126188      symbolSubtreeCount.Remove(symbol.Name);
    127189
    128 
    129190      foreach (var parent in Symbols) {
    130191        List<string> allowedChilds;
     
    137198        }
    138199      }
     200      DeregisterSymbolEvents(symbol);
    139201      ClearCaches();
    140202    }
  • trunk/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/SymbolicExpressionTreeGrammar.cs

    r5809 r6233  
    3636    }
    3737    public override IDeepCloneable Clone(Cloner cloner) {
     38      foreach (ISymbol symbol in base.Symbols)
     39        cloner.RegisterClonedObject(symbol, symbol);
    3840      return new SymbolicExpressionTreeGrammar(this, cloner);
    3941    }
  • trunk/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/SymbolicExpressionTreeTerminalNode.cs

    r5809 r6233  
    4545    protected SymbolicExpressionTreeTerminalNode() : base() { }
    4646
    47     protected SymbolicExpressionTreeTerminalNode(Symbol symbol)
     47    protected SymbolicExpressionTreeTerminalNode(ISymbol symbol)
    4848      : base() {
    4949      // symbols are reused
  • trunk/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/SymbolicExpressionTreeTopLevelNode.cs

    r5809 r6233  
    4242    }
    4343    public SymbolicExpressionTreeTopLevelNode() : base() { }
    44     public SymbolicExpressionTreeTopLevelNode(Symbol symbol) : base(symbol) { }
     44    public SymbolicExpressionTreeTopLevelNode(ISymbol symbol) : base(symbol) { }
    4545
    4646
  • trunk/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/Symbols/Argument.cs

    r5809 r6233  
    3838    }
    3939
    40     public override bool CanChangeDescription {
    41       get { return false; }
    42     }
    43 
    4440    [StorableConstructor]
    4541    private Argument(bool deserializing) : base(deserializing) { }
  • trunk/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/Symbols/InvokeFunction.cs

    r5809 r6233  
    2020#endregion
    2121
    22 using System;
    2322using HeuristicLab.Common;
    2423using HeuristicLab.Core;
     
    3837    public string FunctionName {
    3938      get { return functionName; }
    40       set {
    41         if (value == null) throw new ArgumentNullException();
    42         functionName = value;
    43       }
    4439    }
    4540
     
    5348    public InvokeFunction(string functionName)
    5449      : base("Invoke: " + functionName, InvokeFunction.InvokeFunctionDescription) {
    55       this.FunctionName = functionName;
     50      this.functionName = functionName;
    5651    }
    5752
  • trunk/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/Symbols/Symbol.cs

    r5809 r6233  
    4343    }
    4444    public override bool CanChangeName {
    45       get { return false; }
     45      get { return !(this is IReadOnlySymbol); }
    4646    }
    4747    public override bool CanChangeDescription {
     
    5656      initialFrequency = original.initialFrequency;
    5757    }
    58     protected Symbol()
    59       : base() {
    60       initialFrequency = 1.0;
    61     }
    6258
    6359    protected Symbol(string name, string description)
     
    6561      initialFrequency = 1.0;
    6662    }
    67 
    6863
    6964    public virtual ISymbolicExpressionTreeNode CreateTreeNode() {
  • trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic.Classification/3.4/SymbolicDiscriminantFunctionClassificationModel.cs

    r5942 r6233  
    2020#endregion
    2121
     22using System;
    2223using System.Collections.Generic;
    2324using System.Linq;
    2425using HeuristicLab.Common;
    2526using HeuristicLab.Core;
    26 using HeuristicLab.Data;
    2727using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
    28 using HeuristicLab.Operators;
    29 using HeuristicLab.Parameters;
    3028using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    31 using HeuristicLab.Optimization;
    32 using System;
    3329
    3430namespace HeuristicLab.Problems.DataAnalysis.Symbolic.Classification {
     
    149145      } else {
    150146        var mainBranch = startNode.GetSubtree(0);
     147        var product = MakeProduct(mainBranch, beta);
    151148        startNode.RemoveSubtree(0);
    152         var scaledMainBranch = MakeSum(MakeProduct(beta, mainBranch), alpha);
     149        startNode.AddSubtree(product);
     150
     151        var scaledMainBranch = MakeSum(product, alpha);
     152        startNode.RemoveSubtree(0);
    153153        startNode.AddSubtree(scaledMainBranch);
    154154      }
     
    159159        return treeNode;
    160160      } else {
    161         var node = (new Addition()).CreateTreeNode();
     161        var addition = treeNode.Grammar.Symbols.OfType<Addition>().FirstOrDefault();
     162        if (addition == null) addition = new Addition();
     163        var node = addition.CreateTreeNode();
    162164        var alphaConst = MakeConstant(alpha);
    163165        node.AddSubtree(treeNode);
     
    167169    }
    168170
    169     private static ISymbolicExpressionTreeNode MakeProduct(double beta, ISymbolicExpressionTreeNode treeNode) {
     171    private static ISymbolicExpressionTreeNode MakeProduct(ISymbolicExpressionTreeNode treeNode, double beta) {
    170172      if (beta.IsAlmost(1.0)) {
    171173        return treeNode;
    172174      } else {
    173         var node = (new Multiplication()).CreateTreeNode();
     175        var multipliciation = treeNode.Grammar.Symbols.OfType<Multiplication>().FirstOrDefault();
     176        if (multipliciation == null) multipliciation = new Multiplication();
     177        var node = multipliciation.CreateTreeNode();
    174178        var betaConst = MakeConstant(beta);
    175179        node.AddSubtree(treeNode);
  • trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/SymbolicRegressionModel.cs

    r5942 r6233  
    2121
    2222using System.Collections.Generic;
     23using System.Linq;
    2324using HeuristicLab.Common;
    2425using HeuristicLab.Core;
     
    9495      } else {
    9596        var mainBranch = startNode.GetSubtree(0);
     97        var product = MakeProduct(mainBranch, beta);
    9698        startNode.RemoveSubtree(0);
    97         var scaledMainBranch = MakeSum(MakeProduct(beta, mainBranch), alpha);
     99        startNode.AddSubtree(product);
     100
     101        var scaledMainBranch = MakeSum(product, alpha);
     102        startNode.RemoveSubtree(0);
    98103        startNode.AddSubtree(scaledMainBranch);
    99104      }
     
    104109        return treeNode;
    105110      } else {
    106         var node = (new Addition()).CreateTreeNode();
     111        var addition = treeNode.Grammar.Symbols.OfType<Addition>().FirstOrDefault();
     112        if (addition == null) addition = new Addition();
     113        var node = addition.CreateTreeNode();
    107114        var alphaConst = MakeConstant(alpha);
    108115        node.AddSubtree(treeNode);
     
    112119    }
    113120
    114     private static ISymbolicExpressionTreeNode MakeProduct(double beta, ISymbolicExpressionTreeNode treeNode) {
     121    private static ISymbolicExpressionTreeNode MakeProduct(ISymbolicExpressionTreeNode treeNode, double beta) {
    115122      if (beta.IsAlmost(1.0)) {
    116123        return treeNode;
    117124      } else {
    118         var node = (new Multiplication()).CreateTreeNode();
     125        var multipliciation = treeNode.Grammar.Symbols.OfType<Multiplication>().FirstOrDefault();
     126        if (multipliciation == null) multipliciation = new Multiplication();
     127        var node = multipliciation.CreateTreeNode();
    119128        var betaConst = MakeConstant(beta);
    120129        node.AddSubtree(treeNode);
  • trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/SymbolicRegressionSolution.cs

    r5975 r6233  
    7575    }
    7676
    77     private new void RecalculateResults() {
     77    private void RecalculateResults() {
    7878      ModelLength = Model.SymbolicExpressionTree.Length;
    7979      ModelDepth = Model.SymbolicExpressionTree.Depth;
  • trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic.Views/3.4/Symbols/VariableView.cs

    r5809 r6233  
    2323using System.Linq;
    2424using System.Windows.Forms;
     25using HeuristicLab.Collections;
     26using HeuristicLab.Core;
     27using HeuristicLab.Core.Views;
     28using HeuristicLab.Data;
    2529using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Views;
    2630using HeuristicLab.MainForm;
    2731using HeuristicLab.MainForm.WindowsForms;
    28 using HeuristicLab.Core;
    29 using HeuristicLab.Data;
    30 using HeuristicLab.Core.Views;
    31 using HeuristicLab.Collections;
    3232
    3333
     
    8181    protected override void OnContentChanged() {
    8282      base.OnContentChanged();
     83      variableNamesView.Content.Clear();
    8384      UpdateControl();
    8485    }
     
    162163      } else {
    163164        var existingEntries = variableNamesView.Content.Select(x => x.Value);
    164        
     165
    165166        // temporarily deregister to prevent circular calling of events
    166167        DeregisterVariableNamesViewContentEvents();
  • trunk/sources/HeuristicLab.Problems.DataAnalysis/3.4/Interfaces/Regression/IRegressionEnsembleSolution.cs

    r6184 r6233  
    2121
    2222using System.Collections.Generic;
    23 using HeuristicLab.Core;
    2423namespace HeuristicLab.Problems.DataAnalysis {
    2524  public interface IRegressionEnsembleSolution : IRegressionSolution {
    26     IRegressionEnsembleModel Model { get; }
     25    new IRegressionEnsembleModel Model { get; }
    2726    IEnumerable<IEnumerable<double>> GetEstimatedValueVectors(Dataset dataset, IEnumerable<int> rows);
    2827  }
Note: See TracChangeset for help on using the changeset viewer.