Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
01/17/11 16:50:15 (13 years ago)
Author:
mkofler
Message:

#852: Adjusted parameter modifiers as discussed in ticket.

Location:
branches/PSO/HeuristicLab.Algorithms.ParticleSwarmOptimization/3.3
Files:
2 added
2 deleted
2 edited

Legend:

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

    r5225 r5311  
    110110  <ItemGroup>
    111111    <Compile Include="BestPointInitializer.cs" />
    112     <Compile Include="WeightedValueModifierSelector.cs" />
    113     <Compile Include="ValueModifierSelector.cs" />
     112    <Compile Include="IDiscreteDoubleMatrixModifier.cs" />
     113    <Compile Include="VelocityBoundsModifier.cs" />
    114114    <Compile Include="RandomTopologyInitializer.cs" />
    115115    <Compile Include="VonNeumannTopologyInitializer.cs" />
  • branches/PSO/HeuristicLab.Algorithms.ParticleSwarmOptimization/3.3/ParticleSwarmOptimization.cs

    r5225 r5311  
    5454      set { AnalyzerParameter.Value = value; }
    5555    }
    56     public ValueModifierSelector OmegaUpdater {
     56    public IDiscreteDoubleValueModifier OmegaUpdater {
    5757      get { return OmegaUpdaterParameter.Value; }
    5858      set { OmegaUpdaterParameter.Value = value; }
    5959    }
    60     public WeightedValueModifierSelector VelocityBoundsUpdater {
     60    public IDiscreteDoubleMatrixModifier VelocityBoundsUpdater {
    6161      get { return VelocityBoundsUpdaterParameter.Value; }
    6262      set { VelocityBoundsUpdaterParameter.Value = value; }
     
    101101      get { return (ConstrainedValueParameter<ITopologyUpdater>)Parameters["TopologyUpdater"]; }
    102102    }
    103     public ValueParameter<WeightedValueModifierSelector> VelocityBoundsUpdaterParameter {
    104       get { return (ValueParameter<WeightedValueModifierSelector>)Parameters["VelocityBoundsUpdater"]; }
    105     }
    106     public ValueParameter<ValueModifierSelector> OmegaUpdaterParameter {
    107       get { return (ValueParameter<ValueModifierSelector>)Parameters["OmegaUpdater"]; }
     103    public OptionalConstrainedValueParameter<IDiscreteDoubleMatrixModifier> VelocityBoundsUpdaterParameter {
     104      get { return (OptionalConstrainedValueParameter<IDiscreteDoubleMatrixModifier>)Parameters["VelocityBoundsUpdater"]; }
     105    }
     106    public OptionalConstrainedValueParameter<IDiscreteDoubleValueModifier> OmegaUpdaterParameter {
     107      get { return (OptionalConstrainedValueParameter<IDiscreteDoubleValueModifier>)Parameters["OmegaUpdater"]; }
    108108    }
    109109    #endregion
     
    112112    [Storable]
    113113    private BestAverageWorstQualityAnalyzer qualityAnalyzer;
    114 
    115     //[Storable]
    116     //private IDiscreteDoubleValueModifier omegaModifier;
    117114    #endregion
    118115
     
    122119      : base(original, cloner) {
    123120      qualityAnalyzer = cloner.Clone(original.qualityAnalyzer);
    124       //omegaModifier = cloner.Clone(original.omegaModifier);
    125121    }
    126122
     
    144140      //Parameters.Add(new ValueParameter<MultiParameterUpdater>("ParameterUpdater", "Updates the algorithm parameters according to some strategy",
    145141      //  new MultiParameterUpdater()));
    146       Parameters.Add(new ValueParameter<ValueModifierSelector>("OmegaUpdater", "Updates the omega parameter", new ValueModifierSelector()));
    147       Parameters.Add(new ValueParameter<WeightedValueModifierSelector>("VelocityBoundsUpdater", "Adjusts the velocity bounds", new WeightedValueModifierSelector()));
     142      Parameters.Add(new OptionalConstrainedValueParameter<IDiscreteDoubleValueModifier>("OmegaUpdater", "Updates the omega parameter"));
     143      //Parameters.Add(new ValueParameter<MatrixValueModifierSelector>("VelocityBoundsUpdater", "Adjusts the velocity bounds", new MatrixValueModifierSelector()));
     144      Parameters.Add(new OptionalConstrainedValueParameter<IDiscreteDoubleMatrixModifier>("VelocityBoundsUpdater", "Adjusts the velocity bounds."));
    148145      ParticleUpdaterParameter.ActualValue = ParticleUpdaterParameter.ValidValues.SingleOrDefault(v => v.GetType() == typeof(TotallyConnectedParticleUpdater));
    149146      TopologyInitializerParameter.ActualValue = TopologyInitializerParameter.ValidValues.SingleOrDefault(v => v.GetType() == typeof(EmptyTopologyInitializer));
     
    254251
    255252      InitializeAnalyzers();
    256       InitializeUpdaters();
     253      InitVelocityBoundsUpdater();
    257254      UpdateAnalyzers();
     255      UpdateOmegaUpdater();
     256      InitOmegaUpdater();
    258257    }
    259258
     
    309308    }
    310309
    311     private void InitializeUpdaters() {
    312       OmegaUpdater.ValueParameter.ActualName = OmegaParameter.Name;
    313       foreach (IDiscreteDoubleValueModifier op in ApplicationManager.Manager.GetInstances<IDiscreteDoubleValueModifier>()) {
    314         OmegaUpdater.ModifierParameter.ValidValues.Add(op);
    315         op.EndIndexParameter.ActualName = MaxIterationsParameter.Name;
    316         op.StartIndexParameter.Value = new IntValue(0);
    317         op.IndexParameter.ActualName = "CurrentIteration";
    318         op.ValueParameter.ActualName = OmegaUpdater.ValueParameter.ActualName;
    319         op.StartValueParameter.Value = new DoubleValue(OmegaParameter.Value.Value);
    320         op.EndValueParameter.Value = new DoubleValue(-2);
    321       }
    322       VelocityBoundsUpdater.ValueParameter.ActualName = VelocityBoundsParameter.Name;
    323       foreach (IDiscreteDoubleValueModifier op in ApplicationManager.Manager.GetInstances<IDiscreteDoubleValueModifier>()) {
    324         VelocityBoundsUpdater.ModifierParameter.ValidValues.Add(op);
    325         op.EndIndexParameter.ActualName = MaxIterationsParameter.Name;
    326         op.StartIndexParameter.Value = new IntValue(0);
    327         op.IndexParameter.ActualName = "CurrentIteration";
    328         op.ValueParameter.ActualName = VelocityBoundsUpdater.ScaleParameter.Name;
    329         op.StartValueParameter.Value = new DoubleValue(VelocityBoundsUpdater.ScaleParameter.Value.Value);
    330         op.EndValueParameter.Value = new DoubleValue(0);
     310    private void InitVelocityBoundsUpdater() {
     311      foreach (IDiscreteDoubleMatrixModifier matrixOp in ApplicationManager.Manager.GetInstances<IDiscreteDoubleMatrixModifier>()) {
     312        VelocityBoundsUpdaterParameter.ValidValues.Add(matrixOp);
     313        matrixOp.ValueParameter.ActualName = VelocityBoundsParameter.Name;
     314        matrixOp.EndIndexParameter.ActualName = MaxIterationsParameter.Name;
     315        matrixOp.StartIndexParameter.Value = new IntValue(0);
     316        matrixOp.IndexParameter.ActualName = "CurrentIteration";
     317        matrixOp.EndValueParameter.Value = new DoubleValue(0);
     318      }
     319      VelocityBoundsUpdaterParameter.ValueChanged += new EventHandler(VelocityBoundsUpdaterParameter_ValueChanged);
     320    }
     321
     322    void VelocityBoundsUpdaterParameter_ValueChanged(object sender, EventArgs e) {
     323      if (VelocityBoundsParameter.Value != null) {
     324        foreach (IDiscreteDoubleMatrixModifier matrixOp in VelocityBoundsUpdaterParameter.Value.ScalingOperatorParameter.ValidValues) {
     325            matrixOp.ValueParameter.ActualName = VelocityBoundsUpdater.ScaleParameter.Name;
     326            matrixOp.StartValueParameter.Value = new DoubleValue(VelocityBoundsUpdater.ScaleParameter.ActualValue.Value);
    331327        }
     328      }
     329    }
     330
     331    private void InitOmegaUpdater() {
     332      foreach (IDiscreteDoubleValueModifier updater in OmegaUpdaterParameter.ValidValues) {
     333        updater.EndIndexParameter.ActualName = MaxIterationsParameter.Name;
     334        updater.StartIndexParameter.Value = new IntValue(0);
     335        updater.IndexParameter.ActualName = "CurrentIteration";
     336        updater.ValueParameter.ActualName = OmegaParameter.Name;
     337        updater.StartValueParameter.Value = new DoubleValue(1);
     338        updater.EndValueParameter.Value = new DoubleValue(0);
     339      }
     340    }
     341
     342    private void UpdateOmegaUpdater() {
     343      IDiscreteDoubleValueModifier oldOmegaUpdater = OmegaUpdater;
     344      OmegaUpdaterParameter.ValidValues.Clear();
     345      foreach (IDiscreteDoubleValueModifier updater in ApplicationManager.Manager.GetInstances<IDiscreteDoubleValueModifier>().OrderBy(x => x.Name)) {
     346        OmegaUpdaterParameter.ValidValues.Add(updater);
     347      }
     348      if (oldOmegaUpdater != null) {
     349        IDiscreteDoubleValueModifier updater = OmegaUpdaterParameter.ValidValues.FirstOrDefault(x => x.GetType() == oldOmegaUpdater.GetType());
     350        if (updater != null) OmegaUpdaterParameter.Value = updater;
     351      }
    332352    }
    333353
Note: See TracChangeset for help on using the changeset viewer.