Changeset 15330


Ignore:
Timestamp:
08/17/17 15:47:54 (2 years ago)
Author:
abeham
Message:

#2457: merged trunk into branch

Location:
branches/PerformanceComparison
Files:
18 edited

Legend:

Unmodified
Added
Removed
  • branches/PerformanceComparison/HeuristicLab.Analysis

  • branches/PerformanceComparison/HeuristicLab.Analysis.Views

  • branches/PerformanceComparison/HeuristicLab.Analysis.Views/3.3/HeatMapView.resx

  • branches/PerformanceComparison/HeuristicLab.Encodings.BinaryVectorEncoding

  • branches/PerformanceComparison/HeuristicLab.Encodings.LinearLinkageEncoding

    • Property svn:mergeinfo changed (with no actual effect on merging)
  • branches/PerformanceComparison/HeuristicLab.Encodings.PermutationEncoding

  • branches/PerformanceComparison/HeuristicLab.Optimization

  • branches/PerformanceComparison/HeuristicLab.Optimization.Views

  • branches/PerformanceComparison/HeuristicLab.Optimization.Views/3.3/IOptimizerView.cs

    r14600 r15330  
    137137    #region Control events
    138138    protected virtual void startButton_Click(object sender, EventArgs e) {
    139       Content.Start();
     139      Content.StartAsync();
    140140    }
    141141    protected virtual void pauseButton_Click(object sender, EventArgs e) {
  • branches/PerformanceComparison/HeuristicLab.Optimization.Views/3.3/ResultCollectionView.cs

    r14600 r15330  
    2121
    2222using System;
     23using System.Windows.Forms;
    2324using HeuristicLab.Core;
    2425using HeuristicLab.Core.Views;
     
    5859      }
    5960    }
     61
     62    protected override void Item_ToStringChanged(object sender, EventArgs e) {
     63      if (InvokeRequired) {
     64        Invoke(new EventHandler(Item_ToStringChanged), sender, e);
     65        return;
     66      }
     67
     68      base.Item_ToStringChanged(sender, e);
     69      Application.DoEvents();
     70    }
    6071  }
    6172}
  • branches/PerformanceComparison/HeuristicLab.Optimization/3.3/Algorithms/Algorithm.cs

    r14600 r15330  
    2424using System.Drawing;
    2525using System.Linq;
     26using System.Threading;
     27using System.Threading.Tasks;
    2628using HeuristicLab.Collections;
    2729using HeuristicLab.Common;
     
    203205    }
    204206    public virtual void Start() {
     207      Start(CancellationToken.None);
     208    }
     209    public virtual void Start(CancellationToken cancellationToken) {
    205210      if ((ExecutionState != ExecutionState.Prepared) && (ExecutionState != ExecutionState.Paused))
    206211        throw new InvalidOperationException(string.Format("Start not allowed in execution state \"{0}\".", ExecutionState));
     212    }
     213    public virtual async Task StartAsync() { await StartAsync(CancellationToken.None); }
     214    public virtual async Task StartAsync(CancellationToken cancellationToken) {
     215      await AsyncHelper.DoAsync(Start, cancellationToken);
    207216    }
    208217    public virtual void Pause() {
  • branches/PerformanceComparison/HeuristicLab.Optimization/3.3/Algorithms/BasicAlgorithm.cs

    r14600 r15330  
    2121
    2222using System;
     23using System.Linq;
    2324using System.Threading;
    24 using System.Threading.Tasks;
    2525using HeuristicLab.Common;
    2626using HeuristicLab.Core;
     
    5757      : base(original, cloner) {
    5858      results = cloner.Clone(original.Results);
     59      initialized = original.initialized;
    5960    }
    6061    protected BasicAlgorithm()
     
    7172    }
    7273
    73     public override void Start() {
    74       base.Start();
    75       CancellationTokenSource = new CancellationTokenSource();
     74    public override void Start(CancellationToken cancellationToken) {
     75      base.Start(cancellationToken);
     76      CancellationTokenSource = CancellationTokenSource.CreateLinkedTokenSource(cancellationToken);
    7677      pausePending = false;
    7778      OnStarted();
    7879
    79       Task task = Task.Factory.StartNew(Run, CancellationTokenSource.Token, CancellationTokenSource.Token);
    80       task.ContinueWith(t => {
    81         try {
    82           t.Wait();
    83         }
    84         catch (AggregateException ex) {
    85           try {
    86             ex.Flatten().Handle(x => x is OperationCanceledException);
    87           }
    88           catch (AggregateException remaining) {
    89             if (remaining.InnerExceptions.Count == 1) OnExceptionOccurred(remaining.InnerExceptions[0]);
    90             else OnExceptionOccurred(remaining);
    91           }
    92         }
    93         CancellationTokenSource.Dispose();
    94         CancellationTokenSource = null;
    95         if (pausePending) OnPaused();
    96         else OnStopped();
    97       });
     80      try {
     81        Run((object)cancellationTokenSource.Token);
     82      }
     83      catch (OperationCanceledException) {
     84      }
     85      catch (AggregateException ae) {
     86        OnExceptionOccurred(ae.InnerExceptions.SingleOrDefault() ?? ae);
     87      }
     88      catch (Exception e) {
     89        OnExceptionOccurred(e);
     90      }
     91
     92      CancellationTokenSource.Dispose();
     93      CancellationTokenSource = null;
     94      if (pausePending) OnPaused();
     95      else OnStopped();
    9896    }
    9997
  • branches/PerformanceComparison/HeuristicLab.Optimization/3.3/Algorithms/EngineAlgorithm.cs

    r14600 r15330  
    169169      }
    170170    }
    171     public override void Start() {
    172       base.Start();
    173       if (engine != null) engine.Start();
     171    public override void Start(System.Threading.CancellationToken cancellationToken) {
     172      base.Start(cancellationToken);
     173      if (engine != null) engine.Start(cancellationToken);
    174174    }
    175175    public override void Pause() {
  • branches/PerformanceComparison/HeuristicLab.Optimization/3.3/MetaOptimizers/BatchRun.cs

    r14600 r15330  
    2323using System.Collections.Generic;
    2424using System.Drawing;
     25using System.Threading;
     26using System.Threading.Tasks;
    2527using HeuristicLab.Collections;
    2628using HeuristicLab.Common;
     
    237239        batchRunAction = BatchRunAction.Prepare;
    238240        // a race-condition may occur when the optimizer has changed the state by itself in the meantime
    239         try { Optimizer.Prepare(clearRuns); }
    240         catch (InvalidOperationException) { }
     241        try { Optimizer.Prepare(clearRuns); } catch (InvalidOperationException) { }
    241242      } else {
    242243        ExecutionState = ExecutionState.Stopped;
     
    244245    }
    245246    public void Start() {
     247      Start(CancellationToken.None);
     248    }
     249    public void Start(CancellationToken cancellationToken) {
    246250      if ((ExecutionState != ExecutionState.Prepared) && (ExecutionState != ExecutionState.Paused))
    247251        throw new InvalidOperationException(string.Format("Start not allowed in execution state \"{0}\".", ExecutionState));
     
    249253      batchRunAction = BatchRunAction.Start;
    250254      if (Optimizer.ExecutionState == ExecutionState.Stopped) Optimizer.Prepare();
    251       // a race-condition may occur when the optimizer has changed the state by itself in the meantime
    252       try { Optimizer.Start(); }
    253       catch (InvalidOperationException) { }
     255      for (int i = repetitionsCounter; i < repetitions; i++) {
     256        // a race-condition may occur when the optimizer has changed the state by itself in the meantime
     257        try { Optimizer.Start(cancellationToken); } catch (InvalidOperationException) { }
     258        if (ExecutionState == ExecutionState.Paused || ExecutionState == ExecutionState.Stopped) break;
     259        Optimizer.Prepare();
     260      }
     261    }
     262    public async Task StartAsync() { await StartAsync(CancellationToken.None); }
     263    public async Task StartAsync(CancellationToken cancellationToken) {
     264      await AsyncHelper.DoAsync(Start, cancellationToken);
    254265    }
    255266    public void Pause() {
     
    260271      if (Optimizer.ExecutionState != ExecutionState.Started) return;
    261272      // a race-condition may occur when the optimizer has changed the state by itself in the meantime
    262       try { Optimizer.Pause(); }
    263       catch (InvalidOperationException) { }
     273      try { Optimizer.Pause(); } catch (InvalidOperationException) { }
    264274    }
    265275    public void Stop() {
     
    273283      }
    274284      // a race-condition may occur when the optimizer has changed the state by itself in the meantime
    275       try { Optimizer.Stop(); }
    276       catch (InvalidOperationException) { }
     285      try { Optimizer.Stop(); } catch (InvalidOperationException) { }
    277286    }
    278287
     
    395404      else if (repetitionsCounter >= repetitions) OnStopped();
    396405      else if (batchRunAction == BatchRunAction.Pause) OnPaused();
    397       else if (batchRunAction == BatchRunAction.Start) {
    398         Optimizer.Prepare();
    399         Optimizer.Start();
    400       } else if (executionState == ExecutionState.Started) {
     406      else if (batchRunAction == BatchRunAction.Start) return;
     407      else if (executionState == ExecutionState.Started) {
    401408        // if the batch run hasn't been started but the inner optimizer was run then pause
    402409        OnPaused();
  • branches/PerformanceComparison/HeuristicLab.Optimization/3.3/MetaOptimizers/Experiment.cs

    r14600 r15330  
    2525using System.Linq;
    2626using System.Threading;
     27using System.Threading.Tasks;
    2728using HeuristicLab.Collections;
    2829using HeuristicLab.Common;
     
    110111    private bool experimentStarted = false;
    111112    private bool experimentStopped = false;
     113    private ManualResetEventSlim allOptimizerFinished; // this indicates that all started optimizers have been paused or stopped
    112114
    113115    public Experiment()
     
    181183      foreach (IOptimizer optimizer in Optimizers.Where(x => x.ExecutionState != ExecutionState.Started)) {
    182184        // a race-condition may occur when the optimizer has changed the state by itself in the meantime
    183         try { optimizer.Prepare(clearRuns); }
    184         catch (InvalidOperationException) { }
     185        try { optimizer.Prepare(clearRuns); } catch (InvalidOperationException) { }
    185186      }
    186187    }
    187188    public void Start() {
     189      Start(CancellationToken.None);
     190    }
     191    public void Start(CancellationToken cancellationToken) {
    188192      if ((ExecutionState != ExecutionState.Prepared) && (ExecutionState != ExecutionState.Paused))
    189193        throw new InvalidOperationException(string.Format("Start not allowed in execution state \"{0}\".", ExecutionState));
     
    192196      experimentStarted = true;
    193197      experimentStopped = false;
    194       IOptimizer optimizer = Optimizers.FirstOrDefault(x => (x.ExecutionState == ExecutionState.Prepared) || (x.ExecutionState == ExecutionState.Paused));
    195       if (optimizer != null) {
     198      allOptimizerFinished = new ManualResetEventSlim(false);
     199
     200      IOptimizer optimizer;
     201      while ((optimizer = Optimizers.FirstOrDefault(x => (x.ExecutionState == ExecutionState.Prepared) || (x.ExecutionState == ExecutionState.Paused))) != null) {
    196202        // a race-condition may occur when the optimizer has changed the state by itself in the meantime
    197         try { optimizer.Start(); }
    198         catch (InvalidOperationException) { }
    199       }
     203        try { optimizer.Start(cancellationToken); } catch (InvalidOperationException) { }
     204        if (ExecutionState == ExecutionState.Paused || ExecutionState == ExecutionState.Stopped) break;
     205      }
     206
     207      allOptimizerFinished.Wait();
     208    }
     209    public async Task StartAsync() { await StartAsync(CancellationToken.None); }
     210    public async Task StartAsync(CancellationToken cancellationToken) {
     211      await AsyncHelper.DoAsync(Start, cancellationToken);
    200212    }
    201213    public void Pause() {
     
    208220      foreach (IOptimizer optimizer in Optimizers.Where(x => x.ExecutionState == ExecutionState.Started)) {
    209221        // a race-condition may occur when the optimizer has changed the state by itself in the meantime
    210         try { optimizer.Pause(); }
    211         catch (InvalidOperationException) { }
     222        try { optimizer.Pause(); } catch (InvalidOperationException) { }
    212223      }
    213224    }
     
    222233        foreach (var optimizer in Optimizers.Where(x => (x.ExecutionState == ExecutionState.Started) || (x.ExecutionState == ExecutionState.Paused))) {
    223234          // a race-condition may occur when the optimizer has changed the state by itself in the meantime
    224           try { optimizer.Stop(); }
    225           catch (InvalidOperationException) { }
     235          try { optimizer.Stop(); } catch (InvalidOperationException) { }
    226236        }
    227237      } else {
     
    357367      try {
    358368        ExecutionTime = Optimizers.Aggregate(TimeSpan.Zero, (t, o) => t + o.ExecutionTime);
    359       }
    360       finally {
     369      } finally {
    361370        Monitor.Exit(locker);
    362371      }
     
    364373    private void optimizer_Paused(object sender, EventArgs e) {
    365374      lock (locker)
    366         if (Optimizers.All(x => x.ExecutionState != ExecutionState.Started)) OnPaused();
     375        if (Optimizers.All(x => x.ExecutionState != ExecutionState.Started)) {
     376          OnPaused();
     377          allOptimizerFinished.Set();
     378        }
    367379    }
    368380    private void optimizer_Prepared(object sender, EventArgs e) {
     
    377389      lock (locker) {
    378390        if (experimentStopped) {
    379           if (Optimizers.All(x => (x.ExecutionState == ExecutionState.Stopped) || (x.ExecutionState == ExecutionState.Prepared))) OnStopped();
     391          if (Optimizers.All(x => (x.ExecutionState == ExecutionState.Stopped) || (x.ExecutionState == ExecutionState.Prepared))) {
     392            OnStopped();
     393            allOptimizerFinished.Set();
     394          }
    380395        } else {
    381           if (experimentStarted && Optimizers.Any(x => (x.ExecutionState == ExecutionState.Prepared) || (x.ExecutionState == ExecutionState.Paused))) {
    382             Optimizers.First(x => (x.ExecutionState == ExecutionState.Prepared) || (x.ExecutionState == ExecutionState.Paused)).Start();
    383           } else if (Optimizers.All(x => x.ExecutionState == ExecutionState.Stopped)) OnStopped();
    384           else if (Optimizers.Any(x => (x.ExecutionState == ExecutionState.Prepared) || (x.ExecutionState == ExecutionState.Paused)) && Optimizers.All(o => o.ExecutionState != ExecutionState.Started)) OnPaused();
     396          if (experimentStarted && Optimizers.Any(x => (x.ExecutionState == ExecutionState.Prepared) || (x.ExecutionState == ExecutionState.Paused))) return;
     397          else if (Optimizers.All(x => x.ExecutionState == ExecutionState.Stopped)) {
     398            OnStopped();
     399            allOptimizerFinished.Set();
     400          } else if (Optimizers.Any(x => (x.ExecutionState == ExecutionState.Prepared) || (x.ExecutionState == ExecutionState.Paused)) && Optimizers.All(o => o.ExecutionState != ExecutionState.Started)) {
     401            OnPaused();
     402            allOptimizerFinished.Set();
     403          }
    385404        }
    386405      }
  • branches/PerformanceComparison/HeuristicLab.Optimization/3.3/MetaOptimizers/TimeLimitRun.cs

    r14600 r15330  
    2525using System.Drawing;
    2626using System.Linq;
     27using System.Threading;
    2728using System.Threading.Tasks;
    2829using HeuristicLab.Collections;
     
    238239    }
    239240    public void Start() {
    240       Algorithm.Start();
     241      Start(CancellationToken.None);
     242    }
     243    public void Start(CancellationToken cancellationToken) {
     244      Algorithm.Start(cancellationToken);
     245    }
     246    public async Task StartAsync() { await StartAsync(CancellationToken.None); }
     247    public async Task StartAsync(CancellationToken cancellationToken) {
     248      await AsyncHelper.DoAsync(Start, cancellationToken);
    241249    }
    242250    public void Pause() {
  • branches/PerformanceComparison/HeuristicLab.Optimization/3.3/Problems/SingleObjectiveHeuristicOptimizationProblem.cs

  • branches/PerformanceComparison/HeuristicLab.Problems.Instances.QAPLIB

    • Property svn:mergeinfo changed (with no actual effect on merging)
Note: See TracChangeset for help on using the changeset viewer.