Changeset 17283
- Timestamp:
- 10/01/19 14:36:32 (5 years ago)
- Location:
- branches/3026_IntegrationIntoSymSpace/HeuristicLab.Manufacture
- Files:
-
- 18 edited
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
branches/3026_IntegrationIntoSymSpace/HeuristicLab.Manufacture/Converters/BaseConverter.cs
r17281 r17283 10 10 public abstract class BaseConverter : IJsonItemConverter 11 11 { 12 public ComponentExtract(IItem value) {13 Componentdata = ExtractData(value);12 public JsonItem Extract(IItem value) { 13 JsonItem 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, Componentdata) {18 public void Inject(IItem item, JsonItem data) { 19 19 if(data.Reference != null) { 20 Component.Merge(data, data.Reference);20 JsonItem.Merge(data, data.Reference); 21 21 } 22 22 InjectData(item, data); 23 23 } 24 24 25 public abstract void InjectData(IItem item, Componentdata);26 public abstract ComponentExtractData(IItem value);25 public abstract void InjectData(IItem item, JsonItem data); 26 public abstract JsonItem ExtractData(IItem value); 27 27 28 28 #region Helper -
branches/3026_IntegrationIntoSymSpace/HeuristicLab.Manufacture/Converters/ConstrainedValueParameterConverter.cs
r17281 r17283 8 8 namespace HeuristicLab.Manufacture { 9 9 public class ConstrainedValueParameterConverter : ParameterBaseConverter { 10 public override void InjectData(IParameter parameter, Componentdata) {10 public override void InjectData(IParameter parameter, JsonItem 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 ComponentExtractData(IParameter value) =>20 new Component() {19 public override JsonItem ExtractData(IParameter value) => 20 new JsonItem() { 21 21 Name = value.Name, 22 22 Default = value.ActualValue?.GetType().Name, … … 33 33 } 34 34 // id = kombi aus path + default 35 private IList< Component> GetParameterizedChilds(IParameter value) {36 List< Component> list = new List<Component>();35 private IList<JsonItem> GetParameterizedChilds(IParameter value) { 36 List<JsonItem> list = new List<JsonItem>(); 37 37 var values = value.Cast<dynamic>().ValidValues; 38 38 foreach(var x in values) { 39 39 if (x is IParameterizedItem) { 40 Componenttmp = JsonItemConverter.Extract(x);40 JsonItem tmp = JsonItemConverter.Extract(x); 41 41 tmp.PrependPath(value.Name); 42 42 list.Add(tmp); -
branches/3026_IntegrationIntoSymSpace/HeuristicLab.Manufacture/Converters/DummyConverter.cs
r17281 r17283 8 8 namespace HeuristicLab.Manufacture { 9 9 public class DummyConverter : BaseConverter { 10 public override void InjectData(IItem item, Componentdata) {10 public override void InjectData(IItem item, JsonItem 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 ComponentExtractData(IItem value) =>16 new Component() { Default = value.GetType().Name };15 public override JsonItem ExtractData(IItem value) => 16 new JsonItem() { Default = value.GetType().Name }; 17 17 } 18 18 } -
branches/3026_IntegrationIntoSymSpace/HeuristicLab.Manufacture/Converters/EnumTypeConverter.cs
r17281 r17283 9 9 namespace HeuristicLab.Manufacture { 10 10 public class EnumTypeConverter : BaseConverter { 11 public override void InjectData(IItem item, Componentdata) =>11 public override void InjectData(IItem item, JsonItem data) => 12 12 item.Cast<dynamic>().Value = Enum.Parse( 13 13 item.GetType().GenericTypeArguments.First(), 14 14 CastValue<string>(data.Default)); 15 15 16 public override ComponentExtractData(IItem value) {17 Component data = new Component();16 public override JsonItem ExtractData(IItem value) { 17 JsonItem data = new JsonItem(); 18 18 object val = ((dynamic)value).Value; 19 19 Type enumType = val.GetType(); -
branches/3026_IntegrationIntoSymSpace/HeuristicLab.Manufacture/Converters/LookupParameterConverter.cs
r17281 r17283 8 8 namespace HeuristicLab.Manufacture { 9 9 public class LookupParameterConverter : ParameterBaseConverter { 10 public override ComponentExtractData(IParameter value) {11 return new Component() { Name = value.Name };10 public override JsonItem ExtractData(IParameter value) { 11 return new JsonItem() { Name = value.Name }; 12 12 } 13 13 14 public override void InjectData(IParameter parameter, Componentdata) {14 public override void InjectData(IParameter parameter, JsonItem data) { 15 15 16 16 } -
branches/3026_IntegrationIntoSymSpace/HeuristicLab.Manufacture/Converters/MultiCheckedOperatorConverter.cs
r17281 r17283 8 8 namespace HeuristicLab.Manufacture { 9 9 public class MultiCheckedOperatorConverter : ParameterizedItemConverter { 10 public override ComponentExtractData(IItem value) {11 Componentdata = base.ExtractData(value);10 public override JsonItem ExtractData(IItem value) { 11 JsonItem data = base.ExtractData(value); 12 12 13 13 data.Default = value.GetType().Name; 14 data.Operators = new List<Component>(); 15 /* 16 if (data.ParameterizedItems == null) 17 data.ParameterizedItems = new List<Component>(); 18 data.ParameterizedItems.Add(data); 19 */ 14 data.Operators = new List<JsonItem>(); 20 15 dynamic val = value.Cast<dynamic>(); 21 16 foreach (var op in val.Operators) { 22 data.Operators.Add(new Component() {17 data.Operators.Add(new JsonItem() { 23 18 Name = op.Name, 24 19 Default = val.Operators.ItemChecked(op), … … 30 25 } 31 26 32 public override void InjectData(IItem item, Componentdata) {27 public override void InjectData(IItem item, JsonItem data) { 33 28 base.InjectData(item, data); 34 29 … … 39 34 } 40 35 41 private bool GetOperatorState(string name, Componentdata) {36 private bool GetOperatorState(string name, JsonItem data) { 42 37 foreach(var op in data.Operators) { 43 38 if (op.Name == name) return op.Default.Cast<bool>(); -
branches/3026_IntegrationIntoSymSpace/HeuristicLab.Manufacture/Converters/ParameterBaseConverter.cs
r17281 r17283 8 8 namespace HeuristicLab.Manufacture { 9 9 public abstract class ParameterBaseConverter : BaseConverter { 10 public override ComponentExtractData(IItem value) {10 public override JsonItem ExtractData(IItem value) { 11 11 IParameter param = value.Cast<IParameter>(); 12 Componentcomp = ExtractData(param);12 JsonItem comp = ExtractData(param); 13 13 //comp.Path = value.Cast<IParameter>().ActualValue?.ItemName; 14 14 /*comp.Path = value.Cast<IParameter>().Name + "." + comp.Path; … … 20 20 return comp; 21 21 } 22 public abstract ComponentExtractData(IParameter value);22 public abstract JsonItem ExtractData(IParameter value); 23 23 24 public override void InjectData(IItem item, Componentdata) => InjectData(item.Cast<IParameter>(), data);24 public override void InjectData(IItem item, JsonItem data) => InjectData(item.Cast<IParameter>(), data); 25 25 26 public abstract void InjectData(IParameter parameter, Componentdata);26 public abstract void InjectData(IParameter parameter, JsonItem data); 27 27 } 28 28 } -
branches/3026_IntegrationIntoSymSpace/HeuristicLab.Manufacture/Converters/ParameterizedItemConverter.cs
r17281 r17283 2 2 using System.Collections.Generic; 3 3 using System.Linq; 4 using System.Text; 4 using System.Text;JsonItem obj 5 5 using System.Threading.Tasks; 6 6 using HeuristicLab.Core; … … 9 9 { 10 10 public class ParameterizedItemConverter : BaseConverter { 11 public override void InjectData(IItem item, Componentdata) {11 public override void InjectData(IItem item, JsonItem data) { 12 12 IParameterizedItem pItem = item.Cast<IParameterizedItem>(); 13 13 … … 19 19 } 20 20 21 public override ComponentExtractData(IItem value) {22 Component obj = new Component();23 obj.Name = value.ItemName;24 obj.Type = value.GetType().AssemblyQualifiedName;25 obj.Path = value.ItemName;21 public override JsonItem ExtractData(IItem value) { 22 JsonItem item = new JsonItem(); 23 item.Name = value.ItemName; 24 item.Type = value.GetType().AssemblyQualifiedName; 25 item.Path = value.ItemName; 26 26 27 27 foreach (var param in value.Cast<IParameterizedItem>().Parameters) { 28 Componentdata = JsonItemConverter.Extract(param);28 JsonItem data = JsonItemConverter.Extract(param); 29 29 data.Name = param.Name; 30 30 data.Path = param.Name; 31 data.PrependPath( obj.Path);31 data.PrependPath(item.Path); 32 32 data.UpdatePaths(); 33 33 34 if ( obj.Parameters == null)35 obj.Parameters = new List<Component>();36 obj.Parameters.Add(data);34 if (item.Parameters == null) 35 item.Parameters = new List<JsonItem>(); 36 item.Parameters.Add(data); 37 37 } 38 return obj;38 return item; 39 39 } 40 40 } -
branches/3026_IntegrationIntoSymSpace/HeuristicLab.Manufacture/Converters/StringValueConverter.cs
r17281 r17283 9 9 namespace HeuristicLab.Manufacture { 10 10 public class StringValueConverter : BaseConverter { 11 public override void InjectData(IItem item, Componentdata) =>11 public override void InjectData(IItem item, JsonItem data) => 12 12 item.Cast<StringValue>().Value = CastValue<string>(data.Default); 13 13 14 public override ComponentExtractData(IItem value) =>15 new Component() {14 public override JsonItem ExtractData(IItem value) => 15 new JsonItem() { 16 16 Default = value.Cast<StringValue>().Value 17 17 }; -
branches/3026_IntegrationIntoSymSpace/HeuristicLab.Manufacture/Converters/ValueParameterConverter.cs
r17281 r17283 9 9 public class ValueParameterConverter : ParameterBaseConverter { 10 10 11 public override void InjectData(IParameter parameter, Componentdata) =>11 public override void InjectData(IParameter parameter, JsonItem data) => 12 12 JsonItemConverter.Inject(parameter.ActualValue, data); 13 13 14 public override ComponentExtractData(IParameter value) {15 Componentdata = null;14 public override JsonItem ExtractData(IParameter value) { 15 JsonItem data = null; 16 16 if (value.ActualValue == null) 17 data = new Component();17 data = new JsonItem(); 18 18 else 19 19 data = JsonItemConverter.Extract(value.ActualValue); -
branches/3026_IntegrationIntoSymSpace/HeuristicLab.Manufacture/Converters/ValueTypeArrayConverter.cs
r17281 r17283 13 13 where T : struct 14 14 { 15 public override void InjectData(IItem item, Componentdata) =>15 public override void InjectData(IItem item, JsonItem data) => 16 16 CopyArrayData(item.Cast<ArrayType>(), CastValue<T[]>(data.Default)); 17 17 18 public override ComponentExtractData(IItem value) =>19 new Component() {18 public override JsonItem ExtractData(IItem value) => 19 new JsonItem() { 20 20 Default = value.Cast<ArrayType>().CloneAsArray() 21 21 }; -
branches/3026_IntegrationIntoSymSpace/HeuristicLab.Manufacture/Converters/ValueTypeMatrixConverter.cs
r17281 r17283 13 13 where T : struct 14 14 { 15 public override void InjectData(IItem item, Componentdata) =>15 public override void InjectData(IItem item, JsonItem data) => 16 16 CopyMatrixData(item.Cast<MatrixType>(), CastValue<T[,]>(data.Default)); 17 17 18 public override ComponentExtractData(IItem value) =>19 new Component() {18 public override JsonItem ExtractData(IItem value) => 19 new JsonItem() { 20 20 Default = value.Cast<MatrixType>().CloneAsMatrix() 21 21 }; -
branches/3026_IntegrationIntoSymSpace/HeuristicLab.Manufacture/Converters/ValueTypeValueConverter.cs
r17281 r17283 12 12 where T : struct { 13 13 14 public override void InjectData(IItem item, Componentdata) =>14 public override void InjectData(IItem item, JsonItem data) => 15 15 item.Cast<ValueType>().Value = CastValue<T>(data.Default); 16 16 17 public override ComponentExtractData(IItem value) =>18 new Component() {17 public override JsonItem ExtractData(IItem value) => 18 new JsonItem() { 19 19 Default = value.Cast<ValueType>().Value, 20 20 Range = new object[] { GetMinValue(), GetMaxValue() } -
branches/3026_IntegrationIntoSymSpace/HeuristicLab.Manufacture/HeuristicLab.Manufacture.csproj
r17282 r17283 71 71 <Compile Include="Program.cs" /> 72 72 <Compile Include="Properties\AssemblyInfo.cs" /> 73 <Compile Include=" Component.cs" />73 <Compile Include="JsonItem.cs" /> 74 74 <Compile Include="Interfaces\IJsonItemConverter.cs" /> 75 75 <Compile Include="JsonItemConverter.cs" /> -
branches/3026_IntegrationIntoSymSpace/HeuristicLab.Manufacture/Interfaces/IJsonItemConverter.cs
r17281 r17283 10 10 public interface IJsonItemConverter { 11 11 /// <summary> 12 /// Extracts all infos out of an IItem to create a Component.12 /// Extracts all infos out of an IItem to create a JsonItem. 13 13 /// (For template generation.) 14 14 /// </summary> 15 15 /// <param name="value">The IItem to extract infos.</param> 16 /// <returns> Componentwith infos to reinitialise the IItem.</returns>17 ComponentExtract(IItem value);16 /// <returns>JsonItem with infos to reinitialise the IItem.</returns> 17 JsonItem Extract(IItem value); 18 18 19 19 /// <summary> 20 /// Injects the saved infos from the Componentinto the IItem.20 /// Injects the saved infos from the JsonItem into the IItem. 21 21 /// (Sets the necessary values.) 22 22 /// </summary> 23 23 /// <param name="item">The IItem which get the data injected.</param> 24 /// <param name="data">The Componentwith the saved values.</param>25 void Inject(IItem item, Componentdata);24 /// <param name="data">The JsonItem with the saved values.</param> 25 void Inject(IItem item, JsonItem data); 26 26 } 27 27 } -
branches/3026_IntegrationIntoSymSpace/HeuristicLab.Manufacture/JCGenerator.cs
r17281 r17283 27 27 28 28 JArray jsonItems = new JArray(); 29 private void PopulateJsonItems( Component component) {30 if ( component.Parameters != null) {31 if( component.Range == null)32 jsonItems.Add(Serialize( component));33 foreach (var p in component.Parameters)29 private void PopulateJsonItems(JsonItem item) { 30 if (item.Parameters != null) { 31 if(item.Range == null) 32 jsonItems.Add(Serialize(item)); 33 foreach (var p in item.Parameters) 34 34 if(p.Parameters != null) 35 35 PopulateJsonItems(p); … … 37 37 } 38 38 39 private JObject Serialize( Component component) {40 JObject obj = JObject.FromObject( component, Settings());39 private JObject Serialize(JsonItem item) { 40 JObject obj = JObject.FromObject(item, Settings()); 41 41 obj["StaticParameters"] = obj["Parameters"]; 42 42 obj["FreeParameters"] = obj["Parameters"]; … … 49 49 obj.Property("Type")?.Remove(); 50 50 51 TypeList.Add( component.Path, component.Type);51 TypeList.Add(item.Path, item.Type); 52 52 return obj; 53 53 } … … 55 55 public string GenerateTemplate(IAlgorithm algorithm, IProblem problem, params string[] freeParameters) { 56 56 algorithm.Problem = problem; 57 ComponentalgorithmData = JsonItemConverter.Extract(algorithm);58 ComponentproblemData = JsonItemConverter.Extract(problem);57 JsonItem algorithmData = JsonItemConverter.Extract(algorithm); 58 JsonItem problemData = JsonItemConverter.Extract(problem); 59 59 PopulateJsonItems(algorithmData); 60 60 PopulateJsonItems(problemData); … … 74 74 IList<JObject> objToRemove = new List<JObject>(); 75 75 TransformNodes(x => { 76 var p = x.ToObject< Component>();76 var p = x.ToObject<JsonItem>(); 77 77 78 78 /*bool isSelected = false; … … 96 96 IList<JObject> objToRemove = new List<JObject>(); 97 97 TransformNodes(x => { 98 var p = x.ToObject< Component>();98 var p = x.ToObject<JsonItem>(); 99 99 x.Property("Range")?.Remove(); 100 100 x.Property("Operators")?.Remove(); … … 105 105 foreach (var x in objToRemove) x.Remove(); 106 106 } 107 108 107 109 108 private JsonSerializer Settings() => new JsonSerializer() { -
branches/3026_IntegrationIntoSymSpace/HeuristicLab.Manufacture/JCInstantiator.cs
r17281 r17283 22 22 TypeList = Config["Types"].ToObject<Dictionary<string, string>>(); 23 23 24 ComponentalgorithmData = GetData(Config["Metadata"]["Algorithm"].ToString());24 JsonItem algorithmData = GetData(Config["Metadata"]["Algorithm"].ToString()); 25 25 ResolveReferences(algorithmData); 26 26 IAlgorithm algorithm = CreateObject<IAlgorithm>(algorithmData); 27 27 28 ComponentproblemData = GetData(Config["Metadata"]["Problem"].ToString());28 JsonItem problemData = GetData(Config["Metadata"]["Problem"].ToString()); 29 29 ResolveReferences(problemData); 30 30 IProblem problem = CreateObject<IProblem>(problemData); … … 37 37 } 38 38 39 private void ResolveReferences( Componentdata) {39 private void ResolveReferences(JsonItem data) { 40 40 foreach (var p in data.Parameters) 41 41 if (p.Default is string && p.Reference == null) … … 43 43 } 44 44 45 private ComponentGetData(string key)45 private JsonItem GetData(string key) 46 46 { 47 47 foreach(JObject item in Config["Objects"]) 48 48 { 49 Component data = BuildComponent(item);49 JsonItem data = BuildJsonItem(item); 50 50 if (data.Name == key) return data; 51 51 } … … 53 53 } 54 54 55 private T CreateObject<T>( Componentdata) {55 private T CreateObject<T>(JsonItem data) { 56 56 if (TypeList.TryGetValue(data.Name, out string typeName)) { 57 57 Type type = Type.GetType(typeName); … … 60 60 } 61 61 62 private Component BuildComponent(JObject obj) =>63 new Component() {64 Name = obj[nameof( Component.Name)]?.ToString(),65 Default = obj[nameof( Component.Default)]?.ToObject<object>(),66 Range = obj[nameof( Component.Range)]?.ToObject<object[]>(),67 Type = obj[nameof( Component.Type)]?.ToObject<string>(),62 private JsonItem BuildJsonItem(JObject obj) => 63 new JsonItem() { 64 Name = obj[nameof(JsonItem.Name)]?.ToString(), 65 Default = obj[nameof(JsonItem.Default)]?.ToObject<object>(), 66 Range = obj[nameof(JsonItem.Range)]?.ToObject<object[]>(), 67 Type = obj[nameof(JsonItem.Type)]?.ToObject<string>(), 68 68 Parameters = PopulateParameters(obj), 69 69 Operators = PopulateOperators(obj) 70 70 }; 71 71 72 private IList< Component> PopulateParameters(JObject obj) {73 IList< Component> list = new List<Component>();72 private IList<JsonItem> PopulateParameters(JObject obj) { 73 IList<JsonItem> list = new List<JsonItem>(); 74 74 if (obj["StaticParameters"] != null) 75 75 foreach (JObject param in obj["StaticParameters"]) 76 list.Add(Build Component(param));76 list.Add(BuildJsonItem(param)); 77 77 78 78 if (obj["FreeParameters"] != null) { 79 79 foreach (JObject param in obj["FreeParameters"]) { 80 Component tmp = BuildComponent(param);81 Componentcomp = null;80 JsonItem tmp = BuildJsonItem(param); 81 JsonItem comp = null; 82 82 foreach (var p in list) // TODO: nicht notwendig, da immer alle params im static block sind 83 83 if (p.Name == tmp.Name) comp = p; 84 84 if (comp != null) 85 Component.Merge(comp, tmp);85 JsonItem.Merge(comp, tmp); 86 86 else list.Add(tmp); 87 87 } … … 90 90 } 91 91 92 private IList< Component> PopulateOperators(JObject obj) {93 IList< Component> list = new List<Component>();92 private IList<JsonItem> PopulateOperators(JObject obj) { 93 IList<JsonItem> list = new List<JsonItem>(); 94 94 if (obj[nameof(Operators)] != null) 95 95 foreach (JObject sp in obj[nameof(Operators)]) { 96 Component tmp = BuildComponent(sp);96 JsonItem tmp = BuildJsonItem(sp); 97 97 list.Add(tmp); 98 98 } -
branches/3026_IntegrationIntoSymSpace/HeuristicLab.Manufacture/JsonItem.cs
r17282 r17283 10 10 namespace HeuristicLab.Manufacture { 11 11 //JsonItem 12 public class Component{12 public class JsonItem { 13 13 private IList<object> range; 14 14 private object defaultValue; … … 35 35 } 36 36 37 public IList< Component> Parameters { get; set; }38 public IList< Component> Operators { get; set; }37 public IList<JsonItem> Parameters { get; set; } 38 public IList<JsonItem> Operators { get; set; } 39 39 40 40 public override bool Equals(object obj) => 41 (obj is Component ? (obj.Cast<Component>().Name == this.Name) : false);41 (obj is JsonItem ? (obj.Cast<JsonItem>().Name == this.Name) : false); 42 42 43 43 public override int GetHashCode() => Name.GetHashCode(); 44 44 45 45 [JsonIgnore] 46 public ComponentReference { get; set; }46 public JsonItem Reference { get; set; } 47 47 48 public static void Merge( Component target, Componentfrom) {48 public static void Merge(JsonItem target, JsonItem from) { 49 49 target.Name = from.Name ?? target.Name; 50 50 target.Type = from.Type ?? target.Type; … … 59 59 public bool FulfillConstraints() => FulfillConstraints(this); 60 60 61 public static bool FulfillConstraints( Componentdata) =>61 public static bool FulfillConstraints(JsonItem data) => 62 62 data.Range != null && data.Default != null && ( 63 63 IsInRangeList(data.Range, data.Default) || … … 91 91 } 92 92 93 private void PrependPathHelper(IEnumerable< Component> components, string str) {94 if ( components != null) {95 foreach (var p in components)93 private void PrependPathHelper(IEnumerable<JsonItem> items, string str) { 94 if (items != null) { 95 foreach (var p in items) 96 96 p.PrependPath(str); 97 97 } -
branches/3026_IntegrationIntoSymSpace/HeuristicLab.Manufacture/JsonItemConverter.cs
r17282 r17283 22 22 } 23 23 24 25 24 public static void Register<T>(IJsonItemConverter converter, int priority) => Register(typeof(T), converter, priority); 26 25 … … 43 42 } 44 43 45 internal static void Inject(IItem item, Componentdata) =>44 internal static void Inject(IItem item, JsonItem data) => 46 45 Get(item.GetType()).Inject(item, data); 47 46 48 internal static ComponentExtract(IItem item) =>47 internal static JsonItem Extract(IItem item) => 49 48 Get(item.GetType()).Extract(item); 50 49
Note: See TracChangeset
for help on using the changeset viewer.