- Timestamp:
- 08/20/12 13:00:30 (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/OaaS/HeuristicLab.Services.Optimization.Controller/Model/ControllerModel.cs
r8384 r8506 4 4 using System.Text; 5 5 using System.Runtime.Serialization; 6 using System.Globalization; 7 using System.Xml; 6 8 7 9 namespace HeuristicLab.Services.Optimization.ControllerService.Model { … … 25 27 26 28 [DataContract] 27 public abstract class Value { 29 public abstract class Value { 30 [DataMember] 31 public string Name { get; set; } 32 33 public abstract bool TrySetFromString(string input); 34 } 35 36 37 [DataContract] 38 public class DecimalMatrix : Value { 39 [DataMember] 40 public double[][] Value { get; set; } 41 42 public override bool TrySetFromString(string input) { 43 var splitted = input.Split(':'); 44 int i, j; 45 if (splitted.Length != 3) 46 return false; 47 48 if (!int.TryParse(splitted[0], out i)) 49 return false; 50 51 if (!int.TryParse(splitted[1], out j)) 52 return false; 53 54 double value; 55 if (!double.TryParse(splitted[2], out value)) 56 return false; 57 // very, very buggy 58 if (i >= Value.Length || j >= Value[0].Length ) { 59 double[][] valueArr = new double[i >= Value.GetLength(0) ? i : Value.GetLength(0)][]; 60 for (int k = 0; k < Value.Length; k++) { 61 valueArr[k] = new double[j >= Value.GetLength(1) ? j : Value.GetLength(1)]; 62 for (int l = 0; l < Value[k].Length; l++) { 63 valueArr[k][l] = Value[k][l]; 64 } 65 } 66 Value = valueArr; 67 } 68 69 Value[i][j] = value; 70 return true; 71 } 72 } 73 74 [DataContract] 75 public class DecimalVector : Value { 76 [DataMember] 77 public double[] Value { get; set; } 78 79 public override bool TrySetFromString(string input) { 80 var splitted = input.Split(':'); 81 int index; 82 if (splitted.Length != 2) 83 return false; 84 85 if (!int.TryParse(splitted[0], out index)) 86 return false; 87 88 double value; 89 if (!double.TryParse(splitted[1], out value)) 90 return false; 91 92 if (index >= Value.Length) { 93 double[] valueArr = new double[index + 1]; 94 Array.Copy(Value, valueArr, Value.Length); 95 Value = valueArr; 96 } 97 98 Value[index] = value; 99 return true; 100 } 101 } 102 103 [DataContract] 104 public class TypeValue : Value { 105 [DataMember] 106 public string Value { get; set; } 107 108 [DataMember] 109 public string[] Options { get; set; } 110 111 public override bool TrySetFromString(string input) { 112 if (Options.Contains(input)) { 113 Value = input; 114 return true; 115 } 116 return false; 117 } 28 118 } 29 119 … … 32 122 [DataMember] 33 123 public double Value { get; set; } 124 125 public override bool TrySetFromString(string input) { 126 double result; 127 if (double.TryParse(input, out result)) { 128 Value = result; 129 return true; 130 } 131 return false; 132 } 34 133 } 35 134 … … 38 137 [DataMember] 39 138 public bool Value { get; set; } 139 140 public override bool TrySetFromString(string input) { 141 bool result; 142 if (input.Contains(",")) 143 input = input.Split(',')[0].Trim(); 144 if (bool.TryParse(input, out result)) { 145 Value = result; 146 return true; 147 } 148 return false; 149 } 40 150 } 41 151 … … 43 153 [KnownType(typeof(BoolValue))] 44 154 [KnownType(typeof(DecimalValue))] 45 public class Parameter {46 [DataMember]47 public string Name { get; set; }48 155 [KnownType(typeof(TypeValue))] 156 [KnownType(typeof(DecimalVector))] 157 [KnownType(typeof(DecimalMatrix))] 158 public class Parameter { 49 159 // some kind of value type 50 160 [DataMember] … … 52 162 53 163 [DataMember] 54 public Value Value { get; set; } 55 164 public Value Value { get; set; } 56 165 /* 57 166 //[DataMember] … … 60 169 61 170 [DataContract] 171 public class InputParameters { 172 private IList<Parameter> items = new List<Parameter>(); 173 174 [DataMember] 175 public IList<Parameter> Items { 176 get { return items; } 177 set { items = value; } 178 } 179 } 180 181 [DataContract] 182 public class AlgorithmParameters { 183 private IList<Parameter> items = new List<Parameter>(); 184 185 [DataMember] 186 public IList<Parameter> Items { 187 get { return items; } 188 set { items = value; } 189 } 190 } 191 192 [DataContract] 62 193 public class OptimizationScenario { 63 194 [DataMember] 64 195 public string Name { get; set; } 65 196 66 private IList<Parameter> inputParameters = new List<Parameter>(); 67 68 [DataMember] 69 public IList<Parameter> InputParameters { 70 get { return inputParameters; } 71 set { inputParameters = value; } 72 } 73 74 private IList<Parameter> algorithmParameters = new List<Parameter>(); 75 76 [DataMember] 77 public IList<Parameter> AlgorithmParameters { 197 private InputParameters inputParams = new InputParameters(); 198 199 [DataMember] 200 public InputParameters InputParameters { 201 get { return inputParams; } 202 set { inputParams = value; } 203 } 204 205 206 private AlgorithmParameters algorithmParameters = new AlgorithmParameters(); 207 208 [DataMember] 209 public AlgorithmParameters AlgorithmParameters { 78 210 get { return algorithmParameters; } 79 211 set { algorithmParameters = value; } 80 212 } 213 81 214 } 82 215 }
Note: See TracChangeset
for help on using the changeset viewer.