Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
05/30/11 18:07:32 (13 years ago)
Author:
abeham
Message:

#1465, #1469, #1470, #1494, #1496, #1497, #1539, #1487

  • merged to trunk
Location:
trunk/sources
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources

  • trunk/sources/HeuristicLab.Problems.QuadraticAssignment/3.3/QuadraticAssignmentProblem.cs

    r6088 r6342  
    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; }
     
    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<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));
    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("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      if (Parameters.ContainsKey("DistanceMatrix")) {
     167        DoubleMatrix bla = ((ValueParameter<DoubleMatrix>)Parameters["DistanceMatrix"]).Value;
     168        Parameters.Remove("DistanceMatrix");
     169        Parameters.Add(new ValueParameter<DoubleMatrix>("Distances", "bla", bla));
     170      }
     171      AttachEventHandlers();
     172      #endregion
    132173    }
    133174
     
    217258
    218259    #region Helpers
    219     [StorableHook(HookType.AfterDeserialization)]
    220     private void AfterDeserializationHook() {
    221       AttachEventHandlers();
    222     }
    223 
    224260    private void AttachEventHandlers() {
    225261      SolutionCreator.PermutationParameter.ActualNameChanged += new EventHandler(SolutionCreator_PermutationParameter_ActualNameChanged);
     
    238274      Operators.AddRange(ApplicationManager.Manager.GetInstances<IQAPMoveEvaluator>());
    239275      Operators.Add(new BestQAPSolutionAnalyzer());
     276      Operators.Add(new QAPAlleleFrequencyAnalyzer());
     277      Operators.Add(new QAPPopulationDiversityAnalyzer());
     278      Operators.Add(new QAPExhaustiveSwap2LocalImprovement());
    240279      ParameterizeAnalyzers();
    241280      ParameterizeOperators();
     
    262301        BestQAPSolutionAnalyzer.ResultsParameter.ActualName = "Results";
    263302        BestQAPSolutionAnalyzer.BestKnownQualityParameter.ActualName = BestKnownQualityParameter.Name;
    264         BestQAPSolutionAnalyzer.BestKnownSolutionParameter.ActualName = BestKnownSolutionParameter.Name;
     303        BestQAPSolutionAnalyzer.BestKnownSolutionsParameter.ActualName = BestKnownSolutionsParameter.Name;
    265304        BestQAPSolutionAnalyzer.MaximizationParameter.ActualName = MaximizationParameter.Name;
     305      }
     306      if (QAPAlleleFrequencyAnalyzer != null) {
     307        QAPAlleleFrequencyAnalyzer.QualityParameter.ActualName = Evaluator.QualityParameter.ActualName;
     308        QAPAlleleFrequencyAnalyzer.BestKnownSolutionParameter.ActualName = BestKnownSolutionParameter.Name;
     309        QAPAlleleFrequencyAnalyzer.DistancesParameter.ActualName = DistancesParameter.Name;
     310        QAPAlleleFrequencyAnalyzer.MaximizationParameter.ActualName = MaximizationParameter.Name;
     311        QAPAlleleFrequencyAnalyzer.ResultsParameter.ActualName = "Results";
     312        QAPAlleleFrequencyAnalyzer.SolutionParameter.ActualName = SolutionCreator.PermutationParameter.ActualName;
     313        QAPAlleleFrequencyAnalyzer.WeightsParameter.ActualName = WeightsParameter.Name;
     314      }
     315      if (QAPPopulationDiversityAnalyzer != null) {
     316        QAPPopulationDiversityAnalyzer.MaximizationParameter.ActualName = MaximizationParameter.Name;
     317        QAPPopulationDiversityAnalyzer.QualityParameter.ActualName = Evaluator.QualityParameter.ActualName;
     318        QAPPopulationDiversityAnalyzer.ResultsParameter.ActualName = "Results";
     319        QAPPopulationDiversityAnalyzer.SolutionParameter.ActualName = SolutionCreator.PermutationParameter.ActualName;
    266320      }
    267321    }
     
    291345      foreach (var op in Operators.OfType<IPermutationMultiNeighborhoodShakingOperator>())
    292346        op.PermutationParameter.ActualName = SolutionCreator.PermutationParameter.ActualName;
     347
     348      QAPExhaustiveSwap2LocalImprovement localOpt = Operators.OfType<QAPExhaustiveSwap2LocalImprovement>().SingleOrDefault();
     349      if (localOpt != null) {
     350        localOpt.AssignmentParameter.ActualName = SolutionCreator.PermutationParameter.ActualName;
     351        localOpt.DistancesParameter.ActualName = DistancesParameter.Name;
     352        localOpt.MaximizationParameter.ActualName = MaximizationParameter.Name;
     353        localOpt.QualityParameter.ActualName = Evaluator.QualityParameter.ActualName;
     354        localOpt.WeightsParameter.ActualName = WeightsParameter.Name;
     355      }
    293356    }
    294357
     
    315378      Description = "Imported problem data using QAPLIBParser " + Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(AssemblyFileVersionAttribute), true).Cast<AssemblyFileVersionAttribute>().FirstOrDefault().Version + ".";
    316379      BestKnownQuality = null;
    317       BestKnownSolution = null;
     380      BestKnownSolutions = null;
    318381      OnReset();
    319382    }
     
    348411            if (solParser.Quality.IsAlmost(QAPEvaluator.Apply(new Permutation(PermutationTypes.Absolute, solParser.Assignment), Weights, Distances))) {
    349412              BestKnownQuality = new DoubleValue(solParser.Quality);
     413              BestKnownSolutions = new ItemList<Permutation>(new Permutation[] { new Permutation(PermutationTypes.Absolute, solParser.Assignment) });
    350414              BestKnownSolution = new Permutation(PermutationTypes.Absolute, solParser.Assignment);
    351415            } else {
    352416              BestKnownQuality = new DoubleValue(solParser.Quality);
     417              BestKnownSolutions = null;
    353418              BestKnownSolution = null;
    354419            }
    355420          } else {
    356421            BestKnownQuality = new DoubleValue(solParser.Quality);
     422            BestKnownSolutions = new ItemList<Permutation>(new Permutation[] { new Permutation(PermutationTypes.Absolute, solParser.Assignment) });
    357423            BestKnownSolution = new Permutation(PermutationTypes.Absolute, solParser.Assignment);
    358424          }
     
    360426      } else {
    361427        BestKnownQuality = null;
     428        BestKnownSolutions = null;
    362429        BestKnownSolution = null;
    363430      }
Note: See TracChangeset for help on using the changeset viewer.