Free cookie consent management tool by TermsFeed Policy Generator

Changeset 13046


Ignore:
Timestamp:
10/21/15 17:42:18 (9 years ago)
Author:
pfleck
Message:

#2269

  • Changed the age type from int to double.
  • Changed EldersSelector to make use of a ScopeTreeLookupParameter.
  • Removed unused operators in LayerUpdator.
Location:
branches/ALPS/HeuristicLab.Algorithms.ALPS/3.3
Files:
10 edited

Legend:

Unmodified
Added
Removed
  • branches/ALPS/HeuristicLab.Algorithms.ALPS/3.3/AlpsGeneticAlgorithm.cs

    r12999 r13046  
    344344      initializeLayerPopulationSize.Successor = initializeLocalEvaluatedSolutions;
    345345
    346       initializeAge.CollectedValues.Add(new ValueParameter<IntValue>("Age", new IntValue(0)));
     346      initializeAge.CollectedValues.Add(new ValueParameter<DoubleValue>("Age", new DoubleValue(0)));
    347347      initializeAge.Successor = null;
    348348
  • branches/ALPS/HeuristicLab.Algorithms.ALPS/3.3/AlpsGeneticAlgorithmMainLoop.cs

    r13035 r13046  
    216216      // Increment ages of all individuals after replacement
    217217      var incrementAgeProcessor = new UniformSubScopesProcessor();
    218       var ageIncrementor = new IntCounter() { Name = "Increment Age" };
     218      var ageIncrementor = new DoubleCounter() { Name = "Increment Age" };
    219219      replacementBranch.Successor = incrementAgeProcessor;
    220220      incrementAgeProcessor.Operator = ageIncrementor;
    221221      incrementAgeProcessor.Successor = null;
    222222      ageIncrementor.ValueParameter.ActualName = "Age";
    223       ageIncrementor.Increment = new IntValue(1);
    224       //ageIncrementor.Successor = null;
     223      ageIncrementor.Increment = new DoubleValue(1.0);
    225224
    226225      // Insert AgeCalculator between crossover and its successor
  • branches/ALPS/HeuristicLab.Algorithms.ALPS/3.3/Analyzers/AgeDistributionAnalyzer.cs

    r12046 r13046  
    3737
    3838    #region Parameter Properties
    39     public IScopeTreeLookupParameter<IntValue> AgeParameter {
    40       get { return (IScopeTreeLookupParameter<IntValue>)Parameters["Age"]; }
     39    public IScopeTreeLookupParameter<DoubleValue> AgeParameter {
     40      get { return (IScopeTreeLookupParameter<DoubleValue>)Parameters["Age"]; }
    4141    }
    4242    public ValueLookupParameter<ResultCollection> ResultsParameter {
     
    7878    public AgeDistributionAnalyzer()
    7979      : base() {
    80       Parameters.Add(new ScopeTreeLookupParameter<IntValue>("Age", "The value which represents the age of a solution."));
     80      Parameters.Add(new ScopeTreeLookupParameter<DoubleValue>("Age", "The value which represents the age of a solution."));
    8181      Parameters.Add(new ValueLookupParameter<ResultCollection>("Results", "The results collection where the analysis values should be stored."));
    8282      Parameters.Add(new FixedValueParameter<StringValue>("HistogramName", "The name of the histogram that gets injected in to the results collection.", new StringValue("Age Distribution")));
     
    110110      }
    111111      var ages = AgeParameter.ActualValue;
    112       row.Values.Replace(ages.Select(x => (double)x.Value));
     112      row.Values.Replace(ages.Select(x => x.Value));
    113113
    114114      if (StoreHistory) {
  • branches/ALPS/HeuristicLab.Algorithms.ALPS/3.3/Analyzers/OldestAverageYoungestAgeAnalyzer.cs

    r12996 r13046  
    3636  public sealed class OldestAverageYoungestAgeAnalyzer : AlgorithmOperator, IAnalyzer {
    3737    #region Parameter properties
    38     public IScopeTreeLookupParameter<IntValue> AgeParameter {
    39       get { return (IScopeTreeLookupParameter<IntValue>)Parameters["Age"]; }
     38    public IScopeTreeLookupParameter<DoubleValue> AgeParameter {
     39      get { return (IScopeTreeLookupParameter<DoubleValue>)Parameters["Age"]; }
    4040    }
    41     public IValueLookupParameter<IntValue> CurrentOldestAgeParameter {
    42       get { return (IValueLookupParameter<IntValue>)Parameters["CurrentOldestAge"]; }
     41    public IValueLookupParameter<DoubleValue> CurrentOldestAgeParameter {
     42      get { return (IValueLookupParameter<DoubleValue>)Parameters["CurrentOldestAge"]; }
    4343    }
    44     public IValueLookupParameter<IntValue> CurrentAverageAgeParameter {
    45       get { return (IValueLookupParameter<IntValue>)Parameters["CurrentAverageAge"]; }
     44    public IValueLookupParameter<DoubleValue> CurrentAverageAgeParameter {
     45      get { return (IValueLookupParameter<DoubleValue>)Parameters["CurrentAverageAge"]; }
    4646    }
    47     public IValueLookupParameter<IntValue> CurrentYoungestAgeParameter {
    48       get { return (IValueLookupParameter<IntValue>)Parameters["CurrentYoungestAge"]; }
     47    public IValueLookupParameter<DoubleValue> CurrentYoungestAgeParameter {
     48      get { return (IValueLookupParameter<DoubleValue>)Parameters["CurrentYoungestAge"]; }
    4949    }
    5050    public IValueLookupParameter<DataTable> AgesParameter {
     
    7979      : base() {
    8080      #region Create parameters
    81       Parameters.Add(new ScopeTreeLookupParameter<IntValue>("Age", "The value which represents the age of a solution."));
    82       Parameters.Add(new ValueLookupParameter<IntValue>("CurrentOldestAge", "The oldest age value found in the current population."));
    83       Parameters.Add(new ValueLookupParameter<IntValue>("CurrentAverageAge", "The average age value of all solutions in the current population."));
    84       Parameters.Add(new ValueLookupParameter<IntValue>("CurrentYoungestAge", "The youngest age value found in the current population."));
     81      Parameters.Add(new ScopeTreeLookupParameter<DoubleValue>("Age", "The value which represents the age of a solution."));
     82      Parameters.Add(new ValueLookupParameter<DoubleValue>("CurrentOldestAge", "The oldest age value found in the current population."));
     83      Parameters.Add(new ValueLookupParameter<DoubleValue>("CurrentAverageAge", "The average age value of all solutions in the current population."));
     84      Parameters.Add(new ValueLookupParameter<DoubleValue>("CurrentYoungestAge", "The youngest age value found in the current population."));
    8585      Parameters.Add(new ValueLookupParameter<DataTable>("Ages", "The data table to store the current oldest, current average, current youngest age value."));
    8686      Parameters.Add(new ValueLookupParameter<ResultCollection>("Results", "The results collection where the analysis values should be stored."));
     
    103103      oldestAverageYoungestAgeCalculator.YoungestAgeParameter.ActualName = CurrentYoungestAgeParameter.Name;
    104104
    105       dataTableValuesCollector.CollectedValues.Add(new LookupParameter<IntValue>("CurrentOldestAge", null, CurrentOldestAgeParameter.Name));
    106       dataTableValuesCollector.CollectedValues.Add(new LookupParameter<IntValue>("CurrentAverageAge", null, CurrentAverageAgeParameter.Name));
    107       dataTableValuesCollector.CollectedValues.Add(new LookupParameter<IntValue>("CurrentYoungestAge", null, CurrentYoungestAgeParameter.Name));
     105      dataTableValuesCollector.CollectedValues.Add(new LookupParameter<DoubleValue>("CurrentOldestAge", null, CurrentOldestAgeParameter.Name));
     106      dataTableValuesCollector.CollectedValues.Add(new LookupParameter<DoubleValue>("CurrentAverageAge", null, CurrentAverageAgeParameter.Name));
     107      dataTableValuesCollector.CollectedValues.Add(new LookupParameter<DoubleValue>("CurrentYoungestAge", null, CurrentYoungestAgeParameter.Name));
    108108      dataTableValuesCollector.DataTableParameter.ActualName = AgesParameter.Name;
    109109
    110       //resultsCollector.CollectedValues.Add(new LookupParameter<IntValue>("CurrentOldestAge", null, CurrentOldestAgeParameter.Name));
    111       //resultsCollector.CollectedValues.Add(new LookupParameter<IntValue>("CurrentAverageAge", null, CurrentAverageAgeParameter.Name));
    112       //resultsCollector.CollectedValues.Add(new LookupParameter<IntValue>("CurrentYoungestAge", null, CurrentYoungestAgeParameter.Name));
    113110      resultsCollector.CollectedValues.Add(new LookupParameter<DataTable>(AgesParameter.Name));
    114111      resultsCollector.ResultsParameter.ActualName = ResultsParameter.Name;
  • branches/ALPS/HeuristicLab.Algorithms.ALPS/3.3/Analyzers/OldestAverageYoungestAgeCalculator.cs

    r12570 r13046  
    3131  [StorableClass]
    3232  public sealed class OldestAverageYoungestAgeCalculator : SingleSuccessorOperator {
    33     public IScopeTreeLookupParameter<IntValue> AgeParameter {
    34       get { return (IScopeTreeLookupParameter<IntValue>)Parameters["Age"]; }
     33    public IScopeTreeLookupParameter<DoubleValue> AgeParameter {
     34      get { return (IScopeTreeLookupParameter<DoubleValue>)Parameters["Age"]; }
    3535    }
    36     public IValueLookupParameter<IntValue> OldestAgeParameter {
    37       get { return (IValueLookupParameter<IntValue>)Parameters["OldestAge"]; }
     36    public IValueLookupParameter<DoubleValue> OldestAgeParameter {
     37      get { return (IValueLookupParameter<DoubleValue>)Parameters["OldestAge"]; }
    3838    }
    39     public IValueLookupParameter<IntValue> AverageAgeParameter {
    40       get { return (IValueLookupParameter<IntValue>)Parameters["AverageAge"]; }
     39    public IValueLookupParameter<DoubleValue> AverageAgeParameter {
     40      get { return (IValueLookupParameter<DoubleValue>)Parameters["AverageAge"]; }
    4141    }
    42     public IValueLookupParameter<IntValue> YoungestAgeParameter {
    43       get { return (IValueLookupParameter<IntValue>)Parameters["YoungestAge"]; }
     42    public IValueLookupParameter<DoubleValue> YoungestAgeParameter {
     43      get { return (IValueLookupParameter<DoubleValue>)Parameters["YoungestAge"]; }
    4444    }
    4545
     
    5555    public OldestAverageYoungestAgeCalculator()
    5656      : base() {
    57       Parameters.Add(new ScopeTreeLookupParameter<IntValue>("Age", "The value contained in the scope tree which represents the solution age."));
    58       Parameters.Add(new ValueLookupParameter<IntValue>("OldestAge", "The age value of the oldest solution."));
    59       Parameters.Add(new ValueLookupParameter<IntValue>("AverageAge", "The average age of all solutions."));
    60       Parameters.Add(new ValueLookupParameter<IntValue>("YoungestAge", "The age value of the youngest solution."));
     57      Parameters.Add(new ScopeTreeLookupParameter<DoubleValue>("Age", "The value contained in the scope tree which represents the solution age."));
     58      Parameters.Add(new ValueLookupParameter<DoubleValue>("OldestAge", "The age value of the oldest solution."));
     59      Parameters.Add(new ValueLookupParameter<DoubleValue>("AverageAge", "The average age of all solutions."));
     60      Parameters.Add(new ValueLookupParameter<DoubleValue>("YoungestAge", "The age value of the youngest solution."));
    6161
    6262      OldestAgeParameter.Hidden = true;
     
    6969
    7070      if (ages.Length > 0) {
    71         int min = int.MaxValue, max = int.MinValue, sum = 0;
     71        double min = double.MaxValue, max = double.MinValue, sum = 0;
    7272        for (int i = 0; i < ages.Length; i++) {
    7373          if (ages[i].Value < min) min = ages[i].Value;
     
    7777
    7878        var oldest = OldestAgeParameter.ActualValue;
    79         if (oldest == null) OldestAgeParameter.ActualValue = new IntValue(max);
     79        if (oldest == null) OldestAgeParameter.ActualValue = new DoubleValue(max);
    8080        else oldest.Value = max;
    8181        var average = AverageAgeParameter.ActualValue;
    82         if (average == null) AverageAgeParameter.ActualValue = new IntValue(sum / ages.Length);
     82        if (average == null) AverageAgeParameter.ActualValue = new DoubleValue(sum / ages.Length);
    8383        else average.Value = sum / ages.Length;
    8484        var youngest = YoungestAgeParameter.ActualValue;
    85         if (youngest == null) YoungestAgeParameter.ActualValue = new IntValue(min);
     85        if (youngest == null) YoungestAgeParameter.ActualValue = new DoubleValue(min);
    8686        else youngest.Value = min;
    8787      }
  • branches/ALPS/HeuristicLab.Algorithms.ALPS/3.3/EldersEmigrator.cs

    r12992 r13046  
    5959      selectorProsessor.Successor = shiftToRightMigrator;
    6060
    61       eldersSelector.CopySelected = new BoolValue(false);
    6261      eldersSelector.Successor = null;
    6362
  • branches/ALPS/HeuristicLab.Algorithms.ALPS/3.3/EldersSelector.cs

    r12018 r13046  
    3333  [Item("EldersSelector", "Select all individuals which are to old for their current layer.")]
    3434  [StorableClass]
    35   public sealed class EldersSelector : SingleObjectiveSelector {
    36 
     35  public sealed class EldersSelector : Selector {
     36    private IScopeTreeLookupParameter<DoubleValue> AgeParameter {
     37      get { return (IScopeTreeLookupParameter<DoubleValue>)Parameters["Age"]; }
     38    }
    3739    private ILookupParameter<IntArray> AgeLimitsParameter {
    3840      get { return (ILookupParameter<IntArray>)Parameters["AgeLimits"]; }
     
    5557    public EldersSelector()
    5658      : base() {
     59      Parameters.Add(new ScopeTreeLookupParameter<DoubleValue>("Age"));
    5760      Parameters.Add(new LookupParameter<IntArray>("AgeLimits"));
    5861      Parameters.Add(new LookupParameter<IntValue>("NumberOfLayers"));
     
    6164
    6265    protected override IScope[] Select(List<IScope> scopes) {
     66      var ages = AgeParameter.ActualValue;
    6367      var ageLimits = AgeLimitsParameter.ActualValue;
    6468      int numberOfLayers = NumberOfLayersParameter.ActualValue.Value;
     
    6973
    7074      int limit = ageLimits[layer];
    71       var eldersQuery =
    72         from scope in scopes
    73         let age = ((IntValue)scope.Variables["Age"].Value).Value
    74         where age > limit
    75         select scope;
     75      var elders = ages
     76        .Select((x, index) => new { index, age = x.Value })
     77        .Where(x => x.age > limit)
     78        .ToList();
    7679
    77       var elders = eldersQuery.ToArray();
    78 
    79       if (!CopySelected.Value)
    80         foreach (var elder in elders)
    81           scopes.Remove(elder);
    82 
    83       return elders;
     80      IScope[] selected = new IScope[elders.Count];
     81      for (int i = 0; i < elders.Count; i++) {
     82        selected[i] = scopes[elders[i].index];
     83        scopes[elders[i].index] = null;
     84      }
     85      scopes.RemoveAll(x => x == null);
     86      return selected;
    8487    }
    8588  }
  • branches/ALPS/HeuristicLab.Algorithms.ALPS/3.3/LayerCreator.cs

    r13037 r13046  
    3535  [StorableClass]
    3636  public sealed class LayerCreator : SingleSuccessorOperator {
    37 
    38     /*private static readonly ISet<string> SavedVariables = new HashSet<string>{
    39       "LocalRandom", "Layer", "LayerEvaluatedSolutions", "NumSubScopes"
    40     };*/
    41 
    4237    private ILookupParameter<IntValue> OpenLayersParameter {
    4338      get { return (ILookupParameter<IntValue>)Parameters["OpenLayers"]; }
     
    7873      // Decrement ages, because MainOperator is goint to increment it
    7974      foreach (var solution in clone.SubScopes)
    80         ((IntValue)solution.Variables["Age"].Value).Value -= 1;
     75        ((DoubleValue)solution.Variables["Age"].Value).Value -= 1;
    8176
    8277      // Reset existing values in the results to NaN to symbolize that no layer existed during that duration
  • branches/ALPS/HeuristicLab.Algorithms.ALPS/3.3/LayerUpdator.cs

    r12992 r13046  
    6464      var newLayerLayerProcessor = new UniformSubScopesProcessor();
    6565      var newLayerReducer = new MergingReducer();
    66       var layerInitializer = new Assigner() { Name = "Init Layer" };
    67       var correctAgeProcessor = new UniformSubScopesProcessor() { Name = "Hack: Decrement Age" };
    68       var correctAgeDecrementor = new IntCounter() { Name = "Age = Age - 1" };
    6966      var incrEvaluatedSolutionsForNewLayer = new SubScopesCounter() { Name = "Update EvaluatedSolutions" };
    7067      var newResultCollectionAssigner = new Assigner() { Name = "Empty Results" };
     
    131128      newLayerReducer.Successor = incrOpenLayers;
    132129
    133       layerInitializer.LeftSideParameter.ActualName = "Layer";
    134       layerInitializer.RightSideParameter.ActualName = "OpenLayers";
    135       layerInitializer.Successor = correctAgeProcessor;
    136 
    137       correctAgeProcessor.Operator = correctAgeDecrementor;
    138       correctAgeProcessor.Successor = incrEvaluatedSolutionsForNewLayer;
    139 
    140       correctAgeDecrementor.Increment = new IntValue(-1);
    141       correctAgeDecrementor.ValueParameter.ActualName = "Age";
    142 
    143130      incrEvaluatedSolutionsForNewLayer.ValueParameter.ActualName = "EvaluatedSolutions";
    144131      incrEvaluatedSolutionsForNewLayer.AccumulateParameter.Value = new BoolValue(true);
     
    179166      initializeAgeProsessor.Successor = incrEvaluatedSolutionsAfterReseeding;
    180167
    181       initializeAge.CollectedValues.Add(new ValueParameter<IntValue>("Age", new IntValue(0)));
     168      initializeAge.CollectedValues.Add(new ValueParameter<DoubleValue>("Age", new DoubleValue(0)));
    182169      initializeAge.Successor = null;
    183170
  • branches/ALPS/HeuristicLab.Algorithms.ALPS/3.3/WeightingReducer.cs

    r12997 r13046  
    3434  public sealed class WeightingReducer : SingleSuccessorOperator {
    3535
    36     public ScopeTreeLookupParameter<IntValue> ParameterToReduce {
    37       get { return (ScopeTreeLookupParameter<IntValue>)Parameters["ParameterToReduce"]; }
     36    public IScopeTreeLookupParameter<DoubleValue> ParameterToReduce {
     37      get { return (IScopeTreeLookupParameter<DoubleValue>)Parameters["ParameterToReduce"]; }
    3838    }
    39     public LookupParameter<IntValue> TargetParameter {
    40       get { return (LookupParameter<IntValue>)Parameters["TargetParameter"]; }
     39    public ILookupParameter<DoubleValue> TargetParameter {
     40      get { return (ILookupParameter<DoubleValue>)Parameters["TargetParameter"]; }
    4141    }
    4242    public IValueLookupParameter<DoubleValue> WeightParameter {
     
    5454    public WeightingReducer()
    5555      : base() {
    56       Parameters.Add(new ScopeTreeLookupParameter<IntValue>("ParameterToReduce", "The parameter on which the weighting should be applied."));
    57       Parameters.Add(new LookupParameter<IntValue>("TargetParameter", "The target variable in which the weighted value should be stored."));
     56      Parameters.Add(new ScopeTreeLookupParameter<DoubleValue>("ParameterToReduce", "The parameter on which the weighting should be applied."));
     57      Parameters.Add(new LookupParameter<DoubleValue>("TargetParameter", "The target variable in which the weighted value should be stored."));
    5858      Parameters.Add(new ValueLookupParameter<DoubleValue>("Weight", "Weight of the two values (0.0 for the smaller, 1.0 for the larger)."));
    5959    }
     
    6464        throw new InvalidOperationException("Weighting between values can only done for two values.");
    6565
    66       var weight = WeightParameter.ActualValue.Value;
     66      double weight = WeightParameter.ActualValue.Value;
    6767
    68       var max = values.Max(v => v.Value);
    69       var min = values.Min(v => v.Value);
     68      double max = values.Max(v => v.Value);
     69      double min = values.Min(v => v.Value);
    7070
    71       int result = (int)(max * weight + min * (1 - weight));
     71      double result = max * weight + min * (1 - weight);
    7272
    7373      if (TargetParameter.ActualValue == null)
    74         TargetParameter.ActualValue = new IntValue(result);
     74        TargetParameter.ActualValue = new DoubleValue(result);
    7575      else TargetParameter.ActualValue.Value = result;
    7676
Note: See TracChangeset for help on using the changeset viewer.