Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
02/28/11 17:25:28 (13 years ago)
Author:
epitzer
Message:

Continue working on SwarmUpdater (#852)

File:
1 edited

Legend:

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

    r5566 r5568  
    2020#endregion
    2121
    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;
    2822using HeuristicLab.Common;
    2923using HeuristicLab.Core;
     24using HeuristicLab.Data;
     25using HeuristicLab.Operators;
     26using HeuristicLab.Optimization;
     27using HeuristicLab.Optimization.Operators;
    3028using 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;
     29using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    3730
    3831namespace HeuristicLab.Algorithms.ParticleSwarmOptimization {
     
    5952      get { return (IValueLookupParameter<DoubleValue>)Parameters["PersonalBestAttraction"]; }
    6053    }
    61     public IValueLookupParameter<DoubleValue> NeighborsBestAttractionParameter {
    62       get { return (IValueLookupParameter<DoubleValue>)Parameters["NeighborsBestAttraction"]; }
     54    public IValueLookupParameter<DoubleValue> NeighborBestAttractionParameter {
     55      get { return (IValueLookupParameter<DoubleValue>)Parameters["NeighborBestAttraction"]; }
    6356    }
    6457    public IValueLookupParameter<DoubleMatrix> VelocityBoundsParameter {
    6558      get { return (IValueLookupParameter<DoubleMatrix>)Parameters["VelocityBounds"]; }
    66     }                                     
     59    }
    6760    public IValueLookupParameter<IOperator> ParticleUpdaterParameter {
    6861      get { return (IValueLookupParameter<IOperator>)Parameters["ParticleUpdater"]; }
     
    7467      get { return (IValueLookupParameter<IOperator>)Parameters["InertiaUpdater"]; }
    7568    }
    76     public IValueLookupParameter<VariableCollection> ResultsParameter {
    77       get { return (IValueLookupParameter<VariableCollection>)Parameters["Results"]; }
     69    public IValueLookupParameter<ResultCollection> ResultsParameter {
     70      get { return (IValueLookupParameter<ResultCollection>)Parameters["Results"]; }
    7871    }
    7972    public IValueLookupParameter<IOperator> EvaluatorParameter {
    8073      get { return (IValueLookupParameter<IOperator>)Parameters["Evaluator"]; }
    8174    }
     75    public ValueLookupParameter<ISwarmUpdater> SwarmUpdaterParameter {
     76      get { return (ValueLookupParameter<ISwarmUpdater>)Parameters["SwarmUpdater"]; }
     77    }
    8278    #endregion
    83                                                                  
     79
    8480    public ParticleSwarmOptimizationMainLoop()
    8581      : base() {
     
    10298      Parameters.Add(new ValueLookupParameter<IntValue>("SwarmSize", "Size of the particle swarm.", new IntValue(10)));
    10399      Parameters.Add(new ValueLookupParameter<IntValue>("MaxIterations", "Maximal number of iterations.", new IntValue(1000)));
    104      
     100
    105101      Parameters.Add(new ValueLookupParameter<IOperator>("Analyzer", "The operator used to analyze each generation."));
    106102
    107103      Parameters.Add(new ValueLookupParameter<DoubleValue>("Inertia", "Inertia weight on a particle's movement (omega)."));
    108104      Parameters.Add(new ValueLookupParameter<DoubleValue>("PersonalBestAttraction", "Weight for particle's pull towards its personal best soution (phi_p)."));
    109       Parameters.Add(new ValueLookupParameter<DoubleValue>("NeighborsBestAttraction", "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
    111107      Parameters.Add(new ValueLookupParameter<IOperator>("ParticleUpdater", "Operator that calculates new position and velocity of a particle"));
    112108      Parameters.Add(new ValueLookupParameter<IOperator>("TopologyUpdater", "Updates the neighborhood description vectors"));
     
    114110      Parameters.Add(new ValueLookupParameter<IOperator>("Evaluator", "Evaluates a particle solution."));
    115111
    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."));
    117115      #endregion
    118116
    119117      #region Create operators
     118      ResultsCollector resultsCollector = new ResultsCollector();
     119      Placeholder swarmUpdaterPlaceholer1 = new Placeholder();
    120120      Placeholder evaluatorPlaceholder = new Placeholder();
    121121      Placeholder analyzerPlaceholder = new Placeholder();
     
    135135
    136136      #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;
    138147
    139148      analyzerPlaceholder.Name = "(Analyzer)";
    140       analyzerPlaceholder.OperatorParameter.ActualName = AnalyzerParameter.Name; 
     149      analyzerPlaceholder.OperatorParameter.ActualName = AnalyzerParameter.Name;
    141150      analyzerPlaceholder.Successor = uniformSubScopeProcessor;
    142151
     
    145154
    146155      particleUpdaterPlaceholder.Name = "(ParticleUpdater)";
    147       particleUpdaterPlaceholder.OperatorParameter.ActualName = ParticleUpdaterParameter.Name; 
     156      particleUpdaterPlaceholder.OperatorParameter.ActualName = ParticleUpdaterParameter.Name;
    148157
    149158      evaluationProcessor.Parallel = new BoolValue(true);
     
    152161
    153162      evaluatorPlaceholder.Name = "(Evaluator)";
    154       evaluatorPlaceholder.OperatorParameter.ActualName = EvaluatorParameter.Name; 
     163      evaluatorPlaceholder.OperatorParameter.ActualName = EvaluatorParameter.Name;
    155164
    156165      topologyUpdaterPlaceholder.Name = "(TopologyUpdater)";
    157       topologyUpdaterPlaceholder.OperatorParameter.ActualName = TopologyUpdaterParameter.Name; 
     166      topologyUpdaterPlaceholder.OperatorParameter.ActualName = TopologyUpdaterParameter.Name;
    158167      topologyUpdaterPlaceholder.Successor = swarmUpdater;
    159168
    160169      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;
    163176
    164177      currentIterationCounter.Name = "CurrentIteration++";
    165178      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;
    171180
    172181      currentIterationComparator.LeftSideParameter.ActualName = "CurrentIteration";
Note: See TracChangeset for help on using the changeset viewer.