Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
09/14/11 13:59:25 (13 years ago)
Author:
epitzer
Message:

#1530 integrate changes from trunk

Location:
branches/PersistenceSpeedUp
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/PersistenceSpeedUp

  • branches/PersistenceSpeedUp/HeuristicLab.Problems.QuadraticAssignment/3.3/QuadraticAssignmentProblem.cs

    r6088 r6760  
    4949
    5050    #region Parameter Properties
     51    public IValueParameter<ItemSet<Permutation>> BestKnownSolutionsParameter {
     52      get { return (IValueParameter<ItemSet<Permutation>>)Parameters["BestKnownSolutions"]; }
     53    }
    5154    public IValueParameter<Permutation> BestKnownSolutionParameter {
    5255      get { return (IValueParameter<Permutation>)Parameters["BestKnownSolution"]; }
     
    6164
    6265    #region Properties
     66    public ItemSet<Permutation> BestKnownSolutions {
     67      get { return BestKnownSolutionsParameter.Value; }
     68      set { BestKnownSolutionsParameter.Value = value; }
     69    }
    6370    public Permutation BestKnownSolution {
    6471      get { return BestKnownSolutionParameter.Value; }
     
    8895      get { return Operators.OfType<BestQAPSolutionAnalyzer>().FirstOrDefault(); }
    8996    }
     97
     98    private QAPAlleleFrequencyAnalyzer QAPAlleleFrequencyAnalyzer {
     99      get { return Operators.OfType<QAPAlleleFrequencyAnalyzer>().FirstOrDefault(); }
     100    }
     101
     102    private QAPPopulationDiversityAnalyzer QAPPopulationDiversityAnalyzer {
     103      get { return Operators.OfType<QAPPopulationDiversityAnalyzer>().FirstOrDefault(); }
     104    }
    90105    #endregion
    91106
     
    98113    public QuadraticAssignmentProblem()
    99114      : base(new QAPEvaluator(), new RandomPermutationCreator()) {
     115      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));
    100116      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));
    101117      Parameters.Add(new ValueParameter<DoubleMatrix>("Weights", "The strength of the connection between the facilities.", new DoubleMatrix(5, 5)));
     
    130146    public override IDeepCloneable Clone(Cloner cloner) {
    131147      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("BestKnownSolutions")) {
     155        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));
     156      } else if (Parameters["BestKnownSolutions"].GetType().Equals(typeof(OptionalValueParameter<ItemList<Permutation>>))) {
     157        ItemList<Permutation> list = ((OptionalValueParameter<ItemList<Permutation>>)Parameters["BestKnownSolutions"]).Value;
     158        Parameters.Remove("BestKnownSolutions");
     159        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.", (list != null ? new ItemSet<Permutation>(list) : null)));
     160      }
     161      if (Parameters.ContainsKey("DistanceMatrix")) {
     162        DoubleMatrix d = ((ValueParameter<DoubleMatrix>)Parameters["DistanceMatrix"]).Value;
     163        Parameters.Remove("DistanceMatrix");
     164        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.", d));
     165      }
     166      AttachEventHandlers();
     167      #endregion
    132168    }
    133169
     
    217253
    218254    #region Helpers
    219     [StorableHook(HookType.AfterDeserialization)]
    220     private void AfterDeserializationHook() {
    221       AttachEventHandlers();
    222     }
    223 
    224255    private void AttachEventHandlers() {
    225256      SolutionCreator.PermutationParameter.ActualNameChanged += new EventHandler(SolutionCreator_PermutationParameter_ActualNameChanged);
     
    238269      Operators.AddRange(ApplicationManager.Manager.GetInstances<IQAPMoveEvaluator>());
    239270      Operators.Add(new BestQAPSolutionAnalyzer());
     271      Operators.Add(new QAPAlleleFrequencyAnalyzer());
     272      Operators.Add(new QAPPopulationDiversityAnalyzer());
     273      Operators.Add(new QAPExhaustiveSwap2LocalImprovement());
    240274      ParameterizeAnalyzers();
    241275      ParameterizeOperators();
     
    262296        BestQAPSolutionAnalyzer.ResultsParameter.ActualName = "Results";
    263297        BestQAPSolutionAnalyzer.BestKnownQualityParameter.ActualName = BestKnownQualityParameter.Name;
    264         BestQAPSolutionAnalyzer.BestKnownSolutionParameter.ActualName = BestKnownSolutionParameter.Name;
     298        BestQAPSolutionAnalyzer.BestKnownSolutionsParameter.ActualName = BestKnownSolutionsParameter.Name;
    265299        BestQAPSolutionAnalyzer.MaximizationParameter.ActualName = MaximizationParameter.Name;
     300      }
     301      if (QAPAlleleFrequencyAnalyzer != null) {
     302        QAPAlleleFrequencyAnalyzer.QualityParameter.ActualName = Evaluator.QualityParameter.ActualName;
     303        QAPAlleleFrequencyAnalyzer.BestKnownSolutionParameter.ActualName = BestKnownSolutionParameter.Name;
     304        QAPAlleleFrequencyAnalyzer.DistancesParameter.ActualName = DistancesParameter.Name;
     305        QAPAlleleFrequencyAnalyzer.MaximizationParameter.ActualName = MaximizationParameter.Name;
     306        QAPAlleleFrequencyAnalyzer.ResultsParameter.ActualName = "Results";
     307        QAPAlleleFrequencyAnalyzer.SolutionParameter.ActualName = SolutionCreator.PermutationParameter.ActualName;
     308        QAPAlleleFrequencyAnalyzer.WeightsParameter.ActualName = WeightsParameter.Name;
     309      }
     310      if (QAPPopulationDiversityAnalyzer != null) {
     311        QAPPopulationDiversityAnalyzer.MaximizationParameter.ActualName = MaximizationParameter.Name;
     312        QAPPopulationDiversityAnalyzer.QualityParameter.ActualName = Evaluator.QualityParameter.ActualName;
     313        QAPPopulationDiversityAnalyzer.ResultsParameter.ActualName = "Results";
     314        QAPPopulationDiversityAnalyzer.SolutionParameter.ActualName = SolutionCreator.PermutationParameter.ActualName;
    266315      }
    267316    }
     
    291340      foreach (var op in Operators.OfType<IPermutationMultiNeighborhoodShakingOperator>())
    292341        op.PermutationParameter.ActualName = SolutionCreator.PermutationParameter.ActualName;
     342
     343      QAPExhaustiveSwap2LocalImprovement localOpt = Operators.OfType<QAPExhaustiveSwap2LocalImprovement>().SingleOrDefault();
     344      if (localOpt != null) {
     345        localOpt.AssignmentParameter.ActualName = SolutionCreator.PermutationParameter.ActualName;
     346        localOpt.DistancesParameter.ActualName = DistancesParameter.Name;
     347        localOpt.MaximizationParameter.ActualName = MaximizationParameter.Name;
     348        localOpt.QualityParameter.ActualName = Evaluator.QualityParameter.ActualName;
     349        localOpt.WeightsParameter.ActualName = WeightsParameter.Name;
     350      }
    293351    }
    294352
     
    315373      Description = "Imported problem data using QAPLIBParser " + Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(AssemblyFileVersionAttribute), true).Cast<AssemblyFileVersionAttribute>().FirstOrDefault().Version + ".";
    316374      BestKnownQuality = null;
    317       BestKnownSolution = null;
     375      BestKnownSolutions = null;
    318376      OnReset();
    319377    }
     
    327385        Distances = new DoubleMatrix(parser.Distances);
    328386        Weights = new DoubleMatrix(parser.Weights);
    329         Name = "Quadratic Assignment Problem (loaded instance " + instance + ")";
    330         Description = "Loaded embedded problem data of instance " + instance + ".";
     387        Name = instance;
     388        Description = "Loaded embedded QAPLIB problem data of instance " + instance + ".";
    331389        OnReset();
    332390      }
     
    348406            if (solParser.Quality.IsAlmost(QAPEvaluator.Apply(new Permutation(PermutationTypes.Absolute, solParser.Assignment), Weights, Distances))) {
    349407              BestKnownQuality = new DoubleValue(solParser.Quality);
     408              BestKnownSolutions = new ItemSet<Permutation>(new Permutation[] { new Permutation(PermutationTypes.Absolute, solParser.Assignment) }, new PermutationEqualityComparer());
    350409              BestKnownSolution = new Permutation(PermutationTypes.Absolute, solParser.Assignment);
    351410            } else {
    352411              BestKnownQuality = new DoubleValue(solParser.Quality);
     412              BestKnownSolutions = null;
    353413              BestKnownSolution = null;
    354414            }
    355415          } else {
    356416            BestKnownQuality = new DoubleValue(solParser.Quality);
     417            BestKnownSolutions = new ItemSet<Permutation>(new Permutation[] { new Permutation(PermutationTypes.Absolute, solParser.Assignment) }, new PermutationEqualityComparer());
    357418            BestKnownSolution = new Permutation(PermutationTypes.Absolute, solParser.Assignment);
    358419          }
     
    360421      } else {
    361422        BestKnownQuality = null;
     423        BestKnownSolutions = new ItemSet<Permutation>(new PermutationEqualityComparer());
    362424        BestKnownSolution = null;
    363425      }
Note: See TracChangeset for help on using the changeset viewer.