1 | using System;
|
---|
2 | using System.Collections.Generic;
|
---|
3 | using System.Linq;
|
---|
4 | using System.Text;
|
---|
5 | using System.ServiceModel;
|
---|
6 | using HeuristicLab.Services.Optimization.ControllerService.Interfaces;
|
---|
7 | using HeuristicLab.Services.Optimization.ControllerService.Model;
|
---|
8 |
|
---|
9 | namespace HeuristicLab.Services.Optimization.ControllerService {
|
---|
10 | [ServiceBehavior(InstanceContextMode = InstanceContextMode.PerCall, IgnoreExtensionDataObject = true)]
|
---|
11 | public class PlaceholderControllerService : IControllerService {
|
---|
12 |
|
---|
13 | private IList<Model.OptimizationScenario> scenarios;
|
---|
14 |
|
---|
15 | private ScenarioParser parser = new ScenarioParser();
|
---|
16 |
|
---|
17 | private IScenarioManager hiveManager;
|
---|
18 |
|
---|
19 | public PlaceholderControllerService() {
|
---|
20 | /*var tsp = new Model.OptimizationScenario() { Name = "Traveling Salesman Problem" };
|
---|
21 | hiveManager = new HiveScenarioManager();
|
---|
22 | tsp.InputParameters.Items.Add(new Model.Parameter() { Type = Model.ParameterType.Decimal, Value = new Model.DecimalValue() { Name = "BestKnownQuality", Value = 6110.0d } });
|
---|
23 | tsp.InputParameters.Items.Add(new Model.Parameter() { Type = Model.ParameterType.DecimalVector
|
---|
24 | ,Value =
|
---|
25 | new Model.DecimalVector() {
|
---|
26 | Name = "BestKnownSolution",
|
---|
27 | Value = new double[]{
|
---|
28 | 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
|
---|
29 | }}});
|
---|
30 | tsp.InputParameters.Items.Add(new Model.Parameter() {
|
---|
31 | Type = Model.ParameterType.DecimalMatrix,
|
---|
32 | Value =
|
---|
33 | new Model.DecimalMatrix() {
|
---|
34 | Name = "Coordinates",
|
---|
35 | Value = Utility.ToJagged(new double[,] { { 334.5909245845, 161.7809319139 }, { 334.5909245845, 161.7809319139 }, { 503.8741827107, 172.8741151168 } })
|
---|
36 | }
|
---|
37 | });
|
---|
38 | 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" } } });
|
---|
39 | //tsp.InputParameters.Add(new Model.Parameter() { Name = "SolutionCreator" });
|
---|
40 | tsp.InputParameters.Items.Add(new Model.Parameter() { Type = Model.ParameterType.Boolean, Value = new Model.BoolValue() { Name = "UseDistanceMatrix", Value = true } });
|
---|
41 |
|
---|
42 | tsp.AlgorithmParameters.Items.Add(new Model.Parameter() { Type = Model.ParameterType.Type, Value = new Model.TypeValue() { Name = "CrossoverParameter", Value = "OrderCrossover2", Options = new string[] { "OrderCrossover2", "CosaCrossover" } } });
|
---|
43 | tsp.AlgorithmParameters.Items.Add(new Model.Parameter() { Type = Model.ParameterType.Integer, Value = new Model.DecimalValue() { Name = "Elites", Value = 1 } });
|
---|
44 | tsp.AlgorithmParameters.Items.Add(new Model.Parameter() { Type = Model.ParameterType.Integer, Value = new Model.DecimalValue() { Name = "MaximumGenerations", Value = 1000 } });//, Value = 1000});
|
---|
45 | tsp.AlgorithmParameters.Items.Add(new Model.Parameter() { Type = Model.ParameterType.Percent, Value = new Model.DecimalValue() { Name = "MutationProbability", Value = 5 } });//, Value = 5});
|
---|
46 | tsp.AlgorithmParameters.Items.Add(new Model.Parameter() { Type = Model.ParameterType.Type, Value = new Model.TypeValue() { Name = "Mutator", Value = "InversionManipulator", Options = new string[] { "InversionManipulator", "ScrambleManipulator" } } });
|
---|
47 | tsp.AlgorithmParameters.Items.Add(new Model.Parameter() { Type = Model.ParameterType.Integer, Value = new Model.DecimalValue() { Name = "PopulationSize", Value = 100 } });//, Value = 100 });
|
---|
48 | tsp.AlgorithmParameters.Items.Add(new Model.Parameter() { Type = Model.ParameterType.Integer, Value = new Model.DecimalValue() { Name = "Seed", Value = 100 } });//, Value = 100 });
|
---|
49 | tsp.AlgorithmParameters.Items.Add(new Model.Parameter() { Type = Model.ParameterType.Type, Value = new Model.TypeValue() { Name = "Selector", Value = "ProportionalSelector", Options = new string[] { "ProportionalSelector", "BestSelector" } } });
|
---|
50 | tsp.AlgorithmParameters.Items.Add(new Model.Parameter() { Type = Model.ParameterType.Boolean, Value = new Model.BoolValue() { Name = "SetSeedRandomly", Value = true } });//, Value = true });
|
---|
51 | this.scenarios = new List<Model.OptimizationScenario>() { tsp };*/
|
---|
52 | //hiveManager.DispatchScenario(tsp);
|
---|
53 | //hiveManager = new MockupScenarioManager();
|
---|
54 | hiveManager = new HiveScenarioManager();
|
---|
55 | scenarios = parser.Scenarios;
|
---|
56 | //hiveManager.DispatchScenario(new User() { Username = "fschoeppl", Password = "fschoeppl" }, scenarios[0]);
|
---|
57 | }
|
---|
58 |
|
---|
59 | public IEnumerable<Model.OptimizationScenario> GetOptimizationScenarios() {
|
---|
60 | return scenarios;
|
---|
61 | }
|
---|
62 |
|
---|
63 |
|
---|
64 | public Model.OptimizationScenario GetOptimizationScenarioByName(string name) {
|
---|
65 | var scen = (from e in scenarios
|
---|
66 | where e.Id == name
|
---|
67 | select e).FirstOrDefault();
|
---|
68 | return scen;
|
---|
69 | }
|
---|
70 |
|
---|
71 | public void ScheduleOptimizationScenario(Model.User user, Model.OptimizationScenario scenario, JobExecutionDetails details) {
|
---|
72 | hiveManager.DispatchScenario(user, scenario, details);
|
---|
73 | }
|
---|
74 |
|
---|
75 | public IEnumerable<Model.Job> GetJobs(Model.User user) {
|
---|
76 | return hiveManager.GetJobs(user);
|
---|
77 | }
|
---|
78 |
|
---|
79 |
|
---|
80 | public Model.Job GetJob(Model.User user, string id) {
|
---|
81 | return hiveManager.GetJob(user, id);
|
---|
82 | }
|
---|
83 |
|
---|
84 |
|
---|
85 | public void DeleteJob(Model.User user, string id) {
|
---|
86 | hiveManager.DeleteJob(user, id);
|
---|
87 | }
|
---|
88 |
|
---|
89 |
|
---|
90 | public IList<Model.Run> GetJobResults(Model.User user, string id) {
|
---|
91 | return hiveManager.GetJobResults(user, id);
|
---|
92 | }
|
---|
93 |
|
---|
94 |
|
---|
95 | public bool AddHiveScenario(User user, string scenarioXml, string scenarioMapper) {
|
---|
96 | var scenario = parser.ParseScenarioFromXml(scenarioXml);
|
---|
97 | if (scenario == null) {
|
---|
98 | return false;
|
---|
99 | }
|
---|
100 | var added = hiveManager.AddScenario(user, scenario.Id, scenarioXml, scenarioMapper);
|
---|
101 | if (added)
|
---|
102 | scenarios.Add(scenario);
|
---|
103 | return added;
|
---|
104 | }
|
---|
105 |
|
---|
106 | public bool DeleteHiveScenario(User user, string scenarioName) {
|
---|
107 | var scen = GetOptimizationScenarioByName(scenarioName);
|
---|
108 | if (scen != null) {
|
---|
109 | scenarios.Remove(scen);
|
---|
110 | return hiveManager.DeleteScenario(user, scenarioName);
|
---|
111 | }
|
---|
112 | return false;
|
---|
113 | }
|
---|
114 |
|
---|
115 | public IEnumerable<string> GetOptimizationScenarioNames() {
|
---|
116 | return (from e in scenarios
|
---|
117 | select e.Id).AsEnumerable();
|
---|
118 | }
|
---|
119 | }
|
---|
120 | }
|
---|