Free cookie consent management tool by TermsFeed Policy Generator

Changeset 12102


Ignore:
Timestamp:
03/02/15 16:11:20 (10 years ago)
Author:
jkarder
Message:

#2332: used ISolutionSimilarityCalculator instead of ISingleObjectiveSolutionSimilarityCalculator

  • changed interfaces
  • removed ISimilarityCalculatorView
  • renamed ISingleObjectiveSolutionSimilarityCalculatorView to ISolutionSimilarityCalculatorView
  • algorithms no longer add QualitySimilarityCalculator and NoSimilarityCalculator; problems do that now
Location:
trunk/sources
Files:
2 added
4 deleted
8 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Algorithms.RAPGA/3.3/RAPGA.cs

    r12069 r12102  
    103103      get { return (ValueParameter<IntValue>)Parameters["MaximumGenerations"]; }
    104104    }
    105     public IConstrainedValueParameter<ISingleObjectiveSolutionSimilarityCalculator> SimilarityCalculatorParameter {
    106       get { return (IConstrainedValueParameter<ISingleObjectiveSolutionSimilarityCalculator>)Parameters["SimilarityCalculator"]; }
     105    public IConstrainedValueParameter<ISolutionSimilarityCalculator> SimilarityCalculatorParameter {
     106      get { return (IConstrainedValueParameter<ISolutionSimilarityCalculator>)Parameters["SimilarityCalculator"]; }
    107107    }
    108108    #endregion
     
    173173      set { MaximumGenerationsParameter.Value = value; }
    174174    }
    175     public ISingleObjectiveSolutionSimilarityCalculator SimilarityCalculator {
     175    public ISolutionSimilarityCalculator SimilarityCalculator {
    176176      get { return SimilarityCalculatorParameter.Value; }
    177177      set { SimilarityCalculatorParameter.Value = value; }
     
    204204      if (!Parameters.ContainsKey("ReevaluateElites")) {
    205205        Parameters.Add(new FixedValueParameter<BoolValue>("ReevaluateElites", "Flag to determine if elite individuals should be reevaluated (i.e., if stochastic fitness functions are used.)", (BoolValue)new BoolValue(false).AsReadOnly()) { Hidden = true });
     206      }
     207      if (Parameters.ContainsKey("SimilarityCalculator")) {
     208        var oldParameter = (IConstrainedValueParameter<ISingleObjectiveSolutionSimilarityCalculator>)Parameters["SimilarityCalculator"];
     209        Parameters.Remove(oldParameter);
     210        var newParameter = new ConstrainedValueParameter<ISolutionSimilarityCalculator>("SimilarityCalculator", "The operator used to calculate the similarity between two solutions.", new ItemSet<ISolutionSimilarityCalculator>(oldParameter.ValidValues));
     211        var selectedSimilarityCalculator = newParameter.ValidValues.SingleOrDefault(x => x.GetType() == oldParameter.Value.GetType());
     212        newParameter.Value = selectedSimilarityCalculator;
     213        Parameters.Add(newParameter);
    206214      }
    207215      #endregion
     
    234242      Parameters.Add(new ValueParameter<MultiAnalyzer>("Analyzer", "The operator used to analyze each generation.", new MultiAnalyzer()));
    235243      Parameters.Add(new ValueParameter<IntValue>("MaximumGenerations", "The maximum number of generations which should be processed.", new IntValue(1000)));
    236       Parameters.Add(new ConstrainedValueParameter<ISingleObjectiveSolutionSimilarityCalculator>("SimilarityCalculator", "The operator used to calculate the similarity between two solutions."));
     244      Parameters.Add(new ConstrainedValueParameter<ISolutionSimilarityCalculator>("SimilarityCalculator", "The operator used to calculate the similarity between two solutions."));
    237245
    238246      RandomCreator randomCreator = new RandomCreator();
     
    448456    }
    449457    private void ParameterizeSimilarityCalculators() {
    450       foreach (ISingleObjectiveSolutionSimilarityCalculator calc in SimilarityCalculatorParameter.ValidValues) {
     458      foreach (ISolutionSimilarityCalculator calc in SimilarityCalculatorParameter.ValidValues) {
    451459        calc.QualityVariableName = Problem.Evaluator.QualityParameter.ActualName;
    452460      }
     
    493501    }
    494502    private void UpdateSimilarityCalculators() {
    495       ISingleObjectiveSolutionSimilarityCalculator oldSimilarityCalculator = SimilarityCalculatorParameter.Value;
     503      ISolutionSimilarityCalculator oldSimilarityCalculator = SimilarityCalculatorParameter.Value;
    496504      SimilarityCalculatorParameter.ValidValues.Clear();
    497       ISingleObjectiveSolutionSimilarityCalculator defaultSimilarityCalculator = Problem.Operators.OfType<ISingleObjectiveSolutionSimilarityCalculator>().FirstOrDefault();
    498 
    499       SimilarityCalculatorParameter.ValidValues.Add(new QualitySimilarityCalculator { QualityVariableName = Problem.Evaluator.QualityParameter.ActualName });
    500       SimilarityCalculatorParameter.ValidValues.Add(new NoSimilarityCalculator());
    501 
    502       foreach (ISingleObjectiveSolutionSimilarityCalculator similarityCalculator in Problem.Operators.OfType<ISingleObjectiveSolutionSimilarityCalculator>())
     505      ISolutionSimilarityCalculator defaultSimilarityCalculator = Problem.Operators.OfType<ISolutionSimilarityCalculator>().FirstOrDefault();
     506
     507      foreach (ISolutionSimilarityCalculator similarityCalculator in Problem.Operators.OfType<ISolutionSimilarityCalculator>())
    503508        SimilarityCalculatorParameter.ValidValues.Add(similarityCalculator);
    504509
    505510      if (oldSimilarityCalculator != null) {
    506         ISingleObjectiveSolutionSimilarityCalculator similarityCalculator = SimilarityCalculatorParameter.ValidValues.FirstOrDefault(x => x.GetType() == oldSimilarityCalculator.GetType());
     511        ISolutionSimilarityCalculator similarityCalculator = SimilarityCalculatorParameter.ValidValues.FirstOrDefault(x => x.GetType() == oldSimilarityCalculator.GetType());
    507512        if (similarityCalculator != null) SimilarityCalculatorParameter.Value = similarityCalculator;
    508513        else oldSimilarityCalculator = null;
  • trunk/sources/HeuristicLab.Algorithms.ScatterSearch/3.3/ScatterSearch.cs

    r12069 r12102  
    8888      get { return (IValueParameter<BoolValue>)Parameters["SetSeedRandomly"]; }
    8989    }
    90     public IConstrainedValueParameter<ISingleObjectiveSolutionSimilarityCalculator> SimilarityCalculatorParameter {
    91       get { return (IConstrainedValueParameter<ISingleObjectiveSolutionSimilarityCalculator>)Parameters["SimilarityCalculator"]; }
     90    public IConstrainedValueParameter<ISolutionSimilarityCalculator> SimilarityCalculatorParameter {
     91      get { return (IConstrainedValueParameter<ISolutionSimilarityCalculator>)Parameters["SimilarityCalculator"]; }
    9292    }
    9393    #endregion
     
    138138      set { SetSeedRandomlyParameter.Value = value; }
    139139    }
    140     public ISingleObjectiveSolutionSimilarityCalculator SimilarityCalculator {
     140    public ISolutionSimilarityCalculator SimilarityCalculator {
    141141      get { return SimilarityCalculatorParameter.Value; }
    142142      set { SimilarityCalculatorParameter.Value = value; }
     
    160160    [StorableHook(HookType.AfterDeserialization)]
    161161    private void AfterDeserialization() {
     162      // BackwardsCompatibility3.3
     163      #region Backwards compatible code, remove with 3.4
     164      if (Parameters.ContainsKey("SimilarityCalculator")) {
     165        var oldParameter = (IConstrainedValueParameter<ISingleObjectiveSolutionSimilarityCalculator>)Parameters["SimilarityCalculator"];
     166        Parameters.Remove(oldParameter);
     167        var newParameter = new ConstrainedValueParameter<ISolutionSimilarityCalculator>("SimilarityCalculator", "The operator used to calculate the similarity between two solutions.", new ItemSet<ISolutionSimilarityCalculator>(oldParameter.ValidValues));
     168        var selectedSimilarityCalculator = newParameter.ValidValues.SingleOrDefault(x => x.GetType() == oldParameter.Value.GetType());
     169        newParameter.Value = selectedSimilarityCalculator;
     170        Parameters.Add(newParameter);
     171      }
     172      #endregion
    162173      Initialize();
    163174    }
     
    184195      Parameters.Add(new ValueParameter<IntValue>("Seed", "The random seed used to initialize the new pseudo random number generator.", new IntValue(0)));
    185196      Parameters.Add(new ValueParameter<BoolValue>("SetSeedRandomly", "True if the random seed should be set to a random value, otherwise false.", new BoolValue(true)));
    186       Parameters.Add(new ConstrainedValueParameter<ISingleObjectiveSolutionSimilarityCalculator>("SimilarityCalculator", "The operator used to calculate the similarity between two solutions."));
     197      Parameters.Add(new ConstrainedValueParameter<ISolutionSimilarityCalculator>("SimilarityCalculator", "The operator used to calculate the similarity between two solutions."));
    187198      #endregion
    188199
     
    390401    }
    391402    private void UpdateSimilarityCalculators() {
    392       ISingleObjectiveSolutionSimilarityCalculator oldSimilarityCalculator = SimilarityCalculatorParameter.Value;
     403      ISolutionSimilarityCalculator oldSimilarityCalculator = SimilarityCalculatorParameter.Value;
    393404      SimilarityCalculatorParameter.ValidValues.Clear();
    394       ISingleObjectiveSolutionSimilarityCalculator defaultSimilarityCalculator = Problem.Operators.OfType<ISingleObjectiveSolutionSimilarityCalculator>().FirstOrDefault();
    395 
    396       SimilarityCalculatorParameter.ValidValues.Add(new QualitySimilarityCalculator { QualityVariableName = Problem.Evaluator.QualityParameter.ActualName });
    397       SimilarityCalculatorParameter.ValidValues.Add(new NoSimilarityCalculator { QualityVariableName = Problem.Evaluator.QualityParameter.ActualName });
    398 
    399       foreach (ISingleObjectiveSolutionSimilarityCalculator similarityCalculator in Problem.Operators.OfType<ISingleObjectiveSolutionSimilarityCalculator>())
     405      ISolutionSimilarityCalculator defaultSimilarityCalculator = Problem.Operators.OfType<ISolutionSimilarityCalculator>().FirstOrDefault();
     406
     407      foreach (ISolutionSimilarityCalculator similarityCalculator in Problem.Operators.OfType<ISolutionSimilarityCalculator>())
    400408        SimilarityCalculatorParameter.ValidValues.Add(similarityCalculator);
    401409
    402410      if (oldSimilarityCalculator != null) {
    403         ISingleObjectiveSolutionSimilarityCalculator similarityCalculator = SimilarityCalculatorParameter.ValidValues.FirstOrDefault(x => x.GetType() == oldSimilarityCalculator.GetType());
     411        ISolutionSimilarityCalculator similarityCalculator = SimilarityCalculatorParameter.ValidValues.FirstOrDefault(x => x.GetType() == oldSimilarityCalculator.GetType());
    404412        if (similarityCalculator != null) SimilarityCalculatorParameter.Value = similarityCalculator;
    405413        else oldSimilarityCalculator = null;
     
    447455    }
    448456    private void ParameterizeSimilarityCalculators() {
    449       foreach (ISingleObjectiveSolutionSimilarityCalculator calc in SimilarityCalculatorParameter.ValidValues) {
     457      foreach (ISolutionSimilarityCalculator calc in SimilarityCalculatorParameter.ValidValues) {
    450458        calc.QualityVariableName = Problem.Evaluator.QualityParameter.ActualName;
    451459      }
  • trunk/sources/HeuristicLab.Optimization.Views/3.3/HeuristicLab.Optimization.Views-3.3.csproj

    r11963 r12102  
    148148      <DependentUpon>CreateNewSingleEncodingDialog.cs</DependentUpon>
    149149    </Compile>
    150     <Compile Include="ISingleObjectiveSolutionSimilarityCalculatorView.cs">
    151       <SubType>UserControl</SubType>
    152     </Compile>
    153     <Compile Include="ISingleObjectiveSolutionSimilarityCalculatorView.Designer.cs">
    154       <DependentUpon>ISingleObjectiveSolutionSimilarityCalculatorView.cs</DependentUpon>
     150    <Compile Include="ISolutionSimilarityCalculatorView.cs">
     151      <SubType>UserControl</SubType>
     152    </Compile>
     153    <Compile Include="ISolutionSimilarityCalculatorView.Designer.cs">
     154      <DependentUpon>ISolutionSimilarityCalculatorView.cs</DependentUpon>
    155155    </Compile>
    156156    <Compile Include="ExperimentListView.cs">
     
    159159    <Compile Include="ExperimentListView.Designer.cs">
    160160      <DependentUpon>ExperimentListView.cs</DependentUpon>
    161     </Compile>
    162     <Compile Include="ISimilarityCalculatorView.cs">
    163       <SubType>UserControl</SubType>
    164     </Compile>
    165     <Compile Include="ISimilarityCalculatorView.Designer.cs">
    166       <DependentUpon>ISimilarityCalculatorView.cs</DependentUpon>
    167161    </Compile>
    168162    <Compile Include="MultiEncodingView.cs">
  • trunk/sources/HeuristicLab.Optimization/3.3/Interfaces/ISingleObjectiveSolutionSimilarityCalculator.cs

    r12085 r12102  
    2020#endregion
    2121
     22using System;
     23
    2224namespace HeuristicLab.Optimization {
     25  // use HeuristicLab.Optimization.ISolutionSimilarityCalculator instead
     26  // BackwardsCompatibility3.3
     27  #region Backwards compatible code, remove with 3.4
    2328  /// <summary>
    2429  /// An interface which represents an operator for similarity calculation between single objective solutions.
    2530  /// </summary>
     31  [Obsolete("use HeuristicLab.Optimization.ISolutionSimilarityCalculator instead")]
    2632  public interface ISingleObjectiveSolutionSimilarityCalculator : ISolutionSimilarityCalculator, ISingleObjectiveOperator {
    2733
    2834  }
     35  #endregion
    2936}
  • trunk/sources/HeuristicLab.Problems.Knapsack/3.3/KnapsackProblem.cs

    r12087 r12102  
    2929using HeuristicLab.Encodings.BinaryVectorEncoding;
    3030using HeuristicLab.Optimization;
     31using HeuristicLab.Optimization.Operators;
    3132using HeuristicLab.Parameters;
    3233using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
     
    251252      Operators.Add(new KnapsackSimultaneousPathRelinker());
    252253      Operators.Add(new KnapsackSimilarityCalculator());
     254      Operators.Add(new QualitySimilarityCalculator { QualityVariableName = SolutionCreator.BinaryVectorParameter.ActualName });
     255      Operators.Add(new NoSimilarityCalculator());
    253256
    254257      Operators.Add(new BestKnapsackSolutionAnalyzer());
  • trunk/sources/HeuristicLab.Problems.TestFunctions/3.3/SingleObjectiveTestFunctionProblem.cs

    r12087 r12102  
    2929using HeuristicLab.Encodings.RealVectorEncoding;
    3030using HeuristicLab.Optimization;
     31using HeuristicLab.Optimization.Operators;
    3132using HeuristicLab.Parameters;
    3233using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
     
    260261      Operators.Add(new SingleObjectiveTestFunctionPathRelinker());
    261262      Operators.Add(new SingleObjectiveTestFunctionSimilarityCalculator());
     263      Operators.Add(new QualitySimilarityCalculator { QualityVariableName = SolutionCreator.RealVectorParameter.ActualName });
     264      Operators.Add(new NoSimilarityCalculator());
    262265
    263266      Operators.Add(new BestSingleObjectiveTestFunctionSolutionAnalyzer());
     
    315318      try {
    316319        BestKnownSolutionParameter.Value = Evaluator.GetBestKnownSolution(ProblemSize.Value);
    317       } catch (ArgumentException e) {
     320      }
     321      catch (ArgumentException e) {
    318322        ErrorHandling.ShowErrorDialog(e);
    319323        ProblemSize.Value = Evaluator.MinimumProblemSize;
  • trunk/sources/HeuristicLab.Problems.TravelingSalesman/3.3/TravelingSalesmanProblem.cs

    r12087 r12102  
    3030using HeuristicLab.Encodings.PermutationEncoding;
    3131using HeuristicLab.Optimization;
     32using HeuristicLab.Optimization.Operators;
    3233using HeuristicLab.Parameters;
    3334using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
     
    233234      Operators.Add(new TSPSimultaneousPathRelinker());
    234235      Operators.Add(new TSPSimilarityCalculator());
     236      Operators.Add(new QualitySimilarityCalculator { QualityVariableName = SolutionCreator.PermutationParameter.ActualName });
     237      Operators.Add(new NoSimilarityCalculator());
    235238
    236239      Operators.Add(new BestTSPSolutionAnalyzer());
  • trunk/sources/HeuristicLab.Problems.VehicleRouting/3.4/VehicleRoutingProblem.cs

    r12087 r12102  
    2929using HeuristicLab.Data;
    3030using HeuristicLab.Optimization;
     31using HeuristicLab.Optimization.Operators;
    3132using HeuristicLab.Parameters;
    3233using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
     
    253254          ApplicationManager.Manager.GetInstances<IGeneralVRPOperator>().Cast<IOperator>()).OrderBy(op => op.Name));
    254255        Operators.Add(new VRPSimilarityCalculator());
     256        Operators.Add(new QualitySimilarityCalculator());
     257        Operators.Add(new NoSimilarityCalculator());
    255258        Operators.Add(new PopulationSimilarityAnalyzer(Operators.OfType<ISolutionSimilarityCalculator>()));
    256259
     
    284287          op.ParentsParameter.Hidden = true;
    285288        }
    286         foreach (VRPSimilarityCalculator op in Operators.OfType<VRPSimilarityCalculator>()) {
     289        foreach (ISolutionSimilarityCalculator op in Operators.OfType<ISolutionSimilarityCalculator>()) {
    287290          op.SolutionVariableName = SolutionCreator.VRPToursParameter.ActualName;
    288291          op.QualityVariableName = ProblemInstance.SolutionEvaluator.QualityParameter.ActualName;
    289           op.ProblemInstance = ProblemInstance;
     292          var calc = op as VRPSimilarityCalculator;
     293          if (calc != null) calc.ProblemInstance = ProblemInstance;
    290294        }
    291295      }
Note: See TracChangeset for help on using the changeset viewer.