Free cookie consent management tool by TermsFeed Policy Generator

Changeset 5566 for trunk/sources


Ignore:
Timestamp:
02/28/11 15:08:14 (13 years ago)
Author:
mkofler
Message:

#852: PSO code refactoring. Worked on swarm updater and particle updater.

Location:
trunk/sources
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Algorithms.ParticleSwarmOptimization/3.3/ParticleSwarmOptimizationMainLoop.cs

    r5560 r5566  
    126126      UniformSubScopesProcessor evaluationProcessor = new UniformSubScopesProcessor();
    127127      NeighborUpdater neighborUpdater = new NeighborUpdater();
    128       ISwarmUpdater swarmUpdater = new RealVectorSwarmUpdater();
     128      Placeholder swarmUpdater = new Placeholder();
    129129      IntCounter currentIterationCounter = new IntCounter();
    130130      Comparator currentIterationComparator = new Comparator();
    131131      ConditionalBranch conditionalBranch = new ConditionalBranch();
    132132      Placeholder velocityBoundsUpdaterPlaceholder = new Placeholder();
    133       Placeholder omegaUpdaterPlaceholder = new Placeholder();
     133      Placeholder inertiaUpdaterPlaceholder = new Placeholder();
    134134      #endregion
    135135
    136136      #region Create operator graph
    137       //OperatorGraph.InitialOperator = analyzerPlaceholder;
     137      OperatorGraph.InitialOperator = analyzerPlaceholder;
    138138
    139       //analyzerPlaceholder.Name = "(Analyzer)";
    140       //analyzerPlaceholder.OperatorParameter.ActualName = "Analyzer";
    141       //analyzerPlaceholder.Successor = uniformSubScopeProcessor;
     139      analyzerPlaceholder.Name = "(Analyzer)";
     140      analyzerPlaceholder.OperatorParameter.ActualName = AnalyzerParameter.Name;
     141      analyzerPlaceholder.Successor = uniformSubScopeProcessor;
    142142
    143       //uniformSubScopeProcessor.Operator = particleUpdaterPlaceholder;
    144       //uniformSubScopeProcessor.Successor = evaluationProcessor;
     143      uniformSubScopeProcessor.Operator = particleUpdaterPlaceholder;
     144      uniformSubScopeProcessor.Successor = evaluationProcessor;
    145145
    146       //particleUpdaterPlaceholder.Name = "(ParticleUpdater)";
    147       //particleUpdaterPlaceholder.OperatorParameter.ActualName = "ParticleUpdater";
     146      particleUpdaterPlaceholder.Name = "(ParticleUpdater)";
     147      particleUpdaterPlaceholder.OperatorParameter.ActualName = ParticleUpdaterParameter.Name;
    148148
    149       //evaluationProcessor.Parallel = new BoolValue(true);
    150       //evaluationProcessor.Operator = evaluatorPlaceholder;
    151       //evaluationProcessor.Successor = topologyUpdaterPlaceholder;
     149      evaluationProcessor.Parallel = new BoolValue(true);
     150      evaluationProcessor.Operator = evaluatorPlaceholder;
     151      evaluationProcessor.Successor = topologyUpdaterPlaceholder;
    152152
    153       //evaluatorPlaceholder.Name = "(Evaluator)";
    154       //evaluatorPlaceholder.OperatorParameter.ActualName = "Evaluator";
     153      evaluatorPlaceholder.Name = "(Evaluator)";
     154      evaluatorPlaceholder.OperatorParameter.ActualName = EvaluatorParameter.Name;
    155155
    156       //topologyUpdaterPlaceholder.Name = "(TopologyUpdater)";
    157       //topologyUpdaterPlaceholder.OperatorParameter.ActualName = "TopologyUpdater";
    158       //topologyUpdaterPlaceholder.Successor = neighborUpdater;
     156      topologyUpdaterPlaceholder.Name = "(TopologyUpdater)";
     157      topologyUpdaterPlaceholder.OperatorParameter.ActualName = TopologyUpdaterParameter.Name;
     158      topologyUpdaterPlaceholder.Successor = swarmUpdater;
    159159
    160       //neighborUpdater.Successor = uniformSubscopesProcessor2;
     160      swarmUpdater.Name = "Swarm Updater";
     161      swarmUpdater.OperatorParameter.ActualName = "SwarmUpdater";
     162      swarmUpdater.Successor = currentIterationCounter;
    161163
    162       //uniformSubscopesProcessor2.Operator = swarmUpdater;
    163       //uniformSubscopesProcessor2.Successor = analyzerPlaceholder;
     164      currentIterationCounter.Name = "CurrentIteration++";
     165      currentIterationCounter.ValueParameter.ActualName = "CurrentIteration";
     166      currentIterationCounter.Successor = inertiaUpdaterPlaceholder;
    164167
    165       //analyzerPlaceholder.Name = "(Analyzer)";
    166       //analyzerPlaceholder.OperatorParameter.ActualName = "Analyzer";
    167       //analyzerPlaceholder.Successor = currentIterationCounter;
     168      inertiaUpdaterPlaceholder.Name = "(Inertia Updater)";
     169      inertiaUpdaterPlaceholder.OperatorParameter.ActualName = InertiaUpdaterParameter.ActualName;
     170      inertiaUpdaterPlaceholder.Successor = currentIterationComparator;
    168171
    169       //currentIterationCounter.Name = "CurrentIteration++";
    170       //currentIterationCounter.ValueParameter.ActualName = "CurrentIteration";
    171       //currentIterationCounter.Successor = omegaUpdaterPlaceholder;
     172      currentIterationComparator.LeftSideParameter.ActualName = "CurrentIteration";
     173      currentIterationComparator.Comparison = new Comparison(ComparisonType.Less);
     174      currentIterationComparator.RightSideParameter.ActualName = "MaxIterations";
     175      currentIterationComparator.ResultParameter.ActualName = "ContinueIteration";
     176      currentIterationComparator.Successor = conditionalBranch;
    172177
    173       //omegaUpdaterPlaceholder.Name = "(Inertia Updater)";
    174       //omegaUpdaterPlaceholder.OperatorParameter.ActualName = "InertiaUpdater";
    175       //omegaUpdaterPlaceholder.Successor = velocityBoundsUpdaterPlaceholder;
    176 
    177       //velocityBoundsUpdaterPlaceholder.Name = "(Velocity Bounds Updater)";
    178       //velocityBoundsUpdaterPlaceholder.OperatorParameter.ActualName = "VelocityBoundsUpdater";
    179       //velocityBoundsUpdaterPlaceholder.Successor = currentIterationComparator;
    180 
    181       //currentIterationComparator.LeftSideParameter.ActualName = "CurrentIteration";
    182       //currentIterationComparator.Comparison = new Comparison(ComparisonType.Less);
    183       //currentIterationComparator.RightSideParameter.ActualName = "MaxIterations";
    184       //currentIterationComparator.ResultParameter.ActualName = "ContinueIteration";
    185       //currentIterationComparator.Successor = conditionalBranch;
    186 
    187       //conditionalBranch.Name = "ContinueIteration?";
    188       //conditionalBranch.ConditionParameter.ActualName = "ContinueIteration";
    189       //conditionalBranch.TrueBranch = uniformSubScopeProcessor;
     178      conditionalBranch.Name = "ContinueIteration?";
     179      conditionalBranch.ConditionParameter.ActualName = "ContinueIteration";
     180      conditionalBranch.TrueBranch = uniformSubScopeProcessor;
    190181      #endregion
    191182    }
  • trunk/sources/HeuristicLab.Encodings.RealVectorEncoding/3.3/ParticleOperators/RealVectorParticleUpdater.cs

    r5560 r5566  
    4343    }
    4444    public ILookupParameter<RealVector> PersonalBestParameter {
    45       get { return (ILookupParameter<RealVector>)Parameters["PersonalBestParameter"]; }
     45      get { return (ILookupParameter<RealVector>)Parameters["PersonalBest"]; }
    4646    }
    4747    public ILookupParameter<RealVector> NeighborsBestParameter {
  • trunk/sources/HeuristicLab.Encodings.RealVectorEncoding/3.3/ParticleOperators/RealVectorSwarmUpdater.cs

    r5561 r5566  
    132132    public override IOperation Apply() {
    133133      InitializeBestPoint();
     134      UpdateSwarm();
    134135      UpdateNeighbors();
    135136      UpdateVelocityBounds();
    136       UpdateSwarm();
    137137      return base.Apply();
    138138    }
     
    140140    private void InitializeBestPoint() {
    141141      if (BestQuality == null)
    142         BestQualityParameter.ActualValue = new DoubleValue(); 
     142        BestQualityParameter.ActualValue = new DoubleValue();
    143143      BestQuality.Value = Maximization ? Quality.Max(v => v.Value) : Quality.Min(v => v.Value);
    144144      int bestIndex = Quality.FindIndex(v => v.Value == BestQuality.Value);
     
    167167    private void UpdateSwarm() {
    168168      if (PersonalBestQuality.Length == 0) {
    169         PersonalBestQualityParameter.ActualValue = new ItemArray<DoubleValue>(RealVector.Length);
     169        ItemArray<DoubleValue> personalBestQualities = new ItemArray<DoubleValue>(RealVector.Length);
    170170        for (int i = 0; i < RealVector.Length; i++) {
    171171          if (Maximization) {
    172             PersonalBestQuality[i] = new DoubleValue();
     172            personalBestQualities[i] = new DoubleValue(double.MinValue);
    173173          } else {
    174             PersonalBestQuality[i] = new DoubleValue(double.MaxValue);
     174            personalBestQualities[i] = new DoubleValue(double.MaxValue);
    175175          }
    176176        }
     177        PersonalBestQualityParameter.ActualValue = personalBestQualities;
    177178      }
    178179      if (NeighborsBestQuality.Length == 0) {
    179         NeighborsBestQualityParameter.ActualValue = new ItemArray<DoubleValue>(RealVector.Length);
    180         for (int i = 0; i < RealVector.Length; i++) {
    181           if (Maximization) {
    182             NeighborsBestQuality[i] = new DoubleValue();
    183           } else {
    184             NeighborsBestQuality[i] = new DoubleValue(double.MaxValue);
     180        if (NeighborsParameter != null && Neighbors.Length > 0) {
     181          ItemArray<DoubleValue> neighborsBestQualities = new ItemArray<DoubleValue>(RealVector.Length);
     182          for (int i = 0; i < RealVector.Length; i++) {
     183            if (Maximization) {
     184              neighborsBestQualities[i] = new DoubleValue(double.MinValue);
     185            } else {
     186              neighborsBestQualities[i] = new DoubleValue(double.MaxValue);
     187            }
    185188          }
    186         }
    187       }
    188       if (NeighborsBest.Length == 0) {
    189         NeighborsBestParameter.ActualValue = new ItemArray<RealVector>(RealVector.Length);
    190       }
     189          NeighborsBestQualityParameter.ActualValue = neighborsBestQualities;
     190        }
     191      }
     192      ItemArray<RealVector> neighborsBest = new ItemArray<RealVector>(RealVector.Length);
    191193      for (int i = 0; i < RealVector.Length; i++) {
    192194        if (Maximization && Quality[i].Value > PersonalBestQuality[i].Value ||
     
    197199             !Maximization && PersonalBestQuality[i].Value < NeighborsBestQuality[i].Value) {
    198200            NeighborsBestQuality[i].Value = PersonalBestQuality[i].Value;
    199             NeighborsBest[i] = PersonalBest[i];
     201            neighborsBest[i] = PersonalBest[i];
    200202          }
    201203        }
     204      }
     205      if (NeighborsParameter != null && Neighbors.Length > 0) {
     206        NeighborsBestParameter.ActualValue = neighborsBest;
    202207      }
    203208    }
Note: See TracChangeset for help on using the changeset viewer.