Changeset 11191
- Timestamp:
- 07/15/14 16:14:09 (10 years ago)
- Location:
- branches/HeuristicLab.Problems.Orienteering/HeuristicLab.Problems.Orienteering/3.3
- Files:
-
- 2 added
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/HeuristicLab.Problems.Orienteering/HeuristicLab.Problems.Orienteering/3.3/Evaluators/OrienteeringEvaluator.cs
r11187 r11191 34 34 } 35 35 public ILookupParameter<IntegerVector> SolutionParameter { 36 get { return (ILookupParameter<IntegerVector>)Parameters[" Solution"]; }36 get { return (ILookupParameter<IntegerVector>)Parameters["IntegerVector"]; } 37 37 } 38 38 public ILookupParameter<DoubleArray> ScoresParameter { … … 53 53 : base() { 54 54 Parameters.Add(new LookupParameter<DoubleValue>("Quality", "The evaluated quality of the Orienteering solution.")); 55 Parameters.Add(new LookupParameter<IntegerVector>(" Solution", "The Orienteering Solution given in path representation."));55 Parameters.Add(new LookupParameter<IntegerVector>("IntegerVector", "The Orienteering Solution given in path representation.")); 56 56 Parameters.Add(new LookupParameter<DoubleArray>("Scores", "The scores of the points.")); 57 57 } -
branches/HeuristicLab.Problems.Orienteering/HeuristicLab.Problems.Orienteering/3.3/HeuristicLab.Problems.Orienteering-3.3.csproj
r11190 r11191 47 47 <ItemGroup> 48 48 <Compile Include="Analyzers\BestOrienteeringSolutionAnalyser.cs" /> 49 <Compile Include="Creators\GreedyOrienteeringTourCreator.cs" /> 49 50 <Compile Include="DistanceMatrix.cs" /> 50 51 <Compile Include="Interfaces\IOrienteeringEvaluator.cs" /> -
branches/HeuristicLab.Problems.Orienteering/HeuristicLab.Problems.Orienteering/3.3/OrienteeringProblem.cs
r11190 r11191 22 22 using System; 23 23 using System.Linq; 24 using HeuristicLab.Analysis;25 24 using HeuristicLab.Common; 26 25 using HeuristicLab.Core; … … 30 29 using HeuristicLab.Parameters; 31 30 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 31 using HeuristicLab.PluginInfrastructure; 32 32 using HeuristicLab.Problems.Instances; 33 33 … … 47 47 get { return (OptionalValueParameter<DoubleMatrix>)Parameters["Coordinates"]; } 48 48 } 49 public OptionalValueParameter<DistanceMatrix> DistanceMatrixParameter { 50 get { return (OptionalValueParameter<DistanceMatrix>)Parameters["DistanceMatrix"]; } 51 } 52 public ValueParameter<BoolValue> UseDistanceMatrixParameter { 53 get { return (ValueParameter<BoolValue>)Parameters["UseDistanceMatrix"]; } 49 public ValueParameter<DistanceMatrix> DistanceMatrixParameter { 50 get { return (ValueParameter<DistanceMatrix>)Parameters["DistanceMatrix"]; } 54 51 } 55 52 … … 84 81 set { DistanceMatrixParameter.Value = value; } 85 82 } 86 public BoolValue UseDistanceMatrix {87 get { return UseDistanceMatrixParameter.Value; }88 set { UseDistanceMatrixParameter.Value = value; }89 }90 83 public IntValue StartingPoint { 91 84 get { return StartingPointParameter.Value; } … … 115 108 get { return Operators.OfType<BestOrienteeringSolutionAnalyser>().SingleOrDefault(); } 116 109 } 117 private SingleObjectivePopulationDiversityAnalyzer SingleObjectivePopulationDiversityAnalyzer {118 get { return Operators.OfType<SingleObjectivePopulationDiversityAnalyzer>().SingleOrDefault(); }119 }120 110 #endregion 121 111 … … 132 122 } 133 123 public OrienteeringProblem() 134 : base(new OrienteeringEvaluator(), new UniformRandomIntegerVectorCreator()) { // TODO: Greedy route creator for solution creator124 : base(new OrienteeringEvaluator(), new GreedyOrienteeringTourCreator()) { 135 125 Parameters.Add(new OptionalValueParameter<DoubleMatrix>("Coordinates", "The x- and y-Coordinates of the points.")); 136 Parameters.Add(new OptionalValueParameter<DistanceMatrix>("DistanceMatrix", "The matrix which contains the distances between the points.")); 137 Parameters.Add(new ValueParameter<BoolValue>("UseDistanceMatrix", "True if the coordinates based evaluators should calculate the distance matrix from the coordinates and use it for evaluation similar to the distance matrix evaluator, otherwise false.", new BoolValue(true))); 126 Parameters.Add(new ValueParameter<DistanceMatrix>("DistanceMatrix", "The matrix which contains the distances between the points.")); 138 127 Parameters.Add(new ValueParameter<IntValue>("StartingPoint", "Index of the starting point.", new IntValue(0))); 139 128 Parameters.Add(new ValueParameter<IntValue>("TerminusPoint", "Index of the ending point.", new IntValue(0))); … … 182 171 } 183 172 ParameterizeSolutionCreator(); 184 DistanceMatrix = null;173 CalculateDistanceMatrix(); 185 174 } 186 175 private void CoordinatesValue_ItemChanged(object sender, EventArgs<int, int> e) { 187 DistanceMatrix = null;176 CalculateDistanceMatrix(); 188 177 } 189 178 private void CoordinatesValue_Reset(object sender, EventArgs e) { 190 179 ParameterizeSolutionCreator(); 191 DistanceMatrix = null;180 CalculateDistanceMatrix(); 192 181 } 193 182 private void StartingPointParameter_ValueChanged(object sender, EventArgs e) { … … 245 234 246 235 private void ParameterizeSolutionCreator() { 247 if (SolutionCreator is UniformRandomIntegerVectorCreator) { 248 if (SolutionCreator.LengthParameter.Value == null || SolutionCreator.LengthParameter.Value.Value != Scores.Length) { 249 SolutionCreator.LengthParameter.Value = new IntValue(Scores.Length); 250 } 236 if (SolutionCreator is GreedyOrienteeringTourCreator) { 237 var creator = (GreedyOrienteeringTourCreator)SolutionCreator; 238 creator.DistanceMatrixParameter.ActualName = DistanceMatrixParameter.Name; 239 creator.ScoresParameter.ActualName = ScoresParameter.Name; 240 creator.MaximumDistanceParameter.ActualName = MaximumDistanceParameter.Name; 241 creator.StartingPointParameter.ActualName = StartingPointParameter.Name; 242 creator.TerminusPointParameter.ActualName = TerminusPointParameter.Name; 243 creator.FixedPenaltyParameter.ActualName = FixedPenaltyParameter.Name; 251 244 } 252 245 } … … 259 252 } 260 253 private void ParameterizeAnalyzer() { 261 // TODO 254 if (BestOrienteeringSolutionAnalyser != null) { 255 BestOrienteeringSolutionAnalyser.QualityParameter.ActualName = Evaluator.QualityParameter.ActualName; 256 257 BestOrienteeringSolutionAnalyser.IntegerVector.ActualName = SolutionCreator.IntegerVectorParameter.ActualName; 258 BestOrienteeringSolutionAnalyser.CoordinatesParameter.ActualName = CoordinatesParameter.Name; 259 BestOrienteeringSolutionAnalyser.ScoresParameter.ActualName = ScoresParameter.Name; 260 261 BestOrienteeringSolutionAnalyser.ResultsParameter.ActualName = "Results"; 262 BestOrienteeringSolutionAnalyser.BestKnownQualityParameter.ActualName = BestKnownQualityParameter.Name; 263 BestOrienteeringSolutionAnalyser.BestKnownSolutionParameter.ActualName = BestKnownSolutionParameter.Name; 264 } 262 265 } 263 266 private void InitializeOperators() { 264 // TODO 267 Operators.Add(new BestOrienteeringSolutionAnalyser()); 268 ParameterizeAnalyzer(); 269 270 var operators = ApplicationManager.Manager.GetInstances<IIntegerVectorOperator>(); 271 Operators.AddRange(operators); 272 ParameterizeOperators(); 265 273 } 266 274 private void ParameterizeOperators() { 267 // TODO 275 //foreach (var op in Operators.OfType<IIntegerVectorManipulator>()) 276 // op.IntegerVectorParameter.ActualName = SolutionCreator.IntegerVectorParameter.ActualName; 277 foreach (var op in Operators.OfType<IIntegerVectorMultiNeighborhoodShakingOperator>()) 278 op.IntegerVectorParameter.ActualName = SolutionCreator.IntegerVectorParameter.ActualName; 279 foreach (var op in Operators.OfType<ISingleObjectiveImprovementOperator>()) 280 op.SolutionParameter.ActualName = SolutionCreator.IntegerVectorParameter.ActualName; 268 281 } 269 282 #endregion 283 284 private void CalculateDistanceMatrix() { 285 var distances = new double[Coordinates.Rows, Coordinates.Rows]; 286 for (int i = 0; i < Coordinates.Rows; i++) { 287 for (int j = 0; j < Coordinates.Rows; j++) { 288 double distanceX = Math.Abs(Coordinates[i, 0] - Coordinates[j, 0]); 289 double distanceY = Math.Abs(Coordinates[i, 1] - Coordinates[j, 1]); 290 distances[i, j] = Math.Sqrt(Math.Pow(distanceX, 2) + Math.Pow(distanceY, 2)); 291 } 292 } 293 DistanceMatrix = new DistanceMatrix(distances); 294 } 270 295 271 296 private void InitializeInitialOrienteeringInstance() { … … 277 302 { 5.00, 5.60 } 278 303 }); 279 UseDistanceMatrix.Value = false;304 CalculateDistanceMatrix(); 280 305 281 306 StartingPoint.Value = 0; … … 296 321 297 322 Coordinates = data.Coordinates != null ? new DoubleMatrix(data.Coordinates) : null; 298 UseDistanceMatrix.Value = data.Distances != null;299 DistanceMatrix = data.Distances != null ? new DistanceMatrix(data.Distances) : null;323 if (Coordinates == null) 324 DistanceMatrix = new DistanceMatrix(data.Distances); 300 325 StartingPoint = new IntValue(0);// Depot is interpreted as start and endpoint (default) 301 326 TerminusPoint = new IntValue(0);
Note: See TracChangeset
for help on using the changeset viewer.