Free cookie consent management tool by TermsFeed Policy Generator

Changeset 3787


Ignore:
Timestamp:
05/11/10 21:16:12 (15 years ago)
Author:
abeham
Message:

#893

  • Removed best known quality tracking from BestAverageWorstQualityAnalyzer
  • Added best known quality / solution tracking to problem specific analyzers
Location:
trunk/sources
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Analysis/3.3/BestAverageWorstQualityAnalyzer.cs

    r3662 r3787  
    7777      get { return (BestQualityMemorizer)OperatorGraph.InitialOperator; }
    7878    }
    79     private BestQualityMemorizer BestKnownQualityMemorizer {
    80       get { return (BestQualityMemorizer)BestQualityMemorizer.Successor; }
    81     }
    8279    private BestAverageWorstQualityCalculator BestAverageWorstQualityCalculator {
    83       get { return (BestAverageWorstQualityCalculator)BestKnownQualityMemorizer.Successor; }
     80      get { return (BestAverageWorstQualityCalculator)BestQualityMemorizer.Successor; }
    8481    }
    8582    #endregion
     
    103100      #region Create operators
    104101      BestQualityMemorizer bestQualityMemorizer = new BestQualityMemorizer();
    105       BestQualityMemorizer bestKnownQualityMemorizer = new BestQualityMemorizer();
    106102      BestAverageWorstQualityCalculator bestAverageWorstQualityCalculator = new BestAverageWorstQualityCalculator();
    107103      DataTableValuesCollector dataTableValuesCollector = new DataTableValuesCollector();
     
    113109      bestQualityMemorizer.QualityParameter.ActualName = QualityParameter.Name;
    114110      bestQualityMemorizer.QualityParameter.Depth = QualityParameter.Depth;
    115 
    116       bestKnownQualityMemorizer.BestQualityParameter.ActualName = BestKnownQualityParameter.Name;
    117       bestKnownQualityMemorizer.MaximizationParameter.ActualName = MaximizationParameter.Name;
    118       bestKnownQualityMemorizer.QualityParameter.ActualName = QualityParameter.Name;
    119       bestKnownQualityMemorizer.QualityParameter.Depth = QualityParameter.Depth;
    120111
    121112      bestAverageWorstQualityCalculator.AverageQualityParameter.ActualName = CurrentAverageQualityParameter.Name;
     
    151142      #region Create operator graph
    152143      OperatorGraph.InitialOperator = bestQualityMemorizer;
    153       bestQualityMemorizer.Successor = bestKnownQualityMemorizer;
    154       bestKnownQualityMemorizer.Successor = bestAverageWorstQualityCalculator;
     144      bestQualityMemorizer.Successor = bestAverageWorstQualityCalculator;
    155145      bestAverageWorstQualityCalculator.Successor = dataTableValuesCollector;
    156146      dataTableValuesCollector.Successor = qualityDifferenceCalculator;
     
    177167    private void QualityParameter_DepthChanged(object sender, System.EventArgs e) {
    178168      BestQualityMemorizer.QualityParameter.Depth = QualityParameter.Depth;
    179       BestKnownQualityMemorizer.QualityParameter.Depth = QualityParameter.Depth;
    180169      BestAverageWorstQualityCalculator.QualityParameter.Depth = QualityParameter.Depth;
    181170    }
  • trunk/sources/HeuristicLab.Problems.Knapsack/3.3/Analyzers/BestKnapsackSolutionAnalyzer.cs

    r3667 r3787  
    3939  [StorableClass]
    4040  class BestKnapsackSolutionAnalyzer : SingleSuccessorOperator, IAnalyzer {
    41 
     41    public LookupParameter<BoolValue> MaximizationParameter {
     42      get { return (LookupParameter<BoolValue>)Parameters["Maximization"]; }
     43    }
    4244    public ScopeTreeLookupParameter<BinaryVector> BinaryVectorParameter {
    4345      get { return (ScopeTreeLookupParameter<BinaryVector>)Parameters["BinaryVector"]; }
     
    6163      get { return (ValueLookupParameter<ResultCollection>)Parameters["Results"]; }
    6264    }
     65    public LookupParameter<DoubleValue> BestKnownQualityParameter {
     66      get { return (LookupParameter<DoubleValue>)Parameters["BestKnownQuality"]; }
     67    }
     68    public LookupParameter<BinaryVector> BestKnownSolutionParameter {
     69      get { return (LookupParameter<BinaryVector>)Parameters["BestKnownSolution"]; }
     70    }
    6371
    6472    public BestKnapsackSolutionAnalyzer()
    6573      : base() {
     74      Parameters.Add(new LookupParameter<BoolValue>("Maximization", "True if the problem is a maximization problem."));
    6675      Parameters.Add(new ScopeTreeLookupParameter<BinaryVector>("BinaryVector", "The knapsack solutions from which the best solution should be visualized."));
    6776      Parameters.Add(new LookupParameter<IntValue>("KnapsackCapacity", "Capacity of the Knapsack."));
     
    7281      Parameters.Add(new LookupParameter<KnapsackSolution>("BestSolution", "The best knapsack solution."));
    7382      Parameters.Add(new ValueLookupParameter<ResultCollection>("Results", "The result collection where the knapsack solution should be stored."));
     83      Parameters.Add(new LookupParameter<DoubleValue>("BestKnownQuality", "The quality of the best known solution."));
     84      Parameters.Add(new LookupParameter<BinaryVector>("BestKnownSolution", "The best known solution."));
    7485    }
    7586
     
    7889      ItemArray<DoubleValue> qualities = QualityParameter.ActualValue;
    7990      ResultCollection results = ResultsParameter.ActualValue;
     91      bool max = MaximizationParameter.ActualValue.Value;
     92      DoubleValue bestKnownQuality = BestKnownQualityParameter.ActualValue;
    8093
    81       int i = qualities.Select((x, index) => new { index, x.Value }).OrderBy(x => x.Value).First().index;
     94      int i = -1;
     95      if (!max)
     96        i = qualities.Select((x, index) => new { index, x.Value }).OrderBy(x => x.Value).First().index;
     97      else i = qualities.Select((x, index) => new { index, x.Value }).OrderByDescending(x => x.Value).First().index;
     98
     99      if (bestKnownQuality == null ||
     100          max && qualities[i].Value > bestKnownQuality.Value ||
     101          !max && qualities[i].Value < bestKnownQuality.Value) {
     102        BestKnownQualityParameter.ActualValue = new DoubleValue(qualities[i].Value);
     103        BestKnownSolutionParameter.ActualValue = (BinaryVector)binaryVectors[i].Clone();
     104      }
    82105
    83106      KnapsackSolution solution = BestSolutionParameter.ActualValue;
    84107      if (solution == null) {
    85         solution = new KnapsackSolution(binaryVectors[i], qualities[i],
     108        solution = new KnapsackSolution((BinaryVector)binaryVectors[i].Clone(), new DoubleValue(qualities[i].Value),
    86109          KnapsackCapacityParameter.ActualValue, WeightsParameter.ActualValue, ValuesParameter.ActualValue);
    87110        BestSolutionParameter.ActualValue = solution;
    88111        results.Add(new Result("Best Knapsack Solution", solution));
    89112      }  else {
    90         solution.BinaryVector = binaryVectors[i];
    91         solution.Quality = qualities[i];
    92         solution.Capacity = KnapsackCapacityParameter.ActualValue;
    93         solution.Weights = WeightsParameter.ActualValue;
    94         solution.Values = ValuesParameter.ActualValue;
    95 
    96         results["Best Knapsack Solution"].Value = solution;
     113        if (max && qualities[i].Value > solution.Quality.Value ||
     114          !max && qualities[i].Value < solution.Quality.Value) {
     115          solution.BinaryVector = (BinaryVector)binaryVectors[i].Clone();
     116          solution.Quality = new DoubleValue(qualities[i].Value);
     117          solution.Capacity = KnapsackCapacityParameter.ActualValue;
     118          solution.Weights = WeightsParameter.ActualValue;
     119          solution.Values = ValuesParameter.ActualValue;
     120        }
    97121      }
    98122
  • trunk/sources/HeuristicLab.Problems.Knapsack/3.3/KnapsackProblem.cs

    r3739 r3787  
    8080      get { return BestKnownQualityParameter; }
    8181    }
     82    public OptionalValueParameter<BinaryVector> BestKnownSolutionParameter {
     83      get { return (OptionalValueParameter<BinaryVector>)Parameters["BestKnownSolution"]; }
     84    }
    8285    #endregion
    8386
     
    119122      get { return BestKnownQualityParameter.Value; }
    120123      set { BestKnownQualityParameter.Value = value; }
     124    }
     125    public BinaryVector BestKnownSolution {
     126      get { return BestKnownSolutionParameter.Value; }
     127      set { BestKnownSolutionParameter.Value = value; }
    121128    }
    122129    private List<IOperator> operators;
     
    164171      Parameters.Add(new ValueParameter<IKnapsackEvaluator>("Evaluator", "The operator which should be used to evaluate Knapsack solutions.", evaluator));
    165172      Parameters.Add(new OptionalValueParameter<DoubleValue>("BestKnownQuality", "The quality of the best known solution of this Knapsack instance."));
     173      Parameters.Add(new OptionalValueParameter<BinaryVector>("BestKnownSolution", "The best known solution of this Knapsack instance."));
    166174
    167175      creator.BinaryVectorParameter.ActualName = "KnapsackSolution";
  • trunk/sources/HeuristicLab.Problems.OneMax/3.3/Analyzers/BestOneMaxSolutionAnalyzer.cs

    r3667 r3787  
    3939  [StorableClass]
    4040  class BestOneMaxSolutionAnalyzer : SingleSuccessorOperator, IAnalyzer {
    41 
     41    public LookupParameter<BoolValue> MaximizationParameter {
     42      get { return (LookupParameter<BoolValue>)Parameters["Maximization"]; }
     43    }
    4244    public ScopeTreeLookupParameter<BinaryVector> BinaryVectorParameter {
    4345      get { return (ScopeTreeLookupParameter<BinaryVector>)Parameters["BinaryVector"]; }
     
    5254      get { return (ValueLookupParameter<ResultCollection>)Parameters["Results"]; }
    5355    }
     56    public LookupParameter<DoubleValue> BestKnownQualityParameter {
     57      get { return (LookupParameter<DoubleValue>)Parameters["BestKnownQuality"]; }
     58    }
    5459
    5560    public BestOneMaxSolutionAnalyzer()
    5661      : base() {
     62      Parameters.Add(new LookupParameter<BoolValue>("Maximization", "True if the problem is a maximization problem."));
    5763      Parameters.Add(new ScopeTreeLookupParameter<BinaryVector>("BinaryVector", "The Onemax solutions from which the best solution should be visualized."));
    58 
    5964      Parameters.Add(new ScopeTreeLookupParameter<DoubleValue>("Quality", "The qualities of the Onemax solutions which should be visualized."));
    6065      Parameters.Add(new LookupParameter<OneMaxSolution>("BestSolution", "The best Onemax solution."));
    6166      Parameters.Add(new ValueLookupParameter<ResultCollection>("Results", "The result collection where the Onemax solution should be stored."));
     67      Parameters.Add(new LookupParameter<DoubleValue>("BestKnownQuality", "The quality of the best known solution."));
    6268    }
    6369
     
    6672      ItemArray<DoubleValue> qualities = QualityParameter.ActualValue;
    6773      ResultCollection results = ResultsParameter.ActualValue;
     74      bool max = MaximizationParameter.ActualValue.Value;
     75      DoubleValue bestKnownQuality = BestKnownQualityParameter.ActualValue;
    6876
    69       int i = qualities.Select((x, index) => new { index, x.Value }).OrderBy(x => x.Value).First().index;
     77      int i = -1;
     78      if (!max)
     79        i = qualities.Select((x, index) => new { index, x.Value }).OrderBy(x => x.Value).First().index;
     80      else i = qualities.Select((x, index) => new { index, x.Value }).OrderByDescending(x => x.Value).First().index;
     81
     82      if (bestKnownQuality == null ||
     83          max && qualities[i].Value > bestKnownQuality.Value ||
     84          !max && qualities[i].Value < bestKnownQuality.Value) {
     85        BestKnownQualityParameter.ActualValue = new DoubleValue(qualities[i].Value);
     86      }
    7087
    7188      OneMaxSolution solution = BestSolutionParameter.ActualValue;
    7289      if (solution == null) {
    73         solution = new OneMaxSolution(binaryVectors[i], QualityParameter.ActualValue[i]);
     90        solution = new OneMaxSolution((BinaryVector)binaryVectors[i].Clone(), new DoubleValue(qualities[i].Value));
    7491        BestSolutionParameter.ActualValue = solution;
    7592        results.Add(new Result("Best OneMax Solution", solution));
    7693      }  else {
    77         solution.BinaryVector = binaryVectors[i];
    78         solution.Quality = QualityParameter.ActualValue[i];
    79 
    80         results["Best OneMax Solution"].Value = solution;
     94        if (max && qualities[i].Value > solution.Quality.Value ||
     95          !max && qualities[i].Value < solution.Quality.Value) {
     96          solution.BinaryVector = (BinaryVector)binaryVectors[i].Clone();
     97          solution.Quality = new DoubleValue(qualities[i].Value);
     98        }
    8199      }
    82100
  • trunk/sources/HeuristicLab.Problems.TestFunctions/3.3/Analyzers/BestSingleObjectiveTestFunctionSolutionAnalyzer.cs

    r3781 r3787  
    3939  [StorableClass]
    4040  class BestSingleObjectiveTestFunctionSolutionAnalyzer : SingleSuccessorOperator, IBestSingleObjectiveTestFunctionSolutionAnalyzer, IAnalyzer {
    41 
     41    public LookupParameter<BoolValue> MaximizationParameter {
     42      get { return (LookupParameter<BoolValue>)Parameters["Maximization"]; }
     43    }
    4244    public ScopeTreeLookupParameter<RealVector> RealVectorParameter {
    4345      get { return (ScopeTreeLookupParameter<RealVector>)Parameters["RealVector"]; }
     
    7072    public BestSingleObjectiveTestFunctionSolutionAnalyzer()
    7173      : base() {
     74      Parameters.Add(new LookupParameter<BoolValue>("Maximization", "True if the problem is a maximization problem."));
    7275      Parameters.Add(new ScopeTreeLookupParameter<RealVector>("RealVector", "The SingleObjectiveTestFunction solutions from which the best solution should be visualized."));
    7376      Parameters.Add(new ScopeTreeLookupParameter<DoubleValue>("Quality", "The qualities of the SingleObjectiveTestFunction solutions which should be visualized."));
     
    8487      ResultCollection results = ResultsParameter.ActualValue;
    8588      ISingleObjectiveTestFunctionProblemEvaluator evaluator = EvaluatorParameter.ActualValue;
    86       bool max = evaluator.Maximization;
     89      bool max = MaximizationParameter.ActualValue.Value;
     90      DoubleValue bestKnownQuality = BestKnownQualityParameter.ActualValue;
    8791
    8892      int i = qualities.Select((x, index) => new { index, x.Value }).OrderBy(x => x.Value).First().index;
     93
     94      if (bestKnownQuality == null ||
     95          max && qualities[i].Value > bestKnownQuality.Value
     96          || !max && qualities[i].Value < bestKnownQuality.Value) {
     97        BestKnownQualityParameter.ActualValue = new DoubleValue(qualities[i].Value);
     98        BestKnownSolutionParameter.ActualValue = (RealVector)realVectors[i].Clone();
     99      }
     100
    89101      SingleObjectiveTestFunctionSolution solution = BestSolutionParameter.ActualValue;
    90102      if (solution == null) {
    91103        solution = new SingleObjectiveTestFunctionSolution(realVectors[i], qualities[i], evaluator);
    92104        solution.Population = realVectors;
    93         double bestknownQuality = BestKnownQualityParameter.ActualValue.Value;
    94         if (max && qualities[i].Value >= bestknownQuality
    95           || !max && qualities[i].Value <= bestknownQuality) {
    96           BestKnownSolutionParameter.ActualValue = (RealVector)realVectors[i].Clone();
    97         }
    98105        solution.BestKnownRealVector = BestKnownSolutionParameter.ActualValue;
    99106        BestSolutionParameter.ActualValue = solution;
    100         results.Add(new Result("Best SingleObjectiveTestFunction Solution", solution));
     107        results.Add(new Result("Best Solution", solution));
    101108      } else {
    102         double bestknownQuality = BestKnownQualityParameter.ActualValue.Value;
    103         if (max && qualities[i].Value >= bestknownQuality
    104           || !max && qualities[i].Value <= bestknownQuality) {
    105           BestKnownSolutionParameter.ActualValue = (RealVector)realVectors[i].Clone();
    106         }
    107109        if (max && qualities[i].Value > solution.BestQuality.Value
    108110          || !max && qualities[i].Value < solution.BestQuality.Value) {
     
    111113        }
    112114        solution.Population = realVectors;
    113         //results["Best SingleObjectiveTestFunction Solution"].Value = solution;
    114115      }
    115116
  • trunk/sources/HeuristicLab.Problems.TravelingSalesman/3.3/Analyzers/BestTSPSolutionAnalyzer.cs

    r3692 r3787  
    3737  [StorableClass]
    3838  public sealed class BestTSPSolutionAnalyzer : SingleSuccessorOperator, IAnalyzer {
     39    public LookupParameter<BoolValue> MaximizationParameter {
     40      get { return (LookupParameter<BoolValue>)Parameters["Maximization"]; }
     41    }
    3942    public LookupParameter<DoubleMatrix> CoordinatesParameter {
    4043      get { return (LookupParameter<DoubleMatrix>)Parameters["Coordinates"]; }
     
    5255      get { return (ValueLookupParameter<ResultCollection>)Parameters["Results"]; }
    5356    }
     57    public LookupParameter<DoubleValue> BestKnownQualityParameter {
     58      get { return (LookupParameter<DoubleValue>)Parameters["BestKnownQuality"]; }
     59    }
     60    public LookupParameter<Permutation> BestKnownSolutionParameter {
     61      get { return (LookupParameter<Permutation>)Parameters["BestKnownSolution"]; }
     62    }
    5463
    5564    public BestTSPSolutionAnalyzer()
    5665      : base() {
     66      Parameters.Add(new LookupParameter<BoolValue>("Maximization", "True if the problem is a maximization problem."));
    5767      Parameters.Add(new LookupParameter<DoubleMatrix>("Coordinates", "The x- and y-Coordinates of the cities."));
    5868      Parameters.Add(new ScopeTreeLookupParameter<Permutation>("Permutation", "The TSP solutions given in path representation from which the best solution should be analyzed."));
     
    6070      Parameters.Add(new LookupParameter<PathTSPTour>("BestSolution", "The best TSP solution."));
    6171      Parameters.Add(new ValueLookupParameter<ResultCollection>("Results", "The result collection where the best TSP solution should be stored."));
     72      Parameters.Add(new LookupParameter<DoubleValue>("BestKnownQuality", "The quality of the best known solution of this TSP instance."));
     73      Parameters.Add(new LookupParameter<Permutation>("BestKnownSolution", "The best known solution of this TSP instance."));
    6274    }
    6375
     
    6779      ItemArray<DoubleValue> qualities = QualityParameter.ActualValue;
    6880      ResultCollection results = ResultsParameter.ActualValue;
     81      bool max = MaximizationParameter.ActualValue.Value;
     82      DoubleValue bestKnownQuality = BestKnownQualityParameter.ActualValue;
    6983
    70       int i = qualities.Select((x, index) => new { index, x.Value }).OrderBy(x => x.Value).First().index;
     84      int i = -1;
     85      if (!max)
     86        i = qualities.Select((x, index) => new { index, x.Value }).OrderBy(x => x.Value).First().index;
     87      else i = qualities.Select((x, index) => new { index, x.Value }).OrderByDescending(x => x.Value).First().index;
     88     
     89      if (bestKnownQuality == null ||
     90          max && qualities[i].Value > bestKnownQuality.Value ||
     91          !max && qualities[i].Value < bestKnownQuality.Value) {
     92        BestKnownQualityParameter.ActualValue = new DoubleValue(qualities[i].Value);
     93        BestKnownSolutionParameter.ActualValue = (Permutation)permutations[i].Clone();
     94      }
    7195
    7296      PathTSPTour tour = BestSolutionParameter.ActualValue;
     
    76100        results.Add(new Result("Best TSP Solution", tour));
    77101      } else {
    78         if (tour.Quality.Value > qualities[i].Value) {
     102        if (max && tour.Quality.Value < qualities[i].Value ||
     103          !max && tour.Quality.Value > qualities[i].Value) {
    79104          tour.Coordinates = coordinates;
    80105          tour.Permutation = (Permutation)permutations[i].Clone();
    81106          tour.Quality.Value = qualities[i].Value;
    82           results["Best TSP Solution"].Value = tour;
    83107        }
    84108      }
Note: See TracChangeset for help on using the changeset viewer.