using System; using System.Collections.Generic; using System.Linq; using System.Text; using HeuristicLab.Services.Optimization.ControllerService.Interfaces; using Microsoft.WindowsAzure; using Microsoft.WindowsAzure.StorageClient; namespace HeuristicLab.Services.Optimization.ControllerService.Mockup { public static class AzureConstants { public static readonly string SCENARIO_TABLE = "Scenario"; public static readonly string SCENARIO_BLOB_CONTAINER = "scenario"; public static readonly string CLOUD_SETTINGS_KEY = "Cloudia.WindowsAzure.Storage"; } public class ScenarioDao : IScenarioDao { private static List scenarios; static ScenarioDao() { // TODO: Add tsp scenario to list scenarios = new List() { new ScenarioEntity("Benchmark Algorithm", "bmx", "bmm"), new ScenarioEntity("Traveling Salesman Problem", "scenario1", "mapper1") }; } public bool Add(ScenarioEntity entity) { var dbEntity = scenarios.Find(e => e.Scenario == entity.Scenario); if (dbEntity != null) return false; scenarios.Add(entity); return true; } public bool DeleteByName(string scenarioName) { return scenarios.RemoveAll(e => e.RowKey == scenarioName) == 1; } public ScenarioEntity FindByName(string scenarioName) { return scenarios.Find(e => e.RowKey == scenarioName); } public IEnumerable GetAllEntities() { return new List(scenarios); } } public class BlobDao : IBlobDao { private static List entries; static BlobDao() { entries = new List() { new StringEntry() { Key="bmm", Text=@" using System; using System.Collections.Generic; using System.Linq; using System.Text; using HeuristicLab.Data; using HeuristicLab.Services.Optimization.ControllerService.Model; using HeuristicLab.Optimization; using HeuristicLab.Services.Optimization.ControllerService; using HeuristicLab.Algorithms.Benchmarks; using HeuristicLab.Parameters; using HeuristicLab.PluginInfrastructure; namespace HeuristicLab.Mappers { public class BenchmarkScenarioMapper : IScenarioMapper { public void MapScenario(OptimizationScenario scenario, out IAlgorithm algorithm) { var alg = scenario.FirstAlgorithm; var bm = new BenchmarkAlgorithm(); var bmFullName = HLMapper.GetStringValue(alg.Parameters.FindByName(""Benchmark"")); bm.BenchmarkParameter.Value = bm.Benchmark = bm.BenchmarkParameter.ValidValues.First(b => b.GetType().FullName == bmFullName); ((ValueParameter)bm.Parameters[""ChunkSize""]).Value = HLMapper.ConvertToIntValue(alg.Parameters.FindByName(""ChunkSize"")); ((ValueParameter)bm.Parameters[""TimeLimit""]).Value = HLMapper.ConvertToDoubleValue(alg.Parameters.FindByName(""TimeLimit"")); algorithm = bm; } } } " }, new StringEntry() { Key="bmx", Text=@" Benchmark Algorithm " }, new StringEntry() { Key = "scenario1", Text = @" Traveling Salesman Problem " }, new StringEntry() { Key = "mapper1", Text = @"using System; using System.Collections.Generic; using System.Linq; using System.Text; using HeuristicLab.Data; using HeuristicLab.Services.Optimization.ControllerService.Model; using HeuristicLab.Optimization; using HeuristicLab.Services.Optimization.ControllerService; using HeuristicLab.Algorithms.GeneticAlgorithm; using HeuristicLab.Problems.TravelingSalesman; namespace HeuristicLab.Mappers { public class TSPScenarioMapper : IScenarioMapper { public void MapScenario(OptimizationScenario scenario, out IAlgorithm algorithm) { Console.WriteLine(""Mapping scenario!""); var ga = new GeneticAlgorithm(); var problem = new TravelingSalesmanProblem(); ga.Problem = problem; algorithm = ga; problem.BestKnownQuality = HLMapper.ConvertToDoubleValue(scenario.FirstAlgorithm.Problem.Parameters.FindByName(""BestKnownQuality"")); problem.BestKnownSolution = HLMapper.ConvertToPermutation(scenario.FirstAlgorithm.Problem.Parameters.FindByName(""BestKnownSolution"")); problem.Coordinates = HLMapper.ConvertToDoubleMatrix(scenario.FirstAlgorithm.Problem.Parameters.FindByName(""Coordinates"")); var evalParam = HLMapper.GetStringValue(scenario.FirstAlgorithm.Problem.Parameters.FindByName(""EvaluatorParameter"")); if (evalParam == ""HeuristicLab.Problems.TravelingSalesman.TSPRoundedEuclideanPathEvaluator"") { problem.EvaluatorParameter.Value = new TSPRoundedEuclideanPathEvaluator(); } else if (evalParam == ""HeuristicLab.Problems.TravelingSalesman.TSPGeoPathEvaluator"") { problem.EvaluatorParameter.Value = new TSPGeoPathEvaluator(); } else { problem.EvaluatorParameter.Value = new TSPEuclideanPathEvaluator(); } problem.UseDistanceMatrix = HLMapper.ConvertToBoolValue(scenario.FirstAlgorithm.Problem.Parameters.FindByName(""UseDistanceMatrix"")); Console.WriteLine(""Mapping algorithm...""); ga.Mutator = HLMapper.FindInItemSet(ga.MutatorParameter.ValidValues, scenario.FirstAlgorithm.Parameters.FindByName(""Mutator"")); ga.CrossoverParameter.Value = HLMapper.FindOperator(problem, scenario.FirstAlgorithm.Parameters.FindByName(""CrossoverParameter"")); ga.Elites = HLMapper.ConvertToIntValue(scenario.FirstAlgorithm.Parameters.FindByName(""Elites"")); ga.MaximumGenerations = HLMapper.ConvertToIntValue(scenario.FirstAlgorithm.Parameters.FindByName(""MaximumGenerations"")); ga.MutationProbability = HLMapper.ConvertToPercentValue(scenario.FirstAlgorithm.Parameters.FindByName(""MutationProbability"")); ga.PopulationSize = HLMapper.ConvertToIntValue(scenario.FirstAlgorithm.Parameters.FindByName(""PopulationSize"")); ga.Seed = HLMapper.ConvertToIntValue(scenario.FirstAlgorithm.Parameters.FindByName(""Seed"")); ga.Selector = HLMapper.FindInItemSet(ga.SelectorParameter.ValidValues, scenario.FirstAlgorithm.Parameters.FindByName(""Selector"")); ga.SetSeedRandomly = HLMapper.ConvertToBoolValue(scenario.FirstAlgorithm.Parameters.FindByName(""SetSeedRandomly"")); } } }" } }; } public bool Add(StringEntry entry) { entries.RemoveAll(e => e.Key == entry.Key); entries.Add(entry); return true; } public bool DeleteByKey(string entryKey) { return entries.RemoveAll(e => e.Key == entryKey) == 1; } public StringEntry FindByKey(string entryKey) { return entries.Find(e => e.Key == entryKey); } } public class MockupDataAccessLayer : IDataAccessLayer { private IScenarioDao scenarioDao; private IBlobDao blobDao; public IScenarioDao ScenarioDao { get { if (scenarioDao == null) { scenarioDao = new ScenarioDao(); } return scenarioDao; } } public IBlobDao BlobDao { get { if (blobDao == null) { blobDao = new BlobDao(); } return blobDao; } } private IExperimentDao experimentDao; public IExperimentDao ExperimentDao { get { return null; } } public IVisualExtensionDao VisualExtensionDao { get { throw new NotImplementedException(); } } public IJobDao JobDao { get { throw new NotImplementedException(); } } } }