Changeset 5902 for branches/OKB (trunk integration)/HeuristicLab.Clients.OKB/3.3/RunCreation/OKBAlgorithm.cs
- Timestamp:
- 03/31/11 03:24:02 (13 years ago)
- Location:
- branches/OKB (trunk integration)/HeuristicLab.Clients.OKB/3.3
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/OKB (trunk integration)/HeuristicLab.Clients.OKB/3.3
- Property svn:ignore
-
old new 3 3 *.user 4 4 HeuristicLabClientsOKBPlugin.cs 5 *.vs10x
-
- Property svn:ignore
-
branches/OKB (trunk integration)/HeuristicLab.Clients.OKB/3.3/RunCreation/OKBAlgorithm.cs
r5667 r5902 1 1 #region License Information 2 2 /* HeuristicLab 3 * Copyright (C) 2002-201 0Heuristic and Evolutionary Algorithms Laboratory (HEAL)3 * Copyright (C) 2002-2011 Heuristic and Evolutionary Algorithms Laboratory (HEAL) 4 4 * 5 5 * This file is part of HeuristicLab. … … 125 125 } 126 126 127 private int runsCounter;128 127 private RunCollection runs; 129 128 public RunCollection Runs { 130 129 get { return runs; } 130 } 131 private bool storeRunsAutomatically; 132 public bool StoreRunsAutomatically { 133 get { return storeRunsAutomatically; } 134 set { 135 if (value != storeRunsAutomatically) { 136 storeRunsAutomatically = value; 137 OnStoreRunsAutomaticallyChanged(); 138 } 139 } 131 140 } 132 141 public bool StoreAlgorithmInEachRun { … … 149 158 } 150 159 } 151 [Storable(Name = "RunsCounter")]152 private int StorableRunsCounter {153 get { return runsCounter; }154 set { runsCounter = value; }155 }156 160 [Storable(Name = "Runs")] 157 161 private RunCollection StorableRuns { … … 161 165 RegisterRunsEvents(); 162 166 } 167 } 168 [Storable(Name = "StoreRunsAutomatically")] 169 private bool StorableStoreRunsAutomatically { 170 get { return storeRunsAutomatically; } 171 set { storeRunsAutomatically = value; } 163 172 } 164 173 #endregion … … 171 180 algorithm = cloner.Clone(original.algorithm); 172 181 RegisterAlgorithmEvents(); 173 runsCounter = original.runsCounter;174 182 runs = cloner.Clone(original.runs); 183 storeRunsAutomatically = original.storeRunsAutomatically; 175 184 RegisterRunsEvents(); 176 185 } … … 180 189 algorithm = new EmptyAlgorithm("No algorithm selected. Please choose an algorithm from the OKB."); 181 190 RegisterAlgorithmEvents(); 182 runsCounter = 0;183 191 runs = new RunCollection(); 192 storeRunsAutomatically = true; 184 193 RegisterRunsEvents(); 185 194 } … … 213 222 214 223 public void Prepare() { 215 Algorithm.Prepare( true);224 Algorithm.Prepare(); 216 225 } 217 226 public void Prepare(bool clearRuns) { 218 227 if (clearRuns) runs.Clear(); 219 Algorithm.Prepare( true);228 Algorithm.Prepare(clearRuns); 220 229 } 221 230 public void Start() { … … 265 274 if (handler != null) handler(this, EventArgs.Empty); 266 275 } 276 public event EventHandler StoreRunsAutomaticallyChanged; 277 private void OnStoreRunsAutomaticallyChanged() { 278 var handler = StoreRunsAutomaticallyChanged; 279 if (handler != null) handler(this, EventArgs.Empty); 280 } 267 281 public event EventHandler StoreAlgorithmInEachRunChanged; 268 282 private void OnStoreAlgorithmInEachRunChanged() { … … 287 301 public event EventHandler Stopped; 288 302 private void OnStopped() { 289 runsCounter++;290 if (Problem is OKBProblem) {291 OKBProblem problem = (OKBProblem)Problem;292 OKBRun run = new OKBRun(AlgorithmId, problem.ProblemId, new HeuristicLab.Optimization.Run(string.Format("{0} Run {1}", Name, runsCounter), this));293 runs.Add(run);294 run.Store();295 } else {296 runs.Add(new HeuristicLab.Optimization.Run(string.Format("{0} Run {1}", Name, runsCounter), this));297 }298 303 var handler = Stopped; 299 304 if (handler != null) handler(this, EventArgs.Empty); … … 315 320 Algorithm.ExecutionTimeChanged += new EventHandler(Algorithm_ExecutionTimeChanged); 316 321 Algorithm.ProblemChanged += new EventHandler(Algorithm_ProblemChanged); 322 Algorithm.Runs.ItemsAdded += new CollectionItemsChangedEventHandler<IRun>(Algorithm_Runs_ItemsAdded); 317 323 Algorithm.StoreAlgorithmInEachRunChanged += new EventHandler(Algorithm_StoreAlgorithmInEachRunChanged); 318 324 Algorithm.Prepared += new EventHandler(Algorithm_Prepared); … … 333 339 Algorithm.ExecutionTimeChanged -= new EventHandler(Algorithm_ExecutionTimeChanged); 334 340 Algorithm.ProblemChanged -= new EventHandler(Algorithm_ProblemChanged); 341 Algorithm.Runs.ItemsAdded -= new CollectionItemsChangedEventHandler<IRun>(Algorithm_Runs_ItemsAdded); 335 342 Algorithm.StoreAlgorithmInEachRunChanged -= new EventHandler(Algorithm_StoreAlgorithmInEachRunChanged); 336 343 Algorithm.Prepared -= new EventHandler(Algorithm_Prepared); … … 366 373 OnProblemChanged(); 367 374 } 375 private void Algorithm_Runs_ItemsAdded(object sender, CollectionItemsChangedEventArgs<IRun> e) { 376 OKBProblem problem = Problem as OKBProblem; 377 foreach (IRun run in e.Items) { 378 if (problem != null) { 379 OKBRun okbRun = new OKBRun(AlgorithmId, problem.ProblemId, run); 380 runs.Add(okbRun); 381 if (StoreRunsAutomatically) { 382 try { okbRun.Store(); } 383 catch (Exception) { } 384 } 385 } else { 386 runs.Add(run); 387 } 388 } 389 } 368 390 private void Algorithm_StoreAlgorithmInEachRunChanged(object sender, EventArgs e) { 369 391 OnStoreAlgorithmInEachRunChanged(); … … 386 408 387 409 private void RegisterRunsEvents() { 410 runs.ItemsRemoved += new CollectionItemsChangedEventHandler<IRun>(runs_ItemsRemoved); 388 411 runs.CollectionReset += new CollectionItemsChangedEventHandler<IRun>(Runs_CollectionReset); 389 412 } 413 private void runs_ItemsRemoved(object sender, CollectionItemsChangedEventArgs<IRun> e) { 414 foreach (IRun run in e.Items) { 415 OKBRun okbRun = run as OKBRun; 416 if (okbRun != null) 417 Algorithm.Runs.Remove(okbRun.WrappedRun); 418 else 419 Algorithm.Runs.Remove(run); 420 } 421 } 390 422 private void Runs_CollectionReset(object sender, CollectionItemsChangedEventArgs<IRun> e) { 391 runsCounter = runs.Count; 423 foreach (IRun run in e.OldItems) { 424 OKBRun okbRun = run as OKBRun; 425 if (okbRun != null) 426 Algorithm.Runs.Remove(okbRun.WrappedRun); 427 else 428 Algorithm.Runs.Remove(run); 429 } 392 430 } 393 431 #endregion
Note: See TracChangeset
for help on using the changeset viewer.