Changeset 3719 for trunk/sources
- Timestamp:
- 05/08/10 16:33:50 (15 years ago)
- Location:
- trunk/sources
- Files:
-
- 1 added
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Algorithms.ParticleSwarmOptimization/3.3/ParticleSwarmOptimization.cs
r3682 r3719 81 81 82 82 #region Properties 83 [Storable Attribute]83 [Storable] 84 84 private ParticleSwarmOptimizationMainLoop mainLoop; // Check this ! 85 85 private ParticleSwarmOptimizationMainLoop MainLoop { 86 86 get { return mainLoop; } 87 87 } 88 [Storable Attribute]88 [Storable] 89 89 private Assigner bestLocalQualityInitalizer; // Check this ! 90 90 private Assigner BestLocalQualityInitalizer { 91 91 get { return bestLocalQualityInitalizer; } 92 92 } 93 93 [Storable] 94 94 private BestAverageWorstQualityAnalyzer qualityAnalyzer; 95 95 #endregion … … 102 102 Parameters.Add(new ValueParameter<IntValue>("MaxIterations", "Maximal number of iterations.", new IntValue(1000))); 103 103 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)));105 104 Parameters.Add(new ValueParameter<MultiAnalyzer>("Analyzer", "The operator used to analyze each generation.", new MultiAnalyzer())); 106 105 RandomCreator randomCreator = new RandomCreator(); … … 181 180 comparator.Successor = branch; 182 181 uniformSubScopesProcessor2.Successor = mainLoop; 182 InitializeAnalyzers(); 183 UpdateAnalyzers(); 183 184 Initialize(); 184 185 } … … 186 187 [StorableHook(HookType.AfterDeserialization)] 187 188 private void Initialize() { 188 InitializeAnalyzers();189 UpdateAnalyzers();190 189 EncoderParameter.ValueChanged += new EventHandler(EncoderParameter_ValueChanged); 191 190 if (Problem != null) { … … 211 210 UpdateEncoders(); 212 211 UpdateAnalyzers(); 212 ParameterizeAnalyzers(); 213 213 bestLocalQualityInitalizer.RightSideParameter.ActualName = Problem.Evaluator.QualityParameter.ActualName; 214 214 Problem.Evaluator.QualityParameter.ActualNameChanged += new EventHandler(Evaluator_QualityParameter_ActualNameChanged); … … 218 218 219 219 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; 221 221 //((UniformSubScopesProcessor)((VariableCreator)((SolutionsCreator)((RandomCreator)OperatorGraph.InitialOperator).Successor).Successor).Successor).Operator = EncoderParameter.Value; 222 222 //((SingleSuccessorOperator)EncoderParameter.Value).Successor = ((SingleSuccessorOperator)old).Successor; … … 228 228 // 229 229 // 230 }231 232 private void ParameterizeMainLoop() {233 //GeneticAlgorithmMainLoop.QualityParameter.ActualName = Problem.Evaluator.QualityParameter.ActualName;234 230 } 235 231 -
trunk/sources/HeuristicLab.Algorithms.ParticleSwarmOptimization/3.3/ParticleSwarmOptimizationMainLoop.cs
r3682 r3719 12 12 using HeuristicLab.Optimization.Operators; 13 13 using HeuristicLab.Encodings.RealVectorEncoding; 14 using HeuristicLab.Optimization; 14 15 15 16 namespace HeuristicLab.Algorithms.ParticleSwarmOptimization { … … 24 25 get { return (ValueLookupParameter<VariableCollection>)Parameters["Results"]; } 25 26 } 26 public ValueLookupParameter<I Operator> EncoderParameter {27 get { return (ValueLookupParameter<I Operator>)Parameters["Encoder"]; }27 public ValueLookupParameter<IRealVectorEncoder> EncoderParameter { 28 get { return (ValueLookupParameter<IRealVectorEncoder>)Parameters["Encoder"]; } 28 29 } 29 30 public ValueLookupParameter<IOperator> DecoderParameter { … … 47 48 #endregion 48 49 50 [Storable] 51 private ParticleUpdater velocityUpdater; 52 49 53 [StorableConstructor] 50 54 private ParticleSwarmOptimizationMainLoop(bool deserializing) : base() { } … … 57 61 #region Create parameters 58 62 Parameters.Add(new ValueLookupParameter<VariableCollection>("Results", "The variable collection where results should be stored.")); 59 Parameters.Add(new ValueLookupParameter<I Operator>("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.")); 60 64 Parameters.Add(new ValueLookupParameter<IOperator>("Decoder", "The decoding operator that maps a position vector to a solution.")); 61 65 Parameters.Add(new ValueLookupParameter<BoolValue>("Maximization", "True if the problem is a maximization problem, otherwise false.")); … … 66 70 #endregion 67 71 72 EncoderParameter.ActualNameChanged += new EventHandler(EncoderParameter_ActualNameChanged); 73 68 74 #region Create operators 69 75 VariableCreator variableCreator = new VariableCreator(); … … 71 77 IntCounter intCounter = new IntCounter(); 72 78 ConditionalBranch conditionalBranch = new ConditionalBranch(); 73 ParticleUpdatervelocityUpdater = new ParticleUpdater();79 velocityUpdater = new ParticleUpdater(); 74 80 UniformSubScopesProcessor uniformSubScopesProcessor = new UniformSubScopesProcessor(); 75 81 UniformSubScopesProcessor uniformSubScopesProcessor2 = new UniformSubScopesProcessor(); … … 84 90 analyzer1.OperatorParameter.ActualName = AnalyzerParameter.Name; 85 91 86 variableCreator.CollectedValues.Add(new ValueParameter<IntValue>("Generations", new IntValue( 1))); // Initial generation already built92 variableCreator.CollectedValues.Add(new ValueParameter<IntValue>("Generations", new IntValue(0))); // Initial generation already built 87 93 88 94 resultsCollector1.CollectedValues.Add(new LookupParameter<IntValue>("Generations")); … … 103 109 velocityUpdater.CurrentPositionParameter.ActualName = "Position"; 104 110 velocityUpdater.VelocityParameter.ActualName = "Velocity"; 111 // 112 // ToDo: Add correctly 105 113 106 114 encPlaceholder.OperatorParameter.ActualName = EncoderParameter.ActualName; … … 116 124 swarmUpdater.LocalBestQualityParameter.ActualName = "BestQuality"; 117 125 swarmUpdater.GlobalBestQualityParameter.ActualName = "CurrentBestBestQuality"; 118 119 126 #endregion 120 127 … … 125 132 conditionalBranch.FalseBranch = uniformSubScopesProcessor; 126 133 uniformSubScopesProcessor.Operator = velocityUpdater; 134 uniformSubScopesProcessor.Successor = intCounter; 127 135 velocityUpdater.Successor = decPlaceholder; 128 uniformSubScopesProcessor.Successor = uniformSubScopesProcessor2; 129 uniformSubScopesProcessor2.Operator = evaluator; 136 decPlaceholder.Successor = evaluator; 130 137 evaluator.Successor = swarmUpdater; 131 swarmUpdater.Successor = intCounter;138 swarmUpdater.Successor = null; 132 139 intCounter.Successor = resultsCollector1; 133 resultsCollector1.Successor = comparator; //analyzer1;134 //analyzer1.Successor = comparator;140 resultsCollector1.Successor = analyzer1; 141 analyzer1.Successor = comparator; 135 142 #endregion 143 } 144 145 private void EncoderParameter_ActualNameChanged(object sender, EventArgs e) { 146 velocityUpdater.BoundsParameter.ActualName = EncoderParameter.ActualValue.BoundsParameter.ActualName; 136 147 } 137 148 } -
trunk/sources/HeuristicLab.Algorithms.ParticleSwarmOptimization/3.3/ParticleUpdater.cs
r3682 r3719 32 32 get { return (ILookupParameter<RealVector>)Parameters["BestGlobal"]; } 33 33 } 34 35 public ILookupParameter<DoubleMatrix> BoundsParameter { 36 get { return (ILookupParameter<DoubleMatrix>)Parameters["Bounds"]; } 37 } 34 38 #endregion 35 39 … … 41 45 Parameters.Add(new LookupParameter<RealVector>("BestLocal", "Best local position")); 42 46 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.")); 43 48 } 44 49 … … 53 58 for (int i = 0; i < CurrentPositionParameter.ActualValue.Length; i++) { 54 59 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 } 55 65 } 56 66 return base.Apply(); -
trunk/sources/HeuristicLab.Algorithms.ParticleSwarmOptimization/3.3/PermutationToRealVectorEncoder.cs
r3682 r3719 28 28 } 29 29 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 30 39 public PermutationToRealVectorEncoder() : base() { 31 40 Parameters.Add(new LookupParameter<Permutation>("Permutation", "The permutation to encode.")); 32 41 Parameters.Add(new LookupParameter<RealVector>("RealVector", "The resulting real vector.")); 33 42 Parameters.Add(new LookupParameter<IntValue>("Length", "Vector length.")); 43 Parameters.Add(new ValueLookupParameter<DoubleMatrix>("Bounds", "The lower and upper bounds in each dimension.")); 34 44 } 35 45 -
trunk/sources/HeuristicLab.Optimization/3.3/Interfaces/IRealVectorDecoder.cs
r3682 r3719 10 10 IParameter RealVectorParameter { get; } 11 11 ILookupParameter<IntValue> LengthParameter { get; } 12 IValueParameter<DoubleMatrix> BoundsParameter { get; } 12 13 } 13 14 } -
trunk/sources/HeuristicLab.Optimization/3.3/Interfaces/IRealVectorEncoder.cs
r3682 r3719 27 27 namespace HeuristicLab.Optimization { 28 28 public interface IRealVectorEncoder : IOperator { 29 //Type DecoderType { get; }30 29 IParameter RealVectorParameter { get; } 31 30 ILookupParameter<IntValue> LengthParameter { get; } 31 IValueLookupParameter<DoubleMatrix> BoundsParameter { get; } 32 32 } 33 33 } -
trunk/sources/HeuristicLab.Problems.TestFunctions/3.3/HeuristicLab.Problems.TestFunctions-3.3.csproj
r3702 r3719 101 101 <Compile Include="Evaluators\ZakharovEvaluator.cs" /> 102 102 <Compile Include="HeuristicLabProblemsTestFunctionsPlugin.cs" /> 103 <Compile Include="Interfaces\IRealVectorPSODecoder.cs" /> 103 104 <Compile Include="Interfaces\IBestSingleObjectiveTestFunctionSolutionAnalyzer.cs" /> 104 105 <Compile Include="Interfaces\IRastriginMoveEvaluator.cs" /> … … 123 124 <Compile Include="MoveEvaluators\AdditiveMoveEvaluator.cs" /> 124 125 <Compile Include="MoveEvaluators\RealVectorAdditiveMoveWrapper.cs" /> 126 <Compile Include="RealVectorToRealVectorDecoder.cs" /> 127 <Compile Include="RealVectorToRealVectorEncoder.cs" /> 125 128 <Compile Include="SingleObjectiveTestFunctionSolution.cs" /> 126 129 <Compile Include="SingleObjectiveTestFunctionProblem.cs" /> -
trunk/sources/HeuristicLab.Problems.TestFunctions/3.3/SingleObjectiveTestFunctionProblem.cs
r3685 r3719 221 221 if (Bounds.Columns != 2 || Bounds.Rows < 1) 222 222 Bounds = new DoubleMatrix(1, 2); 223 ParameterizeOperators(); 223 224 } 224 225 private void Bounds_ItemChanged(object sender, EventArgs<int, int> e) { … … 227 228 if (e.Value2 == 1 && Bounds[e.Value, 0] >= Bounds[e.Value, 1]) 228 229 Bounds[e.Value, 0] = Bounds[e.Value, 1] - 0.1; 230 ParameterizeOperators(); 229 231 } 230 232 private void MoveGenerator_AdditiveMoveParameter_ActualNameChanged(object sender, EventArgs e) { … … 355 357 } 356 358 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"; 358 362 } 359 363 }
Note: See TracChangeset
for help on using the changeset viewer.