Free cookie consent management tool by TermsFeed Policy Generator

source: branches/OaaS/HeuristicLab.Services.Optimization.Controller/Model/ControllerModel.cs @ 8545

Last change on this file since 8545 was 8545, checked in by fschoepp, 10 years ago

#1888:

  • Controller is now capable of gathering Hive Jobs
  • Hive Jobs will be mapped to independent Job-Class (shared between Controller and Frontend)
  • HiveScenarioManager is capable of gathering Hive Jobs + their results
  • Job Results will be mapped to string properties
  • Frontend renders all Results after opening the job details
  • Misc: Frontend now passes User-object to Controller so that it is able to connect to the Hive Service (hardcoded values removed)
File size: 6.2 KB
Line 
1using System;
2using System.Collections.Generic;
3using System.Linq;
4using System.Text;
5using System.Runtime.Serialization;
6using System.Globalization;
7using System.Xml;
8
9namespace 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    [EnumMember]
27    String
28  }
29
30  [DataContract]
31  public abstract class Value {
32    [DataMember]
33    public string Name { get; set; }
34
35    public abstract bool TrySetFromString(string input);
36  }
37
38
39  [DataContract]
40  public class DecimalMatrix : Value {
41    [DataMember]
42    public double[][] Value { get; set; }
43
44    public override bool TrySetFromString(string input) {
45      var splitted = input.Split(':');
46      int i, j;
47      if (splitted.Length != 3)
48        return false;
49
50      if (!int.TryParse(splitted[0], out i))
51        return false;
52
53      if (!int.TryParse(splitted[1], out j))
54        return false;
55
56      double value;
57      if (!double.TryParse(splitted[2], out value))
58        return false;
59      // very, very buggy
60      if (i >= Value.Length || j >= Value[0].Length ) {
61        double[][] valueArr = new double[i >= Value.GetLength(0) ? i : Value.GetLength(0)][];       
62        for (int k = 0; k < Value.Length; k++) {
63          valueArr[k] = new double[j >= Value.GetLength(1) ? j : Value.GetLength(1)];
64          for (int l = 0; l < Value[k].Length; l++) {
65            valueArr[k][l] = Value[k][l];
66          }
67        }
68        Value = valueArr;
69      }
70
71      Value[i][j] = value;
72      return true;
73    }
74  }
75
76  [DataContract]
77  public class DecimalVector : Value {
78    [DataMember]
79    public double[] Value { get; set; }
80
81    public override bool TrySetFromString(string input) {
82      var splitted = input.Split(':');
83      int index;
84      if (splitted.Length != 2)
85        return false;
86
87      if (!int.TryParse(splitted[0], out index))
88        return false;
89
90      double value;
91      if (!double.TryParse(splitted[1], out value))
92        return false;
93
94      if (index >= Value.Length) {
95        double[] valueArr = new double[index + 1];
96        Array.Copy(Value, valueArr, Value.Length);
97        Value = valueArr;
98      }
99
100      Value[index] = value;
101      return true;
102    }
103  }
104
105  [DataContract]
106  public class TypeValue : Value {
107    [DataMember]
108    public string Value { get; set; }
109
110    [DataMember]
111    public string[] Options { get; set; }
112
113    public override bool TrySetFromString(string input) {
114      if (Options.Contains(input)) {
115        Value = input;
116        return true;
117      }
118      return false;
119    }
120  }
121
122  [DataContract]
123  public class DecimalValue : Value {
124    [DataMember]
125    public double Value { get; set; }
126
127    public override bool TrySetFromString(string input) {
128      double result;
129      if (double.TryParse(input, out result)) {
130        Value = result;
131        return true;
132      }
133      return false;
134    }
135  }
136
137  [DataContract]
138  public class BoolValue : Value {
139    [DataMember]
140    public bool Value { get; set; }
141
142    public override bool TrySetFromString(string input) {
143      bool result;
144      if (input.Contains(","))
145        input = input.Split(',')[0].Trim();
146      if (bool.TryParse(input, out result)) {
147        Value = result;
148        return true;
149      }
150      return false;
151    }
152  }
153
154  [DataContract]
155  public class StringValue : Value {
156    [DataMember]
157    public string Value { get; set; }
158
159    public override bool TrySetFromString(string input) {
160      Value = input;
161      return true;
162    }
163  }
164
165  [DataContract]
166  [KnownType(typeof(BoolValue))]
167  [KnownType(typeof(DecimalValue))]
168  [KnownType(typeof(TypeValue))]
169  [KnownType(typeof(DecimalVector))]
170  [KnownType(typeof(DecimalMatrix))]
171  [KnownType(typeof(StringValue))]
172  public class Parameter {       
173    // some kind of value type
174    [DataMember]
175    public ParameterType Type { get; set; }
176   
177    [DataMember]
178    public Value Value { get; set; }   
179    /*
180    //[DataMember]
181    public object[] Choices { get; set; }*/
182  }
183
184  [DataContract]
185  public class InputParameters {
186    private IList<Parameter> items = new List<Parameter>();
187
188    [DataMember]
189    public IList<Parameter> Items {
190      get { return items; }
191      set { items = value; }
192    }
193  }
194
195  [DataContract]
196  public class AlgorithmParameters {
197    private IList<Parameter> items = new List<Parameter>();
198
199    [DataMember]
200    public IList<Parameter> Items {
201      get { return items; }
202      set { items = value; }
203    }
204  }
205
206  [DataContract]
207  public class OptimizationScenario {
208    [DataMember]
209    public string Name { get; set; }
210
211    private InputParameters inputParams = new InputParameters();
212
213    [DataMember]
214    public InputParameters InputParameters {
215      get { return inputParams; }
216      set { inputParams = value; }
217    }
218
219
220    private AlgorithmParameters algorithmParameters = new AlgorithmParameters();
221
222    [DataMember]
223    public AlgorithmParameters AlgorithmParameters {
224      get { return algorithmParameters; }
225      set { algorithmParameters = value; }
226    }
227  }
228
229  [DataContract]
230  public enum JobState {
231    [EnumMember]
232    Waiting,
233    [EnumMember]
234    Calculating,
235    [EnumMember]
236    Aborted,
237    [EnumMember]
238    Failed,
239    [EnumMember]
240    Finished
241  }
242
243  [DataContract]
244  public class Job {
245    [DataMember]
246    public string Id { get; set; }
247
248    [DataMember]
249    public JobState State { get; set; }
250
251    [DataMember]
252    public string Name { get; set; }
253
254    [DataMember]
255    public string Resource { get; set; }   
256  }
257
258  [DataContract]
259  public class Run {
260    [DataMember]
261    public string Id { get; set; }
262
263    [DataMember]
264    public string Name { get; set; }
265
266    [DataMember]
267    public IList<Parameter> Results { get; set; }
268  }
269
270  [DataContract]
271  public class User {
272    [DataMember]
273    public string Username { get; set; }
274    [DataMember]
275    public string Password { get; set; }
276  }
277}
Note: See TracBrowser for help on using the repository browser.