Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
03/09/11 12:42:41 (14 years ago)
Author:
mkofler
Message:

#852: PSO code refactoring. Cleanup and minor improvements.

Location:
trunk/sources/HeuristicLab.Algorithms.ParticleSwarmOptimization/3.3
Files:
1 deleted
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Algorithms.ParticleSwarmOptimization/3.3/HeuristicLab.Algorithms.ParticleSwarmOptimization-3.3.csproj

    r5581 r5643  
    112112    <Compile Include="VonNeumannTopologyInitializer.cs" />
    113113    <Compile Include="RingTopologyInitializer.cs" />
    114     <Compile Include="NeighborUpdater.cs" />
    115114    <Compile Include="TopologyInitializer.cs" />
    116115    <Compile Include="HeuristicLabAlgorithmsParticleSwarmOptimizationPlugin.cs" />
     
    160159      <Project>{BBAB9DF5-5EF3-4BA8-ADE9-B36E82114937}</Project>
    161160      <Name>HeuristicLab.Data-3.3</Name>
    162     </ProjectReference>
    163     <ProjectReference Include="..\..\HeuristicLab.Encodings.IntegerVectorEncoding\3.3\HeuristicLab.Encodings.IntegerVectorEncoding-3.3.csproj">
    164       <Project>{DDFB14DD-2A85-493C-A52D-E69729BBAEB0}</Project>
    165       <Name>HeuristicLab.Encodings.IntegerVectorEncoding-3.3</Name>
    166     </ProjectReference>
    167     <ProjectReference Include="..\..\HeuristicLab.Encodings.RealVectorEncoding\3.3\HeuristicLab.Encodings.RealVectorEncoding-3.3.csproj">
    168       <Project>{BB6D334A-4BB6-4674-9883-31A6EBB32CAB}</Project>
    169       <Name>HeuristicLab.Encodings.RealVectorEncoding-3.3</Name>
    170161    </ProjectReference>
    171162    <ProjectReference Include="..\..\HeuristicLab.Operators\3.3\HeuristicLab.Operators-3.3.csproj">
  • trunk/sources/HeuristicLab.Algorithms.ParticleSwarmOptimization/3.3/HeuristicLabAlgorithmsParticleSwarmOptimizationPlugin.cs.frame

    r5560 r5643  
    3333  [PluginDependency("HeuristicLab.Core", "3.3")]
    3434  [PluginDependency("HeuristicLab.Data", "3.3")]
    35   [PluginDependency("HeuristicLab.Encodings.RealVectorEncoding", "3.3")]
    3635  [PluginDependency("HeuristicLab.Operators", "3.3")]
    3736  [PluginDependency("HeuristicLab.Optimization", "3.3")]
  • trunk/sources/HeuristicLab.Algorithms.ParticleSwarmOptimization/3.3/ParticleSwarmOptimization.cs

    r5581 r5643  
    167167      VariableCreator variableCreator = new VariableCreator();
    168168      solutionsCreator = new SolutionsCreator();
     169      SubScopesCounter subScopesCounter = new SubScopesCounter();
    169170      Placeholder topologyInitializerPlaceholder = new Placeholder();
    170171      Placeholder analyzerPlaceholder = new Placeholder();
     
    178179
    179180      variableCreator.CollectedValues.Add(new ValueParameter<IntValue>("CurrentIteration", new IntValue(0)));
     181      variableCreator.CollectedValues.Add(new ValueParameter<DoubleValue>("CurrentVelocityBounds", new DoubleValue(0)));
    180182      variableCreator.Successor = solutionsCreator;
    181183
    182184      solutionsCreator.NumberOfSolutionsParameter.ActualName = "SwarmSize";
    183185      ParameterizeSolutionsCreator();
    184       solutionsCreator.Successor = topologyInitializerPlaceholder;
     186      solutionsCreator.Successor = subScopesCounter;
     187
     188      subScopesCounter.Name = "Initialize EvaluatedSolutions";
     189      subScopesCounter.ValueParameter.ActualName = "EvaluatedSolutions";
     190      subScopesCounter.Successor = topologyInitializerPlaceholder;
    185191
    186192      topologyInitializerPlaceholder.Name = "(TopologyInitializer)";
     
    200206      mainLoop.RandomParameter.ActualName = randomCreator.RandomParameter.ActualName;
    201207      mainLoop.ResultsParameter.ActualName = "Results";
    202       // mainLoop.EvaluatedMovesParameter.ActualName = "EvaluatedMoves";
    203208
    204209      InitializeAnalyzers();
    205       ////InitVelocityBoundsUpdater();
    206210      InitializeParticleCreator();
    207211      InitializeSwarmUpdater();
     
    227231      if (Problem != null && ParticleCreator != null && ParticleUpdater != null) {
    228232        base.Prepare();
    229         if (InertiaUpdater != null && InertiaUpdater.StartValueParameter.Value != null) {
    230           this.InertiaParameter.ActualValue = new DoubleValue(InertiaUpdaterParameter.Value.StartValueParameter.Value.Value);
    231         }
    232         //if (VelocityBoundsUpdater != null && VelocityBoundsUpdater.StartValueParameter.Value != null && VelocityBoundsParameter.Value != null) {
    233         //  DoubleMatrix matrix = VelocityBoundsParameter.Value;
    234         //  for (int i = 0; i < matrix.Rows; i++) {
    235         //    matrix[i, 0] = -VelocityBoundsUpdater.StartValueParameter.Value.Value;
    236         //    matrix[i, 1] = VelocityBoundsUpdater.StartValueParameter.Value.Value;
    237         //  }
    238         //}
     233        VariableCreator creator = (VariableCreator)((RandomCreator)OperatorGraph.InitialOperator).Successor;
     234        ValueParameter<DoubleValue> currentInertia = null;
     235        if (creator.CollectedValues.ContainsKey("CurrentInertia")) {
     236          currentInertia = (ValueParameter<DoubleValue>) creator.CollectedValues["CurrentInertia"];
     237        } else {
     238          currentInertia = new ValueParameter<DoubleValue>("CurrentInertia");
     239          creator.CollectedValues.Add(currentInertia);
     240        }
     241        currentInertia.ActualValue = InertiaParameter.ActualValue;
    239242      }
    240243    }
     
    307310    }
    308311
    309     //private void InitVelocityBoundsUpdater() {
    310     //  foreach (IDiscreteDoubleMatrixModifier matrixOp in ApplicationManager.Manager.GetInstances<IDiscreteDoubleMatrixModifier>()) {
    311     //    VelocityBoundsUpdaterParameter.ValidValues.Add(matrixOp);
    312     //    matrixOp.ValueParameter.ActualName = VelocityBoundsParameter.Name;
    313     //    matrixOp.EndIndexParameter.ActualName = MaxIterationsParameter.Name;
    314     //    matrixOp.StartIndexParameter.Value = new IntValue(0);
    315     //    matrixOp.IndexParameter.ActualName = "CurrentIteration";
    316     //    matrixOp.EndValueParameter.Value = new DoubleValue(0);
    317     //  }
    318     //  VelocityBoundsUpdaterParameter.ValueChanged += new EventHandler(VelocityBoundsUpdaterParameter_ValueChanged);
    319     //}
    320 
    321312    private void InitInertiaUpdater() {
    322313      foreach (IDiscreteDoubleValueModifier updater in InertiaUpdaterParameter.ValidValues) {
     
    324315        updater.StartIndexParameter.Value = new IntValue(0);
    325316        updater.IndexParameter.ActualName = "CurrentIteration";
    326         updater.ValueParameter.ActualName = InertiaParameter.Name;
     317        updater.ValueParameter.ActualName = "CurrentInertia";
    327318        updater.StartValueParameter.Value = new DoubleValue(1);
    328319        updater.EndValueParameter.Value = new DoubleValue(0);
  • trunk/sources/HeuristicLab.Algorithms.ParticleSwarmOptimization/3.3/ParticleSwarmOptimizationMainLoop.cs

    r5592 r5643  
    7171      get { return (IValueLookupParameter<ResultCollection>)Parameters["Results"]; }
    7272    }
     73    public LookupParameter<IntValue> EvaluatedSolutionsParameter {
     74      get { return (LookupParameter<IntValue>)Parameters["EvaluatedSolutions"]; }
     75    }
    7376    public IValueLookupParameter<IOperator> EvaluatorParameter {
    7477      get { return (IValueLookupParameter<IOperator>)Parameters["Evaluator"]; }
     
    112115
    113116      Parameters.Add(new ValueLookupParameter<ResultCollection>("Results", "The variable collection where results should be stored."));
     117      Parameters.Add(new LookupParameter<IntValue>("EvaluatedSolutions", "The number of times solutions have been evaluated."));
    114118
    115119      Parameters.Add(new ValueLookupParameter<ISwarmUpdater>("SwarmUpdater", "The encoding-specific swarm updater."));
     
    126130      UniformSubScopesProcessor uniformSubscopesProcessor2 = new UniformSubScopesProcessor();
    127131      UniformSubScopesProcessor evaluationProcessor = new UniformSubScopesProcessor();
    128       NeighborUpdater neighborUpdater = new NeighborUpdater();
    129132      Placeholder swarmUpdater = new Placeholder();
    130133      IntCounter currentIterationCounter = new IntCounter();
     
    133136      Placeholder velocityBoundsUpdaterPlaceholder = new Placeholder();
    134137      Placeholder inertiaUpdaterPlaceholder = new Placeholder();
     138      SubScopesCounter subScopesCounter = new SubScopesCounter();
    135139      #endregion
    136140
     
    138142      OperatorGraph.InitialOperator = resultsCollector;
    139143      resultsCollector.CollectedValues.Add(new LookupParameter<IntValue>("Iterations", null, "CurrentIteration"));
    140       //resultsCollector.CollectedValues.Add(new LookupParameter<IntValue>("Current Inertia", null, "Inertia"));
    141       //resultsCollector.CollectedValues.Add(new LookupParameter<IntValue>("Evaluated Solutions", null, "EvaluatedSolutions"));
     144      resultsCollector.CollectedValues.Add(new LookupParameter<DoubleValue>("Current Inertia", null, "CurrentInertia"));
     145      resultsCollector.CollectedValues.Add(new LookupParameter<IntValue>("Evaluated Solutions", null, "EvaluatedSolutions"));
    142146      resultsCollector.ResultsParameter.ActualName = "Results";
    143147      resultsCollector.Successor = swarmUpdaterPlaceholer1;
     
    159163      evaluationProcessor.Parallel = new BoolValue(true);
    160164      evaluationProcessor.Operator = evaluatorPlaceholder;
    161       evaluationProcessor.Successor = topologyUpdaterPlaceholder;
     165      evaluationProcessor.Successor = subScopesCounter;
    162166
    163167      evaluatorPlaceholder.Name = "(Evaluator)";
    164168      evaluatorPlaceholder.OperatorParameter.ActualName = EvaluatorParameter.Name;
     169
     170      subScopesCounter.Name = "Increment EvaluatedSolutions";
     171      subScopesCounter.ValueParameter.ActualName = EvaluatedSolutionsParameter.Name;
     172      subScopesCounter.Successor = topologyUpdaterPlaceholder;
    165173
    166174      topologyUpdaterPlaceholder.Name = "(TopologyUpdater)";
Note: See TracChangeset for help on using the changeset viewer.