Last change
on this file since 17266 was
17266,
checked in by dpiringe, 5 years ago
|
#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 size:
1.1 KB
|
Line | |
---|
1 | using System;
|
---|
2 | using System.Collections.Generic;
|
---|
3 | using System.Linq;
|
---|
4 | using System.Text;
|
---|
5 | using System.Threading.Tasks;
|
---|
6 | using HeuristicLab.Core;
|
---|
7 |
|
---|
8 | namespace HeuristicLab.Manufacture {
|
---|
9 | public class ConstrainedValueParameterTransformer : ParameterBaseTransformer {
|
---|
10 | public override void InjectData(IParameter parameter, ParameterData data) {
|
---|
11 | foreach (var x in parameter.Cast<dynamic>().ValidValues)
|
---|
12 | if (x.GetType().Name == CastValue<string>(data.Default))
|
---|
13 | parameter.ActualValue = x;
|
---|
14 | }
|
---|
15 |
|
---|
16 | public override ParameterData ExtractData(IParameter value) {
|
---|
17 | return new ParameterData() {
|
---|
18 | Name = value.Name,
|
---|
19 | Default = value.ActualValue?.GetType().Name,
|
---|
20 | Range = GetValidValues(value)
|
---|
21 | };
|
---|
22 | }
|
---|
23 |
|
---|
24 | #region Helper
|
---|
25 | private object[] GetValidValues(IParameter value) {
|
---|
26 | List<object> list = new List<object>();
|
---|
27 | var values = value.Cast<dynamic>().ValidValues;
|
---|
28 | foreach (var x in values) list.Add(x);
|
---|
29 | return list.Select(x => x.GetType().Name).ToArray();
|
---|
30 | }
|
---|
31 | #endregion
|
---|
32 | }
|
---|
33 | }
|
---|
Note: See
TracBrowser
for help on using the repository browser.