Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
09/04/19 09:09:26 (5 years ago)
Author:
abeham
Message:

#2521: Improve speed of Evaluate() in QuadraticAssignmentProblem

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/2521_ProblemRefactoring/HeuristicLab.Problems.QuadraticAssignment/3.3/QuadraticAssignmentProblem.cs

    r17226 r17232  
    5151
    5252    #region Parameter Properties
     53    [Storable]
     54    private IValueParameter<ItemSet<Permutation>> bestKnownSolutionsParameter;
    5355    public IValueParameter<ItemSet<Permutation>> BestKnownSolutionsParameter {
    54       get { return (IValueParameter<ItemSet<Permutation>>)Parameters["BestKnownSolutions"]; }
    55     }
     56      get { return bestKnownSolutionsParameter; }
     57    }
     58    [Storable]
     59    private IValueParameter<Permutation> bestKnownSolutionParameter;
    5660    public IValueParameter<Permutation> BestKnownSolutionParameter {
    57       get { return (IValueParameter<Permutation>)Parameters["BestKnownSolution"]; }
    58     }
     61      get { return bestKnownSolutionParameter; }
     62    }
     63    [Storable]
     64    private IValueParameter<DoubleMatrix> weightsParameter;
    5965    public IValueParameter<DoubleMatrix> WeightsParameter {
    60       get { return (IValueParameter<DoubleMatrix>)Parameters["Weights"]; }
    61     }
     66      get { return weightsParameter; }
     67    }
     68    [Storable]
     69    private IValueParameter<DoubleMatrix> distancesParameter;
    6270    public IValueParameter<DoubleMatrix> DistancesParameter {
    63       get { return (IValueParameter<DoubleMatrix>)Parameters["Distances"]; }
    64     }
     71      get { return distancesParameter; }
     72    }
     73    [Storable]
     74    private IValueParameter<DoubleValue> lowerBoundParameter;
    6575    public IValueParameter<DoubleValue> LowerBoundParameter {
    66       get { return (IValueParameter<DoubleValue>)Parameters["LowerBound"]; }
    67     }
     76      get { return lowerBoundParameter; }
     77    }
     78    [Storable]
     79    private IValueParameter<DoubleValue> averageQualityParameter;
    6880    public IValueParameter<DoubleValue> AverageQualityParameter {
    69       get { return (IValueParameter<DoubleValue>)Parameters["AverageQuality"]; }
     81      get { return averageQualityParameter; }
    7082    }
    7183    #endregion
     
    7385    #region Properties
    7486    public ItemSet<Permutation> BestKnownSolutions {
    75       get { return BestKnownSolutionsParameter.Value; }
    76       set { BestKnownSolutionsParameter.Value = value; }
     87      get { return bestKnownSolutionsParameter.Value; }
     88      set { bestKnownSolutionsParameter.Value = value; }
    7789    }
    7890    public Permutation BestKnownSolution {
    79       get { return BestKnownSolutionParameter.Value; }
    80       set { BestKnownSolutionParameter.Value = value; }
     91      get { return bestKnownSolutionParameter.Value; }
     92      set { bestKnownSolutionParameter.Value = value; }
    8193    }
    8294    public DoubleMatrix Weights {
    83       get { return WeightsParameter.Value; }
    84       set { WeightsParameter.Value = value; }
     95      get { return weightsParameter.Value; }
     96      set { weightsParameter.Value = value; }
    8597    }
    8698    public DoubleMatrix Distances {
    87       get { return DistancesParameter.Value; }
    88       set { DistancesParameter.Value = value; }
     99      get { return distancesParameter.Value; }
     100      set { distancesParameter.Value = value; }
    89101    }
    90102    public DoubleValue LowerBound {
    91       get { return LowerBoundParameter.Value; }
    92       set { LowerBoundParameter.Value = value; }
     103      get { return lowerBoundParameter.Value; }
     104      set { lowerBoundParameter.Value = value; }
    93105    }
    94106    public DoubleValue AverageQuality {
    95       get { return AverageQualityParameter.Value; }
    96       set { AverageQualityParameter.Value = value; }
     107      get { return averageQualityParameter.Value; }
     108      set { averageQualityParameter.Value = value; }
    97109    }
    98110
     
    114126    private QuadraticAssignmentProblem(QuadraticAssignmentProblem original, Cloner cloner)
    115127      : base(original, cloner) {
     128      bestKnownSolutionsParameter = cloner.Clone(original.bestKnownSolutionsParameter);
     129      bestKnownSolutionParameter = cloner.Clone(original.bestKnownSolutionParameter);
     130      weightsParameter = cloner.Clone(original.weightsParameter);
     131      distancesParameter = cloner.Clone(original.distancesParameter);
     132      lowerBoundParameter = cloner.Clone(original.lowerBoundParameter);
     133      averageQualityParameter = cloner.Clone(original.averageQualityParameter);
    116134      RegisterEventHandlers();
    117135    }
    118136    public QuadraticAssignmentProblem()
    119137      : base(new PermutationEncoding("Assignment") { Length = 5 }) {
    120       Parameters.Add(new OptionalValueParameter<ItemSet<Permutation>>("BestKnownSolutions", "The list of best known solutions which is updated whenever a new better solution is found or may be the optimal solution if it is known beforehand.", null));
    121       Parameters.Add(new OptionalValueParameter<Permutation>("BestKnownSolution", "The best known solution which is updated whenever a new better solution is found or may be the optimal solution if it is known beforehand.", null));
    122       Parameters.Add(new ValueParameter<DoubleMatrix>("Weights", "The strength of the connection between the facilities.", new DoubleMatrix(5, 5)));
    123       Parameters.Add(new ValueParameter<DoubleMatrix>("Distances", "The distance matrix which can either be specified directly without the coordinates, or can be calculated automatically from the coordinates.", new DoubleMatrix(5, 5)));
    124       Parameters.Add(new OptionalValueParameter<DoubleValue>("LowerBound", "The Gilmore-Lawler lower bound to the solution quality."));
    125       Parameters.Add(new OptionalValueParameter<DoubleValue>("AverageQuality", "The expected quality of a random solution."));
     138      Parameters.Add(bestKnownSolutionsParameter = new OptionalValueParameter<ItemSet<Permutation>>("BestKnownSolutions", "The list of best known solutions which is updated whenever a new better solution is found or may be the optimal solution if it is known beforehand.", null));
     139      Parameters.Add(bestKnownSolutionParameter = new OptionalValueParameter<Permutation>("BestKnownSolution", "The best known solution which is updated whenever a new better solution is found or may be the optimal solution if it is known beforehand.", null));
     140      Parameters.Add(weightsParameter = new ValueParameter<DoubleMatrix>("Weights", "The strength of the connection between the facilities.", new DoubleMatrix(5, 5)));
     141      Parameters.Add(distancesParameter = new ValueParameter<DoubleMatrix>("Distances", "The distance matrix which can either be specified directly without the coordinates, or can be calculated automatically from the coordinates.", new DoubleMatrix(5, 5)));
     142      Parameters.Add(lowerBoundParameter = new OptionalValueParameter<DoubleValue>("LowerBound", "The Gilmore-Lawler lower bound to the solution quality."));
     143      Parameters.Add(averageQualityParameter = new OptionalValueParameter<DoubleValue>("AverageQuality", "The expected quality of a random solution."));
    126144
    127145      WeightsParameter.GetsCollected = false;
     
    167185    [StorableHook(HookType.AfterDeserialization)]
    168186    private void AfterDeserialization() {
     187      // BackwardsCompatibility3.3
     188      #region Backwards compatible code, remove with 3.4
     189      if (bestKnownSolutionsParameter == null)
     190        bestKnownSolutionsParameter = (IValueParameter<ItemSet<Permutation>>)Parameters["BestKnownSolutions"];
     191      if (bestKnownSolutionParameter == null)
     192        bestKnownSolutionParameter = (IValueParameter<Permutation>)Parameters["BestKnownSolution"];
     193      if (weightsParameter == null)
     194        weightsParameter = (IValueParameter<DoubleMatrix>)Parameters["Weights"];
     195      if (distancesParameter == null)
     196        distancesParameter = (IValueParameter<DoubleMatrix>)Parameters["Distances"];
     197      if (lowerBoundParameter == null)
     198        lowerBoundParameter = (IValueParameter<DoubleValue>)Parameters["LowerBound"];
     199      if (averageQualityParameter == null)
     200        averageQualityParameter = (IValueParameter<DoubleValue>)Parameters["AverageQuality"];
     201      #endregion
    169202      RegisterEventHandlers();
    170203    }
Note: See TracChangeset for help on using the changeset viewer.