Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
04/30/11 15:40:40 (13 years ago)
Author:
abeham
Message:

#1497

  • Added problem-specific local improvement operator (best improvement local search using swap2 moves)
    • Adapted ExhaustiveSwap2MoveGenerator to yield moves
  • Added a parameter BestKnownSolutions to collect possible optimal invariants
    • Adapted BestQAPSolutionAnalyzer to collect optimal invariants
  • Added a function to the QAP Evaluator that calculates the impact of a certain allele
File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/histogram/HeuristicLab.Problems.QuadraticAssignment/3.3/Analyzers/BestQAPSolutionAnalyzer.cs

    r5933 r6086  
    6161      get { return (LookupParameter<DoubleValue>)Parameters["BestKnownQuality"]; }
    6262    }
     63    public LookupParameter<ItemList<Permutation>> BestKnownSolutionsParameter {
     64      get { return (LookupParameter<ItemList<Permutation>>)Parameters["BestKnownSolutions"]; }
     65    }
    6366    public LookupParameter<Permutation> BestKnownSolutionParameter {
    6467      get { return (LookupParameter<Permutation>)Parameters["BestKnownSolution"]; }
     
    8184      Parameters.Add(new ValueLookupParameter<ResultCollection>("Results", "The result collection where the best QAP solution should be stored."));
    8285      Parameters.Add(new LookupParameter<DoubleValue>("BestKnownQuality", "The quality of the best known solution of this QAP instance."));
     86      Parameters.Add(new LookupParameter<ItemList<Permutation>>("BestKnownSolutions", "The best known solutions of this QAP instance."));
    8387      Parameters.Add(new LookupParameter<Permutation>("BestKnownSolution", "The best known solution of this QAP instance."));
     88    }
     89
     90    [StorableHook(HookType.AfterDeserialization)]
     91    private void AfterDeserialization() {
     92      // BackwardsCompatibility3.3
     93      #region Backwards compatible code, remove with 3.4
     94      /*if (Parameters.ContainsKey("BestKnownSolution")) {
     95        Parameters.Remove("BestKnownSolution");
     96        Parameters.Add(new LookupParameter<ItemList<Permutation>>("BestKnownSolutions", "The best known solutions of this QAP instance."));
     97      }*/
     98      if (!Parameters.ContainsKey("BestKnownSolutions")) {
     99        Parameters.Add(new LookupParameter<ItemList<Permutation>>("BestKnownSolutions", "The best known solutions of this QAP instance."));
     100      }
     101      #endregion
    84102    }
    85103
     
    93111      DoubleValue bestKnownQuality = BestKnownQualityParameter.ActualValue;
    94112
    95       int i = -1;
    96       if (!max)
    97         i = qualities.Select((x, index) => new { index, x.Value }).OrderBy(x => x.Value).First().index;
    98       else i = qualities.Select((x, index) => new { index, x.Value }).OrderByDescending(x => x.Value).First().index;
     113      var sorted = qualities.Select((x, index) => new { index, x.Value }).OrderBy(x => x.Value).ToArray();
     114      if (max) sorted = sorted.Reverse().ToArray();
     115      int i = sorted.First().index;
    99116
    100       if (bestKnownQuality == null ||
    101           max && qualities[i].Value > bestKnownQuality.Value ||
    102           !max && qualities[i].Value < bestKnownQuality.Value) {
     117      if (bestKnownQuality == null
     118          || max && qualities[i].Value > bestKnownQuality.Value
     119          || !max && qualities[i].Value < bestKnownQuality.Value
     120          || bestKnownQuality.Value == qualities[i].Value
     121            && (BestKnownSolutionsParameter.ActualValue == null || BestKnownSolutionsParameter.ActualValue.Count == 0)) {
    103122        BestKnownQualityParameter.ActualValue = new DoubleValue(qualities[i].Value);
    104123        BestKnownSolutionParameter.ActualValue = (Permutation)permutations[i].Clone();
     124        BestKnownSolutionsParameter.ActualValue = new ItemList<Permutation>();
     125        BestKnownSolutionsParameter.ActualValue.Add((Permutation)permutations[i].Clone());
     126      } else if (bestKnownQuality != null && qualities[i].Value == bestKnownQuality.Value) {
     127        PermutationEqualityComparer comparer = new PermutationEqualityComparer();
     128        foreach (var k in sorted) {
     129          if (!max && k.Value > qualities[i].Value
     130            || max && k.Value < qualities[i].Value) break;
     131          Permutation p = permutations[k.index];
     132          bool alreadyPresent = false;
     133          foreach (Permutation p2 in BestKnownSolutionsParameter.ActualValue) {
     134            if (comparer.Equals(p, p2)) {
     135              alreadyPresent = true;
     136              break;
     137            }
     138          }
     139          if (!alreadyPresent)
     140            BestKnownSolutionsParameter.ActualValue.Add((Permutation)permutations[k.index].Clone());
     141        }
    105142      }
    106143
Note: See TracChangeset for help on using the changeset viewer.