source: branches/OaaS/HeuristicLab.Services.Optimization.Controller/PlaceholderControllerService.cs @ 9362

Last change on this file since 9362 was 9362, checked in by fschoepp, 6 years ago

#1888:

  • Added IVisualExtensionDao to the backend representing js extension that create new viewable elements of an algorithm.
  • Started to upgrade the frontend to render those new javascript UI extensions.
File size: 9.8 KB
Line 
1using System;
2using System.Collections.Generic;
3using System.Linq;
4using System.Text;
5using System.ServiceModel;
6using HeuristicLab.Services.Optimization.ControllerService.Interfaces;
7using HeuristicLab.Services.Optimization.ControllerService.Model;
8using HeuristicLab.Services.Optimization.ControllerService.General;
9
10namespace HeuristicLab.Services.Optimization.ControllerService {
11  [ServiceBehavior(InstanceContextMode = InstanceContextMode.PerCall, IgnoreExtensionDataObject = true)]
12  public class PlaceholderControllerService : IControllerService {
13   
14    private IList<Model.OptimizationScenario> scenarios;
15
16    private ScenarioParser parser = new ScenarioParser();
17
18    private IScenarioManager hiveManager;
19
20    public PlaceholderControllerService() {
21      /*var tsp = new Model.OptimizationScenario() { Name = "Traveling Salesman Problem" };
22      hiveManager = new HiveScenarioManager();
23      tsp.InputParameters.Items.Add(new Model.Parameter() { Type = Model.ParameterType.Decimal, Value = new Model.DecimalValue() { Name = "BestKnownQuality", Value = 6110.0d } });
24      tsp.InputParameters.Items.Add(new Model.Parameter() { Type = Model.ParameterType.DecimalVector
25      ,Value =
26        new Model.DecimalVector() {
27          Name = "BestKnownSolution",
28          Value = new double[]{
29            0,40,38//,116,111,114,27,61,104,127,15,44,4,10,75,108,60,128,123,63,68,85,87,25,6,96,69,106,126,103,42,33,16,30,26,18,99,14,28,23,115,94,78,86,11,80,102,76,93,88,109,97,67,62,47,24,112,31,35,83,118,110,122,100,81,56,8,55,64,51,74,73,98,72,91,37,105,52,119,57,48,71,90,5,101,9,13,66,12,95,121,54,59,50,41,43,92,36,21,46,39,22,32,20,125,120,77,65,84,124,89,58,29,82,2,113,107,7,17,45,79,117,19,3,34,53,1,49,129,70
30      }}});
31      tsp.InputParameters.Items.Add(new Model.Parameter() {       
32        Type = Model.ParameterType.DecimalMatrix,
33        Value =
34          new Model.DecimalMatrix() {
35            Name = "Coordinates",
36            Value = Utility.ToJagged(new double[,] { { 334.5909245845, 161.7809319139 }, { 334.5909245845, 161.7809319139 }, { 503.8741827107, 172.8741151168 } })
37          }
38      });
39      tsp.InputParameters.Items.Add(new Model.Parameter() { Type = Model.ParameterType.Type, Value = new Model.TypeValue() { Name = "EvaluatorParameter", Value = "HeuristicLab.Problems.TravelingSalesman.TSPRoundedEuclideanPathEvaluator", Options = new string[] { "HeuristicLab.Problems.TravelingSalesman.TSPRoundedEuclideanPathEvaluator", "HeuristicLab.Problems.TravelingSalesman.TSPGeoPathEvaluator", "HeuristicLab.Problems.TravelingSalesman.TSPEuclideanPathEvaluator" } } });
40      //tsp.InputParameters.Add(new Model.Parameter() { Name = "SolutionCreator" });
41      tsp.InputParameters.Items.Add(new Model.Parameter() { Type = Model.ParameterType.Boolean, Value = new Model.BoolValue() { Name = "UseDistanceMatrix", Value = true } });
42
43      tsp.AlgorithmParameters.Items.Add(new Model.Parameter() { Type = Model.ParameterType.Type, Value = new Model.TypeValue() { Name = "CrossoverParameter", Value = "OrderCrossover2", Options = new string[] { "OrderCrossover2", "CosaCrossover" } } });
44      tsp.AlgorithmParameters.Items.Add(new Model.Parameter() { Type = Model.ParameterType.Integer, Value = new Model.DecimalValue() { Name = "Elites", Value = 1 } });
45      tsp.AlgorithmParameters.Items.Add(new Model.Parameter() { Type = Model.ParameterType.Integer, Value = new Model.DecimalValue() { Name = "MaximumGenerations", Value = 1000 } });//, Value = 1000});
46      tsp.AlgorithmParameters.Items.Add(new Model.Parameter() { Type = Model.ParameterType.Percent, Value = new Model.DecimalValue() { Name = "MutationProbability", Value = 5 } });//, Value = 5});
47      tsp.AlgorithmParameters.Items.Add(new Model.Parameter() { Type = Model.ParameterType.Type, Value = new Model.TypeValue() { Name = "Mutator", Value = "InversionManipulator", Options = new string[] { "InversionManipulator", "ScrambleManipulator" } } });
48      tsp.AlgorithmParameters.Items.Add(new Model.Parameter() { Type = Model.ParameterType.Integer, Value = new Model.DecimalValue() { Name = "PopulationSize", Value = 100 } });//, Value = 100 });
49      tsp.AlgorithmParameters.Items.Add(new Model.Parameter() { Type = Model.ParameterType.Integer, Value = new Model.DecimalValue() { Name = "Seed", Value = 100 } });//, Value = 100 });
50      tsp.AlgorithmParameters.Items.Add(new Model.Parameter() { Type = Model.ParameterType.Type, Value = new Model.TypeValue() { Name = "Selector", Value = "ProportionalSelector", Options = new string[] { "ProportionalSelector", "BestSelector" } } });
51      tsp.AlgorithmParameters.Items.Add(new Model.Parameter() { Type = Model.ParameterType.Boolean, Value = new Model.BoolValue() { Name = "SetSeedRandomly", Value = true } });//, Value = true });
52      this.scenarios = new List<Model.OptimizationScenario>() { tsp };*/     
53      //hiveManager.DispatchScenario(tsp);
54      //hiveManager = new MockupScenarioManager();
55      hiveManager = new HiveScenarioManager();
56      scenarios = parser.Scenarios;
57      //hiveManager.DispatchScenario(new User() { Username = "fschoeppl", Password = "fschoeppl" }, scenarios[0]);
58    }
59
60    public IEnumerable<Model.OptimizationScenario> GetOptimizationScenarios() {
61      return scenarios; 
62    }
63
64
65    public Model.OptimizationScenario GetOptimizationScenarioByName(string name) {
66      var scen = (from e in scenarios
67                  where e.Id == name
68                  select e).FirstOrDefault();     
69      return scen;
70    }
71
72    public bool ScheduleOptimizationScenario(Model.User user, Model.OptimizationScenario scenario, JobExecutionDetails details) {
73      hiveManager.DispatchScenario(user, scenario, details);
74      return true;
75    }
76
77    public IEnumerable<Model.Job> GetJobs(Model.User user) {
78      return hiveManager.GetJobs(user);
79    }
80
81
82    public Model.Job GetJob(Model.User user, string id) {
83      return hiveManager.GetJob(user, id);
84    }
85
86
87    public bool DeleteJob(Model.User user, string id) {
88      return hiveManager.DeleteJob(user, id);
89    }
90
91
92    public IList<Model.Run> GetJobResults(Model.User user, string id) {
93      return hiveManager.GetJobResults(user, id);
94    }
95
96
97    public bool AddHiveScenario(User user, string scenarioXml, string scenarioMapper) {
98      var scenario = parser.ParseScenarioFromXml(scenarioXml);
99      if (scenario == null) {
100        return false;
101      }     
102      var added = hiveManager.AddScenario(user, scenario.Id, scenarioXml, scenarioMapper);
103      if (added) 
104        scenarios.Add(scenario);
105      return added;
106    }
107
108    public bool DeleteHiveScenario(User user, string scenarioName) {
109      var scen = GetOptimizationScenarioByName(scenarioName);
110      if (scen != null) {
111        scenarios.Remove(scen);
112        return hiveManager.DeleteScenario(user, scenarioName);
113      }
114      return false;
115    }
116
117    public IEnumerable<string> GetOptimizationScenarioNames() {
118      return (from e in scenarios
119              select e.Id).AsEnumerable();     
120    }
121
122
123    public string SaveExperiment(User user, Experiment experiment) {     
124      // make sure all algorithms store their choices aswell
125      var scenarioMap = new Dictionary<string, OptimizationScenario>();
126      var algos = new Stack<Algorithm>();
127      foreach (var algo in experiment.Algorithm) algos.Push(algo);
128     
129     
130
131      while (algos.Count > 0) {
132        var algo = algos.Pop();
133        if (algo.ChildAlgorithms != null)
134          foreach (var child in algo.ChildAlgorithms) algos.Push(child);
135
136        if (AlgorithmHelper.HasToBeUpdated(algo)) {
137          OptimizationScenario scenario;
138          if (!scenarioMap.TryGetValue(algo.Name, out scenario)) {
139            scenario = GetOptimizationScenarioByName(algo.Name);
140            scenarioMap[algo.Name] = scenario;
141          }
142         
143          AlgorithmHelper.Update(algo, scenario);
144        }
145      }
146
147      // finally store the experiment
148      var id = hiveManager.SaveExperiment(user, experiment);
149      // if it has been stored, and jobdetails are present, run the job!
150      if (id != null && experiment.JobDetails != null) {
151        ScheduleExperiment(user, experiment.Id, experiment.JobDetails);
152      }
153      return id;
154    }
155
156
157    public IEnumerable<string> GetExperimentNames(User user) {
158      return hiveManager.GetExperimentNames(user);
159    }
160
161
162    public bool DeleteExperiment(User user, string experiment) {
163      return hiveManager.DeleteExperiment(user, experiment);
164    }
165
166
167    public Job GetTasks(User u, string jobId) {
168      return hiveManager.GetTasks(u, jobId);
169    }
170
171    public Task GetTaskData(User u, string jobId, string taskId) {
172      return hiveManager.GetTaskData(u, jobId, taskId);
173    }
174
175
176    public Experiment GetExperimentByName(User user, string scenario) {
177      return hiveManager.GetExperimentByName(user, scenario);
178    }
179
180
181    public bool ScheduleExperiment(User user, string experimentId, JobExecutionDetails details) {
182      var exp = hiveManager.GetExperimentById(user, experimentId);
183      return hiveManager.DispatchExperiment(user, exp, details);
184    }
185
186
187    public IEnumerable<Experiment> GetExperiments(User user, bool namesOnly=false) {
188      return hiveManager.GetExperiments(user, namesOnly);
189    }
190
191    public Experiment GetExperimentById(User u, string nodeId) {
192      return hiveManager.GetExperimentById(u, nodeId);
193    }
194
195
196    public string GetVisualExtension(string algorithmId) {
197      return hiveManager.GetVisualExtension(algorithmId); 
198    }
199
200
201    public bool AddVisualExtension(string algorithmId, string script) {
202      return hiveManager.AddVisualExtension(algorithmId, script);
203    }
204
205    public bool DeleteVisualExtension(string algorithmId) {
206      return hiveManager.DeleteVisualExtension(algorithmId);
207    }
208  }
209}
Note: See TracBrowser for help on using the repository browser.