Free cookie consent management tool by TermsFeed Policy Generator

Changeset 3719


Ignore:
Timestamp:
05/08/10 16:33:50 (14 years ago)
Author:
mkofler
Message:

Worked on #852 (PSO)

Location:
trunk/sources
Files:
1 added
8 edited

Legend:

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

    r3682 r3719  
    8181
    8282    #region Properties
    83     [StorableAttribute]
     83    [Storable]
    8484    private ParticleSwarmOptimizationMainLoop mainLoop; // Check this !
    8585    private ParticleSwarmOptimizationMainLoop MainLoop {
    8686      get { return mainLoop; }
    8787    }
    88     [StorableAttribute]
     88    [Storable]
    8989    private Assigner bestLocalQualityInitalizer; // Check this !
    9090    private Assigner BestLocalQualityInitalizer {
    9191      get { return bestLocalQualityInitalizer; }
    9292    }
    93 
     93    [Storable]
    9494    private BestAverageWorstQualityAnalyzer qualityAnalyzer;
    9595    #endregion
     
    102102      Parameters.Add(new ValueParameter<IntValue>("MaxIterations", "Maximal number of iterations.", new IntValue(1000)));
    103103      Parameters.Add(new ConstrainedValueParameter<IRealVectorEncoder>("Encoder", "The operator used to encode solutions as position vector."));
    104       Parameters.Add(new ValueParameter<IntValue>("PositionLength", "Length of the position encoding.", new IntValue(0)));
    105104      Parameters.Add(new ValueParameter<MultiAnalyzer>("Analyzer", "The operator used to analyze each generation.", new MultiAnalyzer()));
    106105      RandomCreator randomCreator = new RandomCreator();
     
    181180      comparator.Successor = branch;
    182181      uniformSubScopesProcessor2.Successor = mainLoop;
     182      InitializeAnalyzers();
     183      UpdateAnalyzers();
    183184      Initialize();
    184185    }
     
    186187    [StorableHook(HookType.AfterDeserialization)]
    187188    private void Initialize() {
    188       InitializeAnalyzers();
    189       UpdateAnalyzers();
    190189      EncoderParameter.ValueChanged += new EventHandler(EncoderParameter_ValueChanged);
    191190      if (Problem != null) {
     
    211210      UpdateEncoders();
    212211      UpdateAnalyzers();
     212      ParameterizeAnalyzers();
    213213      bestLocalQualityInitalizer.RightSideParameter.ActualName = Problem.Evaluator.QualityParameter.ActualName;
    214214      Problem.Evaluator.QualityParameter.ActualNameChanged += new EventHandler(Evaluator_QualityParameter_ActualNameChanged);
     
    218218
    219219    private void EncoderParameter_ValueChanged(object sender, EventArgs e) {
    220       //IRealVectorEncoder old = (IRealVectorEncoder)((UniformSubScopesProcessor)((VariableCreator)((SolutionsCreator)((RandomCreator)OperatorGraph.InitialOperator).Successor).Successor).Successor).Operator;
     220      //MainLoop.EncoderParameter.ActualValue = (IRealVectorEncoder) EncoderParameter.ActualValue;
    221221      //((UniformSubScopesProcessor)((VariableCreator)((SolutionsCreator)((RandomCreator)OperatorGraph.InitialOperator).Successor).Successor).Successor).Operator = EncoderParameter.Value;
    222222      //((SingleSuccessorOperator)EncoderParameter.Value).Successor = ((SingleSuccessorOperator)old).Successor;
     
    228228      //
    229229      //
    230     }
    231 
    232     private void ParameterizeMainLoop() {
    233       //GeneticAlgorithmMainLoop.QualityParameter.ActualName = Problem.Evaluator.QualityParameter.ActualName;
    234230    }
    235231
  • trunk/sources/HeuristicLab.Algorithms.ParticleSwarmOptimization/3.3/ParticleSwarmOptimizationMainLoop.cs

    r3682 r3719  
    1212using HeuristicLab.Optimization.Operators;
    1313using HeuristicLab.Encodings.RealVectorEncoding;
     14using HeuristicLab.Optimization;
    1415
    1516namespace HeuristicLab.Algorithms.ParticleSwarmOptimization {
     
    2425      get { return (ValueLookupParameter<VariableCollection>)Parameters["Results"]; }
    2526    }
    26     public ValueLookupParameter<IOperator> EncoderParameter {
    27       get { return (ValueLookupParameter<IOperator>)Parameters["Encoder"]; }
     27    public ValueLookupParameter<IRealVectorEncoder> EncoderParameter {
     28      get { return (ValueLookupParameter<IRealVectorEncoder>)Parameters["Encoder"]; }
    2829    }
    2930    public ValueLookupParameter<IOperator> DecoderParameter {
     
    4748    #endregion
    4849
     50    [Storable]
     51    private ParticleUpdater velocityUpdater;
     52
    4953    [StorableConstructor]
    5054    private ParticleSwarmOptimizationMainLoop(bool deserializing) : base() { }
     
    5761      #region Create parameters
    5862      Parameters.Add(new ValueLookupParameter<VariableCollection>("Results", "The variable collection where results should be stored."));
    59       Parameters.Add(new ValueLookupParameter<IOperator>("Encoder", "The encoding operator that maps a solution to a position vector."));
     63      Parameters.Add(new ValueLookupParameter<IRealVectorEncoder>("Encoder", "The encoding operator that maps a solution to a position vector."));
    6064      Parameters.Add(new ValueLookupParameter<IOperator>("Decoder", "The decoding operator that maps a position vector to a solution."));
    6165      Parameters.Add(new ValueLookupParameter<BoolValue>("Maximization", "True if the problem is a maximization problem, otherwise false."));
     
    6670      #endregion
    6771
     72      EncoderParameter.ActualNameChanged += new EventHandler(EncoderParameter_ActualNameChanged);
     73
    6874      #region Create operators
    6975      VariableCreator variableCreator = new VariableCreator();
     
    7177      IntCounter intCounter = new IntCounter();
    7278      ConditionalBranch conditionalBranch = new ConditionalBranch();
    73       ParticleUpdater velocityUpdater = new ParticleUpdater();
     79      velocityUpdater = new ParticleUpdater();
    7480      UniformSubScopesProcessor uniformSubScopesProcessor = new UniformSubScopesProcessor();
    7581      UniformSubScopesProcessor uniformSubScopesProcessor2 = new UniformSubScopesProcessor();
     
    8490      analyzer1.OperatorParameter.ActualName = AnalyzerParameter.Name;
    8591
    86       variableCreator.CollectedValues.Add(new ValueParameter<IntValue>("Generations", new IntValue(1))); // Initial generation already built
     92      variableCreator.CollectedValues.Add(new ValueParameter<IntValue>("Generations", new IntValue(0))); // Initial generation already built
    8793
    8894      resultsCollector1.CollectedValues.Add(new LookupParameter<IntValue>("Generations"));
     
    103109      velocityUpdater.CurrentPositionParameter.ActualName = "Position";
    104110      velocityUpdater.VelocityParameter.ActualName = "Velocity";
     111      //
     112      // ToDo: Add correctly
    105113
    106114      encPlaceholder.OperatorParameter.ActualName = EncoderParameter.ActualName;
     
    116124      swarmUpdater.LocalBestQualityParameter.ActualName = "BestQuality";
    117125      swarmUpdater.GlobalBestQualityParameter.ActualName = "CurrentBestBestQuality";
    118 
    119126      #endregion
    120127
     
    125132      conditionalBranch.FalseBranch = uniformSubScopesProcessor;
    126133      uniformSubScopesProcessor.Operator = velocityUpdater;
     134      uniformSubScopesProcessor.Successor = intCounter;
    127135      velocityUpdater.Successor = decPlaceholder;
    128       uniformSubScopesProcessor.Successor = uniformSubScopesProcessor2;
    129       uniformSubScopesProcessor2.Operator = evaluator;
     136      decPlaceholder.Successor = evaluator;
    130137      evaluator.Successor = swarmUpdater;
    131       swarmUpdater.Successor = intCounter;
     138      swarmUpdater.Successor = null;
    132139      intCounter.Successor = resultsCollector1;
    133       resultsCollector1.Successor = comparator; //analyzer1;
    134       //analyzer1.Successor = comparator;
     140      resultsCollector1.Successor = analyzer1;
     141      analyzer1.Successor = comparator;
    135142      #endregion
     143    }
     144
     145    private void EncoderParameter_ActualNameChanged(object sender, EventArgs e) {
     146      velocityUpdater.BoundsParameter.ActualName = EncoderParameter.ActualValue.BoundsParameter.ActualName;
    136147    }
    137148  }
  • trunk/sources/HeuristicLab.Algorithms.ParticleSwarmOptimization/3.3/ParticleUpdater.cs

    r3682 r3719  
    3232      get { return (ILookupParameter<RealVector>)Parameters["BestGlobal"]; }
    3333    }
     34
     35    public ILookupParameter<DoubleMatrix> BoundsParameter {
     36      get { return (ILookupParameter<DoubleMatrix>)Parameters["Bounds"]; }
     37    }
    3438    #endregion
    3539
     
    4145      Parameters.Add(new LookupParameter<RealVector>("BestLocal", "Best local position"));
    4246      Parameters.Add(new LookupParameter<RealVector>("BestGlobal", "Best global position"));
     47      Parameters.Add(new LookupParameter<DoubleMatrix>("Bounds", "The lower and upper bounds for each dimension of the position vector."));
    4348    }
    4449
     
    5358      for (int i = 0; i < CurrentPositionParameter.ActualValue.Length; i++) {
    5459        CurrentPositionParameter.ActualValue[i] = CurrentPositionParameter.ActualValue[i] + VelocityParameter.ActualValue[i];
     60        if (CurrentPositionParameter.ActualValue[i] < BoundsParameter.ActualValue[0,0]) {
     61          CurrentPositionParameter.ActualValue[i] = BoundsParameter.ActualValue[0, 0];
     62        } else if (CurrentPositionParameter.ActualValue[i] > BoundsParameter.ActualValue[0,1]) {
     63          CurrentPositionParameter.ActualValue[i] = BoundsParameter.ActualValue[0, 1];
     64        }
    5565      }
    5666      return base.Apply();
  • trunk/sources/HeuristicLab.Algorithms.ParticleSwarmOptimization/3.3/PermutationToRealVectorEncoder.cs

    r3682 r3719  
    2828    }
    2929
     30    public IValueLookupParameter<DoubleMatrix> BoundsParameter {
     31      get { return (IValueLookupParameter<DoubleMatrix>)Parameters["Bounds"]; }
     32    }
     33
     34    public DoubleMatrix Bounds {
     35      get { return (DoubleMatrix)BoundsParameter.ActualValue; }
     36      set { BoundsParameter.ActualValue = value; }
     37    }
     38
    3039    public PermutationToRealVectorEncoder() : base() {
    3140      Parameters.Add(new LookupParameter<Permutation>("Permutation", "The permutation to encode."));
    3241      Parameters.Add(new LookupParameter<RealVector>("RealVector", "The resulting real vector."));
    3342      Parameters.Add(new LookupParameter<IntValue>("Length", "Vector length."));
     43      Parameters.Add(new ValueLookupParameter<DoubleMatrix>("Bounds", "The lower and upper bounds in each dimension."));
    3444    }
    3545
  • trunk/sources/HeuristicLab.Optimization/3.3/Interfaces/IRealVectorDecoder.cs

    r3682 r3719  
    1010    IParameter RealVectorParameter { get; }
    1111    ILookupParameter<IntValue> LengthParameter { get; }
     12    IValueParameter<DoubleMatrix> BoundsParameter { get; }
    1213  }
    1314}
  • trunk/sources/HeuristicLab.Optimization/3.3/Interfaces/IRealVectorEncoder.cs

    r3682 r3719  
    2727namespace HeuristicLab.Optimization {
    2828  public interface IRealVectorEncoder : IOperator {
    29     //Type DecoderType { get; }
    3029    IParameter RealVectorParameter { get; }
    3130    ILookupParameter<IntValue> LengthParameter { get; }
     31    IValueLookupParameter<DoubleMatrix> BoundsParameter { get; }
    3232  }
    3333}
  • trunk/sources/HeuristicLab.Problems.TestFunctions/3.3/HeuristicLab.Problems.TestFunctions-3.3.csproj

    r3702 r3719  
    101101    <Compile Include="Evaluators\ZakharovEvaluator.cs" />
    102102    <Compile Include="HeuristicLabProblemsTestFunctionsPlugin.cs" />
     103    <Compile Include="Interfaces\IRealVectorPSODecoder.cs" />
    103104    <Compile Include="Interfaces\IBestSingleObjectiveTestFunctionSolutionAnalyzer.cs" />
    104105    <Compile Include="Interfaces\IRastriginMoveEvaluator.cs" />
     
    123124    <Compile Include="MoveEvaluators\AdditiveMoveEvaluator.cs" />
    124125    <Compile Include="MoveEvaluators\RealVectorAdditiveMoveWrapper.cs" />
     126    <Compile Include="RealVectorToRealVectorDecoder.cs" />
     127    <Compile Include="RealVectorToRealVectorEncoder.cs" />
    125128    <Compile Include="SingleObjectiveTestFunctionSolution.cs" />
    126129    <Compile Include="SingleObjectiveTestFunctionProblem.cs" />
  • trunk/sources/HeuristicLab.Problems.TestFunctions/3.3/SingleObjectiveTestFunctionProblem.cs

    r3685 r3719  
    221221      if (Bounds.Columns != 2 || Bounds.Rows < 1)
    222222        Bounds = new DoubleMatrix(1, 2);
     223      ParameterizeOperators();
    223224    }
    224225    private void Bounds_ItemChanged(object sender, EventArgs<int, int> e) {
     
    227228      if (e.Value2 == 1 && Bounds[e.Value, 0] >= Bounds[e.Value, 1])
    228229        Bounds[e.Value, 0] = Bounds[e.Value, 1] - 0.1;
     230      ParameterizeOperators();
    229231    }
    230232    private void MoveGenerator_AdditiveMoveParameter_ActualNameChanged(object sender, EventArgs e) {
     
    355357      }
    356358      foreach (IRealVectorPSOEncoder op in Operators.OfType<IRealVectorPSOEncoder>()) {
    357         ((ILookupParameter)op.OriginalRealVectorParameter).ActualName = SolutionCreator.RealVectorParameter.ActualName;
     359        ((ILookupParameter)op.OriginalRealVectorParameter).ActualName = SolutionCreator.RealVectorParameter.ActualName;
     360        op.BoundsParameter.Value = (DoubleMatrix)BoundsParameter.Value.Clone();
     361        op.BoundsParameter.ActualName = "ParticleBounds";
    358362      }
    359363    }
Note: See TracChangeset for help on using the changeset viewer.