Free cookie consent management tool by TermsFeed Policy Generator

Changeset 5643 for trunk


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
Files:
1 deleted
6 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)";
  • trunk/sources/HeuristicLab.Encodings.RealVectorEncoding/3.3/ParticleOperators/RealVectorParticleUpdater.cs

    r5592 r5643  
    5050      get { return (ILookupParameter<RealVector>)Parameters["NeighborBest"]; }
    5151    }
    52     public LookupParameter<RealVector> BestPointParameter {
    53       get { return (LookupParameter<RealVector>)Parameters["BestPoint"]; }
     52    public LookupParameter<RealVector> BestRealVectorParameter {
     53      get { return (LookupParameter<RealVector>)Parameters["BestRealVector"]; }
    5454    }
    5555    public ILookupParameter<RealVector> RealVectorParameter {
     
    8585    }
    8686    protected RealVector BestPoint {
    87       get { return BestPointParameter.ActualValue; }
     87      get { return BestRealVectorParameter.ActualValue; }
    8888    }
    8989    protected RealVector RealVector {
     
    121121      Parameters.Add(new LookupParameter<RealVector>("Velocity", "Particle's current velocity."));
    122122      Parameters.Add(new LookupParameter<RealVector>("PersonalBest", "Particle's personal best solution."));
    123       Parameters.Add(new LookupParameter<RealVector>("BestPoint", "Global best position."));
     123      Parameters.Add(new LookupParameter<RealVector>("BestRealVector", "Global best position."));
    124124      Parameters.Add(new LookupParameter<RealVector>("NeighborBest", "Best neighboring solution."));
    125125      Parameters.Add(new LookupParameter<DoubleMatrix>("Bounds", "The lower and upper bounds for each dimension of the position vector for the current problem."));
  • trunk/sources/HeuristicLab.Encodings.RealVectorEncoding/3.3/ParticleOperators/RealVectorSwarmUpdater.cs

    r5592 r5643  
    6363      get { return (ILookupParameter<DoubleValue>)Parameters["BestQuality"]; }
    6464    }
    65     public ILookupParameter<RealVector> BestPointParameter {
    66       get { return (ILookupParameter<RealVector>)Parameters["BestPoint"]; }
     65    public ILookupParameter<RealVector> BestRealVectorParameter {
     66      get { return (ILookupParameter<RealVector>)Parameters["BestRealVector"]; }
    6767    }
    6868    public IScopeTreeLookupParameter<IntArray> NeighborsParameter {
     
    8282      set { BestQualityParameter.ActualValue = value; }
    8383    }
    84     private RealVector BestPoint {
    85       get { return BestPointParameter.ActualValue; }
    86       set { BestPointParameter.ActualValue = value; }
     84    private RealVector BestRealVector {
     85      get { return BestRealVectorParameter.ActualValue; }
     86      set { BestRealVectorParameter.ActualValue = value; }
    8787    }
    8888    private ItemArray<DoubleValue> Quality {
     
    131131      : base() {
    132132      Parameters.Add(new LookupParameter<DoubleValue>("BestQuality", "Overall best quality."));
    133       Parameters.Add(new LookupParameter<RealVector>("BestPoint", "Global best particle position"));
     133      Parameters.Add(new LookupParameter<RealVector>("BestRealVector", "Global best particle position"));
    134134      Parameters.Add(new ScopeTreeLookupParameter<DoubleValue>("Quality", "Particle's quality"));
    135135      Parameters.Add(new ScopeTreeLookupParameter<DoubleValue>("PersonalBestQuality", "Particle's personal best quality"));
     
    161161        BestQuality = new DoubleValue();
    162162      BestQuality.Value = Maximization ? Quality.Max(v => v.Value) : Quality.Min(v => v.Value);
    163       BestPoint = (RealVector)RealVector[Quality.FindIndex(v => v.Value == BestQuality.Value)].Clone();
     163      BestRealVector = (RealVector)RealVector[Quality.FindIndex(v => v.Value == BestQuality.Value)].Clone();
    164164    }
    165165
Note: See TracChangeset for help on using the changeset viewer.