[8958] | 1 | using System;
|
---|
| 2 | using System.Collections.Generic;
|
---|
| 3 | using System.Linq;
|
---|
| 4 | using System.Text;
|
---|
| 5 | using HeuristicLab.Data;
|
---|
[9166] | 6 | using HeuristicLab.Services.Optimization.ControllerService.Model;
|
---|
[8958] | 7 | using HeuristicLab.Optimization;
|
---|
| 8 | using HeuristicLab.Services.Optimization.ControllerService;
|
---|
| 9 | using HeuristicLab.Algorithms.GeneticAlgorithm;
|
---|
| 10 | using HeuristicLab.Problems.TravelingSalesman;
|
---|
[9166] | 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"));
|
---|
[8958] | 44 | }
|
---|
| 45 | }
|
---|
| 46 | } |
---|