Changeset 12136
- Timestamp:
- 03/05/15 10:51:17 (10 years ago)
- Location:
- branches/ALPS/HeuristicLab.Algorithms.ALPS.SteadyState/3.3
- Files:
-
- 3 added
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/ALPS/HeuristicLab.Algorithms.ALPS.SteadyState/3.3/AlpsSsGeneticAlgorithm.cs
r12120 r12136 43 43 get { return (IValueParameter<IntArray>)Parameters["PopulationSize"]; } 44 44 } 45 private IValueParameter<IntValue> Maximum GenerationsParameter {46 get { return (IValueParameter<IntValue>)Parameters["Maximum Generations"]; }45 private IValueParameter<IntValue> MaximumIterationsParameter { 46 get { return (IValueParameter<IntValue>)Parameters["MaximumIterations"]; } 47 47 } 48 48 public IConstrainedValueParameter<ISelector> SelectorParameter { … … 71 71 set { PopulationSizeParameter.Value = value; } 72 72 } 73 public IntValue Maximum Generations {74 get { return Maximum GenerationsParameter.Value; }75 set { Maximum GenerationsParameter.Value = value; }73 public IntValue MaximumIterations { 74 get { return MaximumIterationsParameter.Value; } 75 set { MaximumIterationsParameter.Value = value; } 76 76 } 77 77 … … 116 116 : base() { 117 117 Parameters.Add(new ValueParameter<IntArray>("PopulationSize", "The size of the population of solutions each layer.", new IntArray(new[] { 100 }))); 118 Parameters.Add(new ValueParameter<IntValue>("Maximum Generations", "The maximum number of generations that should be processed.", new IntValue(1000)));118 Parameters.Add(new ValueParameter<IntValue>("MaximumIterations", "The maximum number of iterations that should be processed.", new IntValue(1000))); 119 119 Parameters.Add(new ConstrainedValueParameter<ISelector>("Selector", "The operator used to select solutions for reproduction.")); 120 120 Parameters.Add(new ConstrainedValueParameter<ICrossover>("Crossover", "The operator used to cross solutions.")); … … 132 132 var initializeAgeProcessor = new UniformSubScopesProcessor(); 133 133 var initializeAge = new VariableCreator() { Name = "Initialize Age" }; 134 var initializeLocalEvaluatedSolutions = new SubScopesCounter() { Name = "Initialize LayerEvaluatedSolutions" }; 134 var initializeLayerPopulationSize = new SubScopesCounter() { Name = "Init LayerPopulationCounter" }; 135 var initializeLocalEvaluatedSolutions = new Assigner() { Name = "Initialize LayerEvaluatedSolutions" }; 135 136 var initializeGlobalEvaluatedSolutions = new DataReducer() { Name = "Initialize EvaluatedSolutions" }; 137 var initializeCurrentPopulationSize = new Assigner() { Name = "CurrentPopulationSize = EvaluatedSolutions" }; 136 138 var resultsCollector = new ResultsCollector(); 137 139 var mainLoop = new AlpsSsGeneticAlgorithmMainLoop(); … … 156 158 157 159 initializeAgeProcessor.Operator = initializeAge; 158 initializeAgeProcessor.Successor = initializeLocalEvaluatedSolutions; 159 160 initializeAge.CollectedValues.Add(new ValueParameter<IntValue>("Age", new IntValue(0))); 161 162 initializeLocalEvaluatedSolutions.ValueParameter.ActualName = "LayerEvaluatedSolutions"; 160 initializeAgeProcessor.Successor = initializeLayerPopulationSize; 161 162 initializeAge.CollectedValues.Add(new ValueParameter<IntValue>("Age", new IntValue(1))); 163 164 initializeLayerPopulationSize.ValueParameter.ActualName = "LayerPopulationSize"; 165 initializeLayerPopulationSize.Successor = initializeLocalEvaluatedSolutions; 166 167 initializeLocalEvaluatedSolutions.LeftSideParameter.ActualName = "LayerEvaluatedSolutions"; 168 initializeLocalEvaluatedSolutions.RightSideParameter.ActualName = "LayerPopulationSize"; 169 initializeLocalEvaluatedSolutions.Successor = null; 163 170 164 171 initializeGlobalEvaluatedSolutions.ReductionOperation.Value.Value = ReductionOperations.Sum; … … 166 173 initializeGlobalEvaluatedSolutions.ParameterToReduce.ActualName = "LayerEvaluatedSolutions"; 167 174 initializeGlobalEvaluatedSolutions.TargetParameter.ActualName = "EvaluatedSolutions"; 168 initializeGlobalEvaluatedSolutions.Successor = resultsCollector; 175 initializeGlobalEvaluatedSolutions.Successor = initializeCurrentPopulationSize; 176 177 initializeCurrentPopulationSize.LeftSideParameter.ActualName = "CurrentPoulationSize"; 178 initializeCurrentPopulationSize.RightSideParameter.ActualName = "EvaluatedSolutions"; 179 initializeCurrentPopulationSize.Successor = resultsCollector; 169 180 170 181 resultsCollector.CollectedValues.Add(new LookupParameter<IntValue>("Evaluated Solutions", null, "EvaluatedSolutions")); 182 resultsCollector.CollectedValues.Add(new LookupParameter<IntValue>("Current PopulationSize", null, "CurrentPopulationSize")); 171 183 resultsCollector.Successor = mainLoop; 172 184 … … 252 264 if (Problem != null) { 253 265 foreach (var @operator in Problem.Operators.OfType<IIterationBasedOperator>()) { 254 @operator.IterationsParameter.ActualName = " Generations";266 @operator.IterationsParameter.ActualName = "Iteration"; 255 267 @operator.IterationsParameter.Hidden = true; 256 @operator.MaximumIterationsParameter.ActualName = Maximum GenerationsParameter.Name;268 @operator.MaximumIterationsParameter.ActualName = MaximumIterationsParameter.Name; 257 269 @operator.MaximumIterationsParameter.Hidden = true; 258 270 } -
branches/ALPS/HeuristicLab.Algorithms.ALPS.SteadyState/3.3/AlpsSsGeneticAlgorithmMainLoop.cs
r12120 r12136 22 22 using HeuristicLab.Common; 23 23 using HeuristicLab.Core; 24 using HeuristicLab.Data; 24 25 using HeuristicLab.Operators; 26 using HeuristicLab.Optimization.Operators; 27 using HeuristicLab.Parameters; 25 28 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 29 using HeuristicLab.Selection; 26 30 27 31 namespace HeuristicLab.Algorithms.ALPS.SteadyState { … … 29 33 [StorableClass] 30 34 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 31 53 [StorableConstructor] 32 54 private AlpsSsGeneticAlgorithmMainLoop(bool deserializing) … … 40 62 public AlpsSsGeneticAlgorithmMainLoop() 41 63 : 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 42 209 } 43 210 -
branches/ALPS/HeuristicLab.Algorithms.ALPS.SteadyState/3.3/HeuristicLab.Algorithms.ALPS.SteadyState-3.3.csproj
r12120 r12136 126 126 <Reference Include="System" /> 127 127 <Reference Include="System.Core" /> 128 <Reference Include="System.Drawing" /> 128 129 </ItemGroup> 129 130 <ItemGroup> … … 137 138 <Compile Include="Properties\AssemblyInfo.cs" /> 138 139 <Compile Include="Plugin.cs" /> 140 <Compile Include="RandomIntAssigner.cs" /> 141 <Compile Include="RandomLayerProcessor.cs" /> 142 <Compile Include="SteadyStateMatingPoolCreator.cs" /> 139 143 </ItemGroup> 140 144 <ItemGroup>
Note: See TracChangeset
for help on using the changeset viewer.