Changeset 6197 for branches/HeuristicLab.MetaOptimization/HeuristicLab.Problems.MetaOptimization/3.3/Encoding/SymbolicExpressionGrammar
- Timestamp:
- 05/14/11 18:49:46 (14 years ago)
- Location:
- branches/HeuristicLab.MetaOptimization/HeuristicLab.Problems.MetaOptimization/3.3/Encoding/SymbolicExpressionGrammar
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/HeuristicLab.MetaOptimization/HeuristicLab.Problems.MetaOptimization/3.3/Encoding/SymbolicExpressionGrammar/SymbolValueConfiguration.cs
r6023 r6197 1 using System.Collections.Generic; 1 using System; 2 using System.Collections.Generic; 2 3 using System.Linq; 3 4 using HeuristicLab.Common; … … 11 12 [StorableClass] 12 13 public class SymbolValueConfiguration : ParameterizedValueConfiguration { 14 [Storable] 15 private IOptimizable parentOptimizable; 16 public IOptimizable ParentOptimizable { 17 get { return parentOptimizable; } 18 set { this.parentOptimizable = value; } 19 } 13 20 14 21 #region Constructors and Cloning … … 21 28 this.Optimize = false; 22 29 this.Name = symbol.Name; 23 this. actualValue = new ConstrainedValue(symbol, symbol.GetType(), new ItemSet<IItem> { symbol }, false);30 this.ActualValue = new ConstrainedValue(symbol, symbol.GetType(), new ItemSet<IItem> { symbol }, false); 24 31 } 25 32 protected SymbolValueConfiguration(SymbolValueConfiguration original, Cloner cloner) 26 33 : base(original, cloner) { 34 RegisterInitialFrequencyEvents(); 35 this.parentOptimizable = cloner.Clone(original.parentOptimizable); 27 36 } 28 37 public override IDeepCloneable Clone(Cloner cloner) { 29 38 return new SymbolValueConfiguration(this, cloner); 39 } 40 [StorableHook(HookType.AfterDeserialization)] 41 private void AfterDeserialization() { 42 RegisterInitialFrequencyEvents(); 30 43 } 31 44 #endregion … … 33 46 protected override void PopulateParameterConfigurations(IItem item, bool discoverValidValues) { 34 47 this.ClearParameterConfigurations(); 35 36 48 var symbol = (Symbol)item; 37 49 … … 41 53 var initialFrequencyParameterConfiguration = new ParameterConfiguration("InitialFrequency", typeof(Symbol), new DoubleValue(symbol.InitialFrequency), initialFrequencyValueConfigurations); 42 54 this.parameterConfigurations.Add(initialFrequencyParameterConfiguration); 55 RegisterInitialFrequencyEvents(); 43 56 44 57 var constant = symbol as Constant; … … 74 87 75 88 public virtual void Parameterize(Symbol symbol) { 76 symbol.InitialFrequency = GetDoubleValue("InitialFrequency"); 77 89 var actualValueSymbol = this.ActualValue.Value as Symbol; 90 symbol.InitialFrequency = parentOptimizable.Optimize ? GetDoubleValue("InitialFrequency") : actualValueSymbol.InitialFrequency; 91 78 92 var constant = symbol as Constant; 79 93 if (constant != null) { 80 constant.MinValue = GetDoubleValue("MinValue"); 81 constant.MaxValue = GetDoubleValue("MaxValue"); 82 constant.ManipulatorMu = GetDoubleValue("ManipulatorMu"); 83 constant.ManipulatorSigma = GetDoubleValue("ManipulatorSigma"); 84 constant.MultiplicativeManipulatorSigma = GetDoubleValue("MultiplicativeManipulatorSigma"); 94 var actualValueConstant = this.ActualValue.Value as Constant; 95 constant.MinValue = parentOptimizable.Optimize ? GetDoubleValue("MinValue") : actualValueConstant.MinValue; 96 constant.MaxValue = parentOptimizable.Optimize ? GetDoubleValue("MaxValue") : actualValueConstant.MaxValue; 97 constant.ManipulatorMu = parentOptimizable.Optimize ? GetDoubleValue("ManipulatorMu") : actualValueConstant.ManipulatorMu; 98 constant.ManipulatorSigma = parentOptimizable.Optimize ? GetDoubleValue("ManipulatorSigma") : actualValueConstant.ManipulatorSigma; 99 constant.MultiplicativeManipulatorSigma = parentOptimizable.Optimize ? GetDoubleValue("MultiplicativeManipulatorSigma") : actualValueConstant.MultiplicativeManipulatorSigma; 85 100 } 86 101 87 102 var variable = symbol as HeuristicLab.Problems.DataAnalysis.Symbolic.Variable; 88 103 if (variable != null) { 89 variable.WeightMu = GetDoubleValue("WeightMu"); 90 variable.WeightSigma = GetDoubleValue("WeightSigma"); 91 variable.WeightManipulatorMu = GetDoubleValue("WeightManipulatorMu"); 92 variable.WeightManipulatorSigma = GetDoubleValue("WeightManipulatorSigma"); 93 variable.MultiplicativeWeightManipulatorSigma = GetDoubleValue("MultiplicativeWeightManipulatorSigma"); 104 var actualValueVariable = this.ActualValue.Value as HeuristicLab.Problems.DataAnalysis.Symbolic.Variable; 105 variable.WeightMu = parentOptimizable.Optimize ? GetDoubleValue("WeightMu") : actualValueVariable.WeightMu; 106 variable.WeightSigma = parentOptimizable.Optimize ? GetDoubleValue("WeightSigma") : actualValueVariable.WeightSigma; 107 variable.WeightManipulatorMu = parentOptimizable.Optimize ? GetDoubleValue("WeightManipulatorMu") : actualValueVariable.WeightManipulatorMu; 108 variable.WeightManipulatorSigma = parentOptimizable.Optimize ? GetDoubleValue("WeightManipulatorSigma") : actualValueVariable.WeightManipulatorSigma; 109 variable.MultiplicativeWeightManipulatorSigma = parentOptimizable.Optimize ? GetDoubleValue("MultiplicativeWeightManipulatorSigma") : actualValueVariable.MultiplicativeWeightManipulatorSigma; 94 110 } 95 111 } … … 97 113 private double GetDoubleValue(string name) { 98 114 return ((DoubleValue)ParameterConfigurations.Single(x => x.Name == name).ActualValue.Value).Value; 115 } 116 117 private void RegisterInitialFrequencyEvents() { 118 this.parameterConfigurations.Single(x => x.Name == "InitialFrequency").ToStringChanged += new EventHandler(initialFrequencyParameterConfiguration_ToStringChanged); 119 } 120 private void DeregisterInitialFrequencyEvents() { 121 this.parameterConfigurations.Single(x => x.Name == "InitialFrequency").ToStringChanged -= new EventHandler(initialFrequencyParameterConfiguration_ToStringChanged); 122 } 123 124 protected virtual void initialFrequencyParameterConfiguration_ToStringChanged(object sender, EventArgs e) { 125 OnToStringChanged(); 99 126 } 100 127 -
branches/HeuristicLab.MetaOptimization/HeuristicLab.Problems.MetaOptimization/3.3/Encoding/SymbolicExpressionGrammar/SymbolicExpressionGrammarValueConfiguration.cs
r6023 r6197 28 28 var grammar = (ISymbolicExpressionGrammar)item; 29 29 foreach (Symbol symbol in grammar.Symbols) { 30 var pc = new SingleValuedParameterConfiguration(symbol.Name, new SymbolValueConfiguration(symbol)); 30 var svc = new SymbolValueConfiguration(symbol); 31 var pc = new SingleValuedParameterConfiguration(symbol.Name, svc); 32 svc.ParentOptimizable = pc; 31 33 SetOptimizeIfOnlyOneValueConfiguration(pc); 32 34 this.parameterConfigurations.Add(pc); … … 36 38 public virtual void Parameterize(ISymbolicExpressionGrammar grammar) { 37 39 foreach (Symbol symbol in grammar.Symbols) { 38 ((SymbolValueConfiguration)this.parameterConfigurations.Single(pc => pc.Name == symbol.Name).ValueConfigurations.First()).Parameterize(symbol); 40 var symbolValueConfiguration = (SymbolValueConfiguration)this.parameterConfigurations.Single(pc => pc.Name == symbol.Name).ValueConfigurations.First(); 41 symbolValueConfiguration.Parameterize(symbol); 39 42 } 40 43 }
Note: See TracChangeset
for help on using the changeset viewer.