Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
03/31/11 03:24:02 (13 years ago)
Author:
swagner
Message:

Worked on OKB (#1174)

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  
        33*.user
        44HeuristicLabClientsOKBPlugin.cs
         5*.vs10x
  • branches/OKB (trunk integration)/HeuristicLab.Clients.OKB/3.3/RunCreation/OKBAlgorithm.cs

    r5667 r5902  
    11#region License Information
    22/* HeuristicLab
    3  * Copyright (C) 2002-2010 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
     3 * Copyright (C) 2002-2011 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
    44 *
    55 * This file is part of HeuristicLab.
     
    125125    }
    126126
    127     private int runsCounter;
    128127    private RunCollection runs;
    129128    public RunCollection Runs {
    130129      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      }
    131140    }
    132141    public bool StoreAlgorithmInEachRun {
     
    149158      }
    150159    }
    151     [Storable(Name = "RunsCounter")]
    152     private int StorableRunsCounter {
    153       get { return runsCounter; }
    154       set { runsCounter = value; }
    155     }
    156160    [Storable(Name = "Runs")]
    157161    private RunCollection StorableRuns {
     
    161165        RegisterRunsEvents();
    162166      }
     167    }
     168    [Storable(Name = "StoreRunsAutomatically")]
     169    private bool StorableStoreRunsAutomatically {
     170      get { return storeRunsAutomatically; }
     171      set { storeRunsAutomatically = value; }
    163172    }
    164173    #endregion
     
    171180      algorithm = cloner.Clone(original.algorithm);
    172181      RegisterAlgorithmEvents();
    173       runsCounter = original.runsCounter;
    174182      runs = cloner.Clone(original.runs);
     183      storeRunsAutomatically = original.storeRunsAutomatically;
    175184      RegisterRunsEvents();
    176185    }
     
    180189      algorithm = new EmptyAlgorithm("No algorithm selected. Please choose an algorithm from the OKB.");
    181190      RegisterAlgorithmEvents();
    182       runsCounter = 0;
    183191      runs = new RunCollection();
     192      storeRunsAutomatically = true;
    184193      RegisterRunsEvents();
    185194    }
     
    213222
    214223    public void Prepare() {
    215       Algorithm.Prepare(true);
     224      Algorithm.Prepare();
    216225    }
    217226    public void Prepare(bool clearRuns) {
    218227      if (clearRuns) runs.Clear();
    219       Algorithm.Prepare(true);
     228      Algorithm.Prepare(clearRuns);
    220229    }
    221230    public void Start() {
     
    265274      if (handler != null) handler(this, EventArgs.Empty);
    266275    }
     276    public event EventHandler StoreRunsAutomaticallyChanged;
     277    private void OnStoreRunsAutomaticallyChanged() {
     278      var handler = StoreRunsAutomaticallyChanged;
     279      if (handler != null) handler(this, EventArgs.Empty);
     280    }
    267281    public event EventHandler StoreAlgorithmInEachRunChanged;
    268282    private void OnStoreAlgorithmInEachRunChanged() {
     
    287301    public event EventHandler Stopped;
    288302    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       }
    298303      var handler = Stopped;
    299304      if (handler != null) handler(this, EventArgs.Empty);
     
    315320        Algorithm.ExecutionTimeChanged += new EventHandler(Algorithm_ExecutionTimeChanged);
    316321        Algorithm.ProblemChanged += new EventHandler(Algorithm_ProblemChanged);
     322        Algorithm.Runs.ItemsAdded += new CollectionItemsChangedEventHandler<IRun>(Algorithm_Runs_ItemsAdded);
    317323        Algorithm.StoreAlgorithmInEachRunChanged += new EventHandler(Algorithm_StoreAlgorithmInEachRunChanged);
    318324        Algorithm.Prepared += new EventHandler(Algorithm_Prepared);
     
    333339        Algorithm.ExecutionTimeChanged -= new EventHandler(Algorithm_ExecutionTimeChanged);
    334340        Algorithm.ProblemChanged -= new EventHandler(Algorithm_ProblemChanged);
     341        Algorithm.Runs.ItemsAdded -= new CollectionItemsChangedEventHandler<IRun>(Algorithm_Runs_ItemsAdded);
    335342        Algorithm.StoreAlgorithmInEachRunChanged -= new EventHandler(Algorithm_StoreAlgorithmInEachRunChanged);
    336343        Algorithm.Prepared -= new EventHandler(Algorithm_Prepared);
     
    366373      OnProblemChanged();
    367374    }
     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    }
    368390    private void Algorithm_StoreAlgorithmInEachRunChanged(object sender, EventArgs e) {
    369391      OnStoreAlgorithmInEachRunChanged();
     
    386408
    387409    private void RegisterRunsEvents() {
     410      runs.ItemsRemoved += new CollectionItemsChangedEventHandler<IRun>(runs_ItemsRemoved);
    388411      runs.CollectionReset += new CollectionItemsChangedEventHandler<IRun>(Runs_CollectionReset);
    389412    }
     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    }
    390422    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      }
    392430    }
    393431    #endregion
Note: See TracChangeset for help on using the changeset viewer.