Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
01/10/11 02:26:55 (13 years ago)
Author:
cneumuel
Message:

#1260

  • added some performance tests for parallel execution and ExecutionTime update intervals
Location:
branches/HeuristicLab.MetaOptimization
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • branches/HeuristicLab.MetaOptimization/HeuristicLab.MetaOptimization.Test/Program.cs

    r5231 r5262  
    5050      //TestCombinations4();
    5151      //TestAlgorithmPerformanceIssue();
    52       TestWaitAny();
     52      //TestWaitAny();
     53      TestExecutionTimeUpdateInvervalPerformance();
     54      return;
    5355
    5456      GeneticAlgorithm baseLevelAlgorithm = new GeneticAlgorithm();
     
    7880
    7981      Console.ReadLine();
     82    }
     83
     84    private static void TestExecutionTimeUpdateInvervalPerformance() {
     85      TableBuilder tb = new TableBuilder("Tasks", "Interval", "TotalExecutionTime", "AvgExecutionTime", "TimeElapsed", "TotalTimeElapsed", "Speedup", "ExecutionTimeChangedCount", "RealExecutionTimeUpdate(ms)");
     86      int tasks = 32;
     87      int repetitions = 3;
     88
     89      // warmup
     90      RepeatExecuteParallel(3, 1, 1, tb);
     91      tb.AppendRow("--", "--", "--", "--", "--", "--", "--", "--", "--");
     92      RepeatExecuteParallel(repetitions, tasks, 1, tb);
     93      RepeatExecuteParallel(repetitions, tasks, 2.5, tb);
     94      RepeatExecuteParallel(repetitions, tasks, 5, tb);
     95      RepeatExecuteParallel(repetitions, tasks, 10, tb);
     96      RepeatExecuteParallel(repetitions, tasks, 25, tb);
     97      RepeatExecuteParallel(repetitions, tasks, 50, tb);
     98      RepeatExecuteParallel(repetitions, tasks, 100, tb);
     99      RepeatExecuteParallel(repetitions, tasks, 250, tb);
     100      RepeatExecuteParallel(repetitions, tasks, 500, tb);
     101      RepeatExecuteParallel(repetitions, tasks, 1000, tb);
     102      RepeatExecuteParallel(repetitions, tasks, 2500, tb);     
     103      RepeatExecuteParallel(repetitions, tasks, 5000, tb);
     104
     105      using (var sw = new StreamWriter("TestExecutionTimeUpdateInvervalPerformance.txt")) {
     106        sw.Write(tb.ToString());
     107      }
     108    }
     109
     110    private static GeneticAlgorithm CreateGA() {
     111      GeneticAlgorithm ga = new GeneticAlgorithm();
     112      ga.Problem = new SingleObjectiveTestFunctionProblem() { ProblemSize = new IntValue(250) };
     113      ga.Engine = new SequentialEngine.SequentialEngine();
     114      ga.SetSeedRandomly.Value = false;
     115      ga.Seed.Value = 0;
     116      return ga;
     117    }
     118
     119    private static void RepeatExecuteParallel(int repetitions, int tasks, double executionTimeUpdateIntervalMs, TableBuilder tb) {
     120      for (int i = 0; i < repetitions; i++) {
     121        ExecuteParallel(tasks, executionTimeUpdateIntervalMs, tb);
     122        Console.Clear();
     123        Console.WriteLine(tb.ToString());
     124      }
     125    }
     126
     127    private static void ExecuteParallel(int taskCount, double executionTimeUpdateIntervalMs, TableBuilder tb) {
     128      Task<TimeSpan>[] tasks = new Task<TimeSpan>[taskCount];
     129      EngineAlgorithm[] algs = new EngineAlgorithm[taskCount];
     130      for (int i = 0; i < taskCount; i++) {
     131        GeneticAlgorithm alg = CreateGA();
     132        ((Engine)alg.Engine).ExecutionTimeUpdateInterval = TimeSpan.FromMilliseconds(executionTimeUpdateIntervalMs);
     133        algs[i] = alg;
     134      }
     135      Console.WriteLine("Creating algs finished.");
     136
     137      for (int i = 0; i < taskCount; i++) {
     138        tasks[i] = new Task<TimeSpan>((alg) => {
     139          Console.WriteLine("Task {0} started.", Task.CurrentId);
     140         
     141          Stopwatch swx = new Stopwatch();
     142          swx.Start();
     143          ((EngineAlgorithm)alg).ExecutionTimeChanged += new EventHandler(Program_ExecutionTimeChanged);
     144          var executor = new AlgorithmExecutor((EngineAlgorithm)alg);
     145          executor.StartSync();
     146          ((EngineAlgorithm)alg).ExecutionTimeChanged -= new EventHandler(Program_ExecutionTimeChanged);
     147          swx.Stop();
     148          Console.WriteLine("Task {0} finished.", Task.CurrentId);
     149          return swx.Elapsed;
     150        }, algs[i]);
     151      }
     152      Console.WriteLine("Creating tasks finished.");
     153      counter = 0;
     154      Stopwatch sw = new Stopwatch();
     155      sw.Start();
     156      foreach (var task in tasks) task.Start();
     157      Task.WaitAll(tasks);
     158      sw.Stop();
     159
     160      if (!algs.All(alg => alg.ExecutionState == ExecutionState.Stopped))
     161        throw new Exception("Not all algs stopped properly");
     162
     163      if (!algs.All(alg => ((DoubleValue)alg.Results["BestQuality"].Value).Value == ((DoubleValue)algs.First().Results["BestQuality"].Value).Value))
     164        throw new Exception("Not all algs have the same resutls");
     165
     166      if (tb != null) {
     167        double totalExecutionTimeMilliseconds = algs.Select(x => x.ExecutionTime.TotalMilliseconds).Sum();
     168        double totalMilliseconds = tasks.Select(t => t.Result.TotalMilliseconds).Sum();
     169        tb.AppendRow(
     170          taskCount.ToString(),
     171          executionTimeUpdateIntervalMs.ToString(),
     172          TimeSpan.FromMilliseconds(totalExecutionTimeMilliseconds).ToString(),
     173          TimeSpan.FromMilliseconds(totalExecutionTimeMilliseconds / taskCount).ToString(),
     174          sw.Elapsed.ToString(),
     175          TimeSpan.FromMilliseconds(totalMilliseconds).ToString(),
     176          (totalMilliseconds / sw.ElapsedMilliseconds).ToString("0.00"),
     177          counter.ToString(),
     178          (totalExecutionTimeMilliseconds/counter).ToString("0.00"));
     179      }
     180      tasks = null;
     181      algs = null;
     182      GC.Collect();
     183      Console.WriteLine("Test finished.");
     184    }
     185
     186    private static int counter = 0;
     187    static void Program_ExecutionTimeChanged(object sender, EventArgs e) {
     188      System.Threading.Interlocked.Increment(ref counter);
    80189    }
    81190
  • branches/HeuristicLab.MetaOptimization/HeuristicLab.Problems.MetaOptimization.Views/3.3/ValueConfigurationViews/ValueView.cs

    r5231 r5262  
    4646
    4747    private void setValueButton_Click(object sender, EventArgs e) {
    48       //var typesWithoutNullValue = Content.ValidTypes.Where(x => x != typeof(NullValue));
    49       //var instances = typesWithoutNullValue.Select(x => (IItem)Activator.CreateInstance(x));
    50       //var groupedInstances = instances.GroupBy(x => ApplicationManager.Manager.GetDeclaringPlugin(x.GetType()).Name);
    51       //var objectSelectorDialog = new ObjectSelectorDialog<IItem>(groupedInstances);
    52 
    5348      var withoutNullValue = Content.ValidValues.Where(x => x != null && !(x is NullValue));
    5449      var objectSelectorDialog = new ObjectSelectorDialog<IItem>(withoutNullValue.GroupBy(x => ApplicationManager.Manager.GetDeclaringPlugin(x.GetType()).Name));
  • branches/HeuristicLab.MetaOptimization/HeuristicLab.Problems.MetaOptimization/3.3/Encoding/ParameterConfigurations/ParameterConfiguration.cs

    r5231 r5262  
    209209      if (IsSubclassOfRawGeneric(typeof(OptionalConstrainedValueParameter<>), parameter.GetType())) {
    210210        var x = (IEnumerable)parameter.GetType().GetProperty("ValidValues").GetValue(parameter, new object[] { });
    211         return new ItemSet<IItem>(x.Cast<IItem>());
     211        return new ItemSet<IItem>(x.Cast<IItem>().Select(y => (IItem)y.Clone()));
    212212      } else {
    213213        return null;
Note: See TracChangeset for help on using the changeset viewer.