Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
03/05/15 10:51:17 (10 years ago)
Author:
pfleck
Message:

#2350

  • Worked on AlpsSsGeneticAlgorithmMainLoop.
  • Added SteadyStateMatingPoolCreator, RandomLayerProcessor and RandomIntAssigner.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/ALPS/HeuristicLab.Algorithms.ALPS.SteadyState/3.3/AlpsSsGeneticAlgorithmMainLoop.cs

    r12120 r12136  
    2222using HeuristicLab.Common;
    2323using HeuristicLab.Core;
     24using HeuristicLab.Data;
    2425using HeuristicLab.Operators;
     26using HeuristicLab.Optimization.Operators;
     27using HeuristicLab.Parameters;
    2528using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
     29using HeuristicLab.Selection;
    2630
    2731namespace HeuristicLab.Algorithms.ALPS.SteadyState {
     
    2933  [StorableClass]
    3034  public class AlpsSsGeneticAlgorithmMainLoop : AlgorithmOperator {
     35    #region Parameter Properties
     36    public ValueLookupParameter<BoolValue> MaximizationParameter {
     37      get { return (ValueLookupParameter<BoolValue>)Parameters["Maximization"]; }
     38    }
     39    public ScopeTreeLookupParameter<DoubleValue> QualityParameter {
     40      get { return (ScopeTreeLookupParameter<DoubleValue>)Parameters["Quality"]; }
     41    }
     42    public ILookupParameter<IntValue> MaximumIterationsParameter {
     43      get { return (ILookupParameter<IntValue>)Parameters["MaximumIterations"]; }
     44    }
     45    public ILookupParameter<IOperator> AnalyzerParameter {
     46      get { return (ILookupParameter<IOperator>)Parameters["Analyzer"]; }
     47    }
     48    public ILookupParameter<IOperator> LayerAnalyzerParameter {
     49      get { return (ILookupParameter<IOperator>)Parameters["LayerAnalyzer"]; }
     50    }
     51    #endregion
     52
    3153    [StorableConstructor]
    3254    private AlpsSsGeneticAlgorithmMainLoop(bool deserializing)
     
    4062    public AlpsSsGeneticAlgorithmMainLoop()
    4163      : base() {
     64      Parameters.Add(new ValueLookupParameter<BoolValue>("Maximization", "True if the problem is a maximization problem, otherwise false."));
     65      Parameters.Add(new ScopeTreeLookupParameter<DoubleValue>("Quality", "The value which represents the quality of a solution."));
     66      Parameters.Add(new LookupParameter<IntValue>("MaximumIterations", "The maximum number of iterations that the algorithm should process."));
     67      Parameters.Add(new LookupParameter<IOperator>("Analyzer", "The operator used to the analyze all individuals."));
     68      Parameters.Add(new LookupParameter<IOperator>("LayerAnalyzer", "The operator used to analyze each layer."));
     69
     70      var variableCreator = new VariableCreator() { Name = "Initialize" };
     71      var randomScopeProcessor = new RandomLayerProcessor() { Name = "Select a layer" }; // TODO LayerSubScopeProcessor for Array conversion
     72      var isLayerZeroComperator = new Comparator() { Name = "IsLayerZero = Layer == 0" };
     73      var isLayerZeroBranch = new ConditionalBranch() { Name = "IsLayerZero?" };
     74      var isDoInitBranch = new ConditionalBranch() { Name = "DoInit?" };
     75      var setTargetIndedxToNextInit = new Assigner() { Name = "TargetIndex = NextInit" };
     76      var incrementNextInit = new IntCounter() { Name = "Incr. NextInit" };
     77      var checkInitFinished = new Comparator() { Name = "DoInit = NextInit >= PopulationSize" };
     78      var createWorkingScope = new BestSelector();
     79      var workingScopeProcessor = new SubScopesProcessor() { Name = "Working Scope Processor" };
     80      var createRandomIndividual = new SolutionsCreator() { Name = "Create random Individual" };
     81      var initializeAgeProcessor = new UniformSubScopesProcessor();
     82      var initializeAge = new Assigner() { Name = "Initialize Age" };
     83      var selectRandomTargetIndex = new RandomIntAssigner();
     84      var copyLayer = new BestSelector();
     85      var copyLayerProcessor = new SubScopesProcessor();
     86      var matingPoolCreator = new SteadyStateMatingPoolCreator() { Name = "Create MatingPool" };
     87      var matingPoolSize = new SubScopesCounter() { Name = "MatingPoolSize" };
     88      var matingPoolSizeMin2 = new Comparator() { Name = "ValidParents = MatingPoolSize >= 2" };
     89      var validParentsBranch = new ConditionalBranch() { Name = "ValidParents?" };
     90      var mainOperator = new EmptyOperator(); // TODO
     91      var reactivateInit = new Assigner() { Name = "DoInit = true" };
     92      var resetNextIndex = new Assigner() { Name = "NextInit = 1" };
     93      var resetTargetIndex = new Assigner() { Name = "TargetIndex = 0" };
     94      var clearMatingPool = new SubScopesRemover() { Name = "Clear WorkingScope" };
     95      var tryMoveUp = new EmptyOperator() { Name = "Try Move Up" }; // TODO
     96      var setNewIndividual = new EmptyOperator() { Name = "Set New Individual" };
     97      var iterationsComparator = new Comparator() { Name = "Iterations >= MaximumIterations" };
     98      var terminateBranch = new ConditionalBranch() { Name = "Terminate?" };
     99
     100
     101      OperatorGraph.InitialOperator = variableCreator;
     102
     103      variableCreator.CollectedValues.Add(new ValueParameter<BoolValue>("DoInit", new BoolValue(false)));
     104      variableCreator.CollectedValues.Add(new ValueParameter<IntValue>("NextInit", new IntValue(0)));
     105      variableCreator.CollectedValues.Add(new ValueParameter<IntValue>("OpenLayers", new IntValue(1)));
     106      variableCreator.CollectedValues.Add(new ValueParameter<IntValue>("TargetIndex", new IntValue(0)));
     107      variableCreator.Successor = randomScopeProcessor;
     108
     109      randomScopeProcessor.Operator = isLayerZeroComperator;
     110
     111      isLayerZeroComperator.LeftSideParameter.ActualName = "Layer";
     112      isLayerZeroComperator.RightSideParameter.Value = new IntValue(0);
     113      isLayerZeroComperator.ResultParameter.ActualName = "IsLayerZero";
     114      isLayerZeroComperator.Comparison = new Comparison(ComparisonType.Equal);
     115      isLayerZeroComperator.Successor = isLayerZeroBranch;
     116
     117      isLayerZeroBranch.ConditionParameter.ActualName = "IsLayerZero";
     118      isLayerZeroBranch.TrueBranch = isDoInitBranch;
     119      isLayerZeroBranch.FalseBranch = selectRandomTargetIndex;
     120      isLayerZeroBranch.Successor = tryMoveUp;
     121
     122      isDoInitBranch.ConditionParameter.ActualName = "DoInit";
     123      isDoInitBranch.TrueBranch = setTargetIndedxToNextInit;
     124      isDoInitBranch.FalseBranch = selectRandomTargetIndex;
     125
     126      setTargetIndedxToNextInit.LeftSideParameter.ActualName = "TargetIndex";
     127      setTargetIndedxToNextInit.RightSideParameter.ActualName = "NextInit";
     128      setTargetIndedxToNextInit.Successor = incrementNextInit;
     129
     130      incrementNextInit.ValueParameter.ActualName = "NextInit";
     131      incrementNextInit.Increment = new IntValue(1);
     132      incrementNextInit.Successor = checkInitFinished;
     133
     134      checkInitFinished.LeftSideParameter.ActualName = "NextInit";
     135      checkInitFinished.RightSideParameter.ActualName = "PopulationSize";
     136      checkInitFinished.Comparison = new Comparison(ComparisonType.GreaterOrEqual);
     137      checkInitFinished.ResultParameter.ActualName = "DoInit";
     138      checkInitFinished.Successor = createWorkingScope;
     139
     140      createWorkingScope.NumberOfSelectedSubScopesParameter.Value = new IntValue(0);
     141      createWorkingScope.CopySelected = new BoolValue(false);
     142      createWorkingScope.Successor = workingScopeProcessor;
     143
     144      workingScopeProcessor.Operators.Add(createRandomIndividual);
     145      workingScopeProcessor.Operators.Add(new EmptyOperator());
     146
     147      createRandomIndividual.NumberOfSolutions = new IntValue(1);
     148      createRandomIndividual.Successor = initializeAgeProcessor;
     149
     150      initializeAgeProcessor.Operator = initializeAge;
     151
     152      initializeAge.LeftSideParameter.ActualName = "EvalsCreated";
     153      initializeAge.RightSideParameter.ActualName = "EvaluatedSolutions";
     154
     155      selectRandomTargetIndex.LeftSideParameter.ActualName = "TargetIndex";
     156      selectRandomTargetIndex.MinimumParameter.Value = new IntValue(0);
     157      selectRandomTargetIndex.MaximumParameter.ActualName = "PopulationSize";
     158      selectRandomTargetIndex.Successor = copyLayer;
     159
     160      copyLayer.NumberOfSelectedSubScopesParameter.ActualName = "LayerPopulationSize";
     161      copyLayer.CopySelected = new BoolValue(true);
     162      copyLayer.Successor = copyLayerProcessor;
     163
     164      copyLayerProcessor.Operators.Add(new EmptyOperator());
     165      copyLayerProcessor.Operators.Add(matingPoolCreator);
     166
     167      matingPoolCreator.Successor = matingPoolSize;
     168
     169      matingPoolSize.ValueParameter.ActualName = "MatingPoolSize";
     170      matingPoolSize.Successor = matingPoolSizeMin2;
     171
     172      matingPoolSizeMin2.LeftSideParameter.ActualName = "MatingPoolSize";
     173      matingPoolSizeMin2.RightSideParameter.Value = new IntValue(2);
     174      matingPoolSizeMin2.Comparison = new Comparison(ComparisonType.GreaterOrEqual);
     175      matingPoolSizeMin2.ResultParameter.ActualName = "ValidParents";
     176      matingPoolSizeMin2.Successor = validParentsBranch;
     177
     178      validParentsBranch.TrueBranch = mainOperator;
     179      validParentsBranch.FalseBranch = reactivateInit;
     180
     181      reactivateInit.Successor = resetNextIndex;
     182      reactivateInit.LeftSideParameter.ActualName = "DoInit";
     183      reactivateInit.RightSideParameter.Value = new BoolValue(true);
     184
     185      resetNextIndex.Successor = resetTargetIndex;
     186      resetNextIndex.LeftSideParameter.ActualName = "NextIndex";
     187      resetNextIndex.RightSideParameter.Value = new IntValue(1);
     188
     189      resetTargetIndex.Successor = clearMatingPool;
     190      resetTargetIndex.LeftSideParameter.ActualName = "TargetIndex";
     191      resetTargetIndex.RightSideParameter.Value = new IntValue(0);
     192
     193      clearMatingPool.Successor = createRandomIndividual;
     194
     195      tryMoveUp.Successor = setNewIndividual;
     196
     197      setNewIndividual.Successor = iterationsComparator;
     198
     199      iterationsComparator.Comparison = new Comparison(ComparisonType.GreaterOrEqual);
     200      iterationsComparator.LeftSideParameter.ActualName = "Iterations";
     201      iterationsComparator.RightSideParameter.ActualName = MaximumIterationsParameter.Name;
     202      iterationsComparator.ResultParameter.ActualName = "Terminate";
     203      iterationsComparator.Successor = terminateBranch;
     204
     205      terminateBranch.ConditionParameter.ActualName = "Terminate";
     206      terminateBranch.FalseBranch = randomScopeProcessor;
     207
     208
    42209    }
    43210
Note: See TracChangeset for help on using the changeset viewer.