- Timestamp:
- 01/15/13 15:50:53 (12 years ago)
- Location:
- branches/OaaS/HeuristicLab.Services.Optimization.Web/Mappings
- Files:
-
- 2 added
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/OaaS/HeuristicLab.Services.Optimization.Web/Mappings/scenario.xsd
r8817 r9166 8 8 <xsd:complexType name="scenarioType"> 9 9 <xsd:sequence maxOccurs="1"> 10 <xsd:element name="name" type="xsd:string"/> 11 <xsd:element name="problemParameters" type="paramsType"/> 12 <xsd:element name="algorithmParameters" type="paramsType"/> 13 </xsd:sequence> 14 <xsd:attribute name="problemType" use="required"/> 15 <xsd:attribute name="algorithmType" use="required"/> 16 <xsd:attribute name="mapper" use="required"/> 10 <xsd:element name="name" minOccurs="1" type="xsd:string"/> 11 <xsd:element name="algorithm" minOccurs="1" maxOccurs="unbounded" type="algorithmType"/> 12 </xsd:sequence> 17 13 </xsd:complexType> 14 15 <xsd:complexType name="algorithmType"> 16 <xsd:sequence maxOccurs="1"> 17 <xsd:element name="parameters" type="paramsType"/> 18 <xsd:element name="problem" minOccurs="0" type="problemType"/> 19 <xsd:element name="algorithm" minOccurs="0" maxOccurs="unbounded" type="algorithmType"/> 20 </xsd:sequence> 21 <xsd:attribute name="mapper" use="required"/> 22 </xsd:complexType> 23 24 <xsd:complexType name="problemType"> 25 <xsd:sequence maxOccurs="1"> 26 <xsd:element name="parameters" type="paramsType"/> 27 </xsd:sequence> 28 <xsd:attribute name="class"/> 29 </xsd:complexType> 18 30 19 31 <xsd:complexType name="paramsType"> 20 32 <xsd:sequence> 21 <xsd:element name="param" type="parameterType" minOccurs=" 1" maxOccurs="unbounded"/>33 <xsd:element name="param" type="parameterType" minOccurs="0" maxOccurs="unbounded"/> 22 34 </xsd:sequence> 23 35 </xsd:complexType> -
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 } -
branches/OaaS/HeuristicLab.Services.Optimization.Web/Mappings/tsp.xml
r8958 r9166 1 1 <?xml version='1.0'?> 2 <scenario problemType="HeuristicLab.Problems.TravelingSalesman.TravelingSalesman" 3 algorithmType="HeuristicLab.Algorithms.GeneticAlgorithm" 4 xmlns="urn:scenario-schema" 5 mapper="HeuristicLab.Controllers.HLMapper"> 2 <scenario xmlns="urn:scenario-schema"> 6 3 <name>Traveling Salesman Problem</name> 7 <problemParameters> 8 <param type="Decimal" name="BestKnownQuality" value="6110.0"/> 9 <param type="DecimalVector" name="BestKnownSolution"> 10 <value v1="0"/> 11 <value v1="40"/> 12 <value v1="38"/> 13 <value v1="60"/> 14 </param> 15 <param type="DecimalMatrix" name="Coordinates"> 16 <value v1="334.5909" v2="161.7809"/> 17 <value v1="503.5909" v2="172.7809"/> 18 <value v1="400.5909" v2="300.7809"/> 19 <value v1="700.5909" v2="700.7809"/> 20 </param> 21 <param type="Type" name="EvaluatorParameter"> 22 <choice name="HeuristicLab.Problems.TravelingSalesman.TSPRoundedEuclideanPathEvaluator" /> 23 <choice name="HeuristicLab.Problems.TravelingSalesman.TSPGeoPathEvaluator" selected="true"/> 24 <choice name="HeuristicLab.Problems.TravelingSalesman.TSPEuclideanPathEvaluator"/> 25 </param> 26 <param type="Boolean" name="UseDistanceMatrix" value="true"/> 27 </problemParameters> 28 <algorithmParameters> 29 <param type="Type" name="CrossoverParameter"> 30 <choice name="OrderCrossover2"/> 31 <choice name="CosaCrossover" selected="true"/> 32 </param> 33 <param type="Integer" name="Elites" value="1"/> 34 <param type="Integer" name="MaximumGenerations" value="1000"/> 35 <param type="Percent" name="MutationProbability" value="5"/> 36 <param type="Type" name="Mutator"> 37 <choice name="InversionManipulator" selected="true"/> 38 <choice name="ScrambleManipulator"/> 39 </param> 40 <param type="Integer" name="PopulationSize" value="100"/> 41 <param type="Integer" name="Seed" value="100"/> 42 <param type="Type" name="Selector"> 43 <choice name="ProportionalSelector" selected="true"/> 44 <choice name="BestSelector"/> 45 </param> 46 <param type="Boolean" name="SetSeedRandomly" value="true"/> 47 </algorithmParameters> 4 <algorithm mapper="HeuristicLab.Mappers.TSPScenarioMapper"> 5 <parameters> 6 <param type="Type" name="CrossoverParameter"> 7 <choice name="OrderCrossover2"/> 8 <choice name="CosaCrossover" selected="true"/> 9 </param> 10 <param type="Integer" name="Elites" value="1"/> 11 <param type="Integer" name="MaximumGenerations" value="1000"/> 12 <param type="Percent" name="MutationProbability" value="5"/> 13 <param type="Type" name="Mutator"> 14 <choice name="InversionManipulator" selected="true"/> 15 <choice name="ScrambleManipulator"/> 16 </param> 17 <param type="Integer" name="PopulationSize" value="100"/> 18 <param type="Integer" name="Seed" value="100"/> 19 <param type="Type" name="Selector"> 20 <choice name="ProportionalSelector" selected="true"/> 21 <choice name="BestSelector"/> 22 </param> 23 <param type="Boolean" name="SetSeedRandomly" value="true"/> 24 </parameters> 25 <problem> 26 <parameters> 27 <param type="Decimal" name="BestKnownQuality" value="6110.0"/> 28 <param type="DecimalVector" name="BestKnownSolution"> 29 <value v1="0"/> 30 <value v1="40"/> 31 <value v1="38"/> 32 <value v1="60"/> 33 </param> 34 <param type="DecimalMatrix" name="Coordinates"> 35 <value v1="334.5909" v2="161.7809"/> 36 <value v1="503.5909" v2="172.7809"/> 37 <value v1="400.5909" v2="300.7809"/> 38 <value v1="700.5909" v2="700.7809"/> 39 </param> 40 <param type="Type" name="EvaluatorParameter"> 41 <choice name="HeuristicLab.Problems.TravelingSalesman.TSPRoundedEuclideanPathEvaluator" /> 42 <choice name="HeuristicLab.Problems.TravelingSalesman.TSPGeoPathEvaluator" selected="true"/> 43 <choice name="HeuristicLab.Problems.TravelingSalesman.TSPEuclideanPathEvaluator"/> 44 </param> 45 <param type="Boolean" name="UseDistanceMatrix" value="true"/> 46 </parameters> 47 </problem> 48 </algorithm> 48 49 </scenario>
Note: See TracChangeset
for help on using the changeset viewer.