Free cookie consent management tool by TermsFeed Policy Generator

Changeset 3080 for trunk


Ignore:
Timestamp:
03/17/10 13:24:11 (15 years ago)
Author:
swagner
Message:

Implemented first version of best and best known quality handling (#920)

Location:
trunk/sources
Files:
11 edited

Legend:

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

    r3076 r3080  
    249249    }
    250250    private void ParameterizeSGAMainLoop() {
     251      SGAMainLoop.BestKnownQualityParameter.ActualName = Problem.BestKnownQualityParameter.Name;
    251252      SGAMainLoop.EvaluatorParameter.ActualName = Problem.EvaluatorParameter.Name;
    252253      SGAMainLoop.MaximizationParameter.ActualName = Problem.MaximizationParameter.Name;
  • trunk/sources/HeuristicLab.Algorithms.SGA/3.3/SGAMainLoop.cs

    r3048 r3080  
    3636  [Creatable("Test")]
    3737  [StorableClass]
    38   public class SGAMainLoop : AlgorithmOperator {
     38  public sealed class SGAMainLoop : AlgorithmOperator {
    3939    #region Parameter properties
    4040    public ValueLookupParameter<IRandom> RandomParameter {
     
    4747      get { return (SubScopesLookupParameter<DoubleValue>)Parameters["Quality"]; }
    4848    }
     49    public ValueLookupParameter<DoubleValue> BestKnownQualityParameter {
     50      get { return (ValueLookupParameter<DoubleValue>)Parameters["BestKnownQuality"]; }
     51    }
    4952    public ValueLookupParameter<IOperator> SelectorParameter {
    5053      get { return (ValueLookupParameter<IOperator>)Parameters["Selector"]; }
     
    8083    #endregion
    8184
     85    [StorableConstructor]
     86    private SGAMainLoop(bool deserializing) : base() { }
    8287    public SGAMainLoop()
    8388      : base() {
     89      Initialize();
     90    }
     91
     92    private void Initialize() {
    8493      #region Create parameters
    8594      Parameters.Add(new ValueLookupParameter<IRandom>("Random", "A pseudo random number generator."));
    8695      Parameters.Add(new ValueLookupParameter<BoolValue>("Maximization", "True if the problem is a maximization problem, otherwise false."));
    8796      Parameters.Add(new SubScopesLookupParameter<DoubleValue>("Quality", "The value which represents the quality of a solution."));
     97      Parameters.Add(new ValueLookupParameter<DoubleValue>("BestKnownQuality", "The best known quality value found so far."));
    8898      Parameters.Add(new ValueLookupParameter<IOperator>("Selector", "The operator used to select solutions for reproduction."));
    8999      Parameters.Add(new ValueLookupParameter<IOperator>("Crossover", "The operator used to cross solutions."));
     
    97107      #endregion
    98108
    99       #region Create operator graph
     109      #region Create operators
    100110      VariableCreator variableCreator = new VariableCreator();
     111      BestQualityMemorizer bestQualityMemorizer1 = new BestQualityMemorizer();
     112      BestAverageWorstQualityCalculator bestAverageWorstQualityCalculator1 = new BestAverageWorstQualityCalculator();
     113      DataTableValuesCollector dataTableValuesCollector1 = new DataTableValuesCollector();
    101114      ResultsCollector resultsCollector = new ResultsCollector();
    102115      SubScopesSorter subScopesSorter1 = new SubScopesSorter();
     
    117130      IntCounter intCounter = new IntCounter();
    118131      Comparator comparator = new Comparator();
    119       BestAverageWorstQualityCalculator bestAverageWorstQualityCalculator = new BestAverageWorstQualityCalculator();
    120       DataTableValuesCollector dataTableValuesCollector = new DataTableValuesCollector();
     132      BestQualityMemorizer bestQualityMemorizer2 = new BestQualityMemorizer();
     133      BestAverageWorstQualityCalculator bestAverageWorstQualityCalculator2 = new BestAverageWorstQualityCalculator();
     134      DataTableValuesCollector dataTableValuesCollector2 = new DataTableValuesCollector();
    121135      ConditionalBranch conditionalBranch = new ConditionalBranch();
    122136
    123       OperatorGraph.InitialOperator = variableCreator;
    124 
    125137      variableCreator.CollectedValues.Add(new ValueParameter<IntValue>("Generations", new IntValue(0)));
    126       variableCreator.CollectedValues.Add(new ValueParameter<DoubleValue>("Best Quality", new DoubleValue(0)));
    127       variableCreator.CollectedValues.Add(new ValueParameter<DoubleValue>("Average Quality", new DoubleValue(0)));
    128       variableCreator.CollectedValues.Add(new ValueParameter<DoubleValue>("Worst Quality", new DoubleValue(0)));
    129       variableCreator.CollectedValues.Add(new ValueParameter<DataTable>("Qualities", new DataTable("Qualities")));
    130       variableCreator.Successor = resultsCollector;
     138
     139      bestQualityMemorizer1.BestQualityParameter.ActualName = "Best Quality";
     140      bestQualityMemorizer1.MaximizationParameter.ActualName = "Maximization";
     141      bestQualityMemorizer1.QualityParameter.ActualName = "Quality";
     142
     143      bestAverageWorstQualityCalculator1.AverageQualityParameter.ActualName = "Current Average Quality";
     144      bestAverageWorstQualityCalculator1.BestQualityParameter.ActualName = "Current Best Quality";
     145      bestAverageWorstQualityCalculator1.MaximizationParameter.ActualName = "Maximization";
     146      bestAverageWorstQualityCalculator1.QualityParameter.ActualName = "Quality";
     147      bestAverageWorstQualityCalculator1.WorstQualityParameter.ActualName = "Current Worst Quality";
     148
     149      dataTableValuesCollector1.CollectedValues.Add(new LookupParameter<DoubleValue>("Current Best Quality"));
     150      dataTableValuesCollector1.CollectedValues.Add(new LookupParameter<DoubleValue>("Current Average Quality"));
     151      dataTableValuesCollector1.CollectedValues.Add(new LookupParameter<DoubleValue>("Current Worst Quality"));
     152      dataTableValuesCollector1.CollectedValues.Add(new LookupParameter<DoubleValue>("Best Quality"));
     153      dataTableValuesCollector1.CollectedValues.Add(new LookupParameter<DoubleValue>("Best Known Quality", null, "BestKnownQuality"));
     154      dataTableValuesCollector1.DataTableParameter.ActualName = "Qualities";
    131155
    132156      resultsCollector.CollectedValues.Add(new LookupParameter<IntValue>("Generations"));
     157      resultsCollector.CollectedValues.Add(new LookupParameter<DoubleValue>("Current Best Quality"));
     158      resultsCollector.CollectedValues.Add(new LookupParameter<DoubleValue>("Current Average Quality"));
     159      resultsCollector.CollectedValues.Add(new LookupParameter<DoubleValue>("Current Worst Quality"));
    133160      resultsCollector.CollectedValues.Add(new LookupParameter<DoubleValue>("Best Quality"));
    134       resultsCollector.CollectedValues.Add(new LookupParameter<DoubleValue>("Average Quality"));
    135       resultsCollector.CollectedValues.Add(new LookupParameter<DoubleValue>("Worst Quality"));
     161      resultsCollector.CollectedValues.Add(new LookupParameter<DoubleValue>("Best Known Quality", null, "BestKnownQuality"));
    136162      resultsCollector.CollectedValues.Add(new LookupParameter<DataTable>("Qualities"));
    137163      resultsCollector.ResultsParameter.ActualName = "Results";
    138       resultsCollector.Successor = subScopesSorter1;
    139164
    140165      subScopesSorter1.DescendingParameter.ActualName = "Maximization";
    141166      subScopesSorter1.ValueParameter.ActualName = "Quality";
    142       subScopesSorter1.Successor = selector;
    143167
    144168      selector.Name = "Selector";
    145169      selector.OperatorParameter.ActualName = "Selector";
    146       selector.Successor = sequentialSubScopesProcessor1;
    147 
    148       sequentialSubScopesProcessor1.Operators.Add(new EmptyOperator());
    149       sequentialSubScopesProcessor1.Operators.Add(childrenCreator);
    150       sequentialSubScopesProcessor1.Successor = sequentialSubScopesProcessor2;
    151170
    152171      childrenCreator.ParentsPerChild = new IntValue(2);
    153       childrenCreator.Successor = uniformSequentialSubScopesProcessor;
    154 
    155       uniformSequentialSubScopesProcessor.Operator = crossover;
    156       uniformSequentialSubScopesProcessor.Successor = subScopesSorter2;
    157172
    158173      crossover.Name = "Crossover";
    159174      crossover.OperatorParameter.ActualName = "Crossover";
    160       crossover.Successor = stochasticBranch;
    161 
    162       stochasticBranch.FirstBranch = mutator;
     175
    163176      stochasticBranch.ProbabilityParameter.ActualName = "MutationProbability";
    164177      stochasticBranch.RandomParameter.ActualName = "Random";
    165       stochasticBranch.SecondBranch = null;
    166       stochasticBranch.Successor = evaluator;
    167178
    168179      mutator.Name = "Mutator";
    169180      mutator.OperatorParameter.ActualName = "Mutator";
    170       mutator.Successor = null;
    171181
    172182      evaluator.Name = "Evaluator";
    173183      evaluator.OperatorParameter.ActualName = "Evaluator";
    174       evaluator.Successor = subScopesRemover;
    175184
    176185      subScopesRemover.RemoveAllSubScopes = true;
    177       subScopesRemover.Successor = null;
    178186
    179187      subScopesSorter2.DescendingParameter.ActualName = "Maximization";
    180188      subScopesSorter2.ValueParameter.ActualName = "Quality";
    181       subScopesSorter2.Successor = null;
    182 
    183       sequentialSubScopesProcessor2.Operators.Add(leftSelector);
    184       sequentialSubScopesProcessor2.Operators.Add(new EmptyOperator());
    185       sequentialSubScopesProcessor2.Successor = mergingReducer;
    186189
    187190      leftSelector.CopySelected = new BoolValue(false);
    188191      leftSelector.NumberOfSelectedSubScopesParameter.ActualName = "Elites";
    189       leftSelector.Successor = rightReducer;
    190 
    191       rightReducer.Successor = null;
    192 
    193       mergingReducer.Successor = intCounter;
    194192
    195193      intCounter.Increment = new IntValue(1);
    196194      intCounter.ValueParameter.ActualName = "Generations";
    197       intCounter.Successor = comparator;
    198195
    199196      comparator.Comparison = new Comparison(ComparisonType.GreaterOrEqual);
     
    201198      comparator.ResultParameter.ActualName = "Terminate";
    202199      comparator.RightSideParameter.ActualName = "MaximumGenerations";
    203       comparator.Successor = bestAverageWorstQualityCalculator;
    204 
    205       bestAverageWorstQualityCalculator.AverageQualityParameter.ActualName = "Average Quality";
    206       bestAverageWorstQualityCalculator.BestQualityParameter.ActualName = "Best Quality";
    207       bestAverageWorstQualityCalculator.MaximizationParameter.ActualName = "Maximization";
    208       bestAverageWorstQualityCalculator.QualityParameter.ActualName = "Quality";
    209       bestAverageWorstQualityCalculator.WorstQualityParameter.ActualName = "Worst Quality";
    210       bestAverageWorstQualityCalculator.Successor = dataTableValuesCollector;
    211 
    212       dataTableValuesCollector.CollectedValues.Add(new LookupParameter<DoubleValue>("Best Quality"));
    213       dataTableValuesCollector.CollectedValues.Add(new LookupParameter<DoubleValue>("Average Quality"));
    214       dataTableValuesCollector.CollectedValues.Add(new LookupParameter<DoubleValue>("Worst Quality"));
    215       dataTableValuesCollector.DataTableParameter.ActualName = "Qualities";
    216       dataTableValuesCollector.Successor = conditionalBranch;
     200
     201      bestQualityMemorizer2.BestQualityParameter.ActualName = "Best Quality";
     202      bestQualityMemorizer2.MaximizationParameter.ActualName = "Maximization";
     203      bestQualityMemorizer2.QualityParameter.ActualName = "Quality";
     204
     205      bestAverageWorstQualityCalculator2.AverageQualityParameter.ActualName = "Current Average Quality";
     206      bestAverageWorstQualityCalculator2.BestQualityParameter.ActualName = "Current Best Quality";
     207      bestAverageWorstQualityCalculator2.MaximizationParameter.ActualName = "Maximization";
     208      bestAverageWorstQualityCalculator2.QualityParameter.ActualName = "Quality";
     209      bestAverageWorstQualityCalculator2.WorstQualityParameter.ActualName = "Current Worst Quality";
     210
     211      dataTableValuesCollector2.CollectedValues.Add(new LookupParameter<DoubleValue>("Current Best Quality"));
     212      dataTableValuesCollector2.CollectedValues.Add(new LookupParameter<DoubleValue>("Current Average Quality"));
     213      dataTableValuesCollector2.CollectedValues.Add(new LookupParameter<DoubleValue>("Current Worst Quality"));
     214      dataTableValuesCollector2.CollectedValues.Add(new LookupParameter<DoubleValue>("Best Quality"));
     215      dataTableValuesCollector2.CollectedValues.Add(new LookupParameter<DoubleValue>("Best Known Quality", null, "BestKnownQuality"));
     216      dataTableValuesCollector2.DataTableParameter.ActualName = "Qualities";
    217217
    218218      conditionalBranch.ConditionParameter.ActualName = "Terminate";
     219      #endregion
     220
     221      #region Create operator graph
     222      OperatorGraph.InitialOperator = variableCreator;
     223      variableCreator.Successor = bestQualityMemorizer1;
     224      bestQualityMemorizer1.Successor = bestAverageWorstQualityCalculator1;
     225      bestAverageWorstQualityCalculator1.Successor = dataTableValuesCollector1;
     226      dataTableValuesCollector1.Successor = resultsCollector;
     227      resultsCollector.Successor = subScopesSorter1;
     228      subScopesSorter1.Successor = selector;
     229      selector.Successor = sequentialSubScopesProcessor1;
     230      sequentialSubScopesProcessor1.Operators.Add(new EmptyOperator());
     231      sequentialSubScopesProcessor1.Operators.Add(childrenCreator);
     232      sequentialSubScopesProcessor1.Successor = sequentialSubScopesProcessor2;
     233      childrenCreator.Successor = uniformSequentialSubScopesProcessor;
     234      uniformSequentialSubScopesProcessor.Operator = crossover;
     235      uniformSequentialSubScopesProcessor.Successor = subScopesSorter2;
     236      crossover.Successor = stochasticBranch;
     237      stochasticBranch.FirstBranch = mutator;
     238      stochasticBranch.SecondBranch = null;
     239      stochasticBranch.Successor = evaluator;
     240      mutator.Successor = null;
     241      evaluator.Successor = subScopesRemover;
     242      subScopesRemover.Successor = null;
     243      subScopesSorter2.Successor = null;
     244      sequentialSubScopesProcessor2.Operators.Add(leftSelector);
     245      sequentialSubScopesProcessor2.Operators.Add(new EmptyOperator());
     246      sequentialSubScopesProcessor2.Successor = mergingReducer;
     247      leftSelector.Successor = rightReducer;
     248      rightReducer.Successor = null;
     249      mergingReducer.Successor = intCounter;
     250      intCounter.Successor = comparator;
     251      comparator.Successor = bestQualityMemorizer2;
     252      bestQualityMemorizer2.Successor = bestAverageWorstQualityCalculator2;
     253      bestAverageWorstQualityCalculator2.Successor = dataTableValuesCollector2;
     254      dataTableValuesCollector2.Successor = conditionalBranch;
    219255      conditionalBranch.FalseBranch = subScopesSorter1;
    220256      conditionalBranch.TrueBranch = null;
  • trunk/sources/HeuristicLab.Analysis.Views/3.3/DataTableView.cs

    r2917 r3080  
    111111      series.ChartType = SeriesChartType.FastLine;
    112112      series.ToolTip = "#VAL";
    113       for (int i = 0; i < row.Values.Count; i++)
    114         series.Points.Add(row.Values[i]);
     113      for (int i = 0; i < row.Values.Count; i++) {
     114        if (double.IsNaN(row.Values[i])) {
     115          DataPoint point = new DataPoint();
     116          point.IsEmpty = true;
     117          series.Points.Add(point);
     118        } else {
     119          series.Points.Add(row.Values[i]);
     120        }
     121      }
    115122      chart.Series.Add(series);
    116123    }
     
    208215      else {
    209216        DataRow row = valuesRowsTable[(IObservableList<double>)sender];
    210         foreach (IndexedItem<double> item in e.Items)
    211           chart.Series[row.Name].Points.InsertY(item.Index, item.Value);
     217        foreach (IndexedItem<double> item in e.Items) {
     218          if (double.IsNaN(item.Value)) {
     219            DataPoint point = new DataPoint();
     220            point.IsEmpty = true;
     221            chart.Series[row.Name].Points.Insert(item.Index, point);
     222          } else {
     223            chart.Series[row.Name].Points.InsertY(item.Index, item.Value);
     224          }
     225        }
    212226      }
    213227    }
     
    229243      else {
    230244        DataRow row = valuesRowsTable[(IObservableList<double>)sender];
    231         foreach (IndexedItem<double> item in e.Items)
    232           chart.Series[row.Name].Points[item.Index].YValues = new double[] { item.Value };
     245        foreach (IndexedItem<double> item in e.Items) {
     246          if (double.IsNaN(item.Value))
     247            chart.Series[row.Name].Points[item.Index].IsEmpty = true;
     248          else
     249            chart.Series[row.Name].Points[item.Index].YValues = new double[] { item.Value };
     250        }
    233251      }
    234252    }
     
    238256      else {
    239257        DataRow row = valuesRowsTable[(IObservableList<double>)sender];
    240         foreach (IndexedItem<double> item in e.Items)
    241           chart.Series[row.Name].Points[item.Index].YValues = new double[] { item.Value };
     258        foreach (IndexedItem<double> item in e.Items) {
     259          if (double.IsNaN(item.Value))
     260            chart.Series[row.Name].Points[item.Index].IsEmpty = true;
     261          else
     262            chart.Series[row.Name].Points[item.Index].YValues = new double[] { item.Value };
     263        }
    242264      }
    243265    }
     
    248270        DataRow row = valuesRowsTable[(IObservableList<double>)sender];
    249271        chart.Series[row.Name].Points.Clear();
    250         foreach (IndexedItem<double> item in e.Items)
    251           chart.Series[row.Name].Points[item.Index].YValues = new double[] { item.Value };
     272        foreach (IndexedItem<double> item in e.Items) {
     273          if (double.IsNaN(item.Value))
     274            chart.Series[row.Name].Points[item.Index].IsEmpty = true;
     275          else
     276            chart.Series[row.Name].Points[item.Index].YValues = new double[] { item.Value };
     277        }
    252278      }
    253279    }
  • trunk/sources/HeuristicLab.Analysis/3.3/BestQualityMemorizer.cs

    r3048 r3080  
    5555      DoubleValue best = BestQualityParameter.ActualValue;
    5656      double max = (best != null) ? (best.Value) : ((maximization) ? (double.MinValue) : (double.MaxValue));
    57      
     57
    5858      foreach (DoubleValue quality in qualities)
    5959        if (IsBetter(maximization, quality.Value, max)) max = quality.Value;
  • trunk/sources/HeuristicLab.Analysis/3.3/DataTableValuesCollector.cs

    r3048 r3080  
    5353      foreach (IParameter param in CollectedValues) {
    5454        DoubleValue data = param.ActualValue as DoubleValue;
    55         if (data == null) throw new InvalidOperationException("Only double data values can be collected by a DataTableValuesCollector.");
     55        if (data == null) data = new DoubleValue(double.NaN);
    5656
    5757        DataRow row;
  • trunk/sources/HeuristicLab.Optimization/3.3/Interfaces/ISingleObjectiveProblem.cs

    r2975 r3080  
    2828  public interface ISingleObjectiveProblem : IProblem {
    2929    IParameter MaximizationParameter { get; }
     30    IParameter BestKnownQualityParameter { get; }
    3031    new ISingleObjectiveEvaluator Evaluator { get; }
    3132  }
  • trunk/sources/HeuristicLab.Parameters/3.3/LookupParameter.cs

    r3077 r3080  
    5757    public LookupParameter()
    5858      : base("Anonymous", typeof(T)) {
    59       actualName = Name;
     59      this.actualName = Name;
    6060    }
    6161    public LookupParameter(string name)
    6262      : base(name, typeof(T)) {
    63       actualName = Name;
     63      this.actualName = Name;
    6464    }
    6565    public LookupParameter(string name, string description)
    6666      : base(name, description, typeof(T)) {
    67       actualName = Name;
     67      this.actualName = Name;
     68    }
     69    public LookupParameter(string name, string description, string actualName)
     70      : base(name, description, typeof(T)) {
     71      this.actualName = actualName == null ? string.Empty : actualName;
    6872    }
    6973
  • trunk/sources/HeuristicLab.Parameters/3.3/ValueLookupParameter.cs

    r3017 r3080  
    7575      Value = value;
    7676    }
     77    public ValueLookupParameter(string name, string description, string actualName)
     78      : base(name, description, actualName) {
     79    }
    7780
    7881    public override IDeepCloneable Clone(Cloner cloner) {
  • trunk/sources/HeuristicLab.Problems.Knapsack/3.3/Knapsack.cs

    r3071 r3080  
    7676      get { return (OptionalValueParameter<DoubleValue>)Parameters["BestKnownQuality"]; }
    7777    }
     78    IParameter ISingleObjectiveProblem.BestKnownQualityParameter {
     79      get { return BestKnownQualityParameter; }
     80    }
    7881    #endregion
    7982
  • trunk/sources/HeuristicLab.Problems.OneMax/3.3/Onemax.cs

    r3067 r3080  
    6464      get { return EvaluatorParameter; }
    6565    }
     66    public ValueParameter<DoubleValue> BestKnownQualityParameter {
     67      get { return (ValueParameter<DoubleValue>)Parameters["BestKnownQuality"]; }
     68    }
     69    IParameter ISingleObjectiveProblem.BestKnownQualityParameter {
     70      get { return BestKnownQualityParameter; }
     71    }
    6672    #endregion
    6773
     
    8490      get { return EvaluatorParameter.Value; }
    8591    }
     92    public DoubleValue BestKnownQuality {
     93      get { return BestKnownQualityParameter.Value; }
     94    }
    8695    private List<IBinaryVectorOperator> operators;
    8796    public IEnumerable<IOperator> Operators {
     
    99108      Parameters.Add(new ValueParameter<IBinaryVectorCreator>("SolutionCreator", "The operator which should be used to create new OneMax solutions.", creator));
    100109      Parameters.Add(new ValueParameter<IOneMaxEvaluator>("Evaluator", "The operator which should be used to evaluate OneMax solutions.", evaluator));
     110      Parameters.Add(new ValueParameter<DoubleValue>("BestKnownQuality", "The quality of the best known solution of this OneMax instance.", new DoubleValue(5)));
    101111
    102112      creator.BinaryVectorParameter.ActualName = "OneMaxSolution";
  • trunk/sources/HeuristicLab.Problems.TSP/3.3/TSP.cs

    r3074 r3080  
    7373      get { return (OptionalValueParameter<DoubleValue>)Parameters["BestKnownQuality"]; }
    7474    }
     75    IParameter ISingleObjectiveProblem.BestKnownQualityParameter {
     76      get { return BestKnownQualityParameter; }
     77    }
    7578    #endregion
    7679
Note: See TracChangeset for help on using the changeset viewer.