Changeset 3280 for trunk/sources/HeuristicLab.Optimization/3.3/Algorithm.cs
- Timestamp:
- 04/07/10 05:22:33 (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Optimization/3.3/Algorithm.cs
r3275 r3280 64 64 } 65 65 66 [Storable] 66 67 private IProblem problem; 67 [Storable]68 private IProblem ProblemPersistence {69 get { return problem; }70 set {71 if (problem != null) DeregisterProblemEvents();72 problem = value;73 if (problem != null) RegisterProblemEvents();74 }75 }76 68 public IProblem Problem { 77 69 get { return problem; } … … 91 83 92 84 [Storable] 85 protected int runsCounter; 86 87 [Storable] 93 88 private RunCollection runs; 94 89 public RunCollection Runs { … … 100 95 executionState = ExecutionState.Stopped; 101 96 executionTime = TimeSpan.Zero; 97 runsCounter = 0; 102 98 runs = new RunCollection(); 103 99 } … … 106 102 executionState = ExecutionState.Stopped; 107 103 executionTime = TimeSpan.Zero; 104 runsCounter = 0; 108 105 runs = new RunCollection(); 109 106 } … … 112 109 executionState = ExecutionState.Stopped; 113 110 executionTime = TimeSpan.Zero; 111 runsCounter = 0; 114 112 runs = new RunCollection(); 115 113 } … … 118 116 executionState = ExecutionState.Stopped; 119 117 executionTime = TimeSpan.Zero; 118 runsCounter = 0; 120 119 runs = new RunCollection(); 121 120 } … … 124 123 executionState = ExecutionState.Stopped; 125 124 executionTime = TimeSpan.Zero; 126 runs = new RunCollection(); 125 runsCounter = 0; 126 runs = new RunCollection(); 127 } 128 internal Algorithm(Algorithm algorithm, Cloner cloner) 129 : base(algorithm.Name, algorithm.Description, (ParameterCollection)cloner.Clone(algorithm.Parameters)) { 130 executionState = algorithm.executionState; 131 executionTime = algorithm.executionTime; 132 problem = (IProblem)cloner.Clone(algorithm.problem); 133 runsCounter = algorithm.runsCounter; 134 runs = (RunCollection)cloner.Clone(algorithm.runs); 135 Initialize(); 136 } 137 [StorableConstructor] 138 protected Algorithm(bool deserializing) : base(deserializing) { } 139 140 [StorableHook(HookType.AfterDeserialization)] 141 private void Initialize() { 142 if (problem != null) RegisterProblemEvents(); 127 143 } 128 144 129 145 public override IDeepCloneable Clone(Cloner cloner) { 146 if (ExecutionState == ExecutionState.Started) throw new InvalidOperationException(string.Format("Clone not allowed in execution state \"{0}\".", ExecutionState)); 130 147 Algorithm clone = (Algorithm)base.Clone(cloner); 131 148 clone.executionState = executionState; 132 149 clone.executionTime = executionTime; 133 clone.Problem = (IProblem)cloner.Clone(problem); 150 clone.problem = (IProblem)cloner.Clone(problem); 151 clone.runsCounter = runsCounter; 134 152 clone.runs = (RunCollection)cloner.Clone(runs); 153 clone.Initialize(); 135 154 return clone; 136 155 } … … 143 162 if ((ExecutionState != ExecutionState.Prepared) && (ExecutionState != ExecutionState.Paused) && (ExecutionState != ExecutionState.Stopped)) 144 163 throw new InvalidOperationException(string.Format("Prepare not allowed in execution state \"{0}\".", ExecutionState)); 145 if (clearRuns) runs.Clear(); 164 if (clearRuns) { 165 runsCounter = 0; 166 runs.Clear(); 167 } 146 168 Prepare(); 147 169 } … … 165 187 public virtual void CollectResultValues(IDictionary<string, IItem> values) { 166 188 foreach (IResult result in Results) 167 values.Add(result.Name, result.Value != null ? (IItem)result.Value.Clone() : null);189 values.Add(result.Name, result.Value); 168 190 } 169 191 … … 205 227 public event EventHandler Stopped; 206 228 protected virtual void OnStopped() { 207 Run run = new Run("Run (" + ExecutionTime.ToString() + ")");208 CollectParameterValues(run.Parameters);209 CollectResultValues(run.Results);210 runs.Add(run);211 229 ExecutionState = ExecutionState.Stopped; 230 runsCounter++; 231 runs.Add(new Run(string.Format("{0} Run {1} ({2})", Name, runsCounter, ExecutionTime), this)); 212 232 EventHandler handler = Stopped; 213 233 if (handler != null) handler(this, EventArgs.Empty);
Note: See TracChangeset
for help on using the changeset viewer.