Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
06/28/11 23:29:26 (13 years ago)
Author:
cneumuel
Message:

#1569 checked in test-case

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab/3.3/Tests/CollectObjectGraphTest.cs

    r6209 r6495  
    2525using System.Linq;
    2626using System.Threading;
     27using System.Threading.Tasks;
    2728using HeuristicLab.Algorithms.GeneticAlgorithm;
    2829using HeuristicLab.Common;
     
    3031using HeuristicLab.Persistence.Default.Xml;
    3132using HeuristicLab.Problems.TestFunctions;
    32 using HeuristicLab.Random;
    3333using HeuristicLab.SequentialEngine;
    3434using Microsoft.VisualStudio.TestTools.UnitTesting;
     
    9696    [TestMethod]
    9797    public void AlgorithmExecutions() {
    98       var random = new MersenneTwister(0);
    9998      var algs = new List<IAlgorithm>();
    10099
     
    117116      }
    118117    }
     118
     119    /// <summary>
     120    /// Test the execution of many algorithms in parallel
     121    /// </summary>
     122    [TestMethod]
     123    public void ParallelAlgorithmExecutions() {
     124      int n = 60;
     125      var tasks = new Task[n];
     126
     127      TestContext.WriteLine("creating tasks...");
     128      for (int i = 0; i < n; i++) {
     129        tasks[i] = new Task((iobj) => {
     130          int locali = (int)iobj;
     131          GeneticAlgorithm ga = new GeneticAlgorithm();
     132          ga.Name = "Alg " + locali;
     133          ga.PopulationSize.Value = 5;
     134          ga.MaximumGenerations.Value = 5;
     135          ga.Engine = new SequentialEngine();
     136          ga.Problem = new SingleObjectiveTestFunctionProblem();
     137          ga.Prepare(true);
     138          Console.WriteLine("{0}; Objects before execution: {1}", ga.Name, ga.GetObjectGraphObjects().Count());
     139          var sw = new Stopwatch();
     140          sw.Start();
     141          ga.StartSync(new CancellationToken());
     142          sw.Stop();
     143          Console.WriteLine("{0}; Objects after execution: {1}", ga.Name, ga.GetObjectGraphObjects().Count());
     144          Console.WriteLine("{0}; ExecutionTime: {1} ", ga.Name, sw.Elapsed);
     145        }, i);
     146      }
     147      TestContext.WriteLine("starting tasks...");
     148      for (int i = 0; i < n; i++) {
     149        tasks[i].Start();
     150      }
     151      TestContext.WriteLine("waiting for tasks to finish...");
     152      Task.WaitAll(tasks);
     153    }
    119154  }
    120155}
Note: See TracChangeset for help on using the changeset viewer.