- Timestamp:
- 01/15/13 15:50:53 (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/OaaS/HeuristicLab.Services.Optimization.Web/Mappings/tsp.cs
r8958 r9166 4 4 using System.Text; 5 5 using HeuristicLab.Data; 6 using HeuristicLab.Services.Optimization.ControllerService.Model; 6 using HeuristicLab.Services.Optimization.ControllerService.Model; 7 7 using HeuristicLab.Optimization; 8 8 using HeuristicLab.Services.Optimization.ControllerService; 9 9 using HeuristicLab.Algorithms.GeneticAlgorithm; 10 10 using HeuristicLab.Problems.TravelingSalesman; 11 public class TSPScenarioMapper : IScenarioMapper { 12 public void MapScenario(OptimizationScenario scenario, IAlgorithm algorithm) { 13 Console.WriteLine("Mapping scenario!"); 14 var ga = algorithm as GeneticAlgorithm; 15 var problem = algorithm.Problem as TravelingSalesmanProblem; 16 17 problem.BestKnownQuality = HLMapper.ConvertToDoubleValue(scenario.InputParameters.FindByName("BestKnownQuality")); 18 problem.BestKnownSolution = HLMapper.ConvertToPermutation(scenario.InputParameters.FindByName("BestKnownSolution")); 19 problem.Coordinates = HLMapper.ConvertToDoubleMatrix(scenario.InputParameters.FindByName("Coordinates")); 20 var evalParam = HLMapper.GetStringValue(scenario.InputParameters.FindByName("EvaluatorParameter")); 21 if (evalParam == "HeuristicLab.Problems.TravelingSalesman.TSPRoundedEuclideanPathEvaluator") { 22 problem.EvaluatorParameter.Value = new TSPRoundedEuclideanPathEvaluator(); 11 namespace HeuristicLab.Mappers { 12 public class TSPScenarioMapper : IScenarioMapper { 13 public void MapScenario(OptimizationScenario scenario, out IAlgorithm algorithm) { 14 Console.WriteLine("Mapping scenario!"); 15 var ga = new GeneticAlgorithm(); 16 var problem = new TravelingSalesmanProblem(); 17 ga.Problem = problem; 18 algorithm = ga; 19 20 problem.BestKnownQuality = HLMapper.ConvertToDoubleValue(scenario.FirstAlgorithm.Problem.Parameters.FindByName("BestKnownQuality")); 21 problem.BestKnownSolution = HLMapper.ConvertToPermutation(scenario.FirstAlgorithm.Problem.Parameters.FindByName("BestKnownSolution")); 22 problem.Coordinates = HLMapper.ConvertToDoubleMatrix(scenario.FirstAlgorithm.Problem.Parameters.FindByName("Coordinates")); 23 var evalParam = HLMapper.GetStringValue(scenario.FirstAlgorithm.Problem.Parameters.FindByName("EvaluatorParameter")); 24 if (evalParam == "HeuristicLab.Problems.TravelingSalesman.TSPRoundedEuclideanPathEvaluator") { 25 problem.EvaluatorParameter.Value = new TSPRoundedEuclideanPathEvaluator(); 26 } 27 else if (evalParam == "HeuristicLab.Problems.TravelingSalesman.TSPGeoPathEvaluator") { 28 problem.EvaluatorParameter.Value = new TSPGeoPathEvaluator(); 29 } 30 else { 31 problem.EvaluatorParameter.Value = new TSPEuclideanPathEvaluator(); 32 } 33 problem.UseDistanceMatrix = HLMapper.ConvertToBoolValue(scenario.FirstAlgorithm.Problem.Parameters.FindByName("UseDistanceMatrix")); 34 Console.WriteLine("Mapping algorithm..."); 35 ga.Mutator = HLMapper.FindInItemSet<HeuristicLab.Optimization.IManipulator>(ga.MutatorParameter.ValidValues, scenario.FirstAlgorithm.Parameters.FindByName("Mutator")); 36 ga.CrossoverParameter.Value = HLMapper.FindOperator<HeuristicLab.Optimization.ICrossover>(problem, scenario.FirstAlgorithm.Parameters.FindByName("CrossoverParameter")); 37 ga.Elites = HLMapper.ConvertToIntValue(scenario.FirstAlgorithm.Parameters.FindByName("Elites")); 38 ga.MaximumGenerations = HLMapper.ConvertToIntValue(scenario.FirstAlgorithm.Parameters.FindByName("MaximumGenerations")); 39 ga.MutationProbability = HLMapper.ConvertToPercentValue(scenario.FirstAlgorithm.Parameters.FindByName("MutationProbability")); 40 ga.PopulationSize = HLMapper.ConvertToIntValue(scenario.FirstAlgorithm.Parameters.FindByName("PopulationSize")); 41 ga.Seed = HLMapper.ConvertToIntValue(scenario.FirstAlgorithm.Parameters.FindByName("Seed")); 42 ga.Selector = HLMapper.FindInItemSet<HeuristicLab.Optimization.ISelector>(ga.SelectorParameter.ValidValues, scenario.FirstAlgorithm.Parameters.FindByName("Selector")); 43 ga.SetSeedRandomly = HLMapper.ConvertToBoolValue(scenario.FirstAlgorithm.Parameters.FindByName("SetSeedRandomly")); 23 44 } 24 else if (evalParam == "HeuristicLab.Problems.TravelingSalesman.TSPGeoPathEvaluator") {25 problem.EvaluatorParameter.Value = new TSPGeoPathEvaluator();26 }27 else {28 problem.EvaluatorParameter.Value = new TSPEuclideanPathEvaluator();29 }30 problem.UseDistanceMatrix = HLMapper.ConvertToBoolValue(scenario.InputParameters.FindByName("UseDistanceMatrix"));31 Console.WriteLine("Mapping algorithm...");32 ga.Mutator = HLMapper.FindInItemSet<HeuristicLab.Optimization.IManipulator>(ga.MutatorParameter.ValidValues, scenario.AlgorithmParameters.FindByName("Mutator"));33 ga.CrossoverParameter.Value = HLMapper.FindOperator<HeuristicLab.Optimization.ICrossover>(problem, scenario.AlgorithmParameters.FindByName("CrossoverParameter"));34 ga.Elites = HLMapper.ConvertToIntValue(scenario.AlgorithmParameters.FindByName("Elites"));35 ga.MaximumGenerations = HLMapper.ConvertToIntValue(scenario.AlgorithmParameters.FindByName("MaximumGenerations"));36 ga.MutationProbability = HLMapper.ConvertToPercentValue(scenario.AlgorithmParameters.FindByName("MutationProbability"));37 ga.PopulationSize = HLMapper.ConvertToIntValue(scenario.AlgorithmParameters.FindByName("PopulationSize"));38 ga.Seed = HLMapper.ConvertToIntValue(scenario.AlgorithmParameters.FindByName("Seed"));39 ga.Selector = HLMapper.FindInItemSet<HeuristicLab.Optimization.ISelector>(ga.SelectorParameter.ValidValues, scenario.AlgorithmParameters.FindByName("Selector"));40 ga.SetSeedRandomly = HLMapper.ConvertToBoolValue(scenario.AlgorithmParameters.FindByName("SetSeedRandomly"));41 45 } 42 46 }
Note: See TracChangeset
for help on using the changeset viewer.