- Timestamp:
- 11/25/14 03:26:00 (10 years ago)
- Location:
- branches/OptimizationNetworks
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/OptimizationNetworks
- Property svn:mergeinfo changed
-
branches/OptimizationNetworks/HeuristicLab.Optimization/3.3/Run.cs
r9456 r11576 1 1 #region License Information 2 2 /* HeuristicLab 3 * Copyright (C) 2002-201 3Heuristic and Evolutionary Algorithms Laboratory (HEAL)3 * Copyright (C) 2002-2014 Heuristic and Evolutionary Algorithms Laboratory (HEAL) 4 4 * 5 5 * This file is part of HeuristicLab. … … 22 22 using System; 23 23 using System.Collections.Generic; 24 using System.ComponentModel; 24 25 using System.Drawing; 25 using System.Linq;26 using HeuristicLab.Collections; 26 27 using HeuristicLab.Common; 27 28 using HeuristicLab.Core; … … 44 45 algorithm = cloner.Clone(original.algorithm); 45 46 46 parameters = new Dictionary<string, IItem>();47 parameters = new ObservableDictionary<string, IItem>(); 47 48 foreach (string key in original.parameters.Keys) 48 49 parameters.Add(key, cloner.Clone(original.parameters[key])); 49 50 50 results = new Dictionary<string, IItem>();51 results = new ObservableDictionary<string, IItem>(); 51 52 foreach (string key in original.results.Keys) 52 53 results.Add(key, cloner.Clone(original.results[key])); 53 54 } 55 54 56 public override IDeepCloneable Clone(Cloner cloner) { 55 57 return new Run(this, cloner); … … 62 64 color = Color.Black; 63 65 algorithm = null; 64 parameters = new Dictionary<string, IItem>();65 results = new Dictionary<string, IItem>();66 parameters = new ObservableDictionary<string, IItem>(); 67 results = new ObservableDictionary<string, IItem>(); 66 68 } 67 69 public Run(IAlgorithm algorithm) … … 88 90 89 91 private void Initialize(IAlgorithm algorithm) { 90 parameters = new Dictionary<string, IItem>();91 results = new Dictionary<string, IItem>();92 parameters = new ObservableDictionary<string, IItem>(); 93 results = new ObservableDictionary<string, IItem>(); 92 94 93 95 if (algorithm.StoreAlgorithmInEachRun) { 94 IAlgorithmclone = (IAlgorithm)algorithm.Clone();96 var clone = (IAlgorithm)algorithm.Clone(); 95 97 clone.CollectParameterValues(parameters); 96 98 clone.CollectResultValues(results); … … 98 100 this.algorithm = clone; 99 101 } else { 100 algorithm.CollectParameterValues(parameters); 101 algorithm.CollectResultValues(results); 102 Cloner cloner = new Cloner(); 103 parameters = parameters.Select(x => new KeyValuePair<string, IItem>(x.Key, cloner.Clone(x.Value))).ToDictionary(x => x.Key, x => x.Value); 104 results = results.Select(x => new KeyValuePair<string, IItem>(x.Key, cloner.Clone(x.Value))).ToDictionary(x => x.Key, x => x.Value); 102 var par = new Dictionary<string, IItem>(); 103 var res = new Dictionary<string, IItem>(); 104 algorithm.CollectParameterValues(par); 105 algorithm.CollectResultValues(res); 106 var cloner = new Cloner(); 107 foreach (var k in par) parameters.Add(k.Key, cloner.Clone(k.Value)); 108 foreach (var k in res) results.Add(k.Key, cloner.Clone(k.Value)); 105 109 } 106 110 } … … 115 119 get { return algorithm; } 116 120 } 117 [Storable] 118 private Dictionary<string, IItem> parameters;119 p ublic IDictionary<string, IItem>Parameters {121 122 [Storable(Name = "parameters")] 123 private IDictionary<string, IItem> StorableParameters { 120 124 get { return parameters; } 125 set { 126 if (!(value is IObservableDictionary<string, IItem>)) 127 parameters = new ObservableDictionary<string, IItem>(value); 128 else parameters = (IObservableDictionary<string, IItem>)value; 129 } 121 130 } 122 [Storable] 123 private Dictionary<string, IItem> results; 124 public IDictionary<string, IItem> Results { 131 private IObservableDictionary<string, IItem> parameters; 132 public IObservableDictionary<string, IItem> Parameters { 133 get { return parameters; } 134 private set { 135 if (parameters != value) { 136 parameters = value; 137 OnPropertyChanged("Parameters"); 138 } 139 } 140 } 141 142 [Storable(Name = "results")] 143 private IDictionary<string, IItem> StorableResults { 125 144 get { return results; } 145 set { 146 if (!(value is IObservableDictionary<string, IItem>)) 147 results = new ObservableDictionary<string, IItem>(value); 148 else results = (IObservableDictionary<string, IItem>)value; 149 } 150 } 151 private IObservableDictionary<string, IItem> results; 152 public IObservableDictionary<string, IItem> Results { 153 get { return results; } 154 private set { 155 if (results != value) { 156 results = value; 157 OnPropertyChanged("Results"); 158 } 159 } 126 160 } 127 161 … … 133 167 if (color != value) { 134 168 this.color = value; 135 this.OnChanged();169 OnPropertyChanged("Color"); 136 170 } 137 171 } … … 143 177 if (visible != value) { 144 178 this.visible = value; 145 this.OnChanged();179 OnPropertyChanged("Visible"); 146 180 } 147 181 } 148 182 } 149 public event EventHandler Changed; 150 p rivate void OnChanged() {151 EventHandler handler = Changed;152 if (handler != null)153 handler(this, EventArgs.Empty);183 184 public event PropertyChangedEventHandler PropertyChanged; 185 private void OnPropertyChanged(string property) { 186 var handler = PropertyChanged; 187 if (handler != null) handler(this, new PropertyChangedEventArgs(property)); 154 188 } 155 189 }
Note: See TracChangeset
for help on using the changeset viewer.