Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
02/20/17 20:41:33 (8 years ago)
Author:
abeham
Message:

#2457: working on identification of problem instances

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/PerformanceComparison/HeuristicLab.Analysis.FitnessLandscape/3.3/ProblemCharacteristicAnalysis/QAP/QAPDirectedWalk.cs

    r14678 r14690  
    3232using System.Collections.Generic;
    3333using System.Linq;
     34using System.Threading;
    3435
    3536namespace HeuristicLab.Analysis.FitnessLandscape {
     
    5051    }
    5152
     53    public IFixedValueParameter<BoolValue> LocalOptimaParameter {
     54      get { return (IFixedValueParameter<BoolValue>)Parameters["LocalOptima"]; }
     55    }
     56
    5257    public int Paths {
    5358      get { return PathsParameter.Value.Value; }
     
    6368      get { return SeedParameter.Value != null ? SeedParameter.Value.Value : (int?)null; }
    6469      set { SeedParameter.Value = value.HasValue ? new IntValue(value.Value) : null; }
     70    }
     71
     72    public bool LocalOptima {
     73      get { return LocalOptimaParameter.Value.Value; }
     74      set { LocalOptimaParameter.Value.Value = value; }
    6575    }
    6676
     
    7484      Parameters.Add(new FixedValueParameter<BoolValue>("BestImprovement", "Whether the best of all alternatives should be chosen for each step in the path or just the first improving (least degrading) move should be made.", new BoolValue(true)));
    7585      Parameters.Add(new OptionalValueParameter<IntValue>("Seed", "The seed for the random number generator."));
     86      Parameters.Add(new FixedValueParameter<BoolValue>("LocalOptima", "Whether to perform walks between local optima.", new BoolValue(false)));
    7687    }
    7788
     
    90101
    91102      var perm = new Permutation(PermutationTypes.Absolute, qap.Weights.Rows, random);
     103      if (LocalOptima) {
     104        var fit = new DoubleValue(QAPEvaluator.Apply(perm, qap.Weights, qap.Distances));
     105        QAPExhaustiveSwap2LocalImprovement.ImproveFast(perm, qap.Weights, qap.Distances, fit, new IntValue(0), new IntValue(0), qap.Maximization.Value, int.MaxValue, CancellationToken.None);
     106      }
    92107      var permutations = new List<Permutation> { perm };
    93108      while (permutations.Count < pathCount + 1) {
    94109        perm = (Permutation)permutations.Last().Clone();
    95110        BiasedShuffle(perm, random);
    96         permutations.Add(perm);
     111        if (LocalOptima) {
     112          var fit = new DoubleValue(QAPEvaluator.Apply(perm, qap.Weights, qap.Distances));
     113          QAPExhaustiveSwap2LocalImprovement.ImproveFast(perm, qap.Weights, qap.Distances, fit, new IntValue(0), new IntValue(0), qap.Maximization.Value, int.MaxValue, CancellationToken.None);
     114        }
     115        if (HammingSimilarityCalculator.CalculateSimilarity(permutations.Last(), perm) < 0.75)
     116          permutations.Add(perm);
    97117      }
    98118
     
    151171
    152172      for (var p = 0; p < f2.Count; p++) {
     173        if (f2[p].Count <= 2) continue;
    153174        var bump = 0;
    154175        var flat = 0;
     
    266287    }
    267288
     289    // Center-of-Mass
    268290    private static double ComBelowZero(IEnumerable<Tuple<Permutation, double>> path) {
    269291      var area = 0.0;
Note: See TracChangeset for help on using the changeset viewer.