Changeset 16657


Ignore:
Timestamp:
03/07/19 16:15:04 (4 months ago)
Author:
bburlacu
Message:

#2987: Improve performance by caching parameter values. Fix plugin dependencies Plugin.cs.frame

Location:
branches/2987_MOEAD_Algorithm/HeuristicLab.Algorithms.MOEAD/3.4
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • branches/2987_MOEAD_Algorithm/HeuristicLab.Algorithms.MOEAD/3.4/MOEADAlgorithm.cs

    r16630 r16657  
    6060      var neighbourhoodSelectionProbability = NeighbourhoodSelectionProbability;
    6161      var rand = RandomParameter.Value;
     62      var normalizeObjectives = NormalizeObjectives;
     63      var maximumNumberOfReplacedSolutions = MaximumNumberOfReplacedSolutions;
    6264
    6365      // cancellation token for the inner operations which should not be immediately cancelled
     
    103105            NadirPoint.UpdateNadir(childSolution.Qualities);
    104106            // update neighbourhood will insert the child into the population
    105             UpdateNeighbourHood(rand, childSolution, subProblemId, neighbourType);
     107            UpdateNeighbourHood(rand, childSolution, subProblemId, neighbourType, maximumNumberOfReplacedSolutions, normalizeObjectives);
    106108
    107109            ++evaluatedSolutions;
  • branches/2987_MOEAD_Algorithm/HeuristicLab.Algorithms.MOEAD/3.4/MOEADAlgorithmBase.cs

    r16649 r16657  
    166166    public new IMultiObjectiveHeuristicOptimizationProblem Problem {
    167167      get { return (IMultiObjectiveHeuristicOptimizationProblem)base.Problem; }
     168      set { base.Problem = value; }
    168169    }
    169170    public int Seed {
     
    472473    }
    473474
    474     protected void UpdateNeighbourHood(IRandom random, IMOEADSolution individual, int subProblemId, NeighborType neighbourType) {
     475    protected void UpdateNeighbourHood(IRandom random, IMOEADSolution individual, int subProblemId, NeighborType neighbourType, int maximumNumberOfReplacedSolutions, bool normalizeObjectives = false) {
    475476      int replacedSolutions = 0;
    476477      int size = neighbourType == NeighborType.NEIGHBOR ? NeighbourSize : population.Length;
     
    481482          : i;
    482483
    483         double f1 = CalculateFitness(population[k].Qualities, lambda[k]);
    484         double f2 = CalculateFitness(individual.Qualities, lambda[k]);
     484        double f1 = CalculateFitness(population[k].Qualities, lambda[k], normalizeObjectives);
     485        double f2 = CalculateFitness(individual.Qualities, lambda[k], normalizeObjectives);
    485486
    486487        if (f2 < f1) {
     
    489490        }
    490491
    491         if (replacedSolutions >= MaximumNumberOfReplacedSolutions) {
     492        if (replacedSolutions >= maximumNumberOfReplacedSolutions) {
    492493          return;
    493494        }
     
    495496    }
    496497
    497     private double CalculateFitness(double[] qualities, double[] lambda) {
     498    private double CalculateFitness(double[] qualities, double[] lambda, bool normalizeObjectives = false) {
    498499      int dim = qualities.Length;
    499500      switch (functionType) {
     
    502503
    503504            for (int n = 0; n < dim; n++) {
    504               var diff = qualities[n] - IdealPoint[n];
    505               if (NormalizeObjectives) {
    506                 diff /= NadirPoint[n] - IdealPoint[n];
     505              // deal with NaN and Infinity
     506              var q = qualities[n];
     507              if (double.IsNaN(q) || double.IsInfinity(q)) {
     508                q = NadirPoint[n];
    507509              }
     510              q -= IdealPoint[n];
     511
     512              if (normalizeObjectives) {
     513                q /= NadirPoint[n] - IdealPoint[n];
     514              }
     515
    508516              var l = lambda[n].IsAlmost(0) ? 1e-4 : lambda[n];
    509               var feval = l * Math.Abs(diff);
     517              var feval = l * Math.Abs(q);
    510518
    511519              if (feval > maxFun) {
     
    562570    protected void UpdateParetoFronts() {
    563571      var qualities = population.Select(x => Enumerable.Range(0, NadirPoint.Length).Select(i => x.Qualities[i] / NadirPoint[i]).ToArray()).ToArray();
    564       var maximization = Enumerable.Repeat(false, IdealPoint.Length).ToArray(); // MOEA/D minimizes everything internally\
     572      var maximization = Enumerable.Repeat(false, IdealPoint.Length).ToArray(); // MOEA/D minimizes everything internally
    565573      var pf = DominationCalculator<IMOEADSolution>.CalculateBestParetoFront(population, qualities, maximization);
    566574
     
    638646          }
    639647          var r = OnlinePearsonsRCalculator.Calculate(points.Select(x => x.X), points.Select(x => x.Y), out OnlineCalculatorError error);
    640           if (error != OnlineCalculatorError.None) { r = double.NaN; }
    641           sp.Name = $"Pareto Front [{c[0]}, {c[1]}], correlation: {r.ToString("N2")}";
     648          var r2 = r * r;
     649          sp.Name = $"Pareto Front [{c[0]}, {c[1]}], correlation: {r2.ToString("N2")}";
    642650        }
    643651      }
  • branches/2987_MOEAD_Algorithm/HeuristicLab.Algorithms.MOEAD/3.4/Plugin.cs.frame

    r16560 r16657  
    3535  [PluginDependency("HeuristicLab.Persistence", "3.3")]
    3636  [PluginDependency("HeuristicLab.Random", "3.3")]
     37  [PluginDependency("HeuristicLab.Problems.DataAnalysis", "3.4")]
     38  [PluginDependency("HeuristicLab.Problems.TestFunctions.MultiObjective", "3.3")]
    3739  public class HeuristicLabAlgorithmsMOEADPlugin : PluginBase {
    3840  }
Note: See TracChangeset for help on using the changeset viewer.