Free cookie consent management tool by TermsFeed Policy Generator

Changeset 15721


Ignore:
Timestamp:
02/04/18 22:33:26 (6 years ago)
Author:
abeham
Message:

#1614:

  • reverted r15603 by reverse merging
  • added expert system plugins from #2457
Location:
branches/1614_GeneralizedQAP
Files:
12 edited
3 copied

Legend:

Unmodified
Added
Removed
  • branches/1614_GeneralizedQAP/GeneralizedQAP.sln

    r15719 r15721  
    2929EndProject
    3030Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HeuristicLab.Analysis.Views-3.3", "HeuristicLab.Analysis.Views\3.3\HeuristicLab.Analysis.Views-3.3.csproj", "{76945D76-CA61-4147-9DC2-0ACDCDDF87F9}"
     31EndProject
     32Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HeuristicLab.OptimizationExpertSystem.Common-3.3", "HeuristicLab.OptimizationExpertSystem.Common\3.3\HeuristicLab.OptimizationExpertSystem.Common-3.3.csproj", "{492CC257-E27C-4497-B2C1-09C45310C91C}"
     33EndProject
     34Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HeuristicLab.OptimizationExpertSystem-3.3", "HeuristicLab.OptimizationExpertSystem\3.3\HeuristicLab.OptimizationExpertSystem-3.3.csproj", "{6240A044-BD4B-4DDB-9E67-A6CFA5E0C7BE}"
    3135EndProject
    3236Global
     
    196200    {76945D76-CA61-4147-9DC2-0ACDCDDF87F9}.Release|x86.ActiveCfg = Release|x86
    197201    {76945D76-CA61-4147-9DC2-0ACDCDDF87F9}.Release|x86.Build.0 = Release|x86
     202    {492CC257-E27C-4497-B2C1-09C45310C91C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
     203    {492CC257-E27C-4497-B2C1-09C45310C91C}.Debug|Any CPU.Build.0 = Debug|Any CPU
     204    {492CC257-E27C-4497-B2C1-09C45310C91C}.Debug|x64.ActiveCfg = Debug|x64
     205    {492CC257-E27C-4497-B2C1-09C45310C91C}.Debug|x64.Build.0 = Debug|x64
     206    {492CC257-E27C-4497-B2C1-09C45310C91C}.Debug|x86.ActiveCfg = Debug|x86
     207    {492CC257-E27C-4497-B2C1-09C45310C91C}.Debug|x86.Build.0 = Debug|x86
     208    {492CC257-E27C-4497-B2C1-09C45310C91C}.Release|Any CPU.ActiveCfg = Release|Any CPU
     209    {492CC257-E27C-4497-B2C1-09C45310C91C}.Release|Any CPU.Build.0 = Release|Any CPU
     210    {492CC257-E27C-4497-B2C1-09C45310C91C}.Release|x64.ActiveCfg = Release|x64
     211    {492CC257-E27C-4497-B2C1-09C45310C91C}.Release|x64.Build.0 = Release|x64
     212    {492CC257-E27C-4497-B2C1-09C45310C91C}.Release|x86.ActiveCfg = Release|x86
     213    {492CC257-E27C-4497-B2C1-09C45310C91C}.Release|x86.Build.0 = Release|x86
     214    {6240A044-BD4B-4DDB-9E67-A6CFA5E0C7BE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
     215    {6240A044-BD4B-4DDB-9E67-A6CFA5E0C7BE}.Debug|Any CPU.Build.0 = Debug|Any CPU
     216    {6240A044-BD4B-4DDB-9E67-A6CFA5E0C7BE}.Debug|x64.ActiveCfg = Debug|x64
     217    {6240A044-BD4B-4DDB-9E67-A6CFA5E0C7BE}.Debug|x64.Build.0 = Debug|x64
     218    {6240A044-BD4B-4DDB-9E67-A6CFA5E0C7BE}.Debug|x86.ActiveCfg = Debug|x86
     219    {6240A044-BD4B-4DDB-9E67-A6CFA5E0C7BE}.Debug|x86.Build.0 = Debug|x86
     220    {6240A044-BD4B-4DDB-9E67-A6CFA5E0C7BE}.Release|Any CPU.ActiveCfg = Release|Any CPU
     221    {6240A044-BD4B-4DDB-9E67-A6CFA5E0C7BE}.Release|Any CPU.Build.0 = Release|Any CPU
     222    {6240A044-BD4B-4DDB-9E67-A6CFA5E0C7BE}.Release|x64.ActiveCfg = Release|x64
     223    {6240A044-BD4B-4DDB-9E67-A6CFA5E0C7BE}.Release|x64.Build.0 = Release|x64
     224    {6240A044-BD4B-4DDB-9E67-A6CFA5E0C7BE}.Release|x86.ActiveCfg = Release|x86
     225    {6240A044-BD4B-4DDB-9E67-A6CFA5E0C7BE}.Release|x86.Build.0 = Release|x86
    198226  EndGlobalSection
    199227  GlobalSection(SolutionProperties) = preSolution
  • branches/1614_GeneralizedQAP/HeuristicLab.Analysis/3.3/HeuristicLab.Analysis-3.3.csproj

    r15720 r15721  
    147147    <Reference Include="HeuristicLab.PluginInfrastructure-3.3">
    148148      <HintPath>..\..\..\..\trunk\bin\HeuristicLab.PluginInfrastructure-3.3.dll</HintPath>
     149      <Private>False</Private>
     150    </Reference>
     151    <Reference Include="HeuristicLab.Random-3.3">
     152      <SpecificVersion>False</SpecificVersion>
     153      <HintPath>..\..\..\..\trunk\bin\HeuristicLab.Random-3.3.dll</HintPath>
    149154      <Private>False</Private>
    150155    </Reference>
  • branches/1614_GeneralizedQAP/HeuristicLab.Optimization.Views/3.3/IOptimizerView.Designer.cs

    r15605 r15721  
    4545    /// </summary>
    4646    private void InitializeComponent() {
    47       this.components = new System.ComponentModel.Container();
    4847      System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(IOptimizerView));
    4948      this.startButton = new System.Windows.Forms.Button();
     
    5352      this.stopButton = new System.Windows.Forms.Button();
    5453      this.resetButton = new System.Windows.Forms.Button();
    55       this.executionTimer = new System.Windows.Forms.Timer(this.components);
    5654      ((System.ComponentModel.ISupportInitialize)(this.errorProvider)).BeginInit();
    5755      this.SuspendLayout();
     
    134132      this.resetButton.Click += new System.EventHandler(this.resetButton_Click);
    135133      //
    136       // executionTimer
    137       //
    138       this.executionTimer.Interval = 200;
    139       this.executionTimer.Tick += new System.EventHandler(this.executionTimer_Tick);
    140       //
    141134      // IOptimizerView
    142135      //
     
    173166    protected System.Windows.Forms.Button pauseButton;
    174167    protected System.Windows.Forms.Button stopButton;
    175     protected System.Windows.Forms.Timer executionTimer;
    176168    protected System.Windows.Forms.Button resetButton;
    177169
  • branches/1614_GeneralizedQAP/HeuristicLab.Optimization.Views/3.3/IOptimizerView.cs

    r15605 r15721  
    4444      Content.ExceptionOccurred -= new EventHandler<EventArgs<Exception>>(Content_ExceptionOccurred);
    4545      Content.ExecutionStateChanged -= new EventHandler(Content_ExecutionStateChanged);
     46      Content.ExecutionTimeChanged -= new EventHandler(Content_ExecutionTimeChanged);
    4647      Content.Prepared -= new EventHandler(Content_Prepared);
    4748      Content.Started -= new EventHandler(Content_Started);
     
    5455      Content.ExceptionOccurred += new EventHandler<EventArgs<Exception>>(Content_ExceptionOccurred);
    5556      Content.ExecutionStateChanged += new EventHandler(Content_ExecutionStateChanged);
     57      Content.ExecutionTimeChanged += new EventHandler(Content_ExecutionTimeChanged);
    5658      Content.Prepared += new EventHandler(Content_Prepared);
    5759      Content.Started += new EventHandler(Content_Started);
     
    6264    protected override void OnContentChanged() {
    6365      base.OnContentChanged();
    64       if (Content != null) {
     66      if (Content == null) {
     67        executionTimeTextBox.Text = "-";
     68      } else {
    6569        Locked = ReadOnly = Content.ExecutionState == ExecutionState.Started;
     70        executionTimeTextBox.Text = Content.ExecutionTime.ToString();
    6671      }
    67       UpdateExecutionTime();
    6872    }
    6973
     
    8690      else {
    8791        nameTextBox.Enabled = infoLabel.Enabled = true;
    88         UpdateExecutionTime();
    8992        ReadOnly = Locked = false;
    9093        SetEnabledStateOfExecutableButtons();
     
    9598        Invoke(new EventHandler(Content_Started), sender, e);
    9699      else {
    97         executionTimer.Start();
    98100        nameTextBox.Enabled = infoLabel.Enabled = false;
    99101        ReadOnly = Locked = true;
     
    105107        Invoke(new EventHandler(Content_Paused), sender, e);
    106108      else {
    107         executionTimer.Stop();
    108         UpdateExecutionTime();
    109109        nameTextBox.Enabled = infoLabel.Enabled = true;
    110110        ReadOnly = Locked = false;
     
    116116        Invoke(new EventHandler(Content_Stopped), sender, e);
    117117      else {
    118         executionTimer.Stop();
    119         UpdateExecutionTime();
    120118        nameTextBox.Enabled = infoLabel.Enabled = true;
    121119        ReadOnly = Locked = false;
     
    123121      }
    124122    }
     123    protected virtual void Content_ExecutionTimeChanged(object sender, EventArgs e) {
     124      if (InvokeRequired)
     125        Invoke(new EventHandler(Content_ExecutionTimeChanged), sender, e);
     126      else
     127        executionTimeTextBox.Text = Content == null ? "-" : Content.ExecutionTime.ToString();
     128    }
    125129    protected virtual void Content_ExceptionOccurred(object sender, EventArgs<Exception> e) {
    126130      if (InvokeRequired)
    127131        Invoke(new EventHandler<EventArgs<Exception>>(Content_ExceptionOccurred), sender, e);
    128       else {
    129         executionTimer.Stop();
    130         UpdateExecutionTime();
     132      else
    131133        ErrorHandling.ShowErrorDialog(this, e.Value);
    132       }
    133134    }
    134135    #endregion
     
    146147    protected virtual void resetButton_Click(object sender, EventArgs e) {
    147148      Content.Prepare(false);
    148     }
    149     private void executionTimer_Tick(object sender, EventArgs e) {
    150       UpdateExecutionTime();
    151     }
    152 
    153     private void UpdateExecutionTime() {
    154       executionTimeTextBox.Text = (Content == null ? "-" : Content.ExecutionTime.ToString());
    155149    }
    156150    #endregion
  • branches/1614_GeneralizedQAP/HeuristicLab.Optimization/3.3/Algorithms/Algorithm.cs

    r15719 r15721  
    6464      }
    6565    }
    66    
    67     public abstract TimeSpan ExecutionTime { get; }
     66
     67    [Storable]
     68    private TimeSpan executionTime;
     69    public TimeSpan ExecutionTime {
     70      get { return executionTime; }
     71      protected set {
     72        executionTime = value;
     73        OnExecutionTimeChanged();
     74      }
     75    }
    6876
    6977    public virtual Type ProblemType {
     
    125133      : base() {
    126134      executionState = ExecutionState.Stopped;
     135      executionTime = TimeSpan.Zero;
    127136      storeAlgorithmInEachRun = false;
    128137      runsCounter = 0;
     
    132141      : base(name) {
    133142      executionState = ExecutionState.Stopped;
     143      executionTime = TimeSpan.Zero;
    134144      storeAlgorithmInEachRun = false;
    135145      runsCounter = 0;
     
    139149      : base(name, parameters) {
    140150      executionState = ExecutionState.Stopped;
     151      executionTime = TimeSpan.Zero;
    141152      storeAlgorithmInEachRun = false;
    142153      runsCounter = 0;
     
    146157      : base(name, description) {
    147158      executionState = ExecutionState.Stopped;
     159      executionTime = TimeSpan.Zero;
    148160      storeAlgorithmInEachRun = false;
    149161      runsCounter = 0;
     
    153165      : base(name, description, parameters) {
    154166      executionState = ExecutionState.Stopped;
     167      executionTime = TimeSpan.Zero;
    155168      storeAlgorithmInEachRun = false;
    156169      runsCounter = 0;
     
    168181      if (ExecutionState == ExecutionState.Started) throw new InvalidOperationException(string.Format("Clone not allowed in execution state \"{0}\".", ExecutionState));
    169182      executionState = original.executionState;
     183      executionTime = original.executionTime;
    170184      problem = cloner.Clone(original.problem);
    171185      storeAlgorithmInEachRun = original.storeAlgorithmInEachRun;
     
    246260      if (handler != null) handler(this, EventArgs.Empty);
    247261    }
     262    public event EventHandler ExecutionTimeChanged;
     263    protected virtual void OnExecutionTimeChanged() {
     264      EventHandler handler = ExecutionTimeChanged;
     265      if (handler != null) handler(this, EventArgs.Empty);
     266    }
    248267    public event EventHandler ProblemChanged;
    249268    protected virtual void OnProblemChanged() {
     
    258277    public event EventHandler Prepared;
    259278    protected virtual void OnPrepared() {
     279      ExecutionTime = TimeSpan.Zero;
    260280      foreach (IStatefulItem statefulObject in this.GetObjectGraphObjects(new HashSet<object>() { Runs }).OfType<IStatefulItem>()) {
    261281        statefulObject.InitializeState();
     
    328348    }
    329349    #endregion
    330 
    331     [Obsolete("Deprecate, does nothing, needs to be removed from IExecutable")]
    332     public event EventHandler ExecutionTimeChanged;
    333350  }
    334351}
  • branches/1614_GeneralizedQAP/HeuristicLab.Optimization/3.3/Algorithms/BasicAlgorithm.cs

    r15605 r15721  
    2121
    2222using System;
     23using System.Linq;
    2324using System.Threading;
    2425using HeuristicLab.Common;
     
    3132
    3233    private bool pausePending;
    33     private bool executionTimeActive;
     34    private DateTime lastUpdateTime;
    3435
    3536    public string Filename { get; set; }
     
    5152    }
    5253
    53     [Storable]
    54     private TimeSpan executionTime;
    55     private DateTime startDate;
    56     public override TimeSpan ExecutionTime {
    57       get { return executionTime + (executionTimeActive ? DateTime.UtcNow - startDate : TimeSpan.Zero); }
    58     }
    59 
    6054    [StorableConstructor]
    6155    protected BasicAlgorithm(bool deserializing) : base(deserializing) { }
     
    6458      results = cloner.Clone(original.Results);
    6559      initialized = original.initialized;
    66       executionTime = original.executionTime;
    6760    }
    6861    protected BasicAlgorithm()
    6962      : base() {
    7063      results = new ResultCollection();
    71       executionTime = TimeSpan.Zero;
    7264    }
    7365
    7466    public override void Prepare() {
    75       executionTime = TimeSpan.Zero;
    7667      if (Problem == null) return;
    7768      base.Prepare();
     
    8273
    8374    public override void Start(CancellationToken cancellationToken) {
    84       startDate = DateTime.UtcNow;
    85       executionTimeActive = true;
    8675      base.Start(cancellationToken);
    8776      CancellationTokenSource = CancellationTokenSource.CreateLinkedTokenSource(cancellationToken);
     
    125114    private void Run(object state) {
    126115      CancellationToken cancellationToken = (CancellationToken)state;
    127       if (!initialized)
    128         Initialize(cancellationToken);
    129       initialized = true;
    130       Run(cancellationToken);
     116      lastUpdateTime = DateTime.UtcNow;
     117      System.Timers.Timer timer = new System.Timers.Timer(250);
     118      timer.AutoReset = true;
     119      timer.Elapsed += new System.Timers.ElapsedEventHandler(timer_Elapsed);
     120      timer.Start();
     121      try {
     122        if (!initialized)
     123          Initialize(cancellationToken);
     124        initialized = true;
     125        Run(cancellationToken);
     126      }
     127      finally {
     128        timer.Elapsed -= new System.Timers.ElapsedEventHandler(timer_Elapsed);
     129        timer.Stop();
     130        ExecutionTime += DateTime.UtcNow - lastUpdateTime;
     131      }
    131132    }
    132133
     
    134135    protected abstract void Run(CancellationToken cancellationToken);
    135136
    136     protected override void OnPaused() {
    137       executionTime += DateTime.UtcNow - startDate;
    138       executionTimeActive = false;
    139       base.OnPaused();
     137    #region Events
     138    private void timer_Elapsed(object sender, System.Timers.ElapsedEventArgs e) {
     139      System.Timers.Timer timer = (System.Timers.Timer)sender;
     140      timer.Enabled = false;
     141      DateTime now = DateTime.UtcNow;
     142      ExecutionTime += now - lastUpdateTime;
     143      lastUpdateTime = now;
     144      timer.Enabled = true;
    140145    }
     146    #endregion
    141147
    142     protected override void OnStopped() {
    143       if (executionTimeActive) { // don't do if going from pause to stop
    144         executionTime += DateTime.UtcNow - startDate;
    145         executionTimeActive = false;
    146       }
    147       base.OnStopped();
    148     }
    149148  }
    150149}
  • branches/1614_GeneralizedQAP/HeuristicLab.Optimization/3.3/Algorithms/EngineAlgorithm.cs

    r15719 r15721  
    7171    }
    7272
    73     public override TimeSpan ExecutionTime {
    74       get { return engine.ExecutionTime; }
    75     }
    76 
    7773    public override ResultCollection Results {
    7874      get {
     
    200196    private void RegisterEngineEvents() {
    201197      Engine.ExceptionOccurred += new EventHandler<EventArgs<Exception>>(Engine_ExceptionOccurred);
     198      Engine.ExecutionTimeChanged += new EventHandler(Engine_ExecutionTimeChanged);
    202199      Engine.Paused += new EventHandler(Engine_Paused);
    203200      Engine.Prepared += new EventHandler(Engine_Prepared);
     
    207204    private void DeregisterEngineEvents() {
    208205      Engine.ExceptionOccurred -= new EventHandler<EventArgs<Exception>>(Engine_ExceptionOccurred);
     206      Engine.ExecutionTimeChanged -= new EventHandler(Engine_ExecutionTimeChanged);
    209207      Engine.Paused -= new EventHandler(Engine_Paused);
    210208      Engine.Prepared -= new EventHandler(Engine_Prepared);
     
    214212    private void Engine_ExceptionOccurred(object sender, EventArgs<Exception> e) {
    215213      OnExceptionOccurred(e.Value);
     214    }
     215    private void Engine_ExecutionTimeChanged(object sender, EventArgs e) {
     216      ExecutionTime = Engine.ExecutionTime;
    216217    }
    217218    private void Engine_Paused(object sender, EventArgs e) {
  • branches/1614_GeneralizedQAP/HeuristicLab.Optimization/3.3/Algorithms/HeuristicOptimizationAlgorithm.cs

    r15605 r15721  
    2121
    2222using System;
    23 using System.Threading;
    2423using HeuristicLab.Common;
    2524using HeuristicLab.Core;
     
    3837    }
    3938
    40     [Storable]
    41     private TimeSpan executionTime;
    42     private DateTime startDate;
    43     public override TimeSpan ExecutionTime {
    44       get { return executionTime + (ExecutionState == ExecutionState.Started ? DateTime.UtcNow - startDate : TimeSpan.Zero); }
    45     }
    46 
    47     protected HeuristicOptimizationAlgorithm() : base() {
    48       executionTime = TimeSpan.Zero;
    49     }
    50     protected HeuristicOptimizationAlgorithm(string name) : base(name) {
    51       executionTime = TimeSpan.Zero;
    52     }
    53     protected HeuristicOptimizationAlgorithm(string name, ParameterCollection parameters) : base(name, parameters) {
    54       executionTime = TimeSpan.Zero;
    55     }
    56     protected HeuristicOptimizationAlgorithm(string name, string description) : base(name, description) {
    57       executionTime = TimeSpan.Zero;
    58     }
    59     protected HeuristicOptimizationAlgorithm(string name, string description, ParameterCollection parameters) : base(name, description, parameters) {
    60       executionTime = TimeSpan.Zero;
    61     }
     39    protected HeuristicOptimizationAlgorithm() : base() { }
     40    protected HeuristicOptimizationAlgorithm(string name) : base(name) { }
     41    protected HeuristicOptimizationAlgorithm(string name, ParameterCollection parameters) : base(name, parameters) { }
     42    protected HeuristicOptimizationAlgorithm(string name, string description) : base(name, description) { }
     43    protected HeuristicOptimizationAlgorithm(string name, string description, ParameterCollection parameters) : base(name, description, parameters) { }
    6244
    6345    [StorableConstructor]
    6446    protected HeuristicOptimizationAlgorithm(bool deserializing) : base(deserializing) { }
    65     protected HeuristicOptimizationAlgorithm(HeuristicOptimizationAlgorithm original, Cloner cloner)
    66       : base(original, cloner) {
    67       executionTime = original.executionTime;
    68     }
    69 
    70     public override void Prepare() {
    71       executionTime = TimeSpan.Zero;
    72       base.Prepare();
    73     }
    74 
    75     public override void Start(CancellationToken cancellationToken) {
    76       startDate = DateTime.UtcNow;
    77       base.Start(cancellationToken);
    78     }
     47    protected HeuristicOptimizationAlgorithm(HeuristicOptimizationAlgorithm original, Cloner cloner) : base(original, cloner) { }
    7948
    8049    #region Events
     
    9362    protected virtual void Problem_EvaluatorChanged(object sender, EventArgs e) { }
    9463    #endregion
    95 
    96     protected override void OnPaused() {
    97       var elapsed = DateTime.UtcNow - startDate;
    98       executionTime += elapsed;
    99       base.OnPaused();
    100     }
    101 
    102     protected override void OnStopped() {
    103       if (ExecutionState == ExecutionState.Started) {
    104         var elapsed = DateTime.UtcNow - startDate;
    105         executionTime += elapsed;
    106       }
    107       base.OnStopped();
    108     }
    10964  }
    11065}
  • branches/1614_GeneralizedQAP/HeuristicLab.Optimization/3.3/MetaOptimizers/BatchRun.cs

    r15605 r15721  
    6868      }
    6969    }
    70    
     70
    7171    [Storable]
    7272    private TimeSpan executionTime;
    7373    public TimeSpan ExecutionTime {
    74       get { return executionTime + (Optimizer?.ExecutionTime ?? TimeSpan.Zero); }
    75     }
     74      get {
     75        if ((Optimizer != null) && (Optimizer.ExecutionState != ExecutionState.Stopped))
     76          return executionTime + Optimizer.ExecutionTime;
     77        else
     78          return executionTime;
     79      }
     80      private set {
     81        executionTime = value;
     82        OnExecutionTimeChanged();
     83      }
     84    }
     85
     86    [Storable]
     87    private TimeSpan runsExecutionTime;
    7688
    7789    [Storable]
     
    162174      executionState = ExecutionState.Stopped;
    163175      executionTime = TimeSpan.Zero;
     176      runsExecutionTime = TimeSpan.Zero;
    164177      repetitions = 10;
    165178      repetitionsCounter = 0;
     
    171184      executionState = ExecutionState.Stopped;
    172185      executionTime = TimeSpan.Zero;
     186      runsExecutionTime = TimeSpan.Zero;
    173187      repetitions = 10;
    174188      repetitionsCounter = 0;
     
    179193      executionState = ExecutionState.Stopped;
    180194      executionTime = TimeSpan.Zero;
     195      runsExecutionTime = TimeSpan.Zero;
    181196      repetitions = 10;
    182197      repetitionsCounter = 0;
     
    194209      executionState = original.executionState;
    195210      executionTime = original.executionTime;
     211      runsExecutionTime = original.runsExecutionTime;
    196212      optimizer = cloner.Clone(original.optimizer);
    197213      repetitions = original.repetitions;
     
    218234        throw new InvalidOperationException(string.Format("Prepare not allowed in execution state \"{0}\".", ExecutionState));
    219235      if (Optimizer != null) {
    220         executionTime = TimeSpan.Zero;
     236        ExecutionTime = TimeSpan.Zero;
    221237        RepetitionsCounter = 0;
    222238        if (clearRuns) runs.Clear();
     
    282298      if (handler != null) handler(this, EventArgs.Empty);
    283299    }
    284     [Obsolete("Deprecated needs to be removed")]
    285300    public event EventHandler ExecutionTimeChanged;
     301    private void OnExecutionTimeChanged() {
     302      EventHandler handler = ExecutionTimeChanged;
     303      if (handler != null) handler(this, EventArgs.Empty);
     304    }
    286305    public event EventHandler OptimizerChanged;
    287306    private void OnOptimizerChanged() {
     
    335354    private void RegisterOptimizerEvents() {
    336355      optimizer.ExceptionOccurred += new EventHandler<EventArgs<Exception>>(Optimizer_ExceptionOccurred);
     356      optimizer.ExecutionTimeChanged += new EventHandler(Optimizer_ExecutionTimeChanged);
    337357      optimizer.Paused += new EventHandler(Optimizer_Paused);
    338358      optimizer.Prepared += new EventHandler(Optimizer_Prepared);
     
    345365    private void DeregisterOptimizerEvents() {
    346366      optimizer.ExceptionOccurred -= new EventHandler<EventArgs<Exception>>(Optimizer_ExceptionOccurred);
     367      optimizer.ExecutionTimeChanged -= new EventHandler(Optimizer_ExecutionTimeChanged);
    347368      optimizer.Paused -= new EventHandler(Optimizer_Paused);
    348369      optimizer.Prepared -= new EventHandler(Optimizer_Prepared);
     
    356377      OnExceptionOccurred(e.Value);
    357378    }
     379    private void Optimizer_ExecutionTimeChanged(object sender, EventArgs e) {
     380      OnExecutionTimeChanged();
     381    }
    358382    private void Optimizer_Paused(object sender, EventArgs e) {
    359383      if (ExecutionState == ExecutionState.Started) {
     
    363387    private void Optimizer_Prepared(object sender, EventArgs e) {
    364388      if (batchRunAction == BatchRunAction.Prepare || ExecutionState == ExecutionState.Stopped) {
     389        ExecutionTime = TimeSpan.Zero;
     390        runsExecutionTime = TimeSpan.Zero;
    365391        RepetitionsCounter = 0;
    366392        OnPrepared();
     
    373399    private void Optimizer_Stopped(object sender, EventArgs e) {
    374400      RepetitionsCounter++;
     401      ExecutionTime += runsExecutionTime;
     402      runsExecutionTime = TimeSpan.Zero;
    375403
    376404      if (batchRunAction == BatchRunAction.Stop) OnStopped();
     
    407435    private void Runs_CollectionReset(object sender, CollectionItemsChangedEventArgs<IRun> e) {
    408436      if (Optimizer != null) Optimizer.Runs.RemoveRange(e.OldItems);
    409       executionTime += SumExecutionTimes(e.OldItems);
    410       executionTime += SumExecutionTimes(e.Items);
     437      foreach (IRun run in e.Items) {
     438        IItem item;
     439        run.Results.TryGetValue("Execution Time", out item);
     440        TimeSpanValue executionTime = item as TimeSpanValue;
     441        if (executionTime != null) ExecutionTime += executionTime.Value;
     442      }
    411443    }
    412444    private void Runs_ItemsAdded(object sender, CollectionItemsChangedEventArgs<IRun> e) {
    413       executionTime += SumExecutionTimes(e.Items);
     445      foreach (IRun run in e.Items) {
     446        IItem item;
     447        run.Results.TryGetValue("Execution Time", out item);
     448        TimeSpanValue executionTime = item as TimeSpanValue;
     449        if (executionTime != null) {
     450          if (Optimizer.ExecutionState == ExecutionState.Started)
     451            runsExecutionTime += executionTime.Value;
     452          else
     453            ExecutionTime += executionTime.Value;
     454        }
     455      }
    414456    }
    415457    private void Runs_ItemsRemoved(object sender, CollectionItemsChangedEventArgs<IRun> e) {
    416458      if (Optimizer != null) Optimizer.Runs.RemoveRange(e.Items);
    417       executionTime -= SumExecutionTimes(e.Items);
    418     }
    419     private TimeSpan SumExecutionTimes(IEnumerable<IRun> runs) {
    420       var sum = TimeSpan.Zero;
    421       foreach (IRun run in runs) {
    422         IItem item;
    423         run.Results.TryGetValue("Execution Time", out item);
    424         TimeSpanValue exTime = item as TimeSpanValue;
    425         if (exTime != null) sum += exTime.Value;
    426       }
    427       return sum;
    428459    }
    429460    #endregion
  • branches/1614_GeneralizedQAP/HeuristicLab.Optimization/3.3/MetaOptimizers/Experiment.cs

    r15605 r15721  
    7070    private TimeSpan executionTime;
    7171    public TimeSpan ExecutionTime {
    72       get { return executionTime + Optimizers.Aggregate(TimeSpan.Zero, (a, x) => a + x.ExecutionTime); }
     72      get { return executionTime; }
     73      private set {
     74        executionTime = value;
     75        OnExecutionTimeChanged();
     76      }
    7377    }
    7478
     
    278282      if (handler != null) handler(this, EventArgs.Empty);
    279283    }
    280     [Obsolete("deprecated needs to be removed")]
    281284    public event EventHandler ExecutionTimeChanged;
     285    private void OnExecutionTimeChanged() {
     286      EventHandler handler = ExecutionTimeChanged;
     287      if (handler != null) handler(this, EventArgs.Empty);
     288    }
    282289    public event EventHandler Prepared;
    283290    private void OnPrepared() {
     
    362369    private void RegisterOptimizerEvents(IOptimizer optimizer) {
    363370      optimizer.ExceptionOccurred += new EventHandler<EventArgs<Exception>>(optimizer_ExceptionOccurred);
     371      optimizer.ExecutionTimeChanged += new EventHandler(optimizer_ExecutionTimeChanged);
    364372      optimizer.Paused += new EventHandler(optimizer_Paused);
    365373      optimizer.Prepared += new EventHandler(optimizer_Prepared);
     
    372380    private void DeregisterOptimizerEvents(IOptimizer optimizer) {
    373381      optimizer.ExceptionOccurred -= new EventHandler<EventArgs<Exception>>(optimizer_ExceptionOccurred);
     382      optimizer.ExecutionTimeChanged -= new EventHandler(optimizer_ExecutionTimeChanged);
    374383      optimizer.Paused -= new EventHandler(optimizer_Paused);
    375384      optimizer.Prepared -= new EventHandler(optimizer_Prepared);
     
    386395      lock (locker)
    387396        OnExceptionOccurred(e.Value);
     397    }
     398    private void optimizer_ExecutionTimeChanged(object sender, EventArgs e) {
     399      // only wait for maximally 100ms to acquire lock, otherwise return and don't update the execution time
     400      var success = Monitor.TryEnter(locker, 100);
     401      if (!success) return;
     402      try {
     403        ExecutionTime = Optimizers.Aggregate(TimeSpan.Zero, (t, o) => t + o.ExecutionTime);
     404      } finally {
     405        Monitor.Exit(locker);
     406      }
    388407    }
    389408    private void optimizer_Paused(object sender, EventArgs e) {
  • branches/1614_GeneralizedQAP/HeuristicLab.Optimization/3.3/MetaOptimizers/TimeLimitRun.cs

    r15605 r15721  
    214214
    215215    private void Initialize() {
    216       timer = new System.Timers.Timer();
    217       timer.Interval = 50;
    218       timer.Elapsed += Timer_Elapsed;
    219216      if (algorithm != null) RegisterAlgorithmEvents();
    220217      snapshotTimes.ItemsAdded += snapshotTimes_Changed;
     
    258255    }
    259256
    260     private System.Timers.Timer timer;
    261 
    262     private void Timer_Elapsed(object sender, EventArgs e) {
    263       if (Algorithm.ExecutionState == ExecutionState.Started) {
    264         if (snapshotTimesIndex < SnapshotTimes.Count && ExecutionTime >= SnapshotTimes[snapshotTimesIndex]
    265           && !pausedForSnapshot) {
    266           pausedForSnapshot = true;
    267           Algorithm.Pause();
    268         }
    269         if (ExecutionTime >= MaximumExecutionTime && !pausedForTermination) {
    270           pausedForTermination = true;
    271           if (!pausedForSnapshot) Algorithm.Pause();
    272         }
    273       }
    274     }
    275 
    276257    #region Events
    277258    protected override void OnNameChanged() {
     
    292273      if (handler != null) handler(this, EventArgs.Empty);
    293274    }
    294     [Obsolete("Deprecated needs to be removed")]
    295275    public event EventHandler ExecutionTimeChanged;
     276    private void OnExecutionTimeChanged() {
     277      var handler = ExecutionTimeChanged;
     278      if (handler != null) handler(this, EventArgs.Empty);
     279    }
    296280    public event EventHandler Prepared;
    297281    private void OnPrepared() {
     
    301285    public event EventHandler Started;
    302286    private void OnStarted() {
    303       timer.Start();
    304287      var handler = Started;
    305288      if (handler != null) handler(this, EventArgs.Empty);
     
    307290    public event EventHandler Paused;
    308291    private void OnPaused() {
    309       timer.Stop();
    310292      var handler = Paused;
    311293      if (handler != null) handler(this, EventArgs.Empty);
     
    313295    public event EventHandler Stopped;
    314296    private void OnStopped() {
    315       timer.Stop();
    316297      var handler = Stopped;
    317298      if (handler != null) handler(this, EventArgs.Empty);
     
    327308    private void RegisterAlgorithmEvents() {
    328309      algorithm.ExceptionOccurred += Algorithm_ExceptionOccurred;
     310      algorithm.ExecutionTimeChanged += Algorithm_ExecutionTimeChanged;
    329311      algorithm.ExecutionStateChanged += Algorithm_ExecutionStateChanged;
    330312      algorithm.Paused += Algorithm_Paused;
     
    335317    private void DeregisterAlgorithmEvents() {
    336318      algorithm.ExceptionOccurred -= Algorithm_ExceptionOccurred;
     319      algorithm.ExecutionTimeChanged -= Algorithm_ExecutionTimeChanged;
    337320      algorithm.ExecutionStateChanged -= Algorithm_ExecutionStateChanged;
    338321      algorithm.Paused -= Algorithm_Paused;
     
    343326    private void Algorithm_ExceptionOccurred(object sender, EventArgs<Exception> e) {
    344327      OnExceptionOccurred(e.Value);
     328    }
     329    private void Algorithm_ExecutionTimeChanged(object sender, EventArgs e) {
     330      if (snapshotTimesIndex < SnapshotTimes.Count && ExecutionTime >= SnapshotTimes[snapshotTimesIndex]
     331        && !pausedForSnapshot) {
     332        pausedForSnapshot = true;
     333        Algorithm.Pause();
     334      }
     335      if (ExecutionTime >= MaximumExecutionTime && !pausedForTermination) {
     336        pausedForTermination = true;
     337        if (!pausedForSnapshot) Algorithm.Pause();
     338      }
     339      OnExecutionTimeChanged();
    345340    }
    346341    private void Algorithm_ExecutionStateChanged(object sender, EventArgs e) {
  • branches/1614_GeneralizedQAP/HeuristicLab.OptimizationExpertSystem.Common/3.3/HeuristicLab.OptimizationExpertSystem.Common-3.3.csproj

    r15694 r15721  
    170170      <Private>False</Private>
    171171    </ProjectReference>
    172     <ProjectReference Include="..\..\HeuristicLab.Encodings.PermutationEncoding\3.3\HeuristicLab.Encodings.PermutationEncoding-3.3.csproj">
    173       <Project>{DBECB8B0-B166-4133-BAF1-ED67C3FD7FCA}</Project>
    174       <Name>HeuristicLab.Encodings.PermutationEncoding-3.3</Name>
    175       <Private>False</Private>
    176     </ProjectReference>
    177172    <ProjectReference Include="..\..\HeuristicLab.Optimization\3.3\HeuristicLab.Optimization-3.3.csproj">
    178173      <Project>{14ab8d24-25bc-400c-a846-4627aa945192}</Project>
Note: See TracChangeset for help on using the changeset viewer.