Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
03/22/11 16:45:46 (14 years ago)
Author:
mkommend
Message:

#1418: Merged trunk changes into branch.

Location:
branches/DataAnalysis Refactoring/HeuristicLab.Algorithms.ParticleSwarmOptimization/3.3
Files:
8 edited
1 copied

Legend:

Unmodified
Added
Removed
  • branches/DataAnalysis Refactoring/HeuristicLab.Algorithms.ParticleSwarmOptimization/3.3/HeuristicLab.Algorithms.ParticleSwarmOptimization-3.3.csproj

    r5426 r5796  
    106106  </ItemGroup>
    107107  <ItemGroup>
    108     <Compile Include="BestPointInitializer.cs" />
    109     <Compile Include="IDiscreteDoubleMatrixModifier.cs" />
    110     <Compile Include="IGlobalParticleUpdater.cs" />
    111     <Compile Include="ILocalParticleUpdater.cs" />
    112108    <Compile Include="MultiPSOTopologyUpdater.cs" />
     109    <Compile Include="ParticleSwarmOptimizationMainLoop.cs" />
    113110    <Compile Include="VelocityBoundsModifier.cs" />
    114111    <Compile Include="RandomTopologyInitializer.cs" />
    115112    <Compile Include="VonNeumannTopologyInitializer.cs" />
    116113    <Compile Include="RingTopologyInitializer.cs" />
    117     <Compile Include="ITopologyUpdater.cs" />
    118     <Compile Include="NeighborUpdater.cs" />
    119114    <Compile Include="TopologyInitializer.cs" />
    120     <Compile Include="ITopologyInitializer.cs" />
    121     <Compile Include="NeighborhoodParticleUpdater.cs" />
    122     <Compile Include="IParticleUpdater.cs" />
    123     <Compile Include="TotallyConnectedParticleUpdater.cs" />
    124115    <Compile Include="HeuristicLabAlgorithmsParticleSwarmOptimizationPlugin.cs" />
    125116    <Compile Include="ParticleSwarmOptimization.cs" />
    126117    <Compile Include="Properties\AssemblyInfo.cs" />
    127     <Compile Include="ParticleUpdater.cs" />
    128     <Compile Include="SwarmUpdater.cs" />
    129118  </ItemGroup>
    130119  <ItemGroup>
     
    170159      <Project>{BBAB9DF5-5EF3-4BA8-ADE9-B36E82114937}</Project>
    171160      <Name>HeuristicLab.Data-3.3</Name>
    172     </ProjectReference>
    173     <ProjectReference Include="..\..\HeuristicLab.Encodings.IntegerVectorEncoding\3.3\HeuristicLab.Encodings.IntegerVectorEncoding-3.3.csproj">
    174       <Project>{DDFB14DD-2A85-493C-A52D-E69729BBAEB0}</Project>
    175       <Name>HeuristicLab.Encodings.IntegerVectorEncoding-3.3</Name>
    176     </ProjectReference>
    177     <ProjectReference Include="..\..\HeuristicLab.Encodings.RealVectorEncoding\3.3\HeuristicLab.Encodings.RealVectorEncoding-3.3.csproj">
    178       <Project>{BB6D334A-4BB6-4674-9883-31A6EBB32CAB}</Project>
    179       <Name>HeuristicLab.Encodings.RealVectorEncoding-3.3</Name>
    180161    </ProjectReference>
    181162    <ProjectReference Include="..\..\HeuristicLab.Operators\3.3\HeuristicLab.Operators-3.3.csproj">
  • branches/DataAnalysis Refactoring/HeuristicLab.Algorithms.ParticleSwarmOptimization/3.3/HeuristicLabAlgorithmsParticleSwarmOptimizationPlugin.cs.frame

    r5446 r5796  
    3333  [PluginDependency("HeuristicLab.Core", "3.3")]
    3434  [PluginDependency("HeuristicLab.Data", "3.3")]
    35   [PluginDependency("HeuristicLab.Encodings.RealVectorEncoding", "3.3")]
    36   [PluginDependency("HeuristicLab.Encodings.IntegerVectorEncoding", "3.3")]
    3735  [PluginDependency("HeuristicLab.Operators", "3.3")]
    3836  [PluginDependency("HeuristicLab.Optimization", "3.3")]
  • branches/DataAnalysis Refactoring/HeuristicLab.Algorithms.ParticleSwarmOptimization/3.3/MultiPSOTopologyUpdater.cs

    r5435 r5796  
    2525using HeuristicLab.Core;
    2626using HeuristicLab.Data;
    27 using HeuristicLab.Encodings.IntegerVectorEncoding;
    2827using HeuristicLab.Operators;
     28using HeuristicLab.Optimization;
    2929using HeuristicLab.Parameters;
    3030using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    3131
    3232namespace HeuristicLab.Algorithms.ParticleSwarmOptimization {
    33   [Item("Multi PSO Topology Initializer/Updater", "Splits swarm into swarmsize / (nrOfConnections + 1) non-overlapping sub-swarms. Swarms are re-grouped every regroupingPeriod iteration. The operator is implemented as described in Liang, J.J. and Suganthan, P.N 2005. Dynamic multi-swarm particle swarm optimizer. IEEE Swarm Intelligence Symposium, pp. 124-129.")]
     33  [Item("Multi PSO Topology Updater", "Splits swarm into NrOfSwarms non-overlapping sub-swarms. Swarms are re-grouped every regroupingPeriod iteration. The operator is implemented as described in Liang, J.J. and Suganthan, P.N 2005. Dynamic multi-swarm particle swarm optimizer. IEEE Swarm Intelligence Symposium, pp. 124-129.")]
    3434  [StorableClass]
    35   public sealed class MultiPSOTopologyUpdater : SingleSuccessorOperator, ITopologyUpdater, ITopologyInitializer {
     35  public sealed class MultiPSOTopologyUpdater : SingleSuccessorOperator, ITopologyUpdater {
     36
    3637    public override bool CanChangeName {
    3738      get { return false; }
     
    4243      get { return (ILookupParameter<IRandom>)Parameters["Random"]; }
    4344    }
    44     public IValueLookupParameter<IntValue> NrOfConnectionsParameter {
    45       get { return (IValueLookupParameter<IntValue>)Parameters["NrOfConnections"]; }
     45    public IValueLookupParameter<IntValue> NrOfSwarmsParameter {
     46      get { return (IValueLookupParameter<IntValue>)Parameters["NrOfSwarms"]; }
    4647    }
    4748    public ILookupParameter<IntValue> SwarmSizeParameter {
    4849      get { return (ILookupParameter<IntValue>)Parameters["SwarmSize"]; }
    4950    }
    50     public IScopeTreeLookupParameter<IntegerVector> NeighborsParameter {
    51       get { return (IScopeTreeLookupParameter<IntegerVector>)Parameters["Neighbors"]; }
     51    public IScopeTreeLookupParameter<IntArray> NeighborsParameter {
     52      get { return (IScopeTreeLookupParameter<IntArray>)Parameters["Neighbors"]; }
    5253    }
    5354    public ILookupParameter<IntValue> CurrentIterationParameter {
     
    6364      get { return RandomParameter.ActualValue; }
    6465    }
    65     private int NrOfConnections {
    66       get { return NrOfConnectionsParameter.ActualValue.Value; }
     66    private int NrOfSwarms {
     67      get { return NrOfSwarmsParameter.ActualValue.Value; }
    6768    }
    6869    private int SwarmSize {
    6970      get { return SwarmSizeParameter.ActualValue.Value; }
    7071    }
    71     private ItemArray<IntegerVector> Neighbors {
     72    private ItemArray<IntArray> Neighbors {
    7273      get { return NeighborsParameter.ActualValue; }
    7374      set { NeighborsParameter.ActualValue = value; }
     
    8182    #endregion
    8283
     84    #region Construction & Cloning
    8385    [StorableConstructor]
    8486    private MultiPSOTopologyUpdater(bool deserializing) : base(deserializing) { }
     
    8789      : base() {
    8890      Parameters.Add(new LookupParameter<IRandom>("Random", "A random number generator."));
    89       Parameters.Add(new ValueLookupParameter<IntValue>("NrOfConnections", "Nr of connected neighbors.", new IntValue(3)));
     91      Parameters.Add(new ValueLookupParameter<IntValue>("NrOfSwarms", "Nr of connected sub-swarms.", new IntValue(3)));
    9092      Parameters.Add(new LookupParameter<IntValue>("SwarmSize", "Number of particles in the swarm."));
    91       Parameters.Add(new ScopeTreeLookupParameter<IntegerVector>("Neighbors", "The list of neighbors for each particle."));
     93      Parameters.Add(new ScopeTreeLookupParameter<IntArray>("Neighbors", "The list of neighbors for each particle."));
    9294      Parameters.Add(new LookupParameter<IntValue>("CurrentIteration", "The current iteration of the algorithm."));
    9395      Parameters.Add(new ValueLookupParameter<IntValue>("RegroupingPeriod", "Update interval (=iterations) for regrouping of neighborhoods.", new IntValue(5)));
    9496    }
    95 
    9697    public override IDeepCloneable Clone(Cloner cloner) {
    9798      return new MultiPSOTopologyUpdater(this, cloner);
    9899    }
     100    #endregion
    99101
    100     // Splits the swarm into non-overlapping sub swarms
    101102    public override IOperation Apply() {
    102       if (CurrentIteration % RegroupingPeriod == 0) {
    103         ItemArray<IntegerVector> neighbors = new ItemArray<IntegerVector>(SwarmSize);
    104         Dictionary<int, List<int>> neighborsPerParticle = new Dictionary<int, List<int>>();
    105         for (int i = 0; i < SwarmSize; i++) {
    106           neighborsPerParticle.Add(i, new List<int>());
     103      if (CurrentIteration > 0 && CurrentIteration % RegroupingPeriod == 0) {
     104        ItemArray<IntArray> neighbors = new ItemArray<IntArray>(SwarmSize);
     105
     106        var particles = Enumerable.Range(0, SwarmSize).ToList();
     107        for (int i = SwarmSize-1; i>0; i--) {
     108          int j = Random.Next(i+1);
     109          int t = particles[j];
     110          particles[j] = particles[i];
     111          particles[i] = t;
    107112        }
    108113
    109         // partition swarm into groups
    110         Dictionary<int, List<int>> groups = new Dictionary<int, List<int>>();
    111         int groupId = 0;
    112         var numbers = Enumerable.Range(0, SwarmSize).ToList();
    113         for (int i = 0; i < SwarmSize; i++) {
    114           int nextParticle = numbers[Random.Next(0, numbers.Count)];
    115           if (!groups.ContainsKey(groupId)) {
    116             groups.Add(groupId, new List<int>());
    117           }
    118           groups[groupId].Add(nextParticle);
    119           if (groups[groupId].Count - 1 == NrOfConnections) {
    120             groupId++;
    121           }
    122           numbers.Remove(nextParticle);
     114        for (int partitionNr = 0; partitionNr<NrOfSwarms; partitionNr++) {
     115          int start = partitionNr*SwarmSize/NrOfSwarms;
     116          int end = (partitionNr+1)*SwarmSize/NrOfSwarms;
     117          for (int i = start; i<end; i++)
     118            neighbors[particles[i]] = GetSegment(particles, start, end, i);
    123119        }
    124120
    125         // add neighbors to each particle
    126         foreach (List<int> group in groups.Values) {
    127           foreach (int sib1 in group) {
    128             foreach (int sib2 in group) {
    129               if (sib1 != sib2 && !neighborsPerParticle[sib1].Contains(sib2)) {
    130                 neighborsPerParticle[sib1].Add(sib2);
    131               }
    132             }
    133           }
    134         }
    135 
    136         for (int particle = 0; particle < neighborsPerParticle.Count; particle++) {
    137           neighbors[particle] = new IntegerVector(neighborsPerParticle[particle].ToArray());
    138         }
    139121        Neighbors = neighbors;
    140122      }
    141123      return base.Apply();
    142124    }
     125
     126    public static IntArray GetSegment(IEnumerable<int> list, int start, int end, int excludedIndex) {
     127      return new IntArray(list
     128        .Skip(start)
     129        .Take(end-start)
     130        .Where((p, j) => start+j != excludedIndex)
     131        .ToArray());
     132    }
    143133  }
    144134}
  • branches/DataAnalysis Refactoring/HeuristicLab.Algorithms.ParticleSwarmOptimization/3.3/ParticleSwarmOptimization.cs

    r5644 r5796  
    2626using HeuristicLab.Core;
    2727using HeuristicLab.Data;
    28 using HeuristicLab.Encodings.RealVectorEncoding;
    2928using HeuristicLab.Operators;
    3029using HeuristicLab.Optimization;
     
    5352      set { AnalyzerParameter.Value = value; }
    5453    }
    55     public IDiscreteDoubleValueModifier OmegaUpdater {
    56       get { return OmegaUpdaterParameter.Value; }
    57       set { OmegaUpdaterParameter.Value = value; }
    58     }
    59     public IDiscreteDoubleMatrixModifier VelocityBoundsUpdater {
    60       get { return VelocityBoundsUpdaterParameter.Value; }
    61       set { VelocityBoundsUpdaterParameter.Value = value; }
     54    public IDiscreteDoubleValueModifier InertiaUpdater {
     55      get { return InertiaUpdaterParameter.Value; }
     56      set { InertiaUpdaterParameter.Value = value; }
    6257    }
    6358    #endregion
     
    7671      get { return (IValueParameter<IntValue>)Parameters["MaxIterations"]; }
    7772    }
    78     public IValueParameter<DoubleValue> OmegaParameter {
    79       get { return (IValueParameter<DoubleValue>)Parameters["Omega"]; }
    80     }
    81     public IValueParameter<DoubleValue> Phi_PParameter {
    82       get { return (IValueParameter<DoubleValue>)Parameters["Phi_P"]; }
    83     }
    84     public IValueParameter<DoubleValue> Phi_GParameter {
    85       get { return (IValueParameter<DoubleValue>)Parameters["Phi_G"]; }
     73    public IValueParameter<DoubleValue> InertiaParameter {
     74      get { return (IValueParameter<DoubleValue>)Parameters["Inertia"]; }
     75    }
     76    public IValueParameter<DoubleValue> PersonalBestAttractionParameter {
     77      get { return (IValueParameter<DoubleValue>)Parameters["PersonalBestAttraction"]; }
     78    }
     79    public IValueParameter<DoubleValue> NeighborBestAttractionParameter {
     80      get { return (IValueParameter<DoubleValue>)Parameters["NeighborBestAttraction"]; }
    8681    }
    8782    public IValueParameter<MultiAnalyzer> AnalyzerParameter {
    8883      get { return (IValueParameter<MultiAnalyzer>)Parameters["Analyzer"]; }
    8984    }
    90     public IValueLookupParameter<DoubleMatrix> VelocityBoundsParameter {
    91       get { return (IValueLookupParameter<DoubleMatrix>)Parameters["VelocityBounds"]; }
     85    public ConstrainedValueParameter<IParticleCreator> ParticleCreatorParameter {
     86      get { return (ConstrainedValueParameter<IParticleCreator>)Parameters["ParticleCreator"]; }
    9287    }
    9388    public ConstrainedValueParameter<IParticleUpdater> ParticleUpdaterParameter {
     
    10095      get { return (OptionalConstrainedValueParameter<ITopologyUpdater>)Parameters["TopologyUpdater"]; }
    10196    }
    102     public OptionalConstrainedValueParameter<IDiscreteDoubleMatrixModifier> VelocityBoundsUpdaterParameter {
    103       get { return (OptionalConstrainedValueParameter<IDiscreteDoubleMatrixModifier>)Parameters["VelocityBoundsUpdater"]; }
    104     }
    105     public OptionalConstrainedValueParameter<IDiscreteDoubleValueModifier> OmegaUpdaterParameter {
    106       get { return (OptionalConstrainedValueParameter<IDiscreteDoubleValueModifier>)Parameters["OmegaUpdater"]; }
     97    public OptionalConstrainedValueParameter<IDiscreteDoubleValueModifier> InertiaUpdaterParameter {
     98      get { return (OptionalConstrainedValueParameter<IDiscreteDoubleValueModifier>)Parameters["InertiaUpdater"]; }
     99    }
     100    public ConstrainedValueParameter<ISwarmUpdater> SwarmUpdaterParameter {
     101      get { return (ConstrainedValueParameter<ISwarmUpdater>)Parameters["SwarmUpdater"]; }
     102
    107103    }
    108104    #endregion
     
    114110    [Storable]
    115111    private BestAverageWorstQualityAnalyzer qualityAnalyzer;
     112
     113    [Storable]
     114    private SolutionsCreator solutionsCreator;
     115
     116    [Storable]
     117    private ParticleSwarmOptimizationMainLoop mainLoop;
    116118
    117119    public ITopologyInitializer TopologyInitializer {
     
    125127    }
    126128
     129    public IParticleCreator ParticleCreator {
     130      get { return ParticleCreatorParameter.Value; }
     131      set { ParticleCreatorParameter.Value = value; }
     132    }
     133
    127134    public IParticleUpdater ParticleUpdater {
    128135      get { return ParticleUpdaterParameter.Value; }
    129136      set { ParticleUpdaterParameter.Value = value; }
    130137    }
    131 
    132138    #endregion
    133139
     
    137143      : base(original, cloner) {
    138144      qualityAnalyzer = cloner.Clone(original.qualityAnalyzer);
     145      solutionsCreator = cloner.Clone(original.solutionsCreator);
     146      mainLoop = cloner.Clone(original.mainLoop);
    139147      Initialize();
    140148    }
     
    146154      Parameters.Add(new ValueParameter<IntValue>("MaxIterations", "Maximal number of iterations.", new IntValue(1000)));
    147155      Parameters.Add(new ValueParameter<MultiAnalyzer>("Analyzer", "The operator used to analyze each generation.", new MultiAnalyzer()));
    148       Parameters.Add(new ValueParameter<DoubleValue>("Omega", "Weight for particle's velocity vector.", new DoubleValue(-0.2)));
    149       Parameters.Add(new ValueParameter<DoubleValue>("Phi_P", "Weight for particle's personal best position.", new DoubleValue(-0.01)));
    150       Parameters.Add(new ValueParameter<DoubleValue>("Phi_G", "Weight for global best position.", new DoubleValue(3.7)));
    151       Parameters.Add(new ValueLookupParameter<DoubleMatrix>("VelocityBounds", "Maximum Velocity in every dimension", new DoubleMatrix(new double[,] { { -1, 1 } })));
    152       Parameters.Add(new ConstrainedValueParameter<IParticleUpdater>("ParticleUpdater", "Operator that calculates new position and velocity of a particle"));
    153       Parameters.Add(new OptionalConstrainedValueParameter<ITopologyInitializer>("TopologyInitializer", "Creates neighborhood description vectors"));
    154       Parameters.Add(new OptionalConstrainedValueParameter<ITopologyUpdater>("TopologyUpdater", "Updates the neighborhood description vectors"));
    155       Parameters.Add(new OptionalConstrainedValueParameter<IDiscreteDoubleValueModifier>("OmegaUpdater", "Updates the omega parameter"));
    156       Parameters.Add(new OptionalConstrainedValueParameter<IDiscreteDoubleMatrixModifier>("VelocityBoundsUpdater", "Adjusts the velocity bounds."));
    157       ParticleUpdaterParameter.ActualValue = ParticleUpdaterParameter.ValidValues.SingleOrDefault(v => v.GetType() == typeof(TotallyConnectedParticleUpdater));
     156      Parameters.Add(new ValueParameter<DoubleValue>("Inertia", "Inertia weight on a particle's movement (omega).", new DoubleValue(-0.2)));
     157      Parameters.Add(new ValueParameter<DoubleValue>("PersonalBestAttraction", "Weight for particle's pull towards its personal best soution (phi_p).", new DoubleValue(-0.01)));
     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)));
     159      Parameters.Add(new ConstrainedValueParameter<IParticleCreator>("ParticleCreator", "Operator creates a new particle."));
     160      Parameters.Add(new ConstrainedValueParameter<IParticleUpdater>("ParticleUpdater", "Operator that updates a particle."));
     161      Parameters.Add(new OptionalConstrainedValueParameter<ITopologyInitializer>("TopologyInitializer", "Creates neighborhood description vectors."));
     162      Parameters.Add(new OptionalConstrainedValueParameter<ITopologyUpdater>("TopologyUpdater", "Updates the neighborhood description vectors."));
     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"));
    158165
    159166      RandomCreator randomCreator = new RandomCreator();
    160167      VariableCreator variableCreator = new VariableCreator();
    161       SolutionsCreator solutionsCreator = new SolutionsCreator();
    162       CombinedOperator particleCreator = new CombinedOperator();
    163       Placeholder evaluatorPlaceholder = new Placeholder();
    164       Assigner bestPersonalQualityAssigner = new Assigner();
    165       BestPointInitializer bestPositionInitializer = new BestPointInitializer();
     168      Assigner assigner = new Assigner();
     169      solutionsCreator = new SolutionsCreator();
     170      SubScopesCounter subScopesCounter = new SubScopesCounter();
    166171      Placeholder topologyInitializerPlaceholder = new Placeholder();
    167       NeighborUpdater neighborUpdater = new NeighborUpdater();
    168172      Placeholder analyzerPlaceholder = new Placeholder();
    169       UniformSubScopesProcessor uniformSubScopeProcessor = new UniformSubScopesProcessor();
    170       Placeholder particleUpdaterPlaceholder = new Placeholder();
    171       Placeholder topologyUpdaterPlaceholder = new Placeholder();
    172       UniformSubScopesProcessor uniformSubscopesProcessor2 = new UniformSubScopesProcessor();
    173       UniformSubScopesProcessor evaluationProcessor = new UniformSubScopesProcessor();
    174       NeighborUpdater neighborUpdater2 = new NeighborUpdater();
    175       Placeholder evaluatorPlaceholder2 = new Placeholder();
    176       SwarmUpdater swarmUpdater = new SwarmUpdater();
    177       Placeholder analyzerPlaceholder2 = new Placeholder();
    178       IntCounter currentIterationCounter = new IntCounter();
    179       Comparator currentIterationComparator = new Comparator();
    180       ConditionalBranch conditionalBranch = new ConditionalBranch();
    181       Placeholder velocityBoundsUpdaterPlaceholder = new Placeholder();
    182       Placeholder omegaUpdaterPlaceholder = new Placeholder();
     173      mainLoop = new ParticleSwarmOptimizationMainLoop();
    183174
    184175      OperatorGraph.InitialOperator = randomCreator;
     
    189180
    190181      variableCreator.CollectedValues.Add(new ValueParameter<IntValue>("CurrentIteration", new IntValue(0)));
    191       variableCreator.Successor = solutionsCreator;
     182      variableCreator.CollectedValues.Add(new ValueParameter<DoubleValue>("CurrentVelocityBounds", new DoubleValue(0)));
     183      variableCreator.Successor = assigner;
     184
     185      assigner.Name = "CurrentInertia := Inertia";
     186      assigner.LeftSideParameter.ActualName = "CurrentInertia";
     187      assigner.RightSideParameter.ActualName = "Inertia";
     188      assigner.Successor = solutionsCreator;
    192189
    193190      solutionsCreator.NumberOfSolutionsParameter.ActualName = "SwarmSize";
    194       solutionsCreator.EvaluatorParameter.Value = evaluatorPlaceholder;
    195       solutionsCreator.SolutionCreatorParameter.Value = particleCreator;
    196       solutionsCreator.Successor = bestPositionInitializer;
    197 
    198       InitializeParticleCreator(particleCreator);
    199 
    200       evaluatorPlaceholder.Name = "(Evaluator)";
    201       evaluatorPlaceholder.OperatorParameter.ActualName = "Evaluator";
    202       evaluatorPlaceholder.Successor = bestPersonalQualityAssigner;
    203 
    204       bestPersonalQualityAssigner.LeftSideParameter.ActualName = "PersonalBestQuality";
    205       bestPersonalQualityAssigner.RightSideParameter.ActualName = "Quality";
    206 
    207       bestPositionInitializer.Successor = topologyInitializerPlaceholder;
     191      ParameterizeSolutionsCreator();
     192      solutionsCreator.Successor = subScopesCounter;
     193
     194      subScopesCounter.Name = "Initialize EvaluatedSolutions";
     195      subScopesCounter.ValueParameter.ActualName = "EvaluatedSolutions";
     196      subScopesCounter.Successor = topologyInitializerPlaceholder;
    208197
    209198      topologyInitializerPlaceholder.Name = "(TopologyInitializer)";
    210199      topologyInitializerPlaceholder.OperatorParameter.ActualName = "TopologyInitializer";
    211       topologyInitializerPlaceholder.Successor = neighborUpdater;
    212 
    213       neighborUpdater.Successor = analyzerPlaceholder;
    214 
    215       analyzerPlaceholder.Name = "(Analyzer)";
    216       analyzerPlaceholder.OperatorParameter.ActualName = "Analyzer";
    217       analyzerPlaceholder.Successor = uniformSubScopeProcessor;
    218 
    219       uniformSubScopeProcessor.Operator = particleUpdaterPlaceholder;
    220       uniformSubScopeProcessor.Successor = evaluationProcessor;
    221 
    222       particleUpdaterPlaceholder.Name = "(ParticleUpdater)";
    223       particleUpdaterPlaceholder.OperatorParameter.ActualName = "ParticleUpdater";
    224 
    225       evaluationProcessor.Parallel = new BoolValue(true);
    226       evaluationProcessor.Operator = evaluatorPlaceholder2;
    227       evaluationProcessor.Successor = topologyUpdaterPlaceholder;
    228 
    229       evaluatorPlaceholder2.Name = "(Evaluator)";
    230       evaluatorPlaceholder2.OperatorParameter.ActualName = "Evaluator";
    231 
    232       topologyUpdaterPlaceholder.Name = "(TopologyUpdater)";
    233       topologyUpdaterPlaceholder.OperatorParameter.ActualName = "TopologyUpdater";
    234       topologyUpdaterPlaceholder.Successor = neighborUpdater2;
    235 
    236       neighborUpdater2.Successor = uniformSubscopesProcessor2;
    237 
    238       uniformSubscopesProcessor2.Operator = swarmUpdater;
    239       uniformSubscopesProcessor2.Successor = analyzerPlaceholder2;
    240 
    241       analyzerPlaceholder2.Name = "(Analyzer)";
    242       analyzerPlaceholder2.OperatorParameter.ActualName = "Analyzer";
    243       analyzerPlaceholder2.Successor = currentIterationCounter;
    244 
    245       currentIterationCounter.Name = "CurrentIteration++";
    246       currentIterationCounter.ValueParameter.ActualName = "CurrentIteration";
    247       currentIterationCounter.Successor = omegaUpdaterPlaceholder;
    248 
    249       omegaUpdaterPlaceholder.Name = "(Omega Updater)";
    250       omegaUpdaterPlaceholder.OperatorParameter.ActualName = "OmegaUpdater";
    251       omegaUpdaterPlaceholder.Successor = velocityBoundsUpdaterPlaceholder;
    252 
    253       velocityBoundsUpdaterPlaceholder.Name = "(Velocity Bounds Updater)";
    254       velocityBoundsUpdaterPlaceholder.OperatorParameter.ActualName = "VelocityBoundsUpdater";
    255       velocityBoundsUpdaterPlaceholder.Successor = currentIterationComparator;
    256 
    257       currentIterationComparator.LeftSideParameter.ActualName = "CurrentIteration";
    258       currentIterationComparator.Comparison = new Comparison(ComparisonType.Less);
    259       currentIterationComparator.RightSideParameter.ActualName = "MaxIterations";
    260       currentIterationComparator.ResultParameter.ActualName = "ContinueIteration";
    261       currentIterationComparator.Successor = conditionalBranch;
    262 
    263       conditionalBranch.Name = "ContinueIteration?";
    264       conditionalBranch.ConditionParameter.ActualName = "ContinueIteration";
    265       conditionalBranch.TrueBranch = uniformSubScopeProcessor;
     200      topologyInitializerPlaceholder.Successor = mainLoop;
     201
     202      mainLoop.AnalyzerParameter.ActualName = AnalyzerParameter.Name;
     203      mainLoop.InertiaParameter.ActualName = "CurrentInertia";
     204      mainLoop.MaxIterationsParameter.ActualName = MaxIterationsParameter.Name;
     205      mainLoop.NeighborBestAttractionParameter.ActualName = NeighborBestAttractionParameter.Name;
     206      mainLoop.InertiaUpdaterParameter.ActualName = InertiaUpdaterParameter.Name;
     207      mainLoop.ParticleUpdaterParameter.ActualName = ParticleUpdaterParameter.Name;
     208      mainLoop.PersonalBestAttractionParameter.ActualName = PersonalBestAttractionParameter.Name;
     209      mainLoop.RandomParameter.ActualName = randomCreator.RandomParameter.ActualName;
     210      mainLoop.SwarmSizeParameter.ActualName = SwarmSizeParameter.Name;
     211      mainLoop.TopologyUpdaterParameter.ActualName = TopologyUpdaterParameter.Name;
     212      mainLoop.RandomParameter.ActualName = randomCreator.RandomParameter.ActualName;
     213      mainLoop.ResultsParameter.ActualName = "Results";
    266214
    267215      InitializeAnalyzers();
    268       InitVelocityBoundsUpdater();
     216      InitializeParticleCreator();
     217      InitializeSwarmUpdater();
     218      ParameterizeSolutionsCreator();
    269219      UpdateAnalyzers();
    270       UpdateOmegaUpdater();
    271       InitOmegaUpdater();
     220      UpdateInertiaUpdater();
     221      InitInertiaUpdater();
    272222      UpdateTopologyInitializer();
    273223      Initialize();
     224      ParameterizeMainLoop();
    274225    }
    275226
     
    284235
    285236    public override void Prepare() {
    286       if (Problem != null) {
     237      if (Problem != null && ParticleCreator != null && ParticleUpdater != null) {
    287238        base.Prepare();
    288         if (OmegaUpdater != null && OmegaUpdater.StartValueParameter.Value != null) {
    289           this.OmegaParameter.ActualValue = new DoubleValue(OmegaUpdaterParameter.Value.StartValueParameter.Value.Value);
    290         }
    291         if (VelocityBoundsUpdater != null && VelocityBoundsUpdater.StartValueParameter.Value != null && VelocityBoundsParameter.Value != null) {
    292           DoubleMatrix matrix = VelocityBoundsParameter.Value;
    293           for (int i = 0; i < matrix.Rows; i++) {
    294             matrix[i, 0] = -VelocityBoundsUpdater.StartValueParameter.Value.Value;
    295             matrix[i, 1] = VelocityBoundsUpdater.StartValueParameter.Value.Value;
    296           }
    297         }
    298239      }
    299240    }
     
    303244      UpdateAnalyzers();
    304245      ParameterizeAnalyzers();
     246      UpdateTopologyParameters();
     247      InitializeParticleCreator();
     248      InitializeSwarmUpdater();
     249      ParameterizeSolutionsCreator();
    305250      base.OnProblemChanged();
    306251    }
     
    308253    void TopologyInitializerParameter_ValueChanged(object sender, EventArgs e) {
    309254      this.UpdateTopologyParameters();
    310     }
    311 
    312     void VelocityBoundsUpdaterParameter_ValueChanged(object sender, EventArgs e) {
    313       if (VelocityBoundsParameter.Value != null) {
    314         foreach (IDiscreteDoubleMatrixModifier matrixOp in VelocityBoundsUpdaterParameter.Value.ScalingOperatorParameter.ValidValues) {
    315           matrixOp.ValueParameter.ActualName = VelocityBoundsUpdater.ScaleParameter.Name;
    316           matrixOp.StartValueParameter.Value = new DoubleValue(VelocityBoundsUpdater.ScaleParameter.ActualValue.Value);
    317         }
    318       }
    319255    }
    320256    #endregion
     
    325261    }
    326262
    327     private static void InitializeParticleCreator(CombinedOperator particleCreator) {
    328       Placeholder positionCreator = new Placeholder();
    329       Assigner personalBestPositionAssigner = new Assigner();
    330       UniformRandomRealVectorCreator velocityCreator = new UniformRandomRealVectorCreator();
    331 
    332       particleCreator.Name = "Particle Creator";
    333       particleCreator.OperatorGraph.InitialOperator = positionCreator;
    334 
    335       positionCreator.Name = "(SolutionCreator)";
    336       positionCreator.OperatorParameter.ActualName = "SolutionCreator";
    337       positionCreator.Successor = personalBestPositionAssigner;
    338 
    339       personalBestPositionAssigner.LeftSideParameter.ActualName = "PersonalBestPoint";
    340       personalBestPositionAssigner.RightSideParameter.ActualName = "Point";
    341       personalBestPositionAssigner.Successor = velocityCreator;
    342 
    343       velocityCreator.LengthParameter.ActualName = "ProblemSize";
    344       velocityCreator.BoundsParameter.ActualName = "VelocityBounds";
    345       velocityCreator.RealVectorParameter.ActualName = "Velocity";
     263    private void InitializeParticleCreator() {
     264      if (Problem != null) {
     265        IParticleCreator oldParticleCreator = ParticleCreator;
     266        ParticleCreatorParameter.ValidValues.Clear();
     267        foreach (IParticleCreator Creator in Problem.Operators.OfType<IParticleCreator>().OrderBy(x => x.Name)) {
     268          ParticleCreatorParameter.ValidValues.Add(Creator);
     269        }
     270        if (oldParticleCreator != null) {
     271          IParticleCreator creator = ParticleCreatorParameter.ValidValues.FirstOrDefault(x => x.GetType() == oldParticleCreator.GetType());
     272          if (creator != null) ParticleCreator = creator;
     273        }
     274      }
    346275    }
    347276
    348277    private void InitializeAnalyzers() {
    349278      qualityAnalyzer = new BestAverageWorstQualityAnalyzer();
     279      qualityAnalyzer.ResultsParameter.ActualName = "Results";
    350280      ParameterizeAnalyzers();
    351281    }
     
    368298    }
    369299
    370     private void InitVelocityBoundsUpdater() {
    371       foreach (IDiscreteDoubleMatrixModifier matrixOp in ApplicationManager.Manager.GetInstances<IDiscreteDoubleMatrixModifier>()) {
    372         VelocityBoundsUpdaterParameter.ValidValues.Add(matrixOp);
    373         matrixOp.ValueParameter.ActualName = VelocityBoundsParameter.Name;
    374         matrixOp.EndIndexParameter.ActualName = MaxIterationsParameter.Name;
    375         matrixOp.StartIndexParameter.Value = new IntValue(0);
    376         matrixOp.IndexParameter.ActualName = "CurrentIteration";
    377         matrixOp.EndValueParameter.Value = new DoubleValue(0);
    378       }
    379       VelocityBoundsUpdaterParameter.ValueChanged += new EventHandler(VelocityBoundsUpdaterParameter_ValueChanged);
    380     }
    381 
    382     private void InitOmegaUpdater() {
    383       foreach (IDiscreteDoubleValueModifier updater in OmegaUpdaterParameter.ValidValues) {
     300    private void InitInertiaUpdater() {
     301      foreach (IDiscreteDoubleValueModifier updater in InertiaUpdaterParameter.ValidValues) {
    384302        updater.EndIndexParameter.ActualName = MaxIterationsParameter.Name;
    385303        updater.StartIndexParameter.Value = new IntValue(0);
    386304        updater.IndexParameter.ActualName = "CurrentIteration";
    387         updater.ValueParameter.ActualName = OmegaParameter.Name;
     305        updater.ValueParameter.ActualName = "CurrentInertia";
    388306        updater.StartValueParameter.Value = new DoubleValue(1);
    389         updater.EndValueParameter.Value = new DoubleValue(0);
    390       }
    391     }
    392 
    393     private void UpdateOmegaUpdater() {
    394       IDiscreteDoubleValueModifier oldOmegaUpdater = OmegaUpdater;
    395       OmegaUpdaterParameter.ValidValues.Clear();
     307        updater.EndValueParameter.Value = new DoubleValue(double.Epsilon);
     308      }
     309    }
     310
     311    private void UpdateInertiaUpdater() {
     312      IDiscreteDoubleValueModifier oldInertiaUpdater = InertiaUpdater;
     313      InertiaUpdaterParameter.ValidValues.Clear();
    396314      foreach (IDiscreteDoubleValueModifier updater in ApplicationManager.Manager.GetInstances<IDiscreteDoubleValueModifier>().OrderBy(x => x.Name)) {
    397         OmegaUpdaterParameter.ValidValues.Add(updater);
    398       }
    399       if (oldOmegaUpdater != null) {
    400         IDiscreteDoubleValueModifier updater = OmegaUpdaterParameter.ValidValues.FirstOrDefault(x => x.GetType() == oldOmegaUpdater.GetType());
    401         if (updater != null) OmegaUpdaterParameter.Value = updater;
     315        InertiaUpdaterParameter.ValidValues.Add(updater);
     316      }
     317      if (oldInertiaUpdater != null) {
     318        IDiscreteDoubleValueModifier updater = InertiaUpdaterParameter.ValidValues.FirstOrDefault(x => x.GetType() == oldInertiaUpdater.GetType());
     319        if (updater != null) InertiaUpdaterParameter.Value = updater;
    402320      }
    403321    }
     
    418336      IParticleUpdater oldParticleUpdater = ParticleUpdater;
    419337      ClearTopologyParameters();
    420       if (TopologyInitializer != null) {
    421         foreach (ITopologyUpdater topologyUpdater in ApplicationManager.Manager.GetInstances<ITopologyUpdater>())
    422           TopologyUpdaterParameter.ValidValues.Add(topologyUpdater);
    423         foreach (IParticleUpdater particleUpdater in ApplicationManager.Manager.GetInstances<ILocalParticleUpdater>())
    424           ParticleUpdaterParameter.ValidValues.Add(particleUpdater);
    425       } else {
    426         foreach (IParticleUpdater particleUpdater in ApplicationManager.Manager.GetInstances<IGlobalParticleUpdater>())
    427           ParticleUpdaterParameter.ValidValues.Add(particleUpdater);
    428       }
    429       if (oldTopologyUpdater != null) {
    430         ITopologyUpdater newTopologyUpdater = TopologyUpdaterParameter.ValidValues.FirstOrDefault(x => x.GetType() == oldParticleUpdater.GetType());
    431         if (newTopologyUpdater != null) TopologyUpdater = newTopologyUpdater;
    432       }
    433       if (oldParticleUpdater != null) {
    434         IParticleUpdater newParticleUpdater = ParticleUpdaterParameter.ValidValues.FirstOrDefault(x => x.GetType() == oldParticleUpdater.GetType());
    435         if (newParticleUpdater != null) ParticleUpdater = newParticleUpdater;
     338      if (Problem != null) {
     339        if (TopologyInitializer != null) {
     340          foreach (ITopologyUpdater topologyUpdater in ApplicationManager.Manager.GetInstances<ITopologyUpdater>())
     341            TopologyUpdaterParameter.ValidValues.Add(topologyUpdater);
     342          foreach (IParticleUpdater particleUpdater in Problem.Operators.OfType<ILocalParticleUpdater>().OrderBy(x => x.Name))
     343            ParticleUpdaterParameter.ValidValues.Add(particleUpdater);
     344        } else {
     345          foreach (IParticleUpdater particleUpdater in Problem.Operators.OfType<IGlobalParticleUpdater>().OrderBy(x => x.Name))
     346            ParticleUpdaterParameter.ValidValues.Add(particleUpdater);
     347        }
     348        if (oldTopologyUpdater != null) {
     349          ITopologyUpdater newTopologyUpdater = TopologyUpdaterParameter.ValidValues.FirstOrDefault(x => x.GetType() == oldParticleUpdater.GetType());
     350          if (newTopologyUpdater != null) TopologyUpdater = newTopologyUpdater;
     351        }
     352        if (oldParticleUpdater != null) {
     353          IParticleUpdater newParticleUpdater = ParticleUpdaterParameter.ValidValues.FirstOrDefault(x => x.GetType() == oldParticleUpdater.GetType());
     354          if (newParticleUpdater != null) ParticleUpdater = newParticleUpdater;
     355        }
    436356      }
    437357    }
     
    441361      ParticleUpdaterParameter.ValidValues.Clear();
    442362    }
     363
     364    private void ParameterizeSolutionsCreator() {
     365      if (Problem != null) {
     366        solutionsCreator.EvaluatorParameter.ActualName = Problem.EvaluatorParameter.Name;
     367        solutionsCreator.SolutionCreatorParameter.ActualName = ParticleCreatorParameter.Name;
     368      }
     369    }
     370
     371    private void ParameterizeMainLoop() {
     372      if (Problem != null) {
     373        mainLoop.EvaluatorParameter.ActualName = Problem.EvaluatorParameter.Name;
     374      }
     375    }
     376
     377    private void InitializeSwarmUpdater() {
     378      if (Problem != null) {
     379        ISwarmUpdater updater = Problem.Operators.OfType<ISwarmUpdater>().FirstOrDefault();
     380        SwarmUpdaterParameter.ValidValues.Clear();
     381        SwarmUpdaterParameter.ValidValues.Add(updater);
     382        SwarmUpdaterParameter.Value = updater;
     383      }
     384    }
    443385    #endregion
    444386
  • branches/DataAnalysis Refactoring/HeuristicLab.Algorithms.ParticleSwarmOptimization/3.3/RandomTopologyInitializer.cs

    r5445 r5796  
    2525using HeuristicLab.Core;
    2626using HeuristicLab.Data;
    27 using HeuristicLab.Encodings.IntegerVectorEncoding;
    2827using HeuristicLab.Parameters;
    2928using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
     
    6665
    6766    public override IOperation Apply() {
    68       ItemArray<IntegerVector> neighbors = new ItemArray<IntegerVector>(SwarmSize);
     67      ItemArray<IntArray> neighbors = new ItemArray<IntArray>(SwarmSize);
    6968      for (int i = 0; i < SwarmSize; i++) {
    7069        var numbers = Enumerable.Range(0, SwarmSize).ToList();
     
    7675          numbers.RemoveAt(index);
    7776        }
    78         neighbors[i] = new IntegerVector(selectedNumbers.ToArray());
     77        neighbors[i] = new IntArray(selectedNumbers.ToArray());
    7978      }
    8079      Neighbors = neighbors;
  • branches/DataAnalysis Refactoring/HeuristicLab.Algorithms.ParticleSwarmOptimization/3.3/RingTopologyInitializer.cs

    r5445 r5796  
    2222using HeuristicLab.Common;
    2323using HeuristicLab.Core;
    24 using HeuristicLab.Encodings.IntegerVectorEncoding;
    2524using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
     25using HeuristicLab.Data;
    2626
    2727namespace HeuristicLab.Algorithms.ParticleSwarmOptimization {
     
    4343
    4444    public override IOperation Apply() {
    45       ItemArray<IntegerVector> neighbors = new ItemArray<IntegerVector>(SwarmSize);
     45      ItemArray<IntArray> neighbors = new ItemArray<IntArray>(SwarmSize);
    4646      for (int i = 0; i < SwarmSize; i++) {
    47         neighbors[i] = new IntegerVector(new[] { (SwarmSize + i - 1) % SwarmSize, (i + 1) % SwarmSize });
     47        neighbors[i] = new IntArray(new[] { (SwarmSize + i - 1) % SwarmSize, (i + 1) % SwarmSize });
    4848      }
    4949      Neighbors = neighbors;
  • branches/DataAnalysis Refactoring/HeuristicLab.Algorithms.ParticleSwarmOptimization/3.3/TopologyInitializer.cs

    r5445 r5796  
    2323using HeuristicLab.Core;
    2424using HeuristicLab.Data;
    25 using HeuristicLab.Encodings.IntegerVectorEncoding;
    2625using HeuristicLab.Operators;
     26using HeuristicLab.Optimization;
    2727using HeuristicLab.Parameters;
    2828using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
     
    3737
    3838    #region Parameters
    39     public IScopeTreeLookupParameter<IntegerVector> NeighborsParameter {
    40       get { return (IScopeTreeLookupParameter<IntegerVector>)Parameters["Neighbors"]; }
     39    public IScopeTreeLookupParameter<IntArray> NeighborsParameter {
     40      get { return (IScopeTreeLookupParameter<IntArray>)Parameters["Neighbors"]; }
    4141    }
     42
    4243    public ILookupParameter<IntValue> SwarmSizeParameter {
    4344      get { return (ILookupParameter<IntValue>)Parameters["SwarmSize"]; }
     
    4748
    4849    #region Parameter Values
    49     protected ItemArray<IntegerVector> Neighbors {
     50    protected ItemArray<IntArray> Neighbors {
    5051      get { return NeighborsParameter.ActualValue; }
    5152      set { NeighborsParameter.ActualValue = value; }
     
    6061    protected TopologyInitializer(bool deserializing) : base(deserializing) { }
    6162    protected TopologyInitializer(TopologyInitializer original, Cloner cloner) : base(original, cloner) { }
     63   
    6264    public TopologyInitializer() {
    63       Parameters.Add(new ScopeTreeLookupParameter<IntegerVector>("Neighbors", "The list of neighbors for each particle."));
     65      Parameters.Add(new ScopeTreeLookupParameter<IntArray>("Neighbors", "The list of neighbors for each particle."));
    6466      Parameters.Add(new LookupParameter<IntValue>("SwarmSize", "Number of particles in the swarm."));
    6567    }
    6668    #endregion
    67 
    6869  }
    6970
  • branches/DataAnalysis Refactoring/HeuristicLab.Algorithms.ParticleSwarmOptimization/3.3/VonNeumannTopologyInitializer.cs

    r5445 r5796  
    2222using HeuristicLab.Common;
    2323using HeuristicLab.Core;
    24 using HeuristicLab.Encodings.IntegerVectorEncoding;
    2524using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
     25using HeuristicLab.Data;
    2626
    2727namespace HeuristicLab.Algorithms.ParticleSwarmOptimization {
     
    4444
    4545    public override IOperation Apply() {
    46       ItemArray<IntegerVector> neighbors = new ItemArray<IntegerVector>(SwarmSize);
     46      ItemArray<IntArray> neighbors = new ItemArray<IntArray>(SwarmSize);
    4747      for (int i = 0; i < SwarmSize; i++) {
    48         neighbors[i] = new IntegerVector(new[] {
     48        neighbors[i] = new IntArray(new[] {
    4949          (SwarmSize + i-2) % SwarmSize,
    5050          (SwarmSize + i-1) % SwarmSize,
Note: See TracChangeset for help on using the changeset viewer.