Changeset 7493


Ignore:
Timestamp:
02/21/12 10:37:49 (7 years ago)
Author:
mkommend
Message:

#1691: Reordered problem dependent operators in the GeneticAlgorithm and the OSGA.

Location:
trunk/sources
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Algorithms.GeneticAlgorithm/3.3/GeneticAlgorithm.cs

    r7259 r7493  
    353353      ICrossover oldCrossover = CrossoverParameter.Value;
    354354      CrossoverParameter.ValidValues.Clear();
     355      ICrossover defaultCrossover = Problem.Operators.OfType<ICrossover>().FirstOrDefault();
     356
    355357      foreach (ICrossover crossover in Problem.Operators.OfType<ICrossover>().OrderBy(x => x.Name))
    356358        CrossoverParameter.ValidValues.Add(crossover);
     359
    357360      if (oldCrossover != null) {
    358361        ICrossover crossover = CrossoverParameter.ValidValues.FirstOrDefault(x => x.GetType() == oldCrossover.GetType());
    359362        if (crossover != null) CrossoverParameter.Value = crossover;
    360       }
     363      } else if (defaultCrossover != null)
     364        CrossoverParameter.Value = defaultCrossover;
    361365    }
    362366    private void UpdateMutators() {
  • trunk/sources/HeuristicLab.Algorithms.OffspringSelectionGeneticAlgorithm/3.3/OffspringSelectionGeneticAlgorithm.cs

    r7259 r7493  
    447447      ICrossover oldCrossover = CrossoverParameter.Value;
    448448      CrossoverParameter.ValidValues.Clear();
     449      ICrossover defaultCrossover = Problem.Operators.OfType<ICrossover>().FirstOrDefault();
     450
    449451      foreach (ICrossover crossover in Problem.Operators.OfType<ICrossover>().OrderBy(x => x.Name))
    450452        CrossoverParameter.ValidValues.Add(crossover);
     453
    451454      if (oldCrossover != null) {
    452455        ICrossover crossover = CrossoverParameter.ValidValues.FirstOrDefault(x => x.GetType() == oldCrossover.GetType());
    453456        if (crossover != null) CrossoverParameter.Value = crossover;
    454       }
     457      } else if (defaultCrossover != null)
     458        CrossoverParameter.Value = defaultCrossover;
    455459    }
    456460    private void UpdateMutators() {
Note: See TracChangeset for help on using the changeset viewer.