- Timestamp:
- 07/17/11 22:51:11 (13 years ago)
- Location:
- branches/QAPAlgorithms
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/QAPAlgorithms
- Property svn:ignore
-
old new 12 12 *.psess 13 13 *.vsp 14 *.docstates
-
- Property svn:mergeinfo changed
- Property svn:ignore
-
branches/QAPAlgorithms/HeuristicLab/3.3/Tests/CollectObjectGraphTest.cs
r6209 r6569 25 25 using System.Linq; 26 26 using System.Threading; 27 using System.Threading.Tasks; 27 28 using HeuristicLab.Algorithms.GeneticAlgorithm; 28 29 using HeuristicLab.Common; … … 30 31 using HeuristicLab.Persistence.Default.Xml; 31 32 using HeuristicLab.Problems.TestFunctions; 32 using HeuristicLab.Random;33 33 using HeuristicLab.SequentialEngine; 34 34 using Microsoft.VisualStudio.TestTools.UnitTesting; … … 96 96 [TestMethod] 97 97 public void AlgorithmExecutions() { 98 var random = new MersenneTwister(0);99 98 var algs = new List<IAlgorithm>(); 100 99 … … 117 116 } 118 117 } 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 } 119 154 } 120 155 }
Note: See TracChangeset
for help on using the changeset viewer.