Changeset 4108 for trunk/sources
- Timestamp:
- 07/27/10 00:07:36 (14 years ago)
- Location:
- trunk/sources
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Problems.ExternalEvaluation.GP/3.3/Interpretation/ITreeInterpreter.cs
r4089 r4108 26 26 namespace HeuristicLab.Problems.ExternalEvaluation.GP { 27 27 public interface ISymbolicExpressionTreeInterpreter : IItem { 28 double InterpretTree(SymbolicExpressionTree tree, Dictionary<string, double> variables); 28 void Prepare(SymbolicExpressionTree tree); 29 double InterpretTree(Dictionary<string, double> variables); 29 30 } 30 31 } -
trunk/sources/HeuristicLab.Problems.ExternalEvaluation.GP/3.3/Interpretation/TreeInterpreter.cs
r4089 r4108 92 92 private Instruction[] code; 93 93 private int pc; 94 94 95 95 public override bool CanChangeName { 96 96 get { return false; } … … 104 104 } 105 105 106 public double InterpretTree(SymbolicExpressionTree tree, Dictionary<string, double> variables) { 107 this.variables = variables; 106 public void Prepare(SymbolicExpressionTree tree) { 108 107 var compiler = new SymbolicExpressionTreeCompiler(); 109 108 code = compiler.Compile(tree, MapSymbolToOpCode); 109 } 110 111 public double InterpretTree(Dictionary<string, double> variables) { 112 this.variables = variables; 110 113 pc = 0; 111 114 argStackPointer = 0; … … 123 126 private int argStackPointer; 124 127 125 p ublicdouble Evaluate() {128 private double Evaluate() { 126 129 var currentInstr = code[pc++]; 127 130 switch (currentInstr.opCode) { -
trunk/sources/HeuristicLab.Problems.ExternalEvaluation.Views/3.3/SolutionMessageBuilderView.cs
r4068 r4108 28 28 [Content(typeof(SolutionMessageBuilder), IsDefaultView = true)] 29 29 public sealed partial class SolutionMessageBuilderView : NamedItemView { 30 CheckedItem CollectionView<IItemToSolutionMessageConverter> converterView;30 CheckedItemListView<IItemToSolutionMessageConverter> converterView; 31 31 32 32 public new SolutionMessageBuilder Content { … … 37 37 public SolutionMessageBuilderView() { 38 38 InitializeComponent(); 39 converterView = new CheckedItem CollectionView<IItemToSolutionMessageConverter>();39 converterView = new CheckedItemListView<IItemToSolutionMessageConverter>(); 40 40 converterView.Dock = DockStyle.Fill; 41 41 convertersGroupBox.Controls.Add(converterView); -
trunk/sources/HeuristicLab.Problems.ExternalEvaluation/3.3/SolutionMessageBuilder.cs
r4068 r4108 24 24 using System.Linq; 25 25 using HeuristicLab.Collections; 26 using HeuristicLab.Common; 26 27 using HeuristicLab.Core; 27 28 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; … … 35 36 private Dictionary<Type, Action<IItem, string, SolutionMessage.Builder>> dispatcher; 36 37 38 // BackwardsCompatibility3.3 39 #region Backwards compatible code, remove with 3.4 37 40 [Storable] 41 [Obsolete] 38 42 private CheckedItemCollection<IItemToSolutionMessageConverter> converters; 39 public CheckedItemCollection<IItemToSolutionMessageConverter> Converters { 40 get { return converters; } 43 #endregion 44 [Storable] 45 private CheckedItemList<IItemToSolutionMessageConverter> convertersList; 46 public CheckedItemList<IItemToSolutionMessageConverter> Converters { 47 get { return convertersList; } 41 48 } 42 49 … … 47 54 name = ItemName; 48 55 description = ItemDescription; 49 converters = new CheckedItemCollection<IItemToSolutionMessageConverter>(); 56 convertersList = new CheckedItemList<IItemToSolutionMessageConverter>(); 57 convertersList.Add(new BoolConverter()); 58 convertersList.Add(new DateTimeValueConverter()); 59 convertersList.Add(new DoubleConverter()); 60 convertersList.Add(new IntegerConverter()); 61 convertersList.Add(new StringConverter()); 62 convertersList.Add(new TimeSpanValueConverter()); 63 50 64 AttachEventHandlers(); 65 } 51 66 52 converters.Add(new BoolConverter()); 53 converters.Add(new DateTimeValueConverter()); 54 converters.Add(new DoubleConverter()); 55 converters.Add(new IntegerConverter()); 56 converters.Add(new StringConverter()); 57 converters.Add(new TimeSpanValueConverter()); 67 public override IDeepCloneable Clone(Cloner cloner) { 68 SolutionMessageBuilder clone = (SolutionMessageBuilder)base.Clone(cloner); 69 clone.convertersList = (CheckedItemList<IItemToSolutionMessageConverter>)cloner.Clone(convertersList); 70 clone.AttachEventHandlers(); 71 return clone; 58 72 } 59 73 60 74 public void AddToMessage(IItem item, string name, SolutionMessage.Builder builder) { 61 if (dispatcher == null) FillDispatcher();75 if (dispatcher == null) BuildDispatcher(); 62 76 Type itemType = item.GetType(); 63 77 while (!dispatcher.ContainsKey(itemType)) { … … 75 89 [StorableHook(HookType.AfterDeserialization)] 76 90 private void AttachEventHandlers() { 77 converters.ItemsAdded += new CollectionItemsChangedEventHandler<IItemToSolutionMessageConverter>(converters_ItemsAdded); 78 converters.ItemsRemoved += new CollectionItemsChangedEventHandler<IItemToSolutionMessageConverter>(converters_ItemsRemoved); 79 converters.CheckedItemsChanged += new CollectionItemsChangedEventHandler<IItemToSolutionMessageConverter>(converters_CheckedItemsChanged); 91 // BackwardsCompatibility3.3 92 #region Backwards compatible code, remove with 3.4 93 #pragma warning disable 0612 94 if (converters != null) { 95 if (convertersList == null) convertersList = new CheckedItemList<IItemToSolutionMessageConverter>(); 96 foreach (IItemToSolutionMessageConverter c in converters) 97 convertersList.Add(c); 98 converters.Clear(); 99 converters = null; 100 } 101 #pragma warning restore 0612 102 #endregion 103 convertersList.ItemsAdded += new CollectionItemsChangedEventHandler<IndexedItem<IItemToSolutionMessageConverter>>(convertersList_Changed); 104 convertersList.ItemsRemoved += new CollectionItemsChangedEventHandler<IndexedItem<IItemToSolutionMessageConverter>>(convertersList_Changed); 105 convertersList.CheckedItemsChanged += new CollectionItemsChangedEventHandler<IndexedItem<IItemToSolutionMessageConverter>>(convertersList_Changed); 106 convertersList.ItemsMoved += new CollectionItemsChangedEventHandler<IndexedItem<IItemToSolutionMessageConverter>>(convertersList_Changed); 107 convertersList.ItemsReplaced += new CollectionItemsChangedEventHandler<IndexedItem<IItemToSolutionMessageConverter>>(convertersList_Changed); 80 108 } 81 109 82 private void converters _ItemsAdded(object sender, CollectionItemsChangedEventArgs<IItemToSolutionMessageConverter> e) {83 AddToDispatcher(e.Items);110 private void convertersList_Changed(object sender, CollectionItemsChangedEventArgs<IndexedItem<IItemToSolutionMessageConverter>> e) { 111 BuildDispatcher(); 84 112 } 85 113 86 private void converters_ItemsRemoved(object sender, CollectionItemsChangedEventArgs<IItemToSolutionMessageConverter> e) { 87 RemoveFromDispatcher(e.Items); 88 } 89 90 private void converters_CheckedItemsChanged(object sender, CollectionItemsChangedEventArgs<IItemToSolutionMessageConverter> e) { 91 FillDispatcher(); 92 } 93 94 private void FillDispatcher() { 114 private void BuildDispatcher() { 95 115 dispatcher = new Dictionary<Type, Action<IItem, string, SolutionMessage.Builder>>(); 96 foreach (IItemToSolutionMessageConverter c in converters .CheckedItems) {116 foreach (IItemToSolutionMessageConverter c in convertersList.CheckedItems.OrderBy(x => x.Index).Select(x => x.Value)) { 97 117 Type[] types = c.ItemTypes; 98 118 foreach (Type t in types) { 99 if (dispatcher.ContainsKey(t)) dispatcher.Remove(t); 100 dispatcher.Add(t, new Action<IItem, string, SolutionMessage.Builder>(c.AddItemToBuilder)); 101 } 102 } 103 } 104 105 private void AddToDispatcher(IEnumerable<IItemToSolutionMessageConverter> items) { 106 if (dispatcher == null) FillDispatcher(); 107 foreach (IItemToSolutionMessageConverter c in items) { 108 Type[] types = c.ItemTypes; 109 foreach (Type t in types) { 110 if (dispatcher.ContainsKey(t)) dispatcher.Remove(t); 111 dispatcher.Add(t, new Action<IItem, string, SolutionMessage.Builder>(c.AddItemToBuilder)); 112 } 113 } 114 } 115 116 private void RemoveFromDispatcher(IEnumerable<IItemToSolutionMessageConverter> items) { 117 if (dispatcher == null) FillDispatcher(); 118 foreach (IItemToSolutionMessageConverter c in items) { 119 Type[] types = c.ItemTypes; 120 foreach (Type t in types) { 121 if (dispatcher.ContainsKey(t)) dispatcher.Remove(t); 119 if (!dispatcher.ContainsKey(t)) 120 dispatcher.Add(t, new Action<IItem, string, SolutionMessage.Builder>(c.AddItemToBuilder)); 122 121 } 123 122 }
Note: See TracChangeset
for help on using the changeset viewer.