[9166] | 1 | using System;
|
---|
| 2 | using System.Collections.Generic;
|
---|
| 3 | using System.Linq;
|
---|
| 4 | using System.Text;
|
---|
| 5 | using HeuristicLab.Services.Optimization.ControllerService.Interfaces;
|
---|
| 6 | using Microsoft.WindowsAzure;
|
---|
| 7 | using Microsoft.WindowsAzure.StorageClient;
|
---|
| 8 |
|
---|
| 9 | namespace HeuristicLab.Services.Optimization.ControllerService.Mockup {
|
---|
| 10 | public static class AzureConstants {
|
---|
| 11 | public static readonly string SCENARIO_TABLE = "Scenario";
|
---|
| 12 | public static readonly string SCENARIO_BLOB_CONTAINER = "scenario";
|
---|
| 13 | public static readonly string CLOUD_SETTINGS_KEY = "Cloudia.WindowsAzure.Storage";
|
---|
| 14 | }
|
---|
| 15 |
|
---|
| 16 | public class ScenarioDao : IScenarioDao {
|
---|
| 17 | private static List<ScenarioEntity> scenarios;
|
---|
| 18 |
|
---|
| 19 | static ScenarioDao() {
|
---|
| 20 | // TODO: Add tsp scenario to list
|
---|
| 21 | scenarios = new List<ScenarioEntity>() {
|
---|
| 22 | new ScenarioEntity("Benchmark Algorithm", "bmx", "bmm"),
|
---|
| 23 | new ScenarioEntity("Traveling Salesman Problem", "scenario1", "mapper1")
|
---|
| 24 | };
|
---|
| 25 | }
|
---|
| 26 |
|
---|
| 27 |
|
---|
| 28 | public bool Add(ScenarioEntity entity) {
|
---|
| 29 | var dbEntity = scenarios.Find(e => e.Scenario == entity.Scenario);
|
---|
| 30 |
|
---|
| 31 | if (dbEntity != null)
|
---|
| 32 | return false;
|
---|
| 33 |
|
---|
| 34 | scenarios.Add(entity);
|
---|
| 35 | return true;
|
---|
| 36 | }
|
---|
| 37 |
|
---|
| 38 | public bool DeleteByName(string scenarioName) {
|
---|
| 39 | return scenarios.RemoveAll(e => e.RowKey == scenarioName) == 1;
|
---|
| 40 | }
|
---|
| 41 |
|
---|
| 42 | public ScenarioEntity FindByName(string scenarioName) {
|
---|
| 43 | return scenarios.Find(e => e.RowKey == scenarioName);
|
---|
| 44 | }
|
---|
| 45 |
|
---|
| 46 |
|
---|
| 47 | public IEnumerable<ScenarioEntity> GetAllEntities() {
|
---|
| 48 | return new List<ScenarioEntity>(scenarios);
|
---|
| 49 | }
|
---|
| 50 | }
|
---|
| 51 |
|
---|
| 52 | public class BlobDao : IBlobDao {
|
---|
| 53 | private static List<StringEntry> entries;
|
---|
| 54 |
|
---|
| 55 | static BlobDao() {
|
---|
| 56 | entries = new List<StringEntry>() {
|
---|
| 57 | new StringEntry() {
|
---|
| 58 | Key="bmm",
|
---|
| 59 | Text=@"
|
---|
| 60 | using System;
|
---|
| 61 | using System.Collections.Generic;
|
---|
| 62 | using System.Linq;
|
---|
| 63 | using System.Text;
|
---|
| 64 | using HeuristicLab.Data;
|
---|
| 65 | using HeuristicLab.Services.Optimization.ControllerService.Model;
|
---|
| 66 | using HeuristicLab.Optimization;
|
---|
| 67 | using HeuristicLab.Services.Optimization.ControllerService;
|
---|
| 68 | using HeuristicLab.Algorithms.Benchmarks;
|
---|
| 69 | using HeuristicLab.Parameters;
|
---|
| 70 | using HeuristicLab.PluginInfrastructure;
|
---|
| 71 |
|
---|
| 72 |
|
---|
| 73 | namespace HeuristicLab.Mappers {
|
---|
| 74 | public class BenchmarkScenarioMapper : IScenarioMapper {
|
---|
| 75 | public void MapScenario(OptimizationScenario scenario, out IAlgorithm algorithm) {
|
---|
| 76 | var alg = scenario.FirstAlgorithm;
|
---|
| 77 | var bm = new BenchmarkAlgorithm();
|
---|
| 78 | var bmFullName = HLMapper.GetStringValue(alg.Parameters.FindByName(""Benchmark""));
|
---|
| 79 | bm.BenchmarkParameter.Value = bm.Benchmark = bm.BenchmarkParameter.ValidValues.First(b => b.GetType().FullName == bmFullName);
|
---|
| 80 | ((ValueParameter<IntValue>)bm.Parameters[""ChunkSize""]).Value = HLMapper.ConvertToIntValue(alg.Parameters.FindByName(""ChunkSize""));
|
---|
| 81 | ((ValueParameter<DoubleValue>)bm.Parameters[""TimeLimit""]).Value = HLMapper.ConvertToDoubleValue(alg.Parameters.FindByName(""TimeLimit""));
|
---|
| 82 |
|
---|
| 83 | algorithm = bm;
|
---|
| 84 | }
|
---|
| 85 | }
|
---|
| 86 | }
|
---|
| 87 | "
|
---|
| 88 | },
|
---|
| 89 | new StringEntry() {
|
---|
| 90 | Key="bmx",
|
---|
| 91 | Text=@"<?xml version='1.0'?>
|
---|
| 92 | <scenario xmlns=""urn:scenario-schema"">
|
---|
| 93 | <name>Benchmark Algorithm</name>
|
---|
| 94 | <algorithm mapper=""HeuristicLab.Mappers.BenchmarkScenarioMapper"">
|
---|
| 95 | <parameters>
|
---|
| 96 | <param type=""Type"" name=""Benchmark"">
|
---|
| 97 | <choice name=""HeuristicLab.Algorithms.Benchmarks.Dhrystone"" selected=""true"" />
|
---|
| 98 | <choice name=""HeuristicLab.Algorithms.Benchmarks.Linpack"" />
|
---|
| 99 | <choice name=""HeuristicLab.Algorithms.Benchmarks.Whetstone""/>
|
---|
| 100 | </param>
|
---|
| 101 | <param type=""Decimal"" name=""ChunkSize"" value=""0""/>
|
---|
| 102 | <param type=""Decimal"" name=""TimeLimit"" value=""0""/>
|
---|
| 103 | </parameters>
|
---|
| 104 | </algorithm>
|
---|
| 105 | </scenario>"
|
---|
| 106 | },
|
---|
| 107 | new StringEntry() {
|
---|
| 108 | Key = "scenario1",
|
---|
| 109 | Text = @"<?xml version='1.0'?>
|
---|
| 110 | <scenario xmlns=""urn:scenario-schema"">
|
---|
| 111 | <name>Traveling Salesman Problem</name>
|
---|
| 112 | <algorithm mapper=""HeuristicLab.Mappers.TSPScenarioMapper"">
|
---|
| 113 | <parameters>
|
---|
| 114 | <param type=""Type"" name=""CrossoverParameter"">
|
---|
| 115 | <choice name=""OrderCrossover2""/>
|
---|
| 116 | <choice name=""CosaCrossover"" selected=""true""/>
|
---|
| 117 | </param>
|
---|
| 118 | <param type=""Integer"" name=""Elites"" value=""1""/>
|
---|
| 119 | <param type=""Integer"" name=""MaximumGenerations"" value=""1000""/>
|
---|
| 120 | <param type=""Percent"" name=""MutationProbability"" value=""5""/>
|
---|
| 121 | <param type=""Type"" name=""Mutator"">
|
---|
| 122 | <choice name=""InversionManipulator"" selected=""true""/>
|
---|
| 123 | <choice name=""ScrambleManipulator""/>
|
---|
| 124 | </param>
|
---|
| 125 | <param type=""Integer"" name=""PopulationSize"" value=""100""/>
|
---|
| 126 | <param type=""Integer"" name=""Seed"" value=""100""/>
|
---|
| 127 | <param type=""Type"" name=""Selector"">
|
---|
| 128 | <choice name=""ProportionalSelector"" selected=""true""/>
|
---|
| 129 | <choice name=""BestSelector""/>
|
---|
| 130 | </param>
|
---|
| 131 | <param type=""Boolean"" name=""SetSeedRandomly"" value=""true""/>
|
---|
| 132 | </parameters>
|
---|
| 133 | <problem>
|
---|
| 134 | <parameters>
|
---|
| 135 | <param type=""Decimal"" name=""BestKnownQuality"" value=""6110.0""/>
|
---|
| 136 | <param type=""DecimalVector"" name=""BestKnownSolution"">
|
---|
| 137 | <value v1=""0""/>
|
---|
| 138 | <value v1=""40""/>
|
---|
| 139 | <value v1=""38""/>
|
---|
| 140 | <value v1=""60""/>
|
---|
| 141 | </param>
|
---|
| 142 | <param type=""DecimalMatrix"" name=""Coordinates"">
|
---|
| 143 | <value v1=""334.5909"" v2=""161.7809""/>
|
---|
| 144 | <value v1=""503.5909"" v2=""172.7809""/>
|
---|
| 145 | <value v1=""400.5909"" v2=""300.7809""/>
|
---|
| 146 | <value v1=""700.5909"" v2=""700.7809""/>
|
---|
| 147 | </param>
|
---|
| 148 | <param type=""Type"" name=""EvaluatorParameter"">
|
---|
| 149 | <choice name=""HeuristicLab.Problems.TravelingSalesman.TSPRoundedEuclideanPathEvaluator"" />
|
---|
| 150 | <choice name=""HeuristicLab.Problems.TravelingSalesman.TSPGeoPathEvaluator"" selected=""true""/>
|
---|
| 151 | <choice name=""HeuristicLab.Problems.TravelingSalesman.TSPEuclideanPathEvaluator""/>
|
---|
| 152 | </param>
|
---|
| 153 | <param type=""Boolean"" name=""UseDistanceMatrix"" value=""true""/>
|
---|
| 154 | </parameters>
|
---|
| 155 | </problem>
|
---|
| 156 | </algorithm>
|
---|
| 157 | </scenario>"
|
---|
| 158 | },
|
---|
| 159 | new StringEntry() {
|
---|
| 160 | Key = "mapper1",
|
---|
| 161 | Text = @"using System;
|
---|
| 162 | using System.Collections.Generic;
|
---|
| 163 | using System.Linq;
|
---|
| 164 | using System.Text;
|
---|
| 165 | using HeuristicLab.Data;
|
---|
| 166 | using HeuristicLab.Services.Optimization.ControllerService.Model;
|
---|
| 167 | using HeuristicLab.Optimization;
|
---|
| 168 | using HeuristicLab.Services.Optimization.ControllerService;
|
---|
| 169 | using HeuristicLab.Algorithms.GeneticAlgorithm;
|
---|
| 170 | using HeuristicLab.Problems.TravelingSalesman;
|
---|
| 171 | namespace HeuristicLab.Mappers {
|
---|
| 172 | public class TSPScenarioMapper : IScenarioMapper {
|
---|
| 173 | public void MapScenario(OptimizationScenario scenario, out IAlgorithm algorithm) {
|
---|
| 174 | Console.WriteLine(""Mapping scenario!"");
|
---|
| 175 | var ga = new GeneticAlgorithm();
|
---|
| 176 | var problem = new TravelingSalesmanProblem();
|
---|
| 177 | ga.Problem = problem;
|
---|
| 178 | algorithm = ga;
|
---|
| 179 |
|
---|
| 180 | problem.BestKnownQuality = HLMapper.ConvertToDoubleValue(scenario.FirstAlgorithm.Problem.Parameters.FindByName(""BestKnownQuality""));
|
---|
| 181 | problem.BestKnownSolution = HLMapper.ConvertToPermutation(scenario.FirstAlgorithm.Problem.Parameters.FindByName(""BestKnownSolution""));
|
---|
| 182 | problem.Coordinates = HLMapper.ConvertToDoubleMatrix(scenario.FirstAlgorithm.Problem.Parameters.FindByName(""Coordinates""));
|
---|
| 183 | var evalParam = HLMapper.GetStringValue(scenario.FirstAlgorithm.Problem.Parameters.FindByName(""EvaluatorParameter""));
|
---|
| 184 | if (evalParam == ""HeuristicLab.Problems.TravelingSalesman.TSPRoundedEuclideanPathEvaluator"") {
|
---|
| 185 | problem.EvaluatorParameter.Value = new TSPRoundedEuclideanPathEvaluator();
|
---|
| 186 | }
|
---|
| 187 | else if (evalParam == ""HeuristicLab.Problems.TravelingSalesman.TSPGeoPathEvaluator"") {
|
---|
| 188 | problem.EvaluatorParameter.Value = new TSPGeoPathEvaluator();
|
---|
| 189 | }
|
---|
| 190 | else {
|
---|
| 191 | problem.EvaluatorParameter.Value = new TSPEuclideanPathEvaluator();
|
---|
| 192 | }
|
---|
| 193 | problem.UseDistanceMatrix = HLMapper.ConvertToBoolValue(scenario.FirstAlgorithm.Problem.Parameters.FindByName(""UseDistanceMatrix""));
|
---|
| 194 | Console.WriteLine(""Mapping algorithm..."");
|
---|
| 195 | ga.Mutator = HLMapper.FindInItemSet<HeuristicLab.Optimization.IManipulator>(ga.MutatorParameter.ValidValues, scenario.FirstAlgorithm.Parameters.FindByName(""Mutator""));
|
---|
| 196 | ga.CrossoverParameter.Value = HLMapper.FindOperator<HeuristicLab.Optimization.ICrossover>(problem, scenario.FirstAlgorithm.Parameters.FindByName(""CrossoverParameter""));
|
---|
| 197 | ga.Elites = HLMapper.ConvertToIntValue(scenario.FirstAlgorithm.Parameters.FindByName(""Elites""));
|
---|
| 198 | ga.MaximumGenerations = HLMapper.ConvertToIntValue(scenario.FirstAlgorithm.Parameters.FindByName(""MaximumGenerations""));
|
---|
| 199 | ga.MutationProbability = HLMapper.ConvertToPercentValue(scenario.FirstAlgorithm.Parameters.FindByName(""MutationProbability""));
|
---|
| 200 | ga.PopulationSize = HLMapper.ConvertToIntValue(scenario.FirstAlgorithm.Parameters.FindByName(""PopulationSize""));
|
---|
| 201 | ga.Seed = HLMapper.ConvertToIntValue(scenario.FirstAlgorithm.Parameters.FindByName(""Seed""));
|
---|
| 202 | ga.Selector = HLMapper.FindInItemSet<HeuristicLab.Optimization.ISelector>(ga.SelectorParameter.ValidValues, scenario.FirstAlgorithm.Parameters.FindByName(""Selector""));
|
---|
| 203 | ga.SetSeedRandomly = HLMapper.ConvertToBoolValue(scenario.FirstAlgorithm.Parameters.FindByName(""SetSeedRandomly""));
|
---|
| 204 | }
|
---|
| 205 | }
|
---|
| 206 | }"
|
---|
| 207 | }
|
---|
| 208 | };
|
---|
| 209 | }
|
---|
| 210 |
|
---|
| 211 | public bool Add(StringEntry entry) {
|
---|
| 212 | entries.RemoveAll(e => e.Key == entry.Key);
|
---|
| 213 | entries.Add(entry);
|
---|
| 214 | return true;
|
---|
| 215 | }
|
---|
| 216 |
|
---|
| 217 | public bool DeleteByKey(string entryKey) {
|
---|
| 218 | return entries.RemoveAll(e => e.Key == entryKey) == 1;
|
---|
| 219 | }
|
---|
| 220 |
|
---|
| 221 | public StringEntry FindByKey(string entryKey) {
|
---|
| 222 | return entries.Find(e => e.Key == entryKey);
|
---|
| 223 | }
|
---|
| 224 | }
|
---|
| 225 |
|
---|
| 226 | public class MockupDataAccessLayer : IDataAccessLayer {
|
---|
| 227 | private IScenarioDao scenarioDao;
|
---|
| 228 | private IBlobDao blobDao;
|
---|
| 229 |
|
---|
| 230 | public IScenarioDao ScenarioDao {
|
---|
| 231 | get {
|
---|
| 232 | if (scenarioDao == null) {
|
---|
| 233 | scenarioDao = new ScenarioDao();
|
---|
| 234 | }
|
---|
| 235 | return scenarioDao;
|
---|
| 236 | }
|
---|
| 237 | }
|
---|
| 238 |
|
---|
| 239 | public IBlobDao BlobDao {
|
---|
| 240 | get {
|
---|
| 241 | if (blobDao == null) {
|
---|
| 242 | blobDao = new BlobDao();
|
---|
| 243 | }
|
---|
| 244 | return blobDao;
|
---|
| 245 | }
|
---|
| 246 | }
|
---|
| 247 |
|
---|
[9215] | 248 | private IExperimentDao experimentDao;
|
---|
| 249 |
|
---|
| 250 | public IExperimentDao ExperimentDao {
|
---|
| 251 | get {
|
---|
| 252 | return null;
|
---|
| 253 | }
|
---|
[9166] | 254 | }
|
---|
[9362] | 255 |
|
---|
| 256 |
|
---|
| 257 | public IVisualExtensionDao VisualExtensionDao {
|
---|
| 258 | get { throw new NotImplementedException(); }
|
---|
| 259 | }
|
---|
[9395] | 260 |
|
---|
| 261 |
|
---|
| 262 | public IJobDao JobDao {
|
---|
| 263 | get { throw new NotImplementedException(); }
|
---|
| 264 | }
|
---|
[9166] | 265 | }
|
---|
| 266 | }
|
---|