Ignore:
Timestamp:
09/20/19 16:23:42 (19 months ago)
Author:
dpiringe
Message:

#3026:

  • changed the namespace from ParameterTest to HeuristicLab.Manufacture
  • added an extension method for Type to get the distance of an interface based on the target type
  • renamed methods ToData, SetValue to Extract, Inject
  • new implementation of the template generation with transformers (not the final name)
  • started to use the new transformers for the instantiation of IOptimizer-objects (out of a template)
  • new transformers: LookupParameterTransformer and DummyTransformer
File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/3026_IntegrationIntoSymSpace/HeuristicLab.Manufacture/Transformer.cs

    r17263 r17266  
    77using HeuristicLab.Data;
    88
    9 namespace ParameterTest {
     9namespace HeuristicLab.Manufacture {
    1010  public static class Transformer {
    1111    private static IDictionary<Type, ITypeTransformer> transformers = new Dictionary<Type, ITypeTransformer>();
     
    2020
    2121    public static ITypeTransformer Get(Type type) {
     22      IList<KeyValuePair<Type, ITypeTransformer>> possibleTransformers = new List<KeyValuePair<Type, ITypeTransformer>>();
    2223      foreach (var x in transformers) {
    23         if (type.IsEqualTo(x.Key)) return x.Value;
     24        if (type.IsEqualTo(x.Key))
     25          possibleTransformers.Add(x);
    2426      }
    25       return null;
     27
     28      if(possibleTransformers.Count > 0) {
     29        ITypeTransformer nearest = possibleTransformers.First().Value;
     30        int nearestDistance = -1;
     31        foreach (var x in possibleTransformers) {
     32          int d = type.GetInterfaceDistance(x.Key);
     33          if (d != -1 && (nearestDistance == -1 || d < nearestDistance)) {
     34            nearestDistance = d;
     35            nearest = x.Value;
     36          }
     37        }
     38        return nearest;
     39      }
     40      return new DummyTransformer();
    2641    }
    2742
    28     internal static void SetValue(IItem item, ParameterData data) {
    29       Get(item.GetType()).SetValue(item, data);
     43    internal static void Inject(IItem item, ParameterData data) {
     44      Get(item.GetType()).Inject(item, data);
     45    }
     46
     47    internal static ParameterData Extract(IItem item) {
     48      return Get(item.GetType()).Extract(item);
    3049    }
    3150
     
    4867      Register<PercentMatrix>(new ValueTypeMatrixTransformer<PercentMatrix, double>());
    4968      Register<BoolMatrix>(new ValueTypeMatrixTransformer<BoolMatrix, bool>());
     69
     70      Register(typeof(IConstrainedValueParameter<>), new ConstrainedValueParameterTransformer());
     71      Register(typeof(ILookupParameter), new LookupParameterTransformer());
     72      Register(typeof(IValueParameter), new ValueParameterTransformer());
    5073    }
    5174
Note: See TracChangeset for help on using the changeset viewer.