Changeset 2865 for trunk/sources/HeuristicLab.Routing.TSP/3.3
- Timestamp:
- 02/25/10 06:35:43 (15 years ago)
- Location:
- trunk/sources/HeuristicLab.Routing.TSP/3.3
- Files:
-
- 2 added
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Routing.TSP/3.3/HeuristicLab.Routing.TSP-3.3.csproj
r2834 r2865 80 80 </Reference> 81 81 <Reference Include="System.Data" /> 82 <Reference Include="System.Drawing" /> 82 83 <Reference Include="System.Xml" /> 83 84 </ItemGroup> 84 85 <ItemGroup> 85 86 <None Include="HeuristicLabRoutingTSPPlugin.cs.frame" /> 87 <Compile Include="TSPEvaluator.cs" /> 88 <Compile Include="ITSPEvaluator.cs" /> 86 89 <Compile Include="TSPDistanceMatrixPathEvaluator.cs" /> 87 90 <Compile Include="TSPLIBParser.cs" /> … … 96 99 <Project>{958B43BC-CC5C-4FA2-8628-2B3B01D890B6}</Project> 97 100 <Name>HeuristicLab.Collections-3.3</Name> 101 </ProjectReference> 102 <ProjectReference Include="..\..\HeuristicLab.Common.Resources\3.2\HeuristicLab.Common.Resources-3.2.csproj"> 103 <Project>{0E27A536-1C4A-4624-A65E-DC4F4F23E3E1}</Project> 104 <Name>HeuristicLab.Common.Resources-3.2</Name> 98 105 </ProjectReference> 99 106 <ProjectReference Include="..\..\HeuristicLab.Core\3.3\HeuristicLab.Core-3.3.csproj"> -
trunk/sources/HeuristicLab.Routing.TSP/3.3/HeuristicLabRoutingTSPPlugin.cs.frame
r2834 r2865 29 29 [PluginFile("HeuristicLab.Routing.TSP-3.3.dll", PluginFileType.Assembly)] 30 30 [PluginDependency("HeuristicLab.Collections", "3.3")] 31 [PluginDependency("HeuristicLab.Common.Resources", "3.2")] 31 32 [PluginDependency("HeuristicLab.Core", "3.3")] 32 33 [PluginDependency("HeuristicLab.Data", "3.3")] -
trunk/sources/HeuristicLab.Routing.TSP/3.3/TSP.cs
r2857 r2865 20 20 #endregion 21 21 22 using System; 23 using System.Drawing; 24 using System.Linq; 22 25 using HeuristicLab.Core; 23 26 using HeuristicLab.Data; … … 26 29 using HeuristicLab.Permutation; 27 30 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 28 using System;31 using HeuristicLab.PluginInfrastructure; 29 32 30 33 namespace HeuristicLab.Routing.TSP { … … 32 35 [Creatable("Problems")] 33 36 [EmptyStorableClass] 34 public sealed class TSP : SingleObjectiveProblem {35 p rivate ValueParameter<DoubleMatrixData> CoordinatesParameter{36 get { return (ValueParameter<DoubleMatrixData>)Parameters["Coordinates"]; }37 public sealed class TSP : ParameterizedNamedItem, ISingleObjectiveProblem { 38 public override Image ItemImage { 39 get { return HeuristicLab.Common.Resources.VS2008ImageLibrary.Type; } 37 40 } 38 41 39 public DoubleMatrixData Coordinates { 40 get { return CoordinatesParameter.Value; } 41 set { CoordinatesParameter.Value = value; } 42 private IValueParameter<BoolData> MaximizationParameter { 43 get { return (IValueParameter<BoolData>)Parameters["Maximization"]; } 44 } 45 public IValueParameter<DoubleMatrixData> CoordinatesParameter { 46 get { return (IValueParameter<DoubleMatrixData>)Parameters["Coordinates"]; } 47 } 48 public IValueParameter<DoubleData> BestKnownQualityParameter { 49 get { return (IValueParameter<DoubleData>)Parameters["BestKnownQuality"]; } 50 } 51 public IValueParameter<IPermutationCreator> SolutionCreatorParameter { 52 get { return (IValueParameter<IPermutationCreator>)Parameters["SolutionCreator"]; } 53 } 54 public IValueParameter<ITSPEvaluator> EvaluatorParameter { 55 get { return (IValueParameter<ITSPEvaluator>)Parameters["Evaluator"]; } 56 } 57 58 public BoolData Maximization { 59 get { return MaximizationParameter.Value; } 60 } 61 public ISolutionCreator SolutionCreator { 62 get { return SolutionCreatorParameter.Value; } 63 } 64 public ISingleObjectiveEvaluator Evaluator { 65 get { return EvaluatorParameter.Value; } 66 } 67 IEvaluator IProblem.Evaluator { 68 get { return EvaluatorParameter.Value; } 69 } 70 private OperatorSet operators; 71 public OperatorSet Operators { 72 get { return operators; } 42 73 } 43 74 44 75 public TSP() 45 76 : base() { 46 Maximization = new BoolData(false); 77 ValueParameter<BoolData> maximizationParameter = new ValueParameter<BoolData>("Maximization", "Set to false as the Traveling Salesman Problem is a minimization problem.", new BoolData(false)); 78 maximizationParameter.ValueChanged += new EventHandler(MaximizationParameter_ValueChanged); 79 Parameters.Add(maximizationParameter); 80 47 81 Parameters.Add(new ValueParameter<DoubleMatrixData>("Coordinates", "The x- and y-Coordinates of the cities.", new DoubleMatrixData(0, 0))); 82 83 ValueParameter<IPermutationCreator> solutionCreatorParameter = new ValueParameter<IPermutationCreator>("SolutionCreator", "The operator which should be used to create new TSP solutions."); 84 solutionCreatorParameter.ValueChanged += new EventHandler(SolutionCreatorParameter_ValueChanged); 85 Parameters.Add(solutionCreatorParameter); 86 87 ValueParameter<ITSPEvaluator> evaluatorParameter = new ValueParameter<ITSPEvaluator>("Evaluator", "The operator which should be used to evaluate TSP solutions."); 88 evaluatorParameter.ValueChanged += new EventHandler(EvaluatorParameter_ValueChanged); 89 Parameters.Add(evaluatorParameter); 90 48 91 Parameters.Add(new ValueParameter<DoubleData>("BestKnownQuality", "The quality of the best known solution of this TSP instance.")); 92 49 93 RandomPermutationCreator creator = new RandomPermutationCreator(); 94 creator.PermutationParameter.ActualName = "TSPTour"; 50 95 creator.LengthParameter.Value = new IntData(0); 51 SolutionCreator = creator; 52 Evaluator = new TSPRoundedEuclideanPathEvaluator(); 96 SolutionCreatorParameter.Value = creator; 97 TSPRoundedEuclideanPathEvaluator evaluator = new TSPRoundedEuclideanPathEvaluator(); 98 evaluator.CoordinatesParameter.ActualName = CoordinatesParameter.Name; 99 evaluator.PermutationParameter.ActualName = creator.PermutationParameter.ActualName; 100 evaluator.QualityParameter.ActualName = "TSPTourLength"; 101 EvaluatorParameter.Value = evaluator; 102 103 operators = new OperatorSet(); 104 var crossovers = ApplicationManager.Manager.GetInstances<IPermutationCrossover>().ToList(); 105 crossovers.ForEach(x => { 106 x.ParentsParameter.ActualName = creator.PermutationParameter.ActualName; 107 x.ChildParameter.ActualName = creator.PermutationParameter.ActualName; 108 }); 109 var manipulators = ApplicationManager.Manager.GetInstances<IPermutationManipulator>().ToList(); 110 manipulators.ForEach(x => x.PermutationParameter.ActualName = creator.PermutationParameter.ActualName); 111 operators = new OperatorSet(crossovers.Cast<IOperator>().Concat(manipulators.Cast<IOperator>())); 53 112 } 54 113 … … 56 115 TSPLIBParser parser = new TSPLIBParser(filename); 57 116 parser.Parse(); 58 Coordinates = new DoubleMatrixData(parser.Vertices); 59 int cities = Coordinates.Rows; 60 RandomPermutationCreator creator = new RandomPermutationCreator(); 61 creator.LengthParameter.Value = new IntData(cities); 62 SolutionCreator = creator; 63 TSPRoundedEuclideanPathEvaluator evaluator = new TSPRoundedEuclideanPathEvaluator(); 64 Evaluator = evaluator; 117 CoordinatesParameter.Value = new DoubleMatrixData(parser.Vertices); 118 int cities = CoordinatesParameter.Value.Rows; 119 SolutionCreatorParameter.Value.LengthParameter.Value = new IntData(cities); 120 } 121 122 private void MaximizationParameter_ValueChanged(object sender, EventArgs e) { 123 OnMaximizationChanged(); 124 } 125 private void SolutionCreatorParameter_ValueChanged(object sender, EventArgs e) { 126 OnSolutionCreatorChanged(); 127 } 128 private void EvaluatorParameter_ValueChanged(object sender, EventArgs e) { 129 OnEvaluatorChanged(); 130 } 131 132 public event EventHandler MaximizationChanged; 133 private void OnMaximizationChanged() { 134 if (MaximizationChanged != null) 135 MaximizationChanged(this, EventArgs.Empty); 136 } 137 public event EventHandler SolutionCreatorChanged; 138 private void OnSolutionCreatorChanged() { 139 if (SolutionCreatorChanged != null) 140 SolutionCreatorChanged(this, EventArgs.Empty); 141 } 142 public event EventHandler EvaluatorChanged; 143 private void OnEvaluatorChanged() { 144 if (EvaluatorChanged != null) 145 EvaluatorChanged(this, EventArgs.Empty); 65 146 } 66 147 } -
trunk/sources/HeuristicLab.Routing.TSP/3.3/TSPDistanceMatrixPathEvaluator.cs
r2834 r2865 22 22 using HeuristicLab.Core; 23 23 using HeuristicLab.Data; 24 using HeuristicLab.Operators;25 24 using HeuristicLab.Parameters; 26 25 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; … … 33 32 [Creatable("Test")] 34 33 [EmptyStorableClass] 35 public sealed class TSPDistanceMatrixPathEvaluator : SingleSuccessorOperator {34 public sealed class TSPDistanceMatrixPathEvaluator : TSPEvaluator { 36 35 public LookupParameter<DoubleMatrixData> DistanceMatrixParameter { 37 36 get { return (LookupParameter<DoubleMatrixData>)Parameters["DistanceMatrix"]; } … … 40 39 get { return (LookupParameter<Permutation.Permutation>)Parameters["Permutation"]; } 41 40 } 42 public LookupParameter<DoubleData> QualityParameter {43 get { return (LookupParameter<DoubleData>)Parameters["Quality"]; }44 }45 41 46 42 public TSPDistanceMatrixPathEvaluator() … … 48 44 Parameters.Add(new LookupParameter<DoubleMatrixData>("DistanceMatrix", "The distance matrix of the cities.")); 49 45 Parameters.Add(new LookupParameter<Permutation.Permutation>("Permutation", "The TSP solution given in path representation which should be evaluated.")); 50 Parameters.Add(new LookupParameter<DoubleData>("Quality", "The evaluated quality of the given TSP solution."));51 46 } 52 47 -
trunk/sources/HeuristicLab.Routing.TSP/3.3/TSPPathEvaluator.cs
r2852 r2865 22 22 using HeuristicLab.Core; 23 23 using HeuristicLab.Data; 24 using HeuristicLab.Optimization;25 24 using HeuristicLab.Parameters; 26 25 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; … … 32 31 [Item("TSPPathEvaluator", "A base class for operators which evaluate TSP solutions given in path representation.")] 33 32 [EmptyStorableClass] 34 public abstract class TSPPathEvaluator : SingleObjectiveEvaluator {33 public abstract class TSPPathEvaluator : TSPEvaluator { 35 34 public LookupParameter<DoubleMatrixData> CoordinatesParameter { 36 35 get { return (LookupParameter<DoubleMatrixData>)Parameters["Coordinates"]; }
Note: See TracChangeset
for help on using the changeset viewer.