Free cookie consent management tool by TermsFeed Policy Generator

Changeset 8330


Ignore:
Timestamp:
07/25/12 17:29:13 (12 years ago)
Author:
jkarder
Message:

#1247: initial version

Location:
branches/RAPGA/HeuristicLab.Algorithms.RAPGA/3.3
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/RAPGA/HeuristicLab.Algorithms.RAPGA/3.3/RAPGA.cs

    r8313 r8330  
    6464      get { return (ValueParameter<IntValue>)Parameters["PopulationSize"]; }
    6565    }
     66    private IValueParameter<IntValue> MinimumPopulationSizeParameter {
     67      get { return (IValueParameter<IntValue>)Parameters["MinimumPopulationSize"]; }
     68    }
     69    private IValueParameter<IntValue> MaximumPopulationSizeParameter {
     70      get { return (IValueParameter<IntValue>) Parameters["MaximumPopulationSize"]; }
     71    }
     72    private IValueParameter<DoubleValue> ComparisonFactorParameter {
     73      get { return (IValueParameter<DoubleValue>)Parameters["ComparisonFactor"]; }
     74    }
     75    private IValueParameter<IntValue> EffortParameter {
     76      get { return (IValueParameter<IntValue>)Parameters["Effort"]; }
     77    }
    6678    public IConstrainedValueParameter<ISelector> SelectorParameter {
    6779      get { return (IConstrainedValueParameter<ISelector>)Parameters["Selector"]; }
     
    99111      get { return PopulationSizeParameter.Value; }
    100112      set { PopulationSizeParameter.Value = value; }
     113    }
     114    public IntValue MinimumPopulationSize {
     115      get { return MinimumPopulationSizeParameter.Value; }
     116      set { MinimumPopulationSizeParameter.Value = value; }
     117    }
     118    public IntValue MaximumPopulationSize {
     119      get { return MaximumPopulationSizeParameter.Value; }
     120      set { MaximumPopulationSizeParameter.Value = value; }
     121    }
     122    public DoubleValue ComparisonFactor {
     123      get { return ComparisonFactorParameter.Value; }
     124      set { ComparisonFactorParameter.Value = value; }
     125    }
     126    public IntValue Effort {
     127      get { return EffortParameter.Value; }
     128      set { EffortParameter.Value = value; }
    101129    }
    102130    public ISelector Selector {
     
    154182      Parameters.Add(new ValueParameter<IntValue>("Seed", "The random seed used to initialize the new pseudo random number generator.", new IntValue(0)));
    155183      Parameters.Add(new ValueParameter<BoolValue>("SetSeedRandomly", "True if the random seed should be set to a random value, otherwise false.", new BoolValue(true)));
    156       Parameters.Add(new ValueParameter<IntValue>("PopulationSize", "The size of the population of solutions.", new IntValue(100)));
     184      Parameters.Add(new ValueParameter<IntValue>("PopulationSize", "The size of the population of solutions.", new IntValue(300)));
     185      Parameters.Add(new ValueParameter<IntValue>("MinimumPopulationSize", "The minimum size of the population of solutions.", new IntValue(2)));
     186      Parameters.Add(new ValueParameter<IntValue>("MaximumPopulationSize", "The maximum size of the population of solutions.", new IntValue(499)));
     187      Parameters.Add(new ValueParameter<DoubleValue>("ComparisonFactor", "The comparison factor.", new DoubleValue(0.0)));
     188      Parameters.Add(new ValueParameter<IntValue>("Effort", "The maximum number of offspring created in each generation.", new IntValue(1000)));
    157189      Parameters.Add(new ConstrainedValueParameter<ISelector>("Selector", "The operator used to select solutions for reproduction."));
    158190      Parameters.Add(new ConstrainedValueParameter<ICrossover>("Crossover", "The operator used to cross solutions."));
  • branches/RAPGA/HeuristicLab.Algorithms.RAPGA/3.3/RAPGAMainLoop.cs

    r8313 r8330  
    7979      get { return (ValueLookupParameter<IntValue>)Parameters["PopulationSize"]; }
    8080    }
     81    public IValueLookupParameter<IntValue> MinimumPopulationSizeParameter {
     82      get { return (IValueLookupParameter<IntValue>)Parameters["MinimumPopulationSize"]; }
     83    }
     84    public IValueLookupParameter<IntValue> MaximumPopulationSizeParameter {
     85      get { return (IValueLookupParameter<IntValue>)Parameters["MaximumPopulationSize"]; }
     86    }
     87    public IValueLookupParameter<DoubleValue> ComparisonFactorParameter {
     88      get { return (IValueLookupParameter<DoubleValue>)Parameters["ComparisonFactor"]; }
     89    }
     90    public IValueLookupParameter<IntValue> EffortParameter {
     91      get { return (IValueLookupParameter<IntValue>)Parameters["Effort"]; }
     92    }
    8193    private ScopeParameter CurrentScopeParameter {
    8294      get { return (ScopeParameter)Parameters["CurrentScope"]; }
     
    115127      Parameters.Add(new ValueLookupParameter<IntValue>("EvaluatedSolutions", "The number of times solutions have been evaluated."));
    116128      Parameters.Add(new ValueLookupParameter<IntValue>("PopulationSize", "The size of the population."));
     129      Parameters.Add(new ValueLookupParameter<IntValue>("MinimumPopulationSize", "The minimum size of the population of solutions."));
     130      Parameters.Add(new ValueLookupParameter<IntValue>("MaximumPopulationSize", "The maximum size of the population of solutions."));
     131      Parameters.Add(new ValueLookupParameter<DoubleValue>("ComparisonFactor", "The comparison factor."));
     132      Parameters.Add(new ValueLookupParameter<IntValue>("Effort", "The maximum number of offspring created in each generation."));
    117133      Parameters.Add(new ScopeParameter("CurrentScope", "The current scope which represents a population of solutions on which the genetic algorithm should be applied."));
    118134      #endregion
     
    120136      #region Create operators
    121137      VariableCreator variableCreator = new VariableCreator();
     138      Assigner assigner1 = new Assigner();
    122139      ResultsCollector resultsCollector1 = new ResultsCollector();
    123140      Placeholder analyzer1 = new Placeholder();
     
    129146      StochasticBranch stochasticBranch = new StochasticBranch();
    130147      Placeholder mutator = new Placeholder();
    131       SubScopesRemover subScopesRemover = new SubScopesRemover();
    132148      UniformSubScopesProcessor uniformSubScopesProcessor2 = new UniformSubScopesProcessor();
    133149      Placeholder evaluator = new Placeholder();
    134       SubScopesCounter subScopesCounter = new SubScopesCounter();
     150      WeightedParentsQualityComparator comparator1 = new WeightedParentsQualityComparator();
     151      ConditionalSelector conditionalSelector = new ConditionalSelector();
     152      RightReducer rightReducer1 = new RightReducer();
     153      SubScopesCounter subScopesCounter1 = new SubScopesCounter();
     154      IntCounter intCounter1 = new IntCounter();
     155      UniformSubScopesProcessor uniformSubScopesProcessor3 = new UniformSubScopesProcessor();
     156      SubScopesRemover subScopesRemover = new SubScopesRemover();
     157      Comparator comparator2 = new Comparator();
     158      ConditionalBranch conditionalBranch1 = new ConditionalBranch();
     159      BestSelector bestSelector1 = new BestSelector();
     160      BestSelector bestSelector2 = new BestSelector();
     161      RightReducer rightReducer2 = new RightReducer();
    135162      SubScopesProcessor subScopesProcessor2 = new SubScopesProcessor();
    136       BestSelector bestSelector = new BestSelector();
    137       RightReducer rightReducer = new RightReducer();
     163      BestSelector bestSelector3 = new BestSelector();
     164      RightReducer rightReducer3 = new RightReducer();
    138165      MergingReducer mergingReducer = new MergingReducer();
    139       IntCounter intCounter = new IntCounter();
    140       Comparator comparator = new Comparator();
     166      IntCounter intCounter2 = new IntCounter();
     167      Comparator comparator3 = new Comparator();
    141168      Placeholder analyzer2 = new Placeholder();
    142       ConditionalBranch conditionalBranch = new ConditionalBranch();
     169      ConditionalBranch conditionalBranch2 = new ConditionalBranch();
     170      Assigner assigner2 = new Assigner();
     171      SubScopesCounter subScopesCounter2 = new SubScopesCounter();
     172      ResultsCollector resultsCollector2 = new ResultsCollector();
     173      Comparator comparator4 = new Comparator();
     174      ConditionalBranch conditionalBranch3 = new ConditionalBranch();
    143175
    144176      variableCreator.CollectedValues.Add(new ValueParameter<IntValue>("Generations", new IntValue(0))); // Class GeneticAlgorithm expects this to be called Generations
     177      variableCreator.CollectedValues.Add(new ValueParameter<IntValue>("CurrentPopulationSize", new IntValue(0)));
     178
     179      assigner1.Name = "Initialize CurrentPopulationSize";
     180      assigner1.LeftSideParameter.ActualName = "CurrentPopulationSize";
     181      assigner1.RightSideParameter.ActualName = EvaluatedSolutionsParameter.ActualName;
    145182
    146183      resultsCollector1.CollectedValues.Add(new LookupParameter<IntValue>("Generations"));
     184      resultsCollector1.CollectedValues.Add(new LookupParameter<IntValue>("CurrentPopulationSize"));
    147185      resultsCollector1.ResultsParameter.ActualName = "Results";
    148186
     
    164202      mutator.OperatorParameter.ActualName = "Mutator";
    165203
    166       subScopesRemover.RemoveAllSubScopes = true;
    167 
    168204      uniformSubScopesProcessor2.Parallel.Value = true;
    169205
     
    171207      evaluator.OperatorParameter.ActualName = "Evaluator";
    172208
    173       subScopesCounter.Name = "Increment EvaluatedSolutions";
    174       subScopesCounter.ValueParameter.ActualName = EvaluatedSolutionsParameter.Name;
    175 
    176       bestSelector.CopySelected = new BoolValue(false);
    177       bestSelector.MaximizationParameter.ActualName = "Maximization";
    178       bestSelector.NumberOfSelectedSubScopesParameter.ActualName = "Elites";
    179       bestSelector.QualityParameter.ActualName = "Quality";
    180 
    181       intCounter.Increment = new IntValue(1);
    182       intCounter.ValueParameter.ActualName = "Generations";
    183 
    184       comparator.Comparison = new Comparison(ComparisonType.GreaterOrEqual);
    185       comparator.LeftSideParameter.ActualName = "Generations";
    186       comparator.ResultParameter.ActualName = "Terminate";
    187       comparator.RightSideParameter.ActualName = "MaximumGenerations";
     209      comparator1.ComparisonFactorParameter.ActualName = ComparisonFactorParameter.Name;
     210      comparator1.LeftSideParameter.ActualName = QualityParameter.Name;
     211      comparator1.MaximizationParameter.ActualName = MaximizationParameter.Name;
     212      comparator1.RightSideParameter.ActualName = QualityParameter.Name;
     213      comparator1.ResultParameter.ActualName = "SuccessfulOffspring";
     214
     215      conditionalSelector.ConditionParameter.ActualName = "SuccessfulOffspring";
     216      conditionalSelector.ConditionParameter.Depth = 1;
     217      conditionalSelector.CopySelected.Value = false;
     218
     219      subScopesCounter1.Name = "Count Successful Offspring";
     220      subScopesCounter1.ValueParameter.ActualName = "NumberOfSuccessfulOffspring";
     221
     222      intCounter1.IncrementParameter.ActualName = "NumberOfSuccessfulOffspring";
     223      intCounter1.IncrementParameter.Value = null;
     224      intCounter1.ValueParameter.ActualName = EvaluatedSolutionsParameter.Name;
     225
     226      uniformSubScopesProcessor3.Parallel.Value = true;
     227
     228      subScopesRemover.RemoveAllSubScopes = true;
     229
     230      comparator2.Comparison = new Comparison(ComparisonType.GreaterOrEqual);
     231      comparator2.LeftSideParameter.ActualName = "NumberOfSuccessfulOffspring";
     232      comparator2.RightSideParameter.ActualName = MaximumPopulationSizeParameter.Name;
     233      comparator2.ResultParameter.ActualName = "SelectMaximum";
     234
     235      conditionalBranch1.ConditionParameter.ActualName = "SelectMaximum";
     236
     237      bestSelector1.CopySelected = new BoolValue(true);
     238      bestSelector1.MaximizationParameter.ActualName = MaximizationParameter.Name;
     239      bestSelector1.NumberOfSelectedSubScopesParameter.ActualName = MaximumPopulationSizeParameter.Name;
     240      bestSelector1.QualityParameter.ActualName = QualityParameter.Name;
     241
     242      bestSelector2.CopySelected = new BoolValue(true);
     243      bestSelector2.MaximizationParameter.ActualName = MaximizationParameter.Name;
     244      bestSelector2.NumberOfSelectedSubScopesParameter.ActualName = "NumberOfSuccessfulOffspring";
     245      bestSelector2.QualityParameter.ActualName = QualityParameter.Name;
     246
     247      bestSelector3.CopySelected = new BoolValue(false);
     248      bestSelector3.MaximizationParameter.ActualName = MaximizationParameter.Name;
     249      bestSelector3.NumberOfSelectedSubScopesParameter.ActualName = "Elites";
     250      bestSelector3.QualityParameter.ActualName = QualityParameter.Name;
     251
     252      intCounter2.Increment = new IntValue(1);
     253      intCounter2.ValueParameter.ActualName = "Generations";
     254
     255      comparator3.Comparison = new Comparison(ComparisonType.GreaterOrEqual);
     256      comparator3.LeftSideParameter.ActualName = "Generations";
     257      comparator3.ResultParameter.ActualName = "Terminate";
     258      comparator3.RightSideParameter.ActualName = MaximumGenerationsParameter.Name;
    188259
    189260      analyzer2.Name = "Analyzer";
    190261      analyzer2.OperatorParameter.ActualName = "Analyzer";
    191262
    192       conditionalBranch.ConditionParameter.ActualName = "Terminate";
     263      conditionalBranch2.ConditionParameter.ActualName = "Terminate";
     264
     265      assigner2.Name = "Reset CurrentPopulationSize";
     266      assigner2.LeftSideParameter.ActualName = "CurrentPopulationSize";
     267      assigner2.RightSideParameter.Value = new IntValue(0);
     268
     269      subScopesCounter2.Name = "Increment EvaluatedSolutions";
     270      subScopesCounter2.ValueParameter.ActualName = "CurrentPopulationSize";
     271
     272      resultsCollector2.CollectedValues.Add(new LookupParameter<IntValue>("CurrentPopulationSize"));
     273      resultsCollector2.ResultsParameter.ActualName = "Results";
     274
     275      comparator4.Comparison = new Comparison(ComparisonType.Less);
     276      comparator4.LeftSideParameter.ActualName = "CurrentPopulationSize";
     277      comparator4.RightSideParameter.ActualName = MinimumPopulationSizeParameter.Name;
     278      comparator4.ResultParameter.ActualName = "Terminate";
     279
     280      conditionalBranch3.ConditionParameter.ActualName = "Terminate";
    193281      #endregion
    194282
    195283      #region Create operator graph
    196284      OperatorGraph.InitialOperator = variableCreator;
    197       variableCreator.Successor = resultsCollector1;
     285      variableCreator.Successor = assigner1;
     286      assigner1.Successor = resultsCollector1;
    198287      resultsCollector1.Successor = analyzer1;
    199288      analyzer1.Successor = selector;
     
    208297      stochasticBranch.FirstBranch = mutator;
    209298      stochasticBranch.SecondBranch = null;
    210       stochasticBranch.Successor = subScopesRemover;
     299      stochasticBranch.Successor = null;
    211300      mutator.Successor = null;
    212301      subScopesRemover.Successor = null;
    213302      uniformSubScopesProcessor2.Operator = evaluator;
    214       uniformSubScopesProcessor2.Successor = subScopesCounter;
    215       evaluator.Successor = null;
    216       subScopesCounter.Successor = null;
    217       subScopesProcessor2.Operators.Add(bestSelector);
     303      uniformSubScopesProcessor2.Successor = conditionalSelector;
     304      evaluator.Successor = comparator1;
     305      conditionalSelector.Successor = rightReducer1;
     306      rightReducer1.Successor = subScopesCounter1;
     307      subScopesCounter1.Successor = intCounter1;
     308      intCounter1.Successor = uniformSubScopesProcessor3;
     309      uniformSubScopesProcessor3.Operator = subScopesRemover;
     310      uniformSubScopesProcessor3.Successor = comparator2;
     311      comparator2.Successor = conditionalBranch1;
     312      conditionalBranch1.TrueBranch = bestSelector1;
     313      conditionalBranch1.FalseBranch = bestSelector2;
     314      bestSelector1.Successor = rightReducer2;
     315      bestSelector2.Successor = rightReducer2;
     316      subScopesProcessor2.Operators.Add(bestSelector3);
    218317      subScopesProcessor2.Operators.Add(new EmptyOperator());
    219318      subScopesProcessor2.Successor = mergingReducer;
    220       bestSelector.Successor = rightReducer;
    221       rightReducer.Successor = null;
    222       mergingReducer.Successor = intCounter;
    223       intCounter.Successor = comparator;
    224       comparator.Successor = analyzer2;
    225       analyzer2.Successor = conditionalBranch;
    226       conditionalBranch.FalseBranch = selector;
    227       conditionalBranch.TrueBranch = null;
    228       conditionalBranch.Successor = null;
     319      bestSelector3.Successor = rightReducer3;
     320      rightReducer3.Successor = null;
     321      mergingReducer.Successor = intCounter2;
     322      intCounter2.Successor = comparator3;
     323      comparator3.Successor = analyzer2;
     324      analyzer2.Successor = conditionalBranch2;
     325      conditionalBranch2.FalseBranch = assigner2;
     326      conditionalBranch2.TrueBranch = null;
     327      conditionalBranch2.Successor = null;
     328      assigner2.Successor = subScopesCounter2;
     329      subScopesCounter2.Successor = resultsCollector2;
     330      resultsCollector2.Successor = comparator4;
     331      comparator4.Successor = conditionalBranch3;
     332      conditionalBranch3.FalseBranch = selector;
     333      conditionalBranch3.TrueBranch = null;
     334      conditionalBranch3.Successor = null;
    229335      #endregion
    230336    }
Note: See TracChangeset for help on using the changeset viewer.