- Timestamp:
- 09/26/19 10:14:35 (5 years ago)
- Location:
- branches/3026_IntegrationIntoSymSpace/HeuristicLab.Manufacture
- Files:
-
- 18 edited
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
branches/3026_IntegrationIntoSymSpace/HeuristicLab.Manufacture/Component.cs
r17270 r17271 17 17 }*/ 18 18 19 public class ParameterData{19 public class Component { 20 20 public string Name { get; set; } 21 21 public string Type { get; set; } … … 24 24 public IList<object> Range { get; set; } 25 25 26 public IList< ParameterData> Parameters { get; set; }27 public IList< ParameterData> Operators { get; set; }26 public IList<Component> Parameters { get; set; } 27 public IList<Component> Operators { get; set; } 28 28 29 29 [JsonIgnore] 30 public ParameterDatathis[string index] {30 public Component this[string index] { 31 31 get { 32 32 if (Parameters == null) return null; … … 37 37 set { 38 38 if (Parameters == null) 39 Parameters = new List< ParameterData>();40 ParameterDatadata = this[index];39 Parameters = new List<Component>(); 40 Component data = this[index]; 41 41 if (data != null && CheckConstraints(value)) 42 42 Merge(data, value); … … 47 47 48 48 public override bool Equals(object obj) { 49 if (!(obj is ParameterData))49 if (!(obj is Component)) 50 50 return false; 51 51 else 52 return obj.Cast< ParameterData>().Name == this.Name;52 return obj.Cast<Component>().Name == this.Name; 53 53 } 54 54 … … 58 58 59 59 [JsonIgnore] 60 public IList< ParameterData> ParameterizedItems { get; set; }60 public IList<Component> ParameterizedItems { get; set; } 61 61 62 62 [JsonIgnore] 63 public ParameterDataReference { get; set; }63 public Component Reference { get; set; } 64 64 65 65 #region Helper 66 public static void Merge( ParameterData target, ParameterDatafrom) {66 public static void Merge(Component target, Component from) { 67 67 target.Name = from.Name ?? target.Name; 68 68 target.Type = from.Type ?? target.Type; … … 75 75 } 76 76 77 private bool CheckConstraints( ParameterDatadata) =>77 private bool CheckConstraints(Component data) => 78 78 data.Range != null && data.Default != null && ( 79 79 IsInRangeList(data.Range, data.Default) || -
branches/3026_IntegrationIntoSymSpace/HeuristicLab.Manufacture/HeuristicLab.Manufacture.csproj
r17269 r17271 70 70 <Compile Include="Program.cs" /> 71 71 <Compile Include="Properties\AssemblyInfo.cs" /> 72 <Compile Include=" Template.cs" />72 <Compile Include="Component.cs" /> 73 73 <Compile Include="Interfaces\ITypeTransformer.cs" /> 74 74 <Compile Include="Transformer.cs" /> -
branches/3026_IntegrationIntoSymSpace/HeuristicLab.Manufacture/Interfaces/ITypeTransformer.cs
r17266 r17271 10 10 //IDataProcessor? 11 11 public interface ITypeTransformer { 12 ParameterDataExtract(IItem value);13 void Inject(IItem item, ParameterDatadata);12 Component Extract(IItem value); 13 void Inject(IItem item, Component data); 14 14 } 15 15 } -
branches/3026_IntegrationIntoSymSpace/HeuristicLab.Manufacture/JCGenerator.cs
r17269 r17271 62 62 public string GenerateTemplate(IAlgorithm algorithm, IProblem problem, params string[] freeParameters) { 63 63 algorithm.Problem = problem; 64 ParameterDataalgorithmData = Transformer.Extract(algorithm);65 ParameterDataproblemData = Transformer.Extract(problem);66 IList< ParameterData> items = algorithmData.ParameterizedItems;64 Component algorithmData = Transformer.Extract(algorithm); 65 Component problemData = Transformer.Extract(problem); 66 IList<Component> items = algorithmData.ParameterizedItems; 67 67 foreach (var pItem in problemData.ParameterizedItems) items.Add(pItem); 68 68 JArray jsonItems = new JArray(); … … 93 93 IList<JObject> objToRemove = new List<JObject>(); 94 94 TransformNodes(x => { 95 var p = x.ToObject< ParameterData>();95 var p = x.ToObject<Component>(); 96 96 97 97 /*bool isSelected = false; … … 114 114 IList<JObject> objToRemove = new List<JObject>(); 115 115 TransformNodes(x => { 116 var p = x.ToObject< ParameterData>();116 var p = x.ToObject<Component>(); 117 117 x.Property("Range")?.Remove(); 118 118 if (p.Default == null) objToRemove.Add(x); -
branches/3026_IntegrationIntoSymSpace/HeuristicLab.Manufacture/JCInstantiator.cs
r17269 r17271 22 22 Config = JToken.Parse(File.ReadAllText(configFile)); 23 23 24 ParameterDataalgorithmData = GetData(Config["Metadata"]["Algorithm"].ToString());24 Component algorithmData = GetData(Config["Metadata"]["Algorithm"].ToString()); 25 25 ResolveReferences(algorithmData); 26 26 IAlgorithm algorithm = CreateObject<IAlgorithm>(algorithmData); 27 27 28 ParameterDataproblemData = GetData(Config["Metadata"]["Problem"].ToString());28 Component problemData = GetData(Config["Metadata"]["Problem"].ToString()); 29 29 ResolveReferences(problemData); 30 30 IProblem problem = CreateObject<IProblem>(problemData); … … 41 41 */ 42 42 43 private void ResolveReferences( ParameterDatadata) {43 private void ResolveReferences(Component data) { 44 44 foreach (var p in data.Parameters) { 45 45 if (p.Default is string && p.Reference == null) { … … 49 49 } 50 50 51 private ParameterDataGetData(string key)51 private Component GetData(string key) 52 52 { 53 53 foreach(JObject item in Config["Objects"]) 54 54 { 55 ParameterDatadata = BuildDataFromJObject(item);55 Component data = BuildDataFromJObject(item); 56 56 if (data.Name == key) return data; 57 57 } … … 59 59 } 60 60 61 private ParameterDataBuildDataFromJObject(JObject obj) {62 ParameterData data = new ParameterData() {61 private Component BuildDataFromJObject(JObject obj) { 62 Component data = new Component() { 63 63 Name = obj["Name"]?.ToString(), 64 64 Default = obj["Default"]?.ToObject<object>(), … … 76 76 77 77 if (obj["Operators"] != null) { 78 data.Operators = new List< ParameterData>();78 data.Operators = new List<Component>(); 79 79 foreach (JObject sp in obj["Operators"]) 80 80 data.Operators.Add(BuildDataFromJObject(sp)); … … 84 84 } 85 85 86 private T CreateObject<T>( ParameterDatadata) {86 private T CreateObject<T>(Component data) { 87 87 Type type = Type.GetType(data.Type); 88 88 return (T)Activator.CreateInstance(type); -
branches/3026_IntegrationIntoSymSpace/HeuristicLab.Manufacture/ParameterTransformer/ConstrainedValueParameterTransformer.cs
r17269 r17271 8 8 namespace HeuristicLab.Manufacture { 9 9 public class ConstrainedValueParameterTransformer : ParameterBaseTransformer { 10 public override void InjectData(IParameter parameter, ParameterDatadata) {10 public override void InjectData(IParameter parameter, Component data) { 11 11 foreach (var x in parameter.Cast<dynamic>().ValidValues) 12 12 if (x.GetType().Name == CastValue<string>(data.Default)) … … 17 17 } 18 18 19 public override ParameterDataExtractData(IParameter value) {19 public override Component ExtractData(IParameter value) { 20 20 21 return new ParameterData() {21 return new Component() { 22 22 Name = value.Name, 23 23 Default = value.ActualValue?.GetType().Name, … … 35 35 } 36 36 37 private IList< ParameterData> GetParameterizedChilds(IParameter value) {38 List< ParameterData> list = new List<ParameterData>();37 private IList<Component> GetParameterizedChilds(IParameter value) { 38 List<Component> list = new List<Component>(); 39 39 var values = value.Cast<dynamic>().ValidValues; 40 40 foreach(var x in values) { 41 41 if (x is IParameterizedItem && 42 42 ((IParameterizedItem)x).Parameters.Any(p => !p.Hidden)) { 43 ParameterDatatmp = Transformer.Extract(x);43 Component tmp = Transformer.Extract(x); 44 44 if (tmp.ParameterizedItems != null) 45 45 list.AddRange(tmp.ParameterizedItems); -
branches/3026_IntegrationIntoSymSpace/HeuristicLab.Manufacture/ParameterTransformer/LookupParameterTransformer.cs
r17266 r17271 8 8 namespace HeuristicLab.Manufacture { 9 9 public class LookupParameterTransformer : ParameterBaseTransformer { 10 public override ParameterDataExtractData(IParameter value) {11 return new ParameterData() { Name = value.Name };10 public override Component ExtractData(IParameter value) { 11 return new Component() { Name = value.Name }; 12 12 } 13 13 14 public override void InjectData(IParameter parameter, ParameterDatadata) {14 public override void InjectData(IParameter parameter, Component data) { 15 15 16 16 } -
branches/3026_IntegrationIntoSymSpace/HeuristicLab.Manufacture/ParameterTransformer/ParameterBaseTransformer.cs
r17266 r17271 8 8 namespace HeuristicLab.Manufacture { 9 9 public abstract class ParameterBaseTransformer : BaseTransformer { 10 public override ParameterDataExtractData(IItem value) => ExtractData(value.Cast<IParameter>());11 public abstract ParameterDataExtractData(IParameter value);10 public override Component ExtractData(IItem value) => ExtractData(value.Cast<IParameter>()); 11 public abstract Component ExtractData(IParameter value); 12 12 13 public override void InjectData(IItem item, ParameterDatadata) => InjectData(item.Cast<IParameter>(), data);13 public override void InjectData(IItem item, Component data) => InjectData(item.Cast<IParameter>(), data); 14 14 15 public abstract void InjectData(IParameter parameter, ParameterDatadata);15 public abstract void InjectData(IParameter parameter, Component data); 16 16 } 17 17 } -
branches/3026_IntegrationIntoSymSpace/HeuristicLab.Manufacture/ParameterTransformer/ParameterizedItemTransformer.cs
r17269 r17271 10 10 public class ParameterizedItemTransformer : BaseTransformer { 11 11 12 public override void InjectData(IItem item, ParameterDatadata) {12 public override void InjectData(IItem item, Component data) { 13 13 IParameterizedItem pItem = item.Cast<IParameterizedItem>(); 14 14 … … 18 18 } 19 19 20 public override ParameterDataExtractData(IItem value) {21 List< ParameterData> list = new List<ParameterData>();20 public override Component ExtractData(IItem value) { 21 List<Component> list = new List<Component>(); 22 22 23 ParameterData obj = new ParameterData();23 Component obj = new Component(); 24 24 obj.Name = value.ItemName; 25 25 obj.Type = value.GetType().AssemblyQualifiedName; … … 29 29 foreach (var param in value.Cast<IParameterizedItem>().Parameters) { 30 30 if (!param.Hidden) { 31 ParameterDatadata = Transformer.Extract(param);31 Component data = Transformer.Extract(param); 32 32 obj[data.Name] = data; 33 33 if(data.ParameterizedItems != null) -
branches/3026_IntegrationIntoSymSpace/HeuristicLab.Manufacture/ParameterTransformer/ValueParameterTransformer.cs
r17269 r17271 9 9 public class ValueParameterTransformer : ParameterBaseTransformer { 10 10 11 public override void InjectData(IParameter parameter, ParameterDatadata) =>11 public override void InjectData(IParameter parameter, Component data) => 12 12 Transformer.Inject(parameter.ActualValue, data); 13 13 14 public override ParameterDataExtractData(IParameter value) {15 ParameterDatadata = null;14 public override Component ExtractData(IParameter value) { 15 Component data = null; 16 16 if (value.ActualValue == null) 17 data = new ParameterData();17 data = new Component(); 18 18 else 19 19 data = Transformer.Extract(value.ActualValue); -
branches/3026_IntegrationIntoSymSpace/HeuristicLab.Manufacture/Transformer.cs
r17269 r17271 49 49 } 50 50 51 internal static void Inject(IItem item, ParameterDatadata) {51 internal static void Inject(IItem item, Component data) { 52 52 IEnumerable<ITypeTransformer> arr = Get(item.GetType()); 53 53 foreach (var transformer in arr) … … 55 55 } 56 56 57 internal static ParameterDataExtract(IItem item) {57 internal static Component Extract(IItem item) { 58 58 IEnumerable<ITypeTransformer> arr = Get(item.GetType()); 59 ParameterData data = new ParameterData();59 Component data = new Component(); 60 60 foreach (var transformer in arr) 61 ParameterData.Merge(data, transformer.Extract(item));61 Component.Merge(data, transformer.Extract(item)); 62 62 return data; 63 63 } -
branches/3026_IntegrationIntoSymSpace/HeuristicLab.Manufacture/TypeTransformer/BaseTransformer.cs
r17266 r17271 10 10 public abstract class BaseTransformer : ITypeTransformer 11 11 { 12 public ParameterDataExtract(IItem value) {13 ParameterDatadata = ExtractData(value);12 public Component Extract(IItem value) { 13 Component data = ExtractData(value); 14 14 data.Name = String.IsNullOrEmpty(data.Name) ? value.ItemName : data.Name; 15 15 return data; 16 16 } 17 17 18 public void Inject(IItem item, ParameterDatadata) => InjectData(item, data);18 public void Inject(IItem item, Component data) => InjectData(item, data); 19 19 20 public abstract void InjectData(IItem item, ParameterDatadata);21 public abstract ParameterDataExtractData(IItem value);20 public abstract void InjectData(IItem item, Component data); 21 public abstract Component ExtractData(IItem value); 22 22 23 23 #region Helper -
branches/3026_IntegrationIntoSymSpace/HeuristicLab.Manufacture/TypeTransformer/DummyTransformer.cs
r17269 r17271 8 8 namespace HeuristicLab.Manufacture { 9 9 public class DummyTransformer : BaseTransformer { 10 public override void InjectData(IItem item, ParameterDatadata) {10 public override void InjectData(IItem item, Component data) { 11 11 // do nothing because the instance already exists and 12 12 // there are no values to inject 13 13 } 14 14 15 public override ParameterDataExtractData(IItem value) =>16 new ParameterData() { Default = value.GetType().Name };15 public override Component ExtractData(IItem value) => 16 new Component() { Default = value.GetType().Name }; 17 17 } 18 18 } -
branches/3026_IntegrationIntoSymSpace/HeuristicLab.Manufacture/TypeTransformer/EnumTypeTransformer.cs
r17266 r17271 10 10 public class EnumTypeTransformer : BaseTransformer { 11 11 12 public override void InjectData(IItem item, ParameterDatadata) =>12 public override void InjectData(IItem item, Component data) => 13 13 item.Cast<dynamic>().Value = Enum.Parse( 14 14 item.GetType().GenericTypeArguments.First(), 15 15 CastValue<string>(data.Default)); 16 16 17 public override ParameterDataExtractData(IItem value) {18 ParameterData data = new ParameterData();17 public override Component ExtractData(IItem value) { 18 Component data = new Component(); 19 19 object val = ((dynamic)value).Value; 20 20 Type enumType = val.GetType(); -
branches/3026_IntegrationIntoSymSpace/HeuristicLab.Manufacture/TypeTransformer/MultiCheckedOperatorTransformer.cs
r17269 r17271 8 8 namespace HeuristicLab.Manufacture { 9 9 public class MultiCheckedOperatorTransformer : ParameterizedItemTransformer { 10 public override ParameterDataExtractData(IItem value) {11 ParameterDatadata = base.ExtractData(value);10 public override Component ExtractData(IItem value) { 11 Component data = base.ExtractData(value); 12 12 13 data.Operators = new List< ParameterData>();13 data.Operators = new List<Component>(); 14 14 dynamic val = value.Cast<dynamic>(); 15 15 foreach (var op in val.Operators) { 16 data.Operators.Add(new ParameterData() {16 data.Operators.Add(new Component() { 17 17 Name = op.Name, 18 18 Default = val.Operators.ItemChecked(op), … … 23 23 } 24 24 25 public override void InjectData(IItem item, ParameterDatadata) {25 public override void InjectData(IItem item, Component data) { 26 26 base.InjectData(item, data); 27 27 … … 32 32 } 33 33 34 private bool GetOperatorState(string name, ParameterDatadata) {34 private bool GetOperatorState(string name, Component data) { 35 35 foreach(var op in data.Operators) { 36 36 if (op.Name == name) return op.Default.Cast<bool>(); -
branches/3026_IntegrationIntoSymSpace/HeuristicLab.Manufacture/TypeTransformer/StringValueTransformer.cs
r17266 r17271 9 9 namespace HeuristicLab.Manufacture { 10 10 public class StringValueTransformer : BaseTransformer { 11 public override void InjectData(IItem item, ParameterDatadata) =>11 public override void InjectData(IItem item, Component data) => 12 12 item.Cast<StringValue>().Value = CastValue<string>(data.Default); 13 13 14 public override ParameterDataExtractData(IItem value) =>15 new ParameterData() {14 public override Component ExtractData(IItem value) => 15 new Component() { 16 16 Default = value.Cast<StringValue>().Value 17 17 }; -
branches/3026_IntegrationIntoSymSpace/HeuristicLab.Manufacture/TypeTransformer/ValueTypeArrayTransformer.cs
r17266 r17271 13 13 where T : struct 14 14 { 15 public override void InjectData(IItem item, ParameterDatadata) =>15 public override void InjectData(IItem item, Component data) => 16 16 CopyArrayData(item.Cast<ArrayType>(), CastValue<T[]>(data.Default)); 17 17 18 public override ParameterDataExtractData(IItem value) =>19 new ParameterData() {18 public override Component ExtractData(IItem value) => 19 new Component() { 20 20 Default = value.Cast<ArrayType>().CloneAsArray() 21 21 }; -
branches/3026_IntegrationIntoSymSpace/HeuristicLab.Manufacture/TypeTransformer/ValueTypeMatrixTransformer.cs
r17266 r17271 13 13 where T : struct 14 14 { 15 public override void InjectData(IItem item, ParameterDatadata) =>15 public override void InjectData(IItem item, Component data) => 16 16 CopyMatrixData(item.Cast<MatrixType>(), CastValue<T[,]>(data.Default)); 17 17 18 public override ParameterDataExtractData(IItem value) =>19 new ParameterData() {18 public override Component ExtractData(IItem value) => 19 new Component() { 20 20 Default = value.Cast<MatrixType>().CloneAsMatrix() 21 21 }; -
branches/3026_IntegrationIntoSymSpace/HeuristicLab.Manufacture/TypeTransformer/ValueTypeValueTransformer.cs
r17266 r17271 12 12 where T : struct { 13 13 14 public override void InjectData(IItem item, ParameterDatadata) =>14 public override void InjectData(IItem item, Component data) => 15 15 item.Cast<ValueType>().Value = CastValue<T>(data.Default); 16 16 17 public override ParameterDataExtractData(IItem value) =>18 new ParameterData() {17 public override Component ExtractData(IItem value) => 18 new Component() { 19 19 Default = value.Cast<ValueType>().Value, 20 20 Range = new object[] { default(T), GetMaxValue() }
Note: See TracChangeset
for help on using the changeset viewer.