Changeset 6767
- Timestamp:
- 09/15/11 14:15:43 (13 years ago)
- Location:
- trunk/sources/HeuristicLab.Optimization/3.3
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Optimization/3.3/BatchRun.cs
r6534 r6767 147 147 } 148 148 149 private bool stopPending; 149 private bool batchRunStarted = false; 150 private bool batchRunPaused = false; 151 private bool batchRunStopped = false; 150 152 151 153 public BatchRun() … … 158 160 repetitionsCounter = 0; 159 161 Runs = new RunCollection(); 160 stopPending = false;161 162 } 162 163 public BatchRun(string name) … … 168 169 repetitionsCounter = 0; 169 170 Runs = new RunCollection(); 170 stopPending = false;171 171 } 172 172 public BatchRun(string name, string description) … … 177 177 repetitionsCounter = 0; 178 178 Runs = new RunCollection(); 179 stopPending = false;180 179 } 181 180 [StorableConstructor] 182 private BatchRun(bool deserializing) 183 : base(deserializing) { 184 stopPending = false; 185 } 181 private BatchRun(bool deserializing) : base(deserializing) { } 186 182 [StorableHook(HookType.AfterDeserialization)] 187 183 private void AfterDeserialization() { … … 197 193 repetitionsCounter = original.repetitionsCounter; 198 194 runs = cloner.Clone(original.runs); 199 stopPending = original.stopPending; 195 batchRunStarted = original.batchRunStarted; 196 batchRunPaused = original.batchRunPaused; 197 batchRunStopped = original.batchRunStopped; 200 198 Initialize(); 201 199 } … … 227 225 if ((ExecutionState != ExecutionState.Prepared) && (ExecutionState != ExecutionState.Paused)) 228 226 throw new InvalidOperationException(string.Format("Start not allowed in execution state \"{0}\".", ExecutionState)); 229 if (Optimizer != null) Optimizer.Start(); 227 if (Optimizer == null) return; 228 229 batchRunStarted = true; 230 batchRunPaused = false; 231 batchRunStopped = false; 232 if (Optimizer.ExecutionState != ExecutionState.Prepared) Optimizer.Prepare(); 233 Optimizer.Start(); 230 234 } 231 235 public void Pause() { 232 236 if (ExecutionState != ExecutionState.Started) 233 237 throw new InvalidOperationException(string.Format("Pause not allowed in execution state \"{0}\".", ExecutionState)); 234 if ((Optimizer != null) && (Optimizer.ExecutionState == ExecutionState.Started)) 235 Optimizer.Pause(); 238 if (Optimizer == null) return; 239 if (Optimizer.ExecutionState != ExecutionState.Started) return; 240 241 batchRunStarted = false; 242 batchRunPaused = true; 243 batchRunStopped = false; 244 Optimizer.Pause(); 236 245 } 237 246 public void Stop() { 238 247 if ((ExecutionState != ExecutionState.Started) && (ExecutionState != ExecutionState.Paused)) 239 248 throw new InvalidOperationException(string.Format("Stop not allowed in execution state \"{0}\".", ExecutionState)); 240 stopPending = true; 241 if ((Optimizer != null) && 242 ((Optimizer.ExecutionState == ExecutionState.Started) || (Optimizer.ExecutionState == ExecutionState.Paused))) 243 Optimizer.Stop(); 249 if (Optimizer == null) return; 250 if (Optimizer.ExecutionState != ExecutionState.Started && Optimizer.ExecutionState != ExecutionState.Paused) return; 251 batchRunStarted = false; 252 batchRunPaused = false; 253 batchRunStopped = true; 254 Optimizer.Stop(); 244 255 } 245 256 … … 324 335 } 325 336 private void Optimizer_Paused(object sender, EventArgs e) { 326 OnPaused(); 337 if (ExecutionState == ExecutionState.Started) { 338 batchRunStarted = false; 339 batchRunPaused = true; 340 batchRunStopped = false; 341 OnPaused(); 342 } 327 343 } 328 344 private void Optimizer_Prepared(object sender, EventArgs e) { 329 if ( (ExecutionState == ExecutionState.Paused) || (ExecutionState == ExecutionState.Stopped))345 if (ExecutionState == ExecutionState.Stopped || !batchRunStarted) { 330 346 OnPrepared(); 347 } 331 348 } 332 349 private void Optimizer_Started(object sender, EventArgs e) { 333 stopPending = false;334 350 if (ExecutionState != ExecutionState.Started) 335 351 OnStarted(); … … 338 354 repetitionsCounter++; 339 355 340 if (!stopPending && (repetitionsCounter < repetitions)) { 356 if (batchRunStopped) OnStopped(); 357 else if (repetitionsCounter >= repetitions) OnStopped(); 358 else if (batchRunPaused) OnPaused(); 359 else if (batchRunStarted) { 341 360 Optimizer.Prepare(); 342 361 Optimizer.Start(); 343 } else { 344 OnStopped(); 345 } 362 } else OnStopped(); 346 363 } 347 364 private void Optimizer_Runs_CollectionReset(object sender, CollectionItemsChangedEventArgs<IRun> e) { -
trunk/sources/HeuristicLab.Optimization/3.3/Experiment.cs
r6534 r6767 104 104 } 105 105 106 private bool stopPending; 106 private bool experimentStarted = false; 107 private bool experimentStopped = false; 107 108 108 109 public Experiment() … … 114 115 optimizers = new OptimizerList(); 115 116 Runs = new RunCollection(); 116 stopPending = false;117 117 Initialize(); 118 118 } … … 124 124 optimizers = new OptimizerList(); 125 125 Runs = new RunCollection(); 126 stopPending = false;127 126 Initialize(); 128 127 } … … 133 132 optimizers = new OptimizerList(); 134 133 Runs = new RunCollection(); 135 stopPending = false;136 134 Initialize(); 137 135 } 138 136 [StorableConstructor] 139 private Experiment(bool deserializing) 140 : base(deserializing) { 141 stopPending = false; 142 } 137 private Experiment(bool deserializing) : base(deserializing) { } 143 138 [StorableHook(HookType.AfterDeserialization)] 144 139 private void AfterDeserialization() { … … 151 146 optimizers = cloner.Clone(original.optimizers); 152 147 runs = cloner.Clone(original.runs); 153 stopPending = original.stopPending; 148 149 experimentStarted = original.experimentStarted; 150 experimentStopped = original.experimentStopped; 154 151 Initialize(); 155 152 } … … 172 169 if ((ExecutionState != ExecutionState.Prepared) && (ExecutionState != ExecutionState.Paused) && (ExecutionState != ExecutionState.Stopped)) 173 170 throw new InvalidOperationException(string.Format("Prepare not allowed in execution state \"{0}\".", ExecutionState)); 174 if (Optimizers.Count > 0) { 175 if (clearRuns) runs.Clear(); 176 foreach (IOptimizer optimizer in Optimizers.Where(x => x.ExecutionState != ExecutionState.Started)) 171 if (Optimizers.Count == 0) return; 172 173 if (clearRuns) runs.Clear(); 174 foreach (IOptimizer optimizer in Optimizers.Where(x => x.ExecutionState != ExecutionState.Started)) 175 if (clearRuns || optimizer.ExecutionState != ExecutionState.Prepared) 177 176 optimizer.Prepare(clearRuns); 178 }179 177 } 180 178 public void Start() { 181 179 if ((ExecutionState != ExecutionState.Prepared) && (ExecutionState != ExecutionState.Paused)) 182 180 throw new InvalidOperationException(string.Format("Start not allowed in execution state \"{0}\".", ExecutionState)); 183 stopPending = false; 184 if (Optimizers.Count > 0) { 185 IOptimizer optimizer = Optimizers.FirstOrDefault(x => (x.ExecutionState == ExecutionState.Prepared) || (x.ExecutionState == ExecutionState.Paused)); 186 if (optimizer != null) optimizer.Start(); 187 } 181 if (Optimizers.Count == 0) return; 182 183 experimentStarted = true; 184 experimentStopped = false; 185 IOptimizer optimizer = Optimizers.FirstOrDefault(x => (x.ExecutionState == ExecutionState.Prepared) || (x.ExecutionState == ExecutionState.Paused)); 186 if (optimizer != null) optimizer.Start(); 188 187 } 189 188 public void Pause() { 190 189 if (ExecutionState != ExecutionState.Started) 191 190 throw new InvalidOperationException(string.Format("Pause not allowed in execution state \"{0}\".", ExecutionState)); 192 if (Optimizers.Count > 0) { 193 foreach (IOptimizer optimizer in Optimizers.Where(x => x.ExecutionState == ExecutionState.Started)) 194 optimizer.Pause(); 195 } 191 if (Optimizers.Count == 0) return; 192 193 experimentStarted = false; 194 experimentStopped = false; 195 foreach (IOptimizer optimizer in Optimizers.Where(x => x.ExecutionState == ExecutionState.Started)) 196 optimizer.Pause(); 196 197 } 197 198 public void Stop() { 198 199 if ((ExecutionState != ExecutionState.Started) && (ExecutionState != ExecutionState.Paused)) 199 200 throw new InvalidOperationException(string.Format("Stop not allowed in execution state \"{0}\".", ExecutionState)); 200 stopPending = true; 201 if (Optimizers.Count > 0) { 202 foreach (IOptimizer optimizer in Optimizers.Where(x => (x.ExecutionState == ExecutionState.Started) || (x.ExecutionState == ExecutionState.Paused))) 203 optimizer.Stop(); 204 } 201 if (Optimizers.Count == 0) return; 202 203 experimentStarted = false; 204 experimentStopped = true; 205 foreach (IOptimizer optimizer in Optimizers.Where(x => (x.ExecutionState == ExecutionState.Started) || (x.ExecutionState == ExecutionState.Paused))) 206 optimizer.Stop(); 205 207 } 206 208 … … 333 335 } 334 336 private void optimizer_Stopped(object sender, EventArgs e) { 335 if (!stopPending && Optimizers.Any(x => (x.ExecutionState == ExecutionState.Prepared) || (x.ExecutionState == ExecutionState.Paused))) { 337 if (experimentStopped && Optimizers.All(o => o.ExecutionState == ExecutionState.Stopped || o.ExecutionState == ExecutionState.Prepared)) OnStopped(); 338 else if (Optimizers.All(o => o.ExecutionState == ExecutionState.Stopped)) OnStopped(); 339 else if (Optimizers.Any(o => o.ExecutionState == ExecutionState.Paused) && Optimizers.All(o => o.ExecutionState != ExecutionState.Started)) OnPaused(); 340 else if (experimentStarted && !experimentStopped && Optimizers.Any(x => (x.ExecutionState == ExecutionState.Prepared) || (x.ExecutionState == ExecutionState.Paused))) { 336 341 Optimizers.First(x => (x.ExecutionState == ExecutionState.Prepared) || (x.ExecutionState == ExecutionState.Paused)).Start(); 337 } else {338 if (Optimizers.All(x => (x.ExecutionState != ExecutionState.Started) && (x.ExecutionState != ExecutionState.Paused))) {339 stopPending = false;340 OnStopped();341 }342 342 } 343 343 }
Note: See TracChangeset
for help on using the changeset viewer.