Changeset 5866 for trunk/sources
- Timestamp:
- 03/29/11 15:19:20 (14 years ago)
- Location:
- trunk/sources
- Files:
-
- 1 deleted
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Algorithms.ParticleSwarmOptimization/3.3/HeuristicLab.Algorithms.ParticleSwarmOptimization-3.3.csproj
r5643 r5866 108 108 <Compile Include="MultiPSOTopologyUpdater.cs" /> 109 109 <Compile Include="ParticleSwarmOptimizationMainLoop.cs" /> 110 <Compile Include="VelocityBoundsModifier.cs" />111 110 <Compile Include="RandomTopologyInitializer.cs" /> 112 111 <Compile Include="VonNeumannTopologyInitializer.cs" /> -
trunk/sources/HeuristicLab.Algorithms.ParticleSwarmOptimization/3.3/ParticleSwarmOptimization.cs
r5844 r5866 163 163 Parameters.Add(new OptionalConstrainedValueParameter<IDiscreteDoubleValueModifier>("InertiaUpdater", "Updates the omega parameter.")); 164 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")); 165 ParticleUpdaterParameter.Hidden = true; 165 166 166 167 RandomCreator randomCreator = new RandomCreator(); 167 168 VariableCreator variableCreator = new VariableCreator(); 168 Assigner assigner = new Assigner();169 Assigner currentInertiaAssigner = new Assigner(); 169 170 solutionsCreator = new SolutionsCreator(); 170 171 SubScopesCounter subScopesCounter = new SubScopesCounter(); 171 172 Placeholder topologyInitializerPlaceholder = new Placeholder(); 172 Placeholder analyzerPlaceholder = new Placeholder();173 173 mainLoop = new ParticleSwarmOptimizationMainLoop(); 174 174 … … 180 180 181 181 variableCreator.CollectedValues.Add(new ValueParameter<IntValue>("CurrentIteration", new IntValue(0))); 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; 182 variableCreator.Successor = currentInertiaAssigner; 183 184 currentInertiaAssigner.Name = "CurrentInertia := Inertia"; 185 currentInertiaAssigner.LeftSideParameter.ActualName = "CurrentInertia"; 186 currentInertiaAssigner.RightSideParameter.ActualName = "Inertia"; 187 currentInertiaAssigner.Successor = solutionsCreator; 189 188 190 189 solutionsCreator.NumberOfSolutionsParameter.ActualName = "SwarmSize"; -
trunk/sources/HeuristicLab.Algorithms.ParticleSwarmOptimization/3.3/ParticleSwarmOptimizationMainLoop.cs
r5645 r5866 56 56 get { return (IValueLookupParameter<DoubleValue>)Parameters["NeighborBestAttraction"]; } 57 57 } 58 public IValueLookupParameter<DoubleMatrix> VelocityBoundsParameter {59 get { return (IValueLookupParameter<DoubleMatrix>)Parameters["VelocityBounds"]; }60 }61 58 public IValueLookupParameter<IOperator> ParticleUpdaterParameter { 62 59 get { return (IValueLookupParameter<IOperator>)Parameters["ParticleUpdater"]; } … … 128 125 Placeholder particleUpdaterPlaceholder = new Placeholder(); 129 126 Placeholder topologyUpdaterPlaceholder = new Placeholder(); 130 UniformSubScopesProcessor uniformSubscopesProcessor2 = new UniformSubScopesProcessor();131 127 UniformSubScopesProcessor evaluationProcessor = new UniformSubScopesProcessor(); 132 128 Placeholder swarmUpdater = new Placeholder(); … … 134 130 Comparator currentIterationComparator = new Comparator(); 135 131 ConditionalBranch conditionalBranch = new ConditionalBranch(); 136 Placeholder velocityBoundsUpdaterPlaceholder = new Placeholder();137 132 Placeholder inertiaUpdaterPlaceholder = new Placeholder(); 138 133 SubScopesCounter subScopesCounter = new SubScopesCounter(); … … 176 171 topologyUpdaterPlaceholder.Successor = swarmUpdater; 177 172 178 swarmUpdater.Name = " Swarm Updater";173 swarmUpdater.Name = "(Swarm Updater)"; 179 174 swarmUpdater.OperatorParameter.ActualName = SwarmUpdaterParameter.ActualName; 180 175 swarmUpdater.Successor = inertiaUpdaterPlaceholder; -
trunk/sources/HeuristicLab.Encodings.RealVectorEncoding/3.3/Interfaces/IRealVectorParticleUpdater.cs
r5568 r5866 27 27 public interface IRealVectorParticleUpdater : IParticleUpdater, IRealVectorOperator { 28 28 ILookupParameter<RealVector> VelocityParameter { get; } 29 ILookupParameter<DoubleMatrix> VelocityBoundsParameter { get; }29 ILookupParameter<DoubleMatrix> CurrentVelocityBoundsParameter { get; } 30 30 ILookupParameter<RealVector> RealVectorParameter { get; } 31 31 ILookupParameter<DoubleMatrix> BoundsParameter { get; } -
trunk/sources/HeuristicLab.Encodings.RealVectorEncoding/3.3/ParticleOperators/RealVectorNeighborhoodParticleUpdater.cs
r5592 r5866 57 57 } 58 58 59 BoundsChecker.Apply(velocity, VelocityBounds);59 BoundsChecker.Apply(velocity, CurrentVelocityBounds); 60 60 for (int i = 0; i < velocity.Length; i++) { 61 61 position[i] = RealVector[i] + velocity[i]; -
trunk/sources/HeuristicLab.Encodings.RealVectorEncoding/3.3/ParticleOperators/RealVectorParticleUpdater.cs
r5645 r5866 59 59 get { return (ILookupParameter<DoubleMatrix>)Parameters["Bounds"]; } 60 60 } 61 public ILookupParameter<DoubleMatrix> VelocityBoundsParameter {62 get { return (ILookupParameter<DoubleMatrix>)Parameters[" VelocityBounds"]; }61 public ILookupParameter<DoubleMatrix> CurrentVelocityBoundsParameter { 62 get { return (ILookupParameter<DoubleMatrix>)Parameters["CurrentVelocityBounds"]; } 63 63 } 64 64 public ILookupParameter<DoubleValue> InertiaParameter { … … 97 97 get { return BoundsParameter.ActualValue; } 98 98 } 99 protected DoubleMatrix VelocityBounds {100 get { return VelocityBoundsParameter.ActualValue; }99 protected DoubleMatrix CurrentVelocityBounds { 100 get { return CurrentVelocityBoundsParameter.ActualValue; } 101 101 } 102 102 protected DoubleValue Inertia { … … 124 124 Parameters.Add(new LookupParameter<RealVector>("NeighborBest", "Best neighboring solution.")); 125 125 Parameters.Add(new LookupParameter<DoubleMatrix>("Bounds", "The lower and upper bounds for each dimension of the position vector for the current problem.")); 126 Parameters.Add(new LookupParameter<DoubleMatrix>(" VelocityBounds", "Upper and lower bounds for the particle's velocity vector."));126 Parameters.Add(new LookupParameter<DoubleMatrix>("CurrentVelocityBounds", "Upper and lower bounds for the particle's velocity vector.")); 127 127 Parameters.Add(new LookupParameter<DoubleValue>("CurrentInertia", "The weight for the particle's velocity vector.")); 128 128 Parameters.Add(new LookupParameter<DoubleValue>("PersonalBestAttraction", "The weight for the particle's personal best position.")); -
trunk/sources/HeuristicLab.Encodings.RealVectorEncoding/3.3/ParticleOperators/RealVectorSwarmUpdater.cs
r5643 r5866 26 26 using HeuristicLab.Operators; 27 27 using HeuristicLab.Optimization; 28 using HeuristicLab.Optimization.Operators; 28 29 using HeuristicLab.Parameters; 29 30 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 31 using HeuristicLab.PluginInfrastructure; 30 32 31 33 namespace HeuristicLab.Encodings.RealVectorEncoding { … … 34 36 public sealed class RealVectorSwarmUpdater : SingleSuccessorOperator, IRealVectorSwarmUpdater { 35 37 38 [Storable] 39 private ResultsCollector ResultsCollector; 40 36 41 public override bool CanChangeName { 37 42 get { return false; } … … 69 74 get { return (IScopeTreeLookupParameter<IntArray>)Parameters["Neighbors"]; } 70 75 } 71 public ValueLookupParameter<IDiscreteDoubleMatrixModifier> VelocityBoundsUpdaterParameter { 72 get { return (ValueLookupParameter<IDiscreteDoubleMatrixModifier>)Parameters["VelocityBoundsUpdater"]; } 73 } 74 public LookupParameter<DoubleMatrix> VelocityBoundsParameter { 75 get { return (LookupParameter<DoubleMatrix>)Parameters["VelocityBounds"]; } 76 } 76 public IValueLookupParameter<DoubleMatrix> VelocityBoundsParameter { 77 get { return (ValueLookupParameter<DoubleMatrix>)Parameters["VelocityBounds"]; } 78 } 79 public ILookupParameter<DoubleMatrix> CurrentVelocityBoundsParameter { 80 get { return (ILookupParameter<DoubleMatrix>)Parameters["CurrentVelocityBounds"]; } 81 } 82 public LookupParameter<ResultCollection> ResultsParameter { 83 get { return (LookupParameter<ResultCollection>)Parameters["Results"]; } 84 } 85 86 #region Velocity Bounds Updating 87 public ILookupParameter<DoubleValue> VelocityBoundsScaleParameter { 88 get { return (ILookupParameter<DoubleValue>)Parameters["VelocityBoundsScale"]; } 89 } 90 public OptionalConstrainedValueParameter<IDiscreteDoubleValueModifier> VelocityBoundsScalingOperatorParameter { 91 get { return (OptionalConstrainedValueParameter<IDiscreteDoubleValueModifier>)Parameters["VelocityBoundsScalingOperator"]; } 92 } 93 public IValueLookupParameter<DoubleValue> VelocityBoundsStartValueParameter { 94 get { return (IValueLookupParameter<DoubleValue>)Parameters["VelocityBoundsStartValue"]; } 95 } 96 public IValueLookupParameter<DoubleValue> VelocityBoundsEndValueParameter { 97 get { return (IValueLookupParameter<DoubleValue>)Parameters["VelocityBoundsEndValue"]; } 98 } 99 public ILookupParameter<IntValue> VelocityBoundsIndexParameter { 100 get { return (ILookupParameter<IntValue>)Parameters["VelocityBoundsIndex"]; } 101 } 102 public IValueLookupParameter<IntValue> VelocityBoundsStartIndexParameter { 103 get { return (IValueLookupParameter<IntValue>)Parameters["VelocityBoundsStartIndex"]; } 104 } 105 public IValueLookupParameter<IntValue> VelocityBoundsEndIndexParameter { 106 get { return (IValueLookupParameter<IntValue>)Parameters["VelocityBoundsEndIndex"]; } 107 } 108 #endregion 109 77 110 #endregion 78 111 … … 114 147 get { return NeighborsParameter.ActualValue; } 115 148 } 116 private IDiscreteDoubleMatrixModifier VelocityBoundsUpdater {117 get { return VelocityBoundsUpdaterParameter.ActualValue; }118 }119 149 private DoubleMatrix VelocityBounds { 120 150 get { return VelocityBoundsParameter.ActualValue; } 121 set { VelocityBoundsParameter.ActualValue = value; } 151 } 152 private DoubleMatrix CurrentVelocityBounds { 153 get { return CurrentVelocityBoundsParameter.ActualValue; } 154 set { CurrentVelocityBoundsParameter.ActualValue = value; } 155 } 156 private DoubleValue VelocityBoundsScale { 157 get { return VelocityBoundsScaleParameter.ActualValue; } 158 set { VelocityBoundsScaleParameter.ActualValue = value; } 159 } 160 private DoubleValue VelocityBoundsStartValue { 161 get { return VelocityBoundsStartValueParameter.ActualValue; } 162 } 163 private IDiscreteDoubleValueModifier VelocityBoundsScalingOperator { 164 get { return VelocityBoundsScalingOperatorParameter.Value; } 165 } 166 private ResultCollection Results { 167 get { return ResultsParameter.ActualValue; } 122 168 } 123 169 #endregion … … 127 173 [StorableConstructor] 128 174 private RealVectorSwarmUpdater(bool deserializing) : base(deserializing) { } 129 private RealVectorSwarmUpdater(RealVectorSwarmUpdater original, Cloner cloner) : base(original, cloner) { } 175 private RealVectorSwarmUpdater(RealVectorSwarmUpdater original, Cloner cloner) 176 : base(original, cloner) { 177 ResultsCollector = cloner.Clone(original.ResultsCollector); 178 } 130 179 public RealVectorSwarmUpdater() 131 180 : base() { … … 140 189 Parameters.Add(new ScopeTreeLookupParameter<IntArray>("Neighbors", "The list of neighbors for each particle.")); 141 190 Parameters.Add(new LookupParameter<BoolValue>("Maximization", "True if the problem is a maximization problem, otherwise false.")); 142 Parameters.Add(new ValueLookupParameter<IDiscreteDoubleMatrixModifier>("VelocityBoundsUpdater", "Modifies the velocity bounds in the course of optimization.")); 143 Parameters.Add(new LookupParameter<DoubleMatrix>("VelocityBounds", "Maximum velocity for each dimension.")); 191 Parameters.Add(new ValueLookupParameter<DoubleMatrix>("VelocityBounds", "Maximum velocity for each dimension.", new DoubleMatrix(new double[,] { { -1, 1 } }))); 192 Parameters.Add(new LookupParameter<DoubleMatrix>("CurrentVelocityBounds", "Current value of velocity bounds.")); 193 Parameters.Add(new LookupParameter<ResultCollection>("Results", "Results")); 194 195 #region Velocity Bounds Updating 196 Parameters.Add(new LookupParameter<DoubleValue>("VelocityBoundsScale", "Scale parameter.")); 197 Parameters.Add(new OptionalConstrainedValueParameter<IDiscreteDoubleValueModifier>("VelocityBoundsScalingOperator", "Modifies the value")); 198 Parameters.Add(new ValueLookupParameter<DoubleValue>("VelocityBoundsStartValue", "The start value of 'Value'.", new DoubleValue(1))); 199 Parameters.Add(new ValueLookupParameter<DoubleValue>("VelocityBoundsEndValue", "The end value of 'Value'.", new DoubleValue(1E-10))); 200 Parameters.Add(new LookupParameter<IntValue>("VelocityBoundsIndex", "The current index.", "CurrentIteration")); 201 Parameters.Add(new ValueLookupParameter<IntValue>("VelocityBoundsStartIndex", "The start index at which to start modifying 'Value'.", new IntValue(0))); 202 Parameters.Add(new ValueLookupParameter<IntValue>("VelocityBoundsEndIndex", "The end index by which 'Value' should have reached 'EndValue'.", "MaxIterations")); 203 VelocityBoundsStartIndexParameter.Hidden = true; 204 VelocityBoundsEndIndexParameter.Hidden = true; 205 #endregion 206 207 Initialize(); 144 208 } 145 209 … … 149 213 150 214 #endregion 215 216 private void Initialize() { 217 ResultsCollector = new ResultsCollector(); 218 ResultsCollector.CollectedValues.Add(CurrentVelocityBoundsParameter); 219 ResultsCollector.CollectedValues.Add(VelocityBoundsParameter); 220 221 foreach (IDiscreteDoubleValueModifier op in ApplicationManager.Manager.GetInstances<IDiscreteDoubleValueModifier>()) { 222 VelocityBoundsScalingOperatorParameter.ValidValues.Add(op); 223 op.ValueParameter.ActualName = VelocityBoundsScaleParameter.Name; 224 op.StartValueParameter.ActualName = VelocityBoundsStartValueParameter.Name; 225 op.EndValueParameter.ActualName = VelocityBoundsEndValueParameter.Name; 226 op.IndexParameter.ActualName = VelocityBoundsIndexParameter.Name; 227 op.StartIndexParameter.ActualName = VelocityBoundsStartIndexParameter.Name; 228 op.EndIndexParameter.ActualName = VelocityBoundsEndIndexParameter.Name; 229 } 230 VelocityBoundsScalingOperatorParameter.Value = null; 231 } 151 232 152 233 public override IOperation Apply() { … … 194 275 } 195 276 277 278 196 279 private IOperation UpdateVelocityBounds() { 197 if ( VelocityBounds == null)198 VelocityBounds = new DoubleMatrix(new double[,] { { -1, 1 } });199 return VelocityBoundsUpdater == null ? 200 base.Apply() :201 new OperationCollection() {202 ExecutionContext.CreateChildOperation( VelocityBoundsUpdater),203 ExecutionContext.CreateOperation(Successor)280 if (CurrentVelocityBounds == null) 281 CurrentVelocityBounds = (DoubleMatrix)VelocityBounds.Clone(); 282 283 if (VelocityBoundsScalingOperator == null) 284 return new OperationCollection() { 285 ExecutionContext.CreateChildOperation(ResultsCollector), 286 base.Apply() 204 287 }; 288 289 290 DoubleMatrix matrix = CurrentVelocityBounds; 291 if (VelocityBoundsScale == null && VelocityBoundsStartValue != null) { 292 VelocityBoundsScale = new DoubleValue(VelocityBoundsStartValue.Value); 293 } 294 for (int i = 0; i < matrix.Rows; i++) { 295 for (int j = 0; j < matrix.Columns; j++) { 296 if (matrix[i, j] >= 0) { 297 matrix[i, j] = VelocityBoundsScale.Value; 298 } else { 299 matrix[i, j] = (-1) * VelocityBoundsScale.Value; 300 } 301 } 302 } 303 304 return new OperationCollection() { 305 ExecutionContext.CreateChildOperation(ResultsCollector), 306 ExecutionContext.CreateChildOperation(VelocityBoundsScalingOperator), 307 base.Apply() 308 }; 205 309 } 206 310 } -
trunk/sources/HeuristicLab.Encodings.RealVectorEncoding/3.3/ParticleOperators/RealVectorTotallyConnectedParticleUpdater.cs
r5592 r5866 57 57 } 58 58 59 BoundsChecker.Apply(velocity, VelocityBounds);59 BoundsChecker.Apply(velocity, CurrentVelocityBounds); 60 60 for (int i = 0; i < velocity.Length; i++) { 61 61 position[i] = RealVector[i] + velocity[i];
Note: See TracChangeset
for help on using the changeset viewer.