Changeset 18198


Ignore:
Timestamp:
01/14/22 15:11:36 (7 days ago)
Author:
mkommend
Message:

#3136: Fixed error in structur GP if only one numeric parameter is present in the template by providing a new copy crossover for real vectors.

Location:
branches/3136_Structural_GP
Files:
1 added
3 edited

Legend:

Unmodified
Added
Removed
  • branches/3136_Structural_GP/HeuristicLab.Encodings.RealVectorEncoding/3.3/Crossovers/MultiRealVectorCrossover.cs

    r17180 r18198  
    2222using System;
    2323using System.Linq;
     24using HEAL.Attic;
    2425using HeuristicLab.Collections;
    2526using HeuristicLab.Common;
     
    2930using HeuristicLab.Optimization;
    3031using HeuristicLab.Parameters;
    31 using HEAL.Attic;
    3232using HeuristicLab.PluginInfrastructure;
    3333
     
    6767
    6868      foreach (Type type in ApplicationManager.Manager.GetTypes(typeof(IRealVectorCrossover))) {
    69         if (!typeof(MultiOperator<IRealVectorCrossover>).IsAssignableFrom(type))
    70           Operators.Add((IRealVectorCrossover)Activator.CreateInstance(type), true);
     69        if (typeof(MultiOperator<IRealVectorCrossover>).IsAssignableFrom(type)) continue;
     70        if (typeof(CopyCrossover).IsAssignableFrom(type)) continue;
     71
     72        Operators.Add((IRealVectorCrossover)Activator.CreateInstance(type), true);
    7173      }
    7274
  • branches/3136_Structural_GP/HeuristicLab.Encodings.RealVectorEncoding/3.3/HeuristicLab.Encodings.RealVectorEncoding-3.3.csproj

    r16658 r18198  
    115115  <ItemGroup>
    116116    <Compile Include="Creators\NormalDistributedRealVectorCreator.cs" />
     117    <Compile Include="Crossovers\CopyCrossover.cs" />
    117118    <Compile Include="Interfaces\IRealVectorMultiNeighborhoodShakingOperator.cs" />
    118119    <Compile Include="ParticleOperators\RealVectorNeighborhoodParticleUpdater.cs" />
  • branches/3136_Structural_GP/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/SingleObjective/StructuredSymbolicRegressionSingleObjectiveProblem.cs

    r18197 r18198  
    3030using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
    3131using HeuristicLab.Optimization;
     32using HeuristicLab.Optimization.Operators;
    3233using HeuristicLab.Parameters;
    3334using HeuristicLab.Problems.Instances;
     
    218219        encoding.SolutionCreator = creator;
    219220
     221
    220222        Encoding.Add(encoding);
    221223      }
     
    234236      }
    235237
    236       //set single point crossover for numeric parameters
     238      //set single point || copy crossover for numeric parameters
    237239      var multiCrossover = (IParameterizedItem)Encoding.Operators.OfType<MultiEncodingCrossover>().First();
    238240      foreach (var param in multiCrossover.Parameters.OfType<ConstrainedValueParameter<ICrossover>>()) {
    239         var singlePointCrossover = param.ValidValues.OfType<SinglePointCrossover>().FirstOrDefault();
    240         param.Value = singlePointCrossover ?? param.ValidValues.First();
     241        if (!param.Name.Contains(NumericParametersEncoding)) continue;
     242
     243        var singlePointCrossover = param.ValidValues.OfType<SinglePointCrossover>().First();
     244        var copyCrossover = param.ValidValues.OfType<CopyCrossover>().First();
     245
     246        var realvectorEncoding = (RealVectorEncoding)Encoding.Encodings.Where(e => e.Name == NumericParametersEncoding).First();
     247        if (realvectorEncoding.Length == 1) { //single-point crossover throws if encoding length == 1
     248          param.Value = copyCrossover;
     249        } else
     250          param.Value = singlePointCrossover;
    241251      }
    242252
Note: See TracChangeset for help on using the changeset viewer.