Free cookie consent management tool by TermsFeed Policy Generator

source: branches/OaaS/HeuristicLab.Services.Optimization.Controller/HL/HLMapper.cs @ 11813

Last change on this file since 11813 was 9508, checked in by fschoepp, 12 years ago

#1888:
HL:

  • Web projects requires different users to interact with hive. The singleton HiveServiceLocator.Instance doesn't allow different users at the same time, resulting in serialization during access of HiveClient methods.

The following changes have been introduced in favor of a parallel use of the HL libs:

  • HiveClient, TaskDownloader and ConcurrentTaskDownloader may now use a different IHiveServiceLocator than HiveServiceLocator.Instance (all methods have appropriate overloads now).
  • The default instance is still HiveServiceLocator.Instance.

Automated Scaling of Instances:

  • Added Scaler project to solution which represents a WorkerRole that scales the slave instances based on the global cpu utilization of all slaves.
  • Scaler is based on WASABi, rules can be adjusted in rulesstore.xml. Basic rule is: if < 45% global cpu utilization => remove an instance; if > 65% cpu => add an instance. Minimum boundary is 1 and maximum boundary is 8 slave instances.
  • Adjusted Slave project to automatically register itself to a SlaveGroup during WebRole startup (can be adjusted in service configuration).

Web-Frontend:

  • Added basic error messages to the dialogs when an ajax call fails.
  • Removed Styling.js from scripts.
File size: 3.2 KB
Line 
1using System;
2using System.Collections.Generic;
3using System.Linq;
4using System.Text;
5using HeuristicLab.Data;
6using HeuristicLab.Services.Optimization.ControllerService.Model;
7using HeuristicLab.Optimization;
8using HeuristicLab.Encodings.PermutationEncoding;
9using HeuristicLab.Core;
10
11namespace HeuristicLab.Services.Optimization.ControllerService {
12  public interface IScenarioMapper {
13    void MapScenario(OptimizationScenario scenario, out IAlgorithm algorithm);
14  }
15
16  public static class HLMapper {
17    public static DoubleValue ConvertToDoubleValue(Parameter parameter) {
18      var dv = parameter.Value as DecimalValue;
19      return new DoubleValue(dv.Value);     
20    }
21
22    public static T Create<T>(Parameter typeParameter) {
23      var type = Type.GetType((typeParameter.Value as TypeValue).Value);     
24      return (T)Activator.CreateInstance(type, null);
25    }
26
27    public static Permutation ConvertToPermutation(Parameter parameter) {
28      double[] input = (parameter.Value as DecimalVector).Value;
29      int[] arr = new int[input.Length];
30      for (int i = 0; i < input.Length; i++) {
31        arr[i] = Convert.ToInt32(input[i]);
32      }
33      var valueObj = new HeuristicLab.Encodings.PermutationEncoding.Permutation(Encodings.PermutationEncoding.PermutationTypes.RelativeUndirected, arr);
34      return valueObj;
35    }
36
37    public static DoubleMatrix ConvertToDoubleMatrix(Parameter parameter) {
38      var matrix = parameter.Value as DecimalMatrix;
39     
40      if (matrix.Value.Length == 0 || matrix.Value[0].Length == 0) {
41        return new DoubleMatrix(new double[0, 0]);
42      }
43
44      double[,] data = new double[matrix.Value.Length, matrix.Value[0].Length];
45      for (int i=0; i < matrix.Value.Length; i++) {
46        for (int j=0; j < matrix.Value[i].Length; j++) {
47          data[i,j] = matrix.Value[i][j];
48        }
49      }
50      return new DoubleMatrix(data);
51    }
52
53    public static HeuristicLab.Data.BoolValue ConvertToBoolValue(Parameter parameter) {
54      return new HeuristicLab.Data.BoolValue((parameter.Value as HeuristicLab.Services.Optimization.ControllerService.Model.BoolValue).Value);
55    }
56
57    public static IntValue ConvertToIntValue(Parameter parameter) {
58      return new IntValue((int)(parameter.Value as DecimalValue).Value);
59    }
60
61    public static PercentValue ConvertToPercentValue(Parameter parameter) {
62      return new PercentValue((parameter.Value as DecimalValue).Value / 100);
63    }
64
65    public static string GetStringValue(Parameter parameter) {
66      return (parameter.Value as HeuristicLab.Services.Optimization.ControllerService.Model.TypeValue).Value;
67    }
68
69    public static T FindInItemSet<T>(Core.IItemSet<T> items, Parameter what) where T : class,Core.INamedItem {
70      return items.FirstOrDefault((entry) => { return entry.Name == (what.Value as HeuristicLab.Services.Optimization.ControllerService.Model.TypeValue).Value; });
71    }
72
73    public static T FindOperator<T>(IProblem problem, Parameter what) where T : IOperator {
74      return problem.Operators.OfType<T>().FirstOrDefault((item) => { return item.ItemName == (what.Value as HeuristicLab.Services.Optimization.ControllerService.Model.TypeValue).Value; });
75    }
76  }
77}
Note: See TracBrowser for help on using the repository browser.