Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
09/26/10 17:05:23 (14 years ago)
Author:
swinkler
Message:

Worked on population diversity analyzer for TSP: Implemented storing of population diversity result overview in the algorithm's results collection. (#1188)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/HeuristicLab.DiversityAnalysis/HeuristicLab.Problems.TravelingSalesman/3.3/Analyzers/TSPPopulationDiversityAnalyzer.cs

    r4432 r4501  
    2222using System;
    2323using System.Linq;
     24using HeuristicLab.Analysis;
    2425using HeuristicLab.Core;
     26using HeuristicLab.Common;
    2527using HeuristicLab.Data;
    2628using HeuristicLab.Encodings.PermutationEncoding;
     
    2931using HeuristicLab.Parameters;
    3032using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
     33using System.Data;
    3134
    3235namespace HeuristicLab.Problems.TravelingSalesman {
     
    4144    // - iterations sampling
    4245    // - view
    43 
     46    // - implement data structure for population diversity details
     47
     48    public const string PermutationKey = "Permutation";
    4449    public ScopeTreeLookupParameter<Permutation> PermutationParameter {
    45       get { return (ScopeTreeLookupParameter<Permutation>)Parameters["Permutation"]; }
    46     }
     50      get { return (ScopeTreeLookupParameter<Permutation>)Parameters[PermutationKey]; }
     51    }
     52    public const string QualityKey = "Quality";
    4753    public ScopeTreeLookupParameter<DoubleValue> QualityParameter {
    48       get { return (ScopeTreeLookupParameter<DoubleValue>)Parameters["Quality"]; }
    49     }
     54      get { return (ScopeTreeLookupParameter<DoubleValue>)Parameters[QualityKey]; }
     55    }
     56
     57    public const string StoreCompleteHistoryKey = "StoreCompleteHistory";
    5058    public ValueParameter<BoolValue> StoreCompleteHistoryParameter {
    51       get { return (ValueParameter<BoolValue>)Parameters["StoreCompleteHistory"]; }
    52     }
     59      get { return (ValueParameter<BoolValue>)Parameters[StoreCompleteHistoryKey]; }
     60    }
     61
     62    public const string SimilaritiesKey = "Similarities";
    5363    public ValueParameter<ItemList<DoubleMatrix>> SimilaritiesParameter {
    54       get { return (ValueParameter<ItemList<DoubleMatrix>>)Parameters["Similarities"]; }
    55     }
     64      get { return (ValueParameter<ItemList<DoubleMatrix>>)Parameters[SimilaritiesKey]; }
     65    }
     66    public const string MaximumSimilaritiesKey = "MaximumSimilarities";
    5667    public ValueParameter<ItemList<DoubleArray>> MaximumSimilaritiesParameter {
    57       get { return (ValueParameter<ItemList<DoubleArray>>)Parameters["MaximumSimilarities"]; }
    58     }
    59     public ValueParameter<ItemList<DoubleValue>> AverageMaximumSimilaritiesParameter {
    60       get { return (ValueParameter<ItemList<DoubleValue>>)Parameters["AverageMaximumSimilarities"]; }
    61     }
    62     public ValueParameter<ItemList<DoubleValue>> AverageSimilaritiesParameter {
    63       get { return (ValueParameter<ItemList<DoubleValue>>)Parameters["AverageSimilarities"]; }
     68      get { return (ValueParameter<ItemList<DoubleArray>>)Parameters[MaximumSimilaritiesKey]; }
     69    }
     70
     71    public const string CurrentAverageSimilarityKey = "Current Average Population Similarity";
     72    public const string AverageSimilarityProgressKey = "Average Population Similarity Progress";
     73    public const string CurrentAverageMaximumSimilarityKey = "Current Average Maximum Population Similarity";
     74    public const string AverageMaximumSimilarityProgressKey = "Average Maximum Population Similarity Progress";
     75
     76    public const string ResultsKey = "Results";
     77    public ValueLookupParameter<ResultCollection> ResultsParameter {
     78      get { return (ValueLookupParameter<ResultCollection>)Parameters[ResultsKey]; }
    6479    }
    6580
    6681    public TSPPopulationDiversityAnalyzer()
    6782      : base() {
    68       Parameters.Add(new ScopeTreeLookupParameter<Permutation>("Permutation", "The TSP solutions given in path representation from which the best solution should be analyzed."));
    69       Parameters.Add(new ScopeTreeLookupParameter<DoubleValue>("Quality", "The qualities of the TSP solutions which should be analyzed."));
    70       Parameters.Add(new ValueParameter<BoolValue>("StoreCompleteHistory", "Flag that denotes whether the complete history of similarity values shall be stored.", new BoolValue(true)));
    71       Parameters.Add(new ValueParameter<ItemList<DoubleMatrix>>("Similarities", "The similarities of the TSP solutions which should be analyzed."));
    72       Parameters.Add(new ValueParameter<ItemList<DoubleArray>>("MaximumSimilarities", "The maximum similarities of the TSP solutions which should be analyzed."));
    73       Parameters.Add(new ValueParameter<ItemList<DoubleValue>>("AverageMaximumSimilarities", "The average maximum similarities of the TSP solutions which should be analyzed."));
    74       Parameters.Add(new ValueParameter<ItemList<DoubleValue>>("AverageSimilarities", "The average similarities of the TSP solutions which should be analyzed."));
     83      Parameters.Add(new ScopeTreeLookupParameter<Permutation>(PermutationKey, "The TSP solutions given in path representation from which the best solution should be analyzed."));
     84      Parameters.Add(new ScopeTreeLookupParameter<DoubleValue>(QualityKey, "The qualities of the TSP solutions which should be analyzed."));
     85      Parameters.Add(new ValueParameter<BoolValue>(StoreCompleteHistoryKey, "Flag that denotes whether the complete history of similarity values shall be stored.", new BoolValue(true)));
     86      Parameters.Add(new ValueLookupParameter<ResultCollection>("Results", "The results collection in which the population diversity analysis results should be stored."));
     87
     88      Parameters.Add(new ValueParameter<ItemList<DoubleMatrix>>(SimilaritiesKey, "The similarities of the TSP solutions which should be analyzed."));
     89      Parameters.Add(new ValueParameter<ItemList<DoubleArray>>(MaximumSimilaritiesKey, "The maximum similarities of the TSP solutions which should be analyzed."));
    7590    }
    7691
    7792    public override IOperation Apply() {
    78 
    79       #region testing
    80       /*
    81       Permutation permutationA = new Permutation(PermutationTypes.Absolute, new int[] { 0, 5, 4, 3, 2, 1 });
    82       Permutation permutationB = new Permutation(PermutationTypes.Absolute, new int[] { 0, 3, 2, 4, 5, 1 });
    83       Permutation permutationC = new Permutation(PermutationTypes.Absolute, new int[] { 3, 2, 4, 5, 1, 0 });
    84       Permutation permutationD = new Permutation(PermutationTypes.Absolute, new int[] { 3, 2, 4, 5, 0, 1 });
    85       int[] edgesA = CalculateEdgesVector(permutationA);
    86       int[] edgesB = CalculateEdgesVector(permutationB);
    87       int[] edgesC = CalculateEdgesVector(permutationC);
    88       int[] edgesD = CalculateEdgesVector(permutationD);
    89       double s = CalculateSimilarity(edgesA, edgesB);
    90       s = CalculateSimilarity(edgesA, edgesA);
    91       s = CalculateSimilarity(edgesB, edgesB);
    92       s = CalculateSimilarity(edgesC, edgesC);
    93       s = CalculateSimilarity(edgesD, edgesD);
    94       s = CalculateSimilarity(edgesB, edgesC);
    95       s = CalculateSimilarity(edgesC, edgesD);
    96       */
    97       #endregion
    9893
    9994      ItemArray<Permutation> permutations = PermutationParameter.ActualValue;
     
    10297      DoubleValue[] qualitiesArray = qualities.ToArray();
    10398      int cities = permutationsArray.Length;
     99      ResultCollection results = ResultsParameter.ActualValue;
     100
    104101      #region sort permutations array
    105102      for (int i = 0; i < cities; i++) {
     
    148145        SimilaritiesParameter.Value = new ItemList<DoubleMatrix>();
    149146        MaximumSimilaritiesParameter.Value = new ItemList<DoubleArray>();
    150         AverageMaximumSimilaritiesParameter.Value = new ItemList<DoubleValue>();
    151         AverageSimilaritiesParameter.Value = new ItemList<DoubleValue>();
    152147      }
    153148      if (!StoreCompleteHistoryParameter.Value.Value && SimilaritiesParameter.Value.Count > 0) {
     
    157152      SimilaritiesParameter.Value.Add(similarities);
    158153      MaximumSimilaritiesParameter.Value.Add(maxSimilarities);
    159       AverageMaximumSimilaritiesParameter.Value.Add(averageMaximumSimilarity);
    160       AverageSimilaritiesParameter.Value.Add(averageSimilarity);
     154
     155      #region Store average similarity values
     156      if (results.ContainsKey(CurrentAverageSimilarityKey))
     157        results[CurrentAverageSimilarityKey].Value = averageSimilarity;
     158      else
     159        results.Add(new Result(CurrentAverageSimilarityKey, averageSimilarity));
     160
     161      if (!results.ContainsKey(AverageSimilarityProgressKey))
     162        results.Add(new Result(AverageSimilarityProgressKey, new Analysis.DataTable(AverageSimilarityProgressKey)));
     163      Analysis.DataTable averageSimilarityProgressDataTable = (Analysis.DataTable)(results[AverageSimilarityProgressKey].Value);
     164      if (averageSimilarityProgressDataTable.Rows.Count == 0)
     165        averageSimilarityProgressDataTable.Rows.Add(new Analysis.DataRow(AverageSimilarityProgressKey));
     166      averageSimilarityProgressDataTable.Rows[AverageSimilarityProgressKey].Values.Add(averageSimilarity.Value);
     167      #endregion
     168      #region Store average maximum similarity values
     169      if (results.ContainsKey(CurrentAverageMaximumSimilarityKey))
     170        results[CurrentAverageMaximumSimilarityKey].Value = averageMaximumSimilarity;
     171      else
     172        results.Add(new Result(CurrentAverageMaximumSimilarityKey, averageMaximumSimilarity));
     173
     174      if (!results.ContainsKey(AverageMaximumSimilarityProgressKey))
     175        results.Add(new Result(AverageMaximumSimilarityProgressKey, new Analysis.DataTable(AverageMaximumSimilarityProgressKey)));
     176      Analysis.DataTable averageMaximumSimilarityProgressDataTable = (Analysis.DataTable)(results[AverageMaximumSimilarityProgressKey].Value);
     177      if (averageMaximumSimilarityProgressDataTable.Rows.Count == 0)
     178        averageMaximumSimilarityProgressDataTable.Rows.Add(new Analysis.DataRow(AverageMaximumSimilarityProgressKey));
     179      averageMaximumSimilarityProgressDataTable.Rows[AverageMaximumSimilarityProgressKey].Values.Add(averageMaximumSimilarity.Value);
     180      #endregion
    161181
    162182      return base.Apply();
Note: See TracChangeset for help on using the changeset viewer.