1 | using System;
|
---|
2 | using System.Collections.Generic;
|
---|
3 | using System.Linq;
|
---|
4 | using System.Text;
|
---|
5 | using System.Runtime.Serialization;
|
---|
6 | using System.Globalization;
|
---|
7 | using System.Xml;
|
---|
8 |
|
---|
9 | namespace HeuristicLab.Services.Optimization.ControllerService.Model {
|
---|
10 | [DataContract]
|
---|
11 | public enum ParameterType {
|
---|
12 | [EnumMember]
|
---|
13 | Decimal,
|
---|
14 | [EnumMember]
|
---|
15 | Integer,
|
---|
16 | [EnumMember]
|
---|
17 | Boolean,
|
---|
18 | [EnumMember]
|
---|
19 | Type,
|
---|
20 | [EnumMember]
|
---|
21 | DecimalMatrix,
|
---|
22 | [EnumMember]
|
---|
23 | DecimalVector,
|
---|
24 | [EnumMember]
|
---|
25 | Percent
|
---|
26 | }
|
---|
27 |
|
---|
28 | [DataContract]
|
---|
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 | }
|
---|
118 | }
|
---|
119 |
|
---|
120 | [DataContract]
|
---|
121 | public class DecimalValue : Value {
|
---|
122 | [DataMember]
|
---|
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 | }
|
---|
133 | }
|
---|
134 |
|
---|
135 | [DataContract]
|
---|
136 | public class BoolValue : Value {
|
---|
137 | [DataMember]
|
---|
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 | }
|
---|
150 | }
|
---|
151 |
|
---|
152 | [DataContract]
|
---|
153 | [KnownType(typeof(BoolValue))]
|
---|
154 | [KnownType(typeof(DecimalValue))]
|
---|
155 | [KnownType(typeof(TypeValue))]
|
---|
156 | [KnownType(typeof(DecimalVector))]
|
---|
157 | [KnownType(typeof(DecimalMatrix))]
|
---|
158 | public class Parameter {
|
---|
159 | // some kind of value type
|
---|
160 | [DataMember]
|
---|
161 | public ParameterType Type { get; set; }
|
---|
162 |
|
---|
163 | [DataMember]
|
---|
164 | public Value Value { get; set; }
|
---|
165 | /*
|
---|
166 | //[DataMember]
|
---|
167 | public object[] Choices { get; set; }*/
|
---|
168 | }
|
---|
169 |
|
---|
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]
|
---|
193 | public class OptimizationScenario {
|
---|
194 | [DataMember]
|
---|
195 | public string Name { get; set; }
|
---|
196 |
|
---|
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 {
|
---|
210 | get { return algorithmParameters; }
|
---|
211 | set { algorithmParameters = value; }
|
---|
212 | }
|
---|
213 |
|
---|
214 | }
|
---|
215 | }
|
---|