- Timestamp:
- 02/28/11 17:25:28 (14 years ago)
- Location:
- trunk/sources/HeuristicLab.Algorithms.ParticleSwarmOptimization/3.3
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
TabularUnified trunk/sources/HeuristicLab.Algorithms.ParticleSwarmOptimization/3.3/ParticleSwarmOptimization.cs ¶
r5561 r5568 26 26 using HeuristicLab.Core; 27 27 using HeuristicLab.Data; 28 using HeuristicLab.Encodings.RealVectorEncoding;29 28 using HeuristicLab.Operators; 30 29 using HeuristicLab.Optimization; … … 78 77 get { return (IValueParameter<DoubleValue>)Parameters["PersonalBestAttraction"]; } 79 78 } 80 public IValueParameter<DoubleValue> Neighbor sBestAttractionParameter {81 get { return (IValueParameter<DoubleValue>)Parameters["Neighbor sBestAttraction"]; }79 public IValueParameter<DoubleValue> NeighborBestAttractionParameter { 80 get { return (IValueParameter<DoubleValue>)Parameters["NeighborBestAttraction"]; } 82 81 } 83 82 public IValueParameter<MultiAnalyzer> AnalyzerParameter { … … 99 98 get { return (OptionalConstrainedValueParameter<IDiscreteDoubleValueModifier>)Parameters["InertiaUpdater"]; } 100 99 } 100 public ConstrainedValueParameter<ISwarmUpdater> SwarmUpdaterParameter { 101 get { return (ConstrainedValueParameter<ISwarmUpdater>)Parameters["SwarmUpdater"]; } 102 103 } 101 104 #endregion 102 105 … … 113 116 [Storable] 114 117 private ParticleSwarmOptimizationMainLoop mainLoop; 115 116 [Storable]117 private CombinedOperator swarmUpdater;118 118 119 119 public ITopologyInitializer TopologyInitializer { … … 145 145 solutionsCreator = cloner.Clone(original.solutionsCreator); 146 146 mainLoop = cloner.Clone(original.mainLoop); 147 swarmUpdater = cloner.Clone(original.swarmUpdater);148 147 Initialize(); 149 148 } … … 157 156 Parameters.Add(new ValueParameter<DoubleValue>("Inertia", "Inertia weight on a particle's movement (omega).", new DoubleValue(-0.2))); 158 157 Parameters.Add(new ValueParameter<DoubleValue>("PersonalBestAttraction", "Weight for particle's pull towards its personal best soution (phi_p).", new DoubleValue(-0.01))); 159 Parameters.Add(new ValueParameter<DoubleValue>("Neighbor sBestAttraction", "Weight for pull towards the neighborhood best solution or global best solution in case of a totally connected topology (phi_g).", new DoubleValue(3.7)));158 Parameters.Add(new ValueParameter<DoubleValue>("NeighborBestAttraction", "Weight for pull towards the neighborhood best solution or global best solution in case of a totally connected topology (phi_g).", new DoubleValue(3.7))); 160 159 Parameters.Add(new ConstrainedValueParameter<IParticleCreator>("ParticleCreator", "Operator creates a new particle.")); 161 160 Parameters.Add(new ConstrainedValueParameter<IParticleUpdater>("ParticleUpdater", "Operator that updates a particle.")); … … 163 162 Parameters.Add(new OptionalConstrainedValueParameter<ITopologyUpdater>("TopologyUpdater", "Updates the neighborhood description vectors.")); 164 163 Parameters.Add(new OptionalConstrainedValueParameter<IDiscreteDoubleValueModifier>("InertiaUpdater", "Updates the omega parameter.")); 164 Parameters.Add(new ConstrainedValueParameter<ISwarmUpdater>("SwarmUpdater", "Encoding-specific parameter which is provided by the problem. May provide additional encoding-specific parameters, such as velocity bounds for real valued problems")); 165 165 166 166 RandomCreator randomCreator = new RandomCreator(); … … 168 168 solutionsCreator = new SolutionsCreator(); 169 169 Placeholder topologyInitializerPlaceholder = new Placeholder(); 170 ResultsCollector resultsCollector = new ResultsCollector();171 170 Placeholder analyzerPlaceholder = new Placeholder(); 172 swarmUpdater = new CombinedOperator();173 171 mainLoop = new ParticleSwarmOptimizationMainLoop(); 174 172 … … 183 181 184 182 solutionsCreator.NumberOfSolutionsParameter.ActualName = "SwarmSize"; 185 ParameterizeSolutionsCreator(); 186 solutionsCreator.Successor = topologyInitializerPlaceholder; 183 ParameterizeSolutionsCreator(); 184 solutionsCreator.Successor = topologyInitializerPlaceholder; 187 185 188 186 topologyInitializerPlaceholder.Name = "(TopologyInitializer)"; 189 187 topologyInitializerPlaceholder.OperatorParameter.ActualName = "TopologyInitializer"; 190 topologyInitializerPlaceholder.Successor = swarmUpdater; 191 192 swarmUpdater.Successor = resultsCollector; 193 194 resultsCollector.CollectedValues.Add(new LookupParameter<IntValue>("Iterations", null, "CurrentIteration")); 195 //resultsCollector.CollectedValues.Add(new LookupParameter<IntValue>("Current Inertia", null, "Inertia")); 196 //resultsCollector.CollectedValues.Add(new LookupParameter<IntValue>("Evaluated Solutions", null, "EvaluatedSolutions")); 197 resultsCollector.ResultsParameter.ActualName = "Results"; 198 resultsCollector.Successor = mainLoop; 188 topologyInitializerPlaceholder.Successor = mainLoop; 199 189 200 190 mainLoop.AnalyzerParameter.ActualName = AnalyzerParameter.Name; 201 191 mainLoop.InertiaParameter.ActualName = InertiaParameter.Name; 202 192 mainLoop.MaxIterationsParameter.ActualName = MaxIterationsParameter.Name; 203 mainLoop.Neighbor sBestAttractionParameter.ActualName = NeighborsBestAttractionParameter.Name;193 mainLoop.NeighborBestAttractionParameter.ActualName = NeighborBestAttractionParameter.Name; 204 194 mainLoop.InertiaUpdaterParameter.ActualName = InertiaUpdaterParameter.Name; 205 195 mainLoop.ParticleUpdaterParameter.ActualName = ParticleUpdaterParameter.Name; 206 196 mainLoop.PersonalBestAttractionParameter.ActualName = PersonalBestAttractionParameter.Name; 207 197 mainLoop.RandomParameter.ActualName = randomCreator.RandomParameter.ActualName; 208 mainLoop.SwarmSizeParameter.ActualName = SwarmSizeParameter.Name; 209 mainLoop.TopologyUpdaterParameter.ActualName = TopologyUpdaterParameter.Name; 198 mainLoop.SwarmSizeParameter.ActualName = SwarmSizeParameter.Name; 199 mainLoop.TopologyUpdaterParameter.ActualName = TopologyUpdaterParameter.Name; 210 200 mainLoop.RandomParameter.ActualName = randomCreator.RandomParameter.ActualName; 211 201 mainLoop.ResultsParameter.ActualName = "Results"; 212 // mainLoop.EvaluatedMovesParameter.ActualName = "EvaluatedMoves";202 // mainLoop.EvaluatedMovesParameter.ActualName = "EvaluatedMoves"; 213 203 214 204 InitializeAnalyzers(); … … 216 206 InitializeParticleCreator(); 217 207 InitializeSwarmUpdater(); 218 ParameterizeSolutionsCreator(); 208 ParameterizeSolutionsCreator(); 219 209 UpdateAnalyzers(); 220 210 UpdateInertiaUpdater(); … … 222 212 UpdateTopologyInitializer(); 223 213 Initialize(); 224 ParameterizeMainLoop(); 214 ParameterizeMainLoop(); 225 215 } 226 216 … … 257 247 InitializeParticleCreator(); 258 248 InitializeSwarmUpdater(); 259 ParameterizeSolutionsCreator(); 249 ParameterizeSolutionsCreator(); 260 250 base.OnProblemChanged(); 261 251 } … … 290 280 IParticleCreator creator = ParticleCreatorParameter.ValidValues.FirstOrDefault(x => x.GetType() == oldParticleCreator.GetType()); 291 281 if (creator != null) ParticleCreator = creator; 292 } 282 } 293 283 } 294 284 } … … 400 390 401 391 private void ParameterizeMainLoop() { 402 if (Problem != null) { 392 if (Problem != null) { 403 393 mainLoop.EvaluatorParameter.ActualName = Problem.EvaluatorParameter.Name; 404 394 } … … 408 398 if (Problem != null) { 409 399 ISwarmUpdater updater = Problem.Operators.OfType<ISwarmUpdater>().FirstOrDefault(); 410 swarmUpdater.OperatorGraph.InitialOperator = updater; 400 SwarmUpdaterParameter.ValidValues.Clear(); 401 SwarmUpdaterParameter.ValidValues.Add(updater); 402 SwarmUpdaterParameter.Value = updater; 411 403 } 412 404 } -
TabularUnified trunk/sources/HeuristicLab.Algorithms.ParticleSwarmOptimization/3.3/ParticleSwarmOptimizationMainLoop.cs ¶
r5566 r5568 20 20 #endregion 21 21 22 using System;23 using System.Collections.Generic;24 using System.Linq;25 using System.Text;26 using HeuristicLab.Operators;27 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;28 22 using HeuristicLab.Common; 29 23 using HeuristicLab.Core; 24 using HeuristicLab.Data; 25 using HeuristicLab.Operators; 26 using HeuristicLab.Optimization; 27 using HeuristicLab.Optimization.Operators; 30 28 using HeuristicLab.Parameters; 31 using HeuristicLab.Data; 32 using HeuristicLab.Analysis; 33 using HeuristicLab.Optimization; 34 using HeuristicLab.Random; 35 using HeuristicLab.Optimization.Operators; 36 using HeuristicLab.Encodings.RealVectorEncoding; 29 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 37 30 38 31 namespace HeuristicLab.Algorithms.ParticleSwarmOptimization { … … 59 52 get { return (IValueLookupParameter<DoubleValue>)Parameters["PersonalBestAttraction"]; } 60 53 } 61 public IValueLookupParameter<DoubleValue> Neighbor sBestAttractionParameter {62 get { return (IValueLookupParameter<DoubleValue>)Parameters["Neighbor sBestAttraction"]; }54 public IValueLookupParameter<DoubleValue> NeighborBestAttractionParameter { 55 get { return (IValueLookupParameter<DoubleValue>)Parameters["NeighborBestAttraction"]; } 63 56 } 64 57 public IValueLookupParameter<DoubleMatrix> VelocityBoundsParameter { 65 58 get { return (IValueLookupParameter<DoubleMatrix>)Parameters["VelocityBounds"]; } 66 } 59 } 67 60 public IValueLookupParameter<IOperator> ParticleUpdaterParameter { 68 61 get { return (IValueLookupParameter<IOperator>)Parameters["ParticleUpdater"]; } … … 74 67 get { return (IValueLookupParameter<IOperator>)Parameters["InertiaUpdater"]; } 75 68 } 76 public IValueLookupParameter< VariableCollection> ResultsParameter {77 get { return (IValueLookupParameter< VariableCollection>)Parameters["Results"]; }69 public IValueLookupParameter<ResultCollection> ResultsParameter { 70 get { return (IValueLookupParameter<ResultCollection>)Parameters["Results"]; } 78 71 } 79 72 public IValueLookupParameter<IOperator> EvaluatorParameter { 80 73 get { return (IValueLookupParameter<IOperator>)Parameters["Evaluator"]; } 81 74 } 75 public ValueLookupParameter<ISwarmUpdater> SwarmUpdaterParameter { 76 get { return (ValueLookupParameter<ISwarmUpdater>)Parameters["SwarmUpdater"]; } 77 } 82 78 #endregion 83 79 84 80 public ParticleSwarmOptimizationMainLoop() 85 81 : base() { … … 102 98 Parameters.Add(new ValueLookupParameter<IntValue>("SwarmSize", "Size of the particle swarm.", new IntValue(10))); 103 99 Parameters.Add(new ValueLookupParameter<IntValue>("MaxIterations", "Maximal number of iterations.", new IntValue(1000))); 104 100 105 101 Parameters.Add(new ValueLookupParameter<IOperator>("Analyzer", "The operator used to analyze each generation.")); 106 102 107 103 Parameters.Add(new ValueLookupParameter<DoubleValue>("Inertia", "Inertia weight on a particle's movement (omega).")); 108 104 Parameters.Add(new ValueLookupParameter<DoubleValue>("PersonalBestAttraction", "Weight for particle's pull towards its personal best soution (phi_p).")); 109 Parameters.Add(new ValueLookupParameter<DoubleValue>("Neighbor sBestAttraction", "Weight for pull towards the neighborhood best solution or global best solution in case of a totally connected topology (phi_g)."));110 105 Parameters.Add(new ValueLookupParameter<DoubleValue>("NeighborBestAttraction", "Weight for pull towards the neighborhood best solution or global best solution in case of a totally connected topology (phi_g).")); 106 111 107 Parameters.Add(new ValueLookupParameter<IOperator>("ParticleUpdater", "Operator that calculates new position and velocity of a particle")); 112 108 Parameters.Add(new ValueLookupParameter<IOperator>("TopologyUpdater", "Updates the neighborhood description vectors")); … … 114 110 Parameters.Add(new ValueLookupParameter<IOperator>("Evaluator", "Evaluates a particle solution.")); 115 111 116 Parameters.Add(new ValueLookupParameter<VariableCollection>("Results", "The variable collection where results should be stored.")); 112 Parameters.Add(new ValueLookupParameter<ResultCollection>("Results", "The variable collection where results should be stored.")); 113 114 Parameters.Add(new ValueLookupParameter<ISwarmUpdater>("SwarmUpdater", "The encoding-specific swarm updater.")); 117 115 #endregion 118 116 119 117 #region Create operators 118 ResultsCollector resultsCollector = new ResultsCollector(); 119 Placeholder swarmUpdaterPlaceholer1 = new Placeholder(); 120 120 Placeholder evaluatorPlaceholder = new Placeholder(); 121 121 Placeholder analyzerPlaceholder = new Placeholder(); … … 135 135 136 136 #region Create operator graph 137 OperatorGraph.InitialOperator = analyzerPlaceholder; 137 OperatorGraph.InitialOperator = resultsCollector; 138 resultsCollector.CollectedValues.Add(new LookupParameter<IntValue>("Iterations", null, "CurrentIteration")); 139 //resultsCollector.CollectedValues.Add(new LookupParameter<IntValue>("Current Inertia", null, "Inertia")); 140 //resultsCollector.CollectedValues.Add(new LookupParameter<IntValue>("Evaluated Solutions", null, "EvaluatedSolutions")); 141 resultsCollector.ResultsParameter.ActualName = "Results"; 142 resultsCollector.Successor = swarmUpdaterPlaceholer1; 143 144 swarmUpdaterPlaceholer1.Name = "(Swarm Updater)"; 145 swarmUpdaterPlaceholer1.OperatorParameter.ActualName = SwarmUpdaterParameter.ActualName; 146 swarmUpdaterPlaceholer1.Successor = analyzerPlaceholder; 138 147 139 148 analyzerPlaceholder.Name = "(Analyzer)"; 140 analyzerPlaceholder.OperatorParameter.ActualName = AnalyzerParameter.Name; 149 analyzerPlaceholder.OperatorParameter.ActualName = AnalyzerParameter.Name; 141 150 analyzerPlaceholder.Successor = uniformSubScopeProcessor; 142 151 … … 145 154 146 155 particleUpdaterPlaceholder.Name = "(ParticleUpdater)"; 147 particleUpdaterPlaceholder.OperatorParameter.ActualName = ParticleUpdaterParameter.Name; 156 particleUpdaterPlaceholder.OperatorParameter.ActualName = ParticleUpdaterParameter.Name; 148 157 149 158 evaluationProcessor.Parallel = new BoolValue(true); … … 152 161 153 162 evaluatorPlaceholder.Name = "(Evaluator)"; 154 evaluatorPlaceholder.OperatorParameter.ActualName = EvaluatorParameter.Name; 163 evaluatorPlaceholder.OperatorParameter.ActualName = EvaluatorParameter.Name; 155 164 156 165 topologyUpdaterPlaceholder.Name = "(TopologyUpdater)"; 157 topologyUpdaterPlaceholder.OperatorParameter.ActualName = TopologyUpdaterParameter.Name; 166 topologyUpdaterPlaceholder.OperatorParameter.ActualName = TopologyUpdaterParameter.Name; 158 167 topologyUpdaterPlaceholder.Successor = swarmUpdater; 159 168 160 169 swarmUpdater.Name = "Swarm Updater"; 161 swarmUpdater.OperatorParameter.ActualName = "SwarmUpdater"; 162 swarmUpdater.Successor = currentIterationCounter; 170 swarmUpdater.OperatorParameter.ActualName = SwarmUpdaterParameter.ActualName; 171 swarmUpdater.Successor = inertiaUpdaterPlaceholder; 172 173 inertiaUpdaterPlaceholder.Name = "(Inertia Updater)"; 174 inertiaUpdaterPlaceholder.OperatorParameter.ActualName = InertiaUpdaterParameter.ActualName; 175 inertiaUpdaterPlaceholder.Successor = currentIterationCounter; 163 176 164 177 currentIterationCounter.Name = "CurrentIteration++"; 165 178 currentIterationCounter.ValueParameter.ActualName = "CurrentIteration"; 166 currentIterationCounter.Successor = inertiaUpdaterPlaceholder; 167 168 inertiaUpdaterPlaceholder.Name = "(Inertia Updater)"; 169 inertiaUpdaterPlaceholder.OperatorParameter.ActualName = InertiaUpdaterParameter.ActualName; 170 inertiaUpdaterPlaceholder.Successor = currentIterationComparator; 179 currentIterationCounter.Successor = currentIterationComparator; 171 180 172 181 currentIterationComparator.LeftSideParameter.ActualName = "CurrentIteration";
Note: See TracChangeset
for help on using the changeset viewer.