Free cookie consent management tool by TermsFeed Policy Generator

Changeset 3426


Ignore:
Timestamp:
04/20/10 00:13:43 (15 years ago)
Author:
abeham
Message:

Added evaluated solutions result to OSGA (this slows down execution extremely if the update is not decoupled in some way)
Made comparison factor modifier an optional parameter #976

Location:
trunk/sources/HeuristicLab.Algorithms.OffspringSelectionGeneticAlgorithm/3.3
Files:
2 edited

Legend:

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

    r3413 r3426  
    8989      get { return (ValueLookupParameter<DoubleValue>)Parameters["ComparisonFactorUpperBound"]; }
    9090    }
    91     private ConstrainedValueParameter<IDiscreteDoubleValueModifier> ComparisonFactorModifierParameter {
    92       get { return (ConstrainedValueParameter<IDiscreteDoubleValueModifier>)Parameters["ComparisonFactorModifier"]; }
     91    private OptionalConstrainedValueParameter<IDiscreteDoubleValueModifier> ComparisonFactorModifierParameter {
     92      get { return (OptionalConstrainedValueParameter<IDiscreteDoubleValueModifier>)Parameters["ComparisonFactorModifier"]; }
    9393    }
    9494    private ValueLookupParameter<DoubleValue> MaximumSelectionPressureParameter {
     
    193193      Parameters.Add(new ValueLookupParameter<DoubleValue>("ComparisonFactorLowerBound", "The lower bound of the comparison factor (start).", new DoubleValue(0)));
    194194      Parameters.Add(new ValueLookupParameter<DoubleValue>("ComparisonFactorUpperBound", "The upper bound of the comparison factor (end).", new DoubleValue(1)));
    195       Parameters.Add(new ConstrainedValueParameter<IDiscreteDoubleValueModifier>("ComparisonFactorModifier", "The operator used to modify the comparison factor."));
     195      Parameters.Add(new OptionalConstrainedValueParameter<IDiscreteDoubleValueModifier>("ComparisonFactorModifier", "The operator used to modify the comparison factor.", new ItemSet<IDiscreteDoubleValueModifier>(new IDiscreteDoubleValueModifier[] { new LinearDiscreteDoubleValueModifier() }), new LinearDiscreteDoubleValueModifier()));
    196196      Parameters.Add(new ValueLookupParameter<DoubleValue>("MaximumSelectionPressure", "The maximum selection pressure that terminates the algorithm.", new DoubleValue(100)));
    197197      Parameters.Add(new ValueLookupParameter<BoolValue>("OffspringSelectionBeforeMutation", "True if the offspring selection step should be applied before mutation, false if it should be applied after mutation.", new BoolValue(false)));
     
    386386    private void UpdateComparisonFactorModifiers() {
    387387      IDiscreteDoubleValueModifier oldModifier = ComparisonFactorModifier;
    388       if (oldModifier == null) oldModifier = new LinearDiscreteDoubleValueModifier();
    389388
    390389      ComparisonFactorModifierParameter.ValidValues.Clear();
    391390      foreach (IDiscreteDoubleValueModifier modifier in comparisonFactorModifiers)
    392391        ComparisonFactorModifierParameter.ValidValues.Add(modifier);
    393      
    394       IDiscreteDoubleValueModifier mod = ComparisonFactorModifierParameter.ValidValues.FirstOrDefault(x => x.GetType() == oldModifier.GetType());
    395       if (mod != null) ComparisonFactorModifierParameter.Value = mod;
     392
     393      if (oldModifier != null) {
     394        IDiscreteDoubleValueModifier mod = ComparisonFactorModifierParameter.ValidValues.FirstOrDefault(x => x.GetType() == oldModifier.GetType());
     395        if (mod != null) ComparisonFactorModifierParameter.Value = mod;
     396      }
    396397    }
    397398    private void UpdateCrossovers() {
  • trunk/sources/HeuristicLab.Algorithms.OffspringSelectionGeneticAlgorithm/3.3/OffspringSelectionGeneticAlgorithmMainLoop.cs

    r3413 r3426  
    152152      ConditionalBranch osBeforeMutationBranch = new ConditionalBranch();
    153153      Placeholder evaluator1 = new Placeholder();
     154      IntCounter evaluationCounter1 = new IntCounter();
    154155      WeightedParentsQualityComparator qualityComparer1 = new WeightedParentsQualityComparator();
    155156      StochasticBranch mutationBranch1 = new StochasticBranch();
    156157      Placeholder mutator1 = new Placeholder();
    157158      Placeholder evaluator2 = new Placeholder();
     159      IntCounter evaluationCounter2 = new IntCounter();
    158160      StochasticBranch mutationBranch2 = new StochasticBranch();
    159161      Placeholder mutator2 = new Placeholder();
    160162      Placeholder evaluator3 = new Placeholder();
     163      IntCounter evaluationCounter3 = new IntCounter();
    161164      WeightedParentsQualityComparator qualityComparer2 = new WeightedParentsQualityComparator();
    162165      SubScopesRemover subScopesRemover = new SubScopesRemover();
     
    171174      Comparator comparator1 = new Comparator();
    172175      Comparator comparator2 = new Comparator();
     176      Assigner evaluatedSolutionsAssigner = new Assigner();
     177      ResultsCollector evalSolCollector = new ResultsCollector();
    173178      BestQualityMemorizer bestQualityMemorizer3 = new BestQualityMemorizer();
    174179      BestQualityMemorizer bestQualityMemorizer4 = new BestQualityMemorizer();
     
    184189      variableCreator.CollectedValues.Add(new ValueParameter<DoubleValue>("SelectionPressure", new DoubleValue(0)));
    185190      variableCreator.CollectedValues.Add(new ValueParameter<DoubleValue>("CurrentSuccessRatio", new DoubleValue(0)));
     191      variableCreator.CollectedValues.Add(new ValueParameter<IntValue>("EvaluatedSolutions", new IntValue(0)));
     192      variableCreator.CollectedValues.Add(new ValueParameter<IntValue>("EvaluatedSolutionsResult", new IntValue(0)));
    186193
    187194      variableAssigner.LeftSideParameter.ActualName = "ComparisonFactor";
     
    222229
    223230      resultsCollector.CollectedValues.Add(new LookupParameter<IntValue>("Generations"));
     231      resultsCollector.CollectedValues.Add(new LookupParameter<IntValue>("Evaluated Solutions", null, "EvaluatedSolutionsResult"));
    224232      resultsCollector.CollectedValues.Add(new LookupParameter<DoubleValue>("Current Best Quality", null, "CurrentBestQuality"));
    225233      resultsCollector.CollectedValues.Add(new LookupParameter<DoubleValue>("Current Average Quality", null, "CurrentAverageQuality"));
     
    250258      evaluator1.OperatorParameter.ActualName = EvaluatorParameter.Name;
    251259
     260      evaluationCounter1.Name = "EvaluatedSolutions++";
     261      evaluationCounter1.Increment = new IntValue(1);
     262      evaluationCounter1.ValueParameter.ActualName = "EvaluatedSolutions";
     263
    252264      qualityComparer1.ComparisonFactorParameter.ActualName = "ComparisonFactor";
    253265      qualityComparer1.LeftSideParameter.ActualName = QualityParameter.Name;
     
    265277      evaluator2.OperatorParameter.ActualName = EvaluatorParameter.Name;
    266278
     279      evaluationCounter2.Name = "EvaluatedSolutions++";
     280      evaluationCounter2.Increment = new IntValue(1);
     281      evaluationCounter2.ValueParameter.ActualName = "EvaluatedSolutions";
     282
    267283      mutationBranch2.ProbabilityParameter.ActualName = MutationProbabilityParameter.Name;
    268284      mutationBranch2.RandomParameter.ActualName = RandomParameter.Name;
     
    273289      evaluator3.Name = "Evaluator (placeholder)";
    274290      evaluator3.OperatorParameter.ActualName = EvaluatorParameter.Name;
     291
     292      evaluationCounter3.Name = "EvaluatedSolutions++";
     293      evaluationCounter3.Increment = new IntValue(1);
     294      evaluationCounter3.ValueParameter.ActualName = "EvaluatedSolutions";
    275295
    276296      qualityComparer2.ComparisonFactorParameter.ActualName = "ComparisonFactor";
     
    313333      comparator2.ResultParameter.ActualName = "TerminateSelectionPressure";
    314334      comparator2.RightSideParameter.ActualName = MaximumSelectionPressureParameter.Name;
     335
     336      evaluatedSolutionsAssigner.LeftSideParameter.ActualName = "EvaluatedSolutionsResult";
     337      evaluatedSolutionsAssigner.RightSideParameter.ActualName = "EvaluatedSolutions";
     338
     339      evalSolCollector.CollectedValues.Add(new LookupParameter<IntValue>("Evaluated Solutions", null, "EvaluatedSolutionsResult"));
     340      evalSolCollector.ResultsParameter.ActualName = ResultsParameter.Name;
    315341
    316342      bestQualityMemorizer3.BestQualityParameter.ActualName = "BestQuality";
     
    377403      osBeforeMutationBranch.FalseBranch = mutationBranch2;
    378404      osBeforeMutationBranch.Successor = subScopesRemover;
    379       evaluator1.Successor = qualityComparer1;
     405      evaluator1.Successor = evaluationCounter1;
     406      evaluationCounter1.Successor = qualityComparer1;
    380407      qualityComparer1.Successor = mutationBranch1;
    381408      mutationBranch1.FirstBranch = mutator1;
     
    383410      mutationBranch1.Successor = null;
    384411      mutator1.Successor = evaluator2;
    385       evaluator2.Successor = null;
     412      evaluator2.Successor = evaluationCounter2;
     413      evaluationCounter2.Successor = null;
    386414      mutationBranch2.FirstBranch = mutator2;
    387415      mutationBranch2.SecondBranch = null;
    388416      mutationBranch2.Successor = evaluator3;
    389417      mutator2.Successor = null;
    390       evaluator3.Successor = qualityComparer2;
     418      evaluator3.Successor = evaluationCounter3;
     419      evaluationCounter3.Successor = qualityComparer2;
    391420      subScopesRemover.Successor = null;
    392421      offspringSelector.OffspringCreator = selector;
     
    401430      comparisonFactorModifier.Successor = comparator1;
    402431      comparator1.Successor = comparator2;
    403       comparator2.Successor = bestQualityMemorizer3;
     432      comparator2.Successor = evaluatedSolutionsAssigner;
     433      evaluatedSolutionsAssigner.Successor = evalSolCollector;
     434      evalSolCollector.Successor = bestQualityMemorizer3;
    404435      bestQualityMemorizer3.Successor = bestQualityMemorizer4;
    405436      bestQualityMemorizer4.Successor = bestAverageWorstQualityCalculator2;
Note: See TracChangeset for help on using the changeset viewer.