Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
01/11/11 16:00:17 (13 years ago)
Author:
cneumuel
Message:

#1215

  • implemented crossover and manipulator operators for int and double values
File:
1 edited

Legend:

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

    r5267 r5277  
    3131    //private static int baseAlgorithmMaxGenerations = 1000;
    3232
    33     private static int metaAlgorithmPopulationSize = 10;
     33    private static int metaAlgorithmPopulationSize = 16;
    3434    private static int metaAlgorithmMaxGenerations = 20;
    3535    private static int metaProblemRepetitions = 3;
    36     private static int baseAlgorithmMaxGenerations = 10;
     36    private static int baseAlgorithmMaxGenerations = 50;
    3737
    3838    static void Main(string[] args) {
     
    5454      //TestWaitAny();
    5555      //TestExecutionTimeUpdateInvervalPerformance();
    56       TestMemoryConsumption();
    57       return;
     56      //TestMemoryConsumption();
    5857
    5958      GeneticAlgorithm baseLevelAlgorithm = new GeneticAlgorithm();
     
    6160      MetaOptimizationProblem metaOptimizationProblem = new MetaOptimizationProblem();
    6261      metaOptimizationProblem.Repetitions = new IntValue(metaProblemRepetitions);
    63       GeneticAlgorithm metaLevelAlgorithm = GetMetaGA(metaOptimizationProblem);
    64       //GeneticAlgorithm metaLevelAlgorithm = GetParallelMetaGA(metaOptimizationProblem);
     62      //GeneticAlgorithm metaLevelAlgorithm = GetMetaGA(metaOptimizationProblem);
     63      GeneticAlgorithm metaLevelAlgorithm = GetParallelMetaGA(metaOptimizationProblem);
    6564      //GeneticAlgorithm metaLevelAlgorithm = GetHiveParallelMetaGA(metaOptimizationProblem);
    6665
     
    106105        algs.Add(clonedGa);
    107106        sw.Reset();
    108         ContentManager.Save((IStorableContent)metaLevelAlgorithm, "alg_"+i+".hl", true);
     107        ContentManager.Save((IStorableContent)metaLevelAlgorithm, "alg_" + i + ".hl", true);
    109108        Console.WriteLine("Cloned alg #{0}", i);
    110109      }
     
    119118      RepeatExecuteParallel(3, 1, 1, tb);
    120119      tb.AppendRow("--", "--", "--", "--", "--", "--", "--", "--", "--");
    121       RepeatExecuteParallel(repetitions, tasks, 1, tb); 
    122       RepeatExecuteParallel(repetitions, tasks, 2.5, tb); 
     120      RepeatExecuteParallel(repetitions, tasks, 1, tb);
     121      RepeatExecuteParallel(repetitions, tasks, 2.5, tb);
    123122      RepeatExecuteParallel(repetitions, tasks, 5, tb);
    124123      RepeatExecuteParallel(repetitions, tasks, 10, tb);
    125124      RepeatExecuteParallel(repetitions, tasks, 25, tb);
    126125      RepeatExecuteParallel(repetitions, tasks, 50, tb);
    127       RepeatExecuteParallel(repetitions, tasks, 100, tb); 
    128       RepeatExecuteParallel(repetitions, tasks, 250, tb); 
    129       RepeatExecuteParallel(repetitions, tasks, 500, tb); 
     126      RepeatExecuteParallel(repetitions, tasks, 100, tb);
     127      RepeatExecuteParallel(repetitions, tasks, 250, tb);
     128      RepeatExecuteParallel(repetitions, tasks, 500, tb);
    130129      RepeatExecuteParallel(repetitions, tasks, 1000, tb);
    131       RepeatExecuteParallel(repetitions, tasks, 2500, tb);     
     130      RepeatExecuteParallel(repetitions, tasks, 2500, tb);
    132131      RepeatExecuteParallel(repetitions, tasks, 5000, tb);
    133132
     
    148147    private static void RepeatExecuteParallel(int repetitions, int tasks, double executionTimeUpdateIntervalMs, TableBuilder tb) {
    149148      for (int i = 0; i < repetitions; i++) {
    150         ExecuteParallel(tasks, executionTimeUpdateIntervalMs, tb); 
    151         Console.Clear(); 
     149        ExecuteParallel(tasks, executionTimeUpdateIntervalMs, tb);
     150        Console.Clear();
    152151        Console.WriteLine(tb.ToString());
    153152      }
     
    167166        tasks[i] = new Task<TimeSpan>((alg) => {
    168167          Console.WriteLine("Task {0} started.", Task.CurrentId);
    169          
     168
    170169          Stopwatch swx = new Stopwatch();
    171170          swx.Start();
     
    197196        double totalMilliseconds = tasks.Select(t => t.Result.TotalMilliseconds).Sum();
    198197        tb.AppendRow(
    199           taskCount.ToString(), 
    200           executionTimeUpdateIntervalMs.ToString(), 
     198          taskCount.ToString(),
     199          executionTimeUpdateIntervalMs.ToString(),
    201200          TimeSpan.FromMilliseconds(totalExecutionTimeMilliseconds).ToString(),
    202           TimeSpan.FromMilliseconds(totalExecutionTimeMilliseconds / taskCount).ToString(), 
     201          TimeSpan.FromMilliseconds(totalExecutionTimeMilliseconds / taskCount).ToString(),
    203202          sw.Elapsed.ToString(),
    204203          TimeSpan.FromMilliseconds(totalMilliseconds).ToString(),
    205204          (totalMilliseconds / sw.ElapsedMilliseconds).ToString("0.00"),
    206205          counter.ToString(),
    207           (totalExecutionTimeMilliseconds/counter).ToString("0.00"));
     206          (totalExecutionTimeMilliseconds / counter).ToString("0.00"));
    208207      }
    209208      tasks = null;
     
    510509      ParameterConfigurationTree algorithmVc = metaOptimizationProblem.ParameterConfigurationTree;
    511510
    512       metaOptimizationProblem.Problems.Add(new HeuristicLab.Problems.TestFunctions.SingleObjectiveTestFunctionProblem() {
    513         Evaluator = new GriewankEvaluator(),
    514         ProblemSize = new IntValue(5)
    515       });
    516       metaOptimizationProblem.Problems.Add(new HeuristicLab.Problems.TestFunctions.SingleObjectiveTestFunctionProblem() {
    517         Evaluator = new GriewankEvaluator(),
    518         ProblemSize = new IntValue(50)
    519       });
     511      //metaOptimizationProblem.Problems.Add(new HeuristicLab.Problems.TestFunctions.SingleObjectiveTestFunctionProblem() {
     512      //  Evaluator = new GriewankEvaluator(),
     513      //  ProblemSize = new IntValue(5)
     514      //});
     515      //metaOptimizationProblem.Problems.Add(new HeuristicLab.Problems.TestFunctions.SingleObjectiveTestFunctionProblem() {
     516      //  Evaluator = new GriewankEvaluator(),
     517      //  ProblemSize = new IntValue(50)
     518      //});
    520519      metaOptimizationProblem.Problems.Add(new HeuristicLab.Problems.TestFunctions.SingleObjectiveTestFunctionProblem() {
    521520        Evaluator = new GriewankEvaluator(),
     
    526525      ConfigureMutationRate(algorithmVc, 0.0, 1.0, 0.01);
    527526      ConfigureMutationOperator(algorithmVc);
    528       ConfigureElites(algorithmVc, 0, 10, 1);
    529       ConfigureSelectionOperator(algorithmVc, true);
     527      //ConfigureElites(algorithmVc, 0, 10, 1);
     528      //ConfigureSelectionOperator(algorithmVc, true);
    530529      return algorithmVc;
    531530    }
     
    554553        IValueConfiguration clonedVc = (IValueConfiguration)algorithmVc.Clone();
    555554        GeneticAlgorithm newAlg = (GeneticAlgorithm)baseLevelAlgorithm.Clone();
    556         //clonedVc.Mutate(rand);
    557 
    558         //.Apply(rand, clonedVc); todo
     555        ParameterConfigurationManipulator.Apply(rand, clonedVc, new UniformIntValueManipulator(), new NormalDoubleValueManipulator());
    559556        clonedVc.Parameterize(newAlg);
     557
    560558        Console.WriteLine(string.Format("PopSize: original: {0}, mutated: {1}", baseLevelAlgorithm.PopulationSize, newAlg.PopulationSize));
    561559        Console.WriteLine(string.Format("MutRate: original: {0}, mutated: {1}", baseLevelAlgorithm.MutationProbability, newAlg.MutationProbability));
     
    588586
    589587        //clonedVc1.Cross(clonedVc2, rand); todo
     588
     589        ParameterConfigurationCrossover.Apply(rand, clonedVc1, clonedVc2, new DiscreteIntValueCrossover(), new AverageDoubleValueCrossover());
    590590        clonedVc1.Parameterize(first);
    591591
     
    706706        int currentGeneration = -1;
    707707        do {
    708           Thread.Sleep(500);
     708          Thread.Sleep(1000);
    709709          if (metaLevelAlgorithm.Results.ContainsKey("Generations") && ((IntValue)metaLevelAlgorithm.Results["Generations"].Value).Value != currentGeneration) {
    710710            while (metaLevelAlgorithm.Results.Count < 3) Thread.Sleep(100);
Note: See TracChangeset for help on using the changeset viewer.