Free cookie consent management tool by TermsFeed Policy Generator

source: branches/1888_OaaS/HeuristicLab.Services.Optimization.Controller/General/AlgorithmHelper.cs @ 16811

Last change on this file since 16811 was 9227, checked in by fschoepp, 12 years ago

#1888:

  • Experiments will be saved as JSON elements within the blob store.
  • Added simple model and JSON converters.
  • Backend stores and runs experiments.
  • Updated interfaces to save/read experiments.
  • Added a binding to automatically map incoming JSON ajax requests to experiment models.
  • Added the javascript DatatypeMapper to map parameter inputs to the right html elements and vice versa.
  • Added smartwizard to generate Wizards for creating new experiments (New.cshtml).
File size: 2.2 KB
Line 
1using System;
2using System.Collections.Generic;
3using System.Linq;
4using System.Text;
5using HeuristicLab.Services.Optimization.ControllerService.Model;
6
7namespace HeuristicLab.Services.Optimization.ControllerService.General {
8  public class AlgorithmHelper {
9    public static bool HasToBeUpdated(Algorithm algo) {
10      if (algo.Parameters != null)
11        foreach (var param in algo.Parameters.Items) {
12          if (RequiresUpdate(param)) return true;
13        }
14
15      if (algo.Problem != null && algo.Problem.Parameters != null)
16        foreach (var param in algo.Problem.Parameters.Items) {
17          if (RequiresUpdate(param)) return true;
18        }
19
20      return false;
21    }
22
23    private static bool RequiresUpdate(Parameter param) {
24      switch (param.Type) {
25        case ParameterType.Type:
26          return ((TypeValue)param.Value).Options == null;
27        default:
28          return false;
29      }
30    }
31
32    public static void Update(Algorithm algo, OptimizationScenario scenario) {
33      if (algo.Parameters != null)
34        for (var i=0; i < algo.Parameters.Items.Count; i++) {
35          if (RequiresUpdate(algo.Parameters.Items[i])) {
36            var otherParam = (from p in scenario.FirstAlgorithm.Parameters.Items where p.Value.Name == algo.Parameters.Items[i].Value.Name select p).FirstOrDefault();
37            UpdateParameter(algo.Parameters.Items[i], otherParam);
38          }
39        }
40
41      if (algo.Problem != null && algo.Problem.Parameters != null)
42        for (var i = 0; i < algo.Problem.Parameters.Items.Count; i++) {
43          if (RequiresUpdate(algo.Problem.Parameters.Items[i])) {
44            var otherParam = (from p in scenario.FirstAlgorithm.Problem.Parameters.Items where p.Value.Name == algo.Problem.Parameters.Items[i].Value.Name select p).FirstOrDefault();
45            UpdateParameter(algo.Problem.Parameters.Items[i], otherParam);
46          }
47        }
48    }
49
50    private static void UpdateParameter(Parameter param, Parameter param2) {
51      switch (param.Type) {
52        case ParameterType.Type:
53          ((TypeValue)param.Value).Options = ((TypeValue)param2.Value).Options;
54          break;
55      }
56    }
57  }
58}
Note: See TracBrowser for help on using the repository browser.