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/QuadraticAssignmentProblem.cs

    r6046 r6086  
    4949
    5050    #region Parameter Properties
     51    public IValueParameter<ItemList<Permutation>> BestKnownSolutionsParameter {
     52      get { return (IValueParameter<ItemList<Permutation>>)Parameters["BestKnownSolutions"]; }
     53    }
    5154    public IValueParameter<Permutation> BestKnownSolutionParameter {
    5255      get { return (IValueParameter<Permutation>)Parameters["BestKnownSolution"]; }
     
    6164
    6265    #region Properties
     66    public ItemList<Permutation> BestKnownSolutions {
     67      get { return BestKnownSolutionsParameter.Value; }
     68      set { BestKnownSolutionsParameter.Value = value; }
     69    }
    6370    public Permutation BestKnownSolution {
    6471      get { return BestKnownSolutionParameter.Value; }
     
    106113    public QuadraticAssignmentProblem()
    107114      : base(new QAPEvaluator(), new RandomPermutationCreator()) {
     115      Parameters.Add(new OptionalValueParameter<ItemList<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));
    108116      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));
    109117      Parameters.Add(new ValueParameter<DoubleMatrix>("Weights", "The strength of the connection between the facilities.", new DoubleMatrix(5, 5)));
     
    138146    public override IDeepCloneable Clone(Cloner cloner) {
    139147      return new QuadraticAssignmentProblem(this, cloner);
     148    }
     149
     150    [StorableHook(HookType.AfterDeserialization)]
     151    private void AfterDeserialization() {
     152      // BackwardsCompatibility3.3
     153      #region Backwards compatible code, remove with 3.4
     154      /*if (Parameters.ContainsKey("BestKnownSolution")) {
     155        Permutation solution = ((IValueParameter<Permutation>)Parameters["BestKnownSolution"]).Value;
     156        Parameters.Remove("BestKnownSolution");
     157        Parameters.Add(new OptionalValueParameter<ItemList<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));
     158        if (solution != null) {
     159          BestKnownSolutions = new ItemList<Permutation>();
     160          BestKnownSolutions.Add(solution);
     161        }
     162      }*/
     163      if (!Parameters.ContainsKey("BestKnownSolutions")) {
     164        Parameters.Add(new OptionalValueParameter<ItemList<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));
     165      }
     166      #endregion
    140167    }
    141168
     
    246273      Operators.Add(new QAPAlleleFrequencyAnalyzer());
    247274      Operators.Add(new QAPPopulationDiversityAnalyzer());
     275      Operators.Add(new QAPExhaustiveSwap2LocalImprovement());
    248276      ParameterizeAnalyzers();
    249277      ParameterizeOperators();
     
    270298        BestQAPSolutionAnalyzer.ResultsParameter.ActualName = "Results";
    271299        BestQAPSolutionAnalyzer.BestKnownQualityParameter.ActualName = BestKnownQualityParameter.Name;
    272         BestQAPSolutionAnalyzer.BestKnownSolutionParameter.ActualName = BestKnownSolutionParameter.Name;
     300        BestQAPSolutionAnalyzer.BestKnownSolutionsParameter.ActualName = BestKnownSolutionsParameter.Name;
    273301        BestQAPSolutionAnalyzer.MaximizationParameter.ActualName = MaximizationParameter.Name;
    274302      }
     
    314342      foreach (var op in Operators.OfType<IPermutationMultiNeighborhoodShakingOperator>())
    315343        op.PermutationParameter.ActualName = SolutionCreator.PermutationParameter.ActualName;
     344
     345      QAPExhaustiveSwap2LocalImprovement localOpt = Operators.OfType<QAPExhaustiveSwap2LocalImprovement>().SingleOrDefault();
     346      if (localOpt != null) {
     347        localOpt.AssignmentParameter.ActualName = SolutionCreator.PermutationParameter.ActualName;
     348        localOpt.DistancesParameter.ActualName = DistancesParameter.Name;
     349        localOpt.MaximizationParameter.ActualName = MaximizationParameter.Name;
     350        localOpt.QualityParameter.ActualName = Evaluator.QualityParameter.ActualName;
     351        localOpt.WeightsParameter.ActualName = WeightsParameter.Name;
     352      }
    316353    }
    317354
     
    338375      Description = "Imported problem data using QAPLIBParser " + Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(AssemblyFileVersionAttribute), true).Cast<AssemblyFileVersionAttribute>().FirstOrDefault().Version + ".";
    339376      BestKnownQuality = null;
    340       BestKnownSolution = null;
     377      BestKnownSolutions = null;
    341378      OnReset();
    342379    }
     
    371408            if (solParser.Quality.IsAlmost(QAPEvaluator.Apply(new Permutation(PermutationTypes.Absolute, solParser.Assignment), Weights, Distances))) {
    372409              BestKnownQuality = new DoubleValue(solParser.Quality);
     410              BestKnownSolutions = new ItemList<Permutation>(new Permutation[] { new Permutation(PermutationTypes.Absolute, solParser.Assignment) });
    373411              BestKnownSolution = new Permutation(PermutationTypes.Absolute, solParser.Assignment);
    374412            } else {
    375413              BestKnownQuality = new DoubleValue(solParser.Quality);
     414              BestKnownSolutions = null;
    376415              BestKnownSolution = null;
    377416            }
    378417          } else {
    379418            BestKnownQuality = new DoubleValue(solParser.Quality);
     419            BestKnownSolutions = new ItemList<Permutation>(new Permutation[] { new Permutation(PermutationTypes.Absolute, solParser.Assignment) });
    380420            BestKnownSolution = new Permutation(PermutationTypes.Absolute, solParser.Assignment);
    381421          }
     
    383423      } else {
    384424        BestKnownQuality = null;
     425        BestKnownSolutions = null;
    385426        BestKnownSolution = null;
    386427      }
Note: See TracChangeset for help on using the changeset viewer.