Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
09/20/19 16:23:42 (5 years 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/JCInstantiator.cs

    r17263 r17266  
    1212using Newtonsoft.Json.Linq;
    1313
    14 namespace ParameterTest {
     14namespace HeuristicLab.Manufacture {
    1515
    1616 
     
    2828
    2929    public IAlgorithm Instantiate(string configFile) {
    30       JObject config = JObject.Parse(File.ReadAllText(configFile));
     30      JArray config = JArray.Parse(File.ReadAllText(configFile));
     31      JCObject obj = config[0].ToObject<JCObject>();
     32      IAlgorithm algorithm = CreateObject<IAlgorithm>(obj);
    3133
     34      foreach(var sp in obj.StaticParameters) {
     35        if(algorithm.Parameters.TryGetValue(sp.Name, out IParameter param)) {
     36          Transformer.Inject(param, sp);
     37        }
     38      }
     39
     40      foreach (var sp in obj.FreeParameters) {
     41        if (algorithm.Parameters.TryGetValue(sp.Name, out IParameter param)) {
     42          if(IsInRangeList(sp.Range, sp.Default) ||
     43            IsInNumericRange<long>(sp.Default, sp.Range[0], sp.Range[1]) ||
     44            IsInNumericRange<double>(sp.Default, sp.Range[0], sp.Range[1]))
     45          Transformer.Inject(param, sp);
     46        }
     47      }
     48
     49
     50      return algorithm;
     51
     52
     53      /*
    3254      TypeList = config[SParametersID][TListID].ToObject<Dictionary<string, string>>();
    3355
     
    4668      UseFreeParams(problemData.Name, freeProblemParameters, algorithm.Problem);
    4769      return algorithm;
     70      */
     71    }
     72
     73    private T CreateObject<T>(JCObject obj) {
     74      Type type = Type.GetType(obj.Type);
     75      return (T)Activator.CreateInstance(type);
    4876    }
    4977
     
    5684
    5785    private void ProcessParameters(JCObject obj, IParameterizedItem instance) {
    58       foreach (var param in obj.Parameters)
     86      foreach (var param in obj.StaticParameters)
    5987        if (param.Default != null)
    6088          SetParameterValue(FindPropertyByKey(instance, param.Name), param.Default);
Note: See TracChangeset for help on using the changeset viewer.