Changeset 4866
- Timestamp:
- 11/20/10 00:35:05 (14 years ago)
- Location:
- trunk/sources
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Problems.TravelingSalesman/3.3/Analyzers/TSPAlleleFrequencyAnalyzer.cs
r4849 r4866 39 39 get { return (LookupParameter<DoubleMatrix>)Parameters["Coordinates"]; } 40 40 } 41 public LookupParameter<DistanceMatrix> DistanceMatrixParameter { 42 get { return (LookupParameter<DistanceMatrix>)Parameters["DistanceMatrix"]; } 43 } 41 44 42 45 [StorableConstructor] … … 46 49 : base() { 47 50 Parameters.Add(new LookupParameter<DoubleMatrix>("Coordinates", "The x- and y-coordinates of the cities.")); 51 Parameters.Add(new LookupParameter<DistanceMatrix>("DistanceMatrix", "The matrix which contains the distances between the cities.")); 48 52 } 49 53 … … 55 59 Allele[] alleles = new Allele[solution.Length]; 56 60 DoubleMatrix coords = CoordinatesParameter.ActualValue; 61 DistanceMatrix dm = DistanceMatrixParameter.ActualValue; 62 int source, target, h; 63 double impact; 57 64 58 for (int i = 0; i < solution.Length - 1; i++) 59 alleles[i] = CreateAllele(solution[i], solution[i + 1], coords); 60 alleles[alleles.Length - 1] = CreateAllele(solution[solution.Length - 1], solution[0], coords); 65 for (int i = 0; i < solution.Length - 1; i++) { 66 source = solution[i]; 67 target = solution[i + 1]; 68 if (source > target) { h = source; source = target; target = h; } 69 impact = dm != null ? dm[source, target] : CalculateLength(coords[source, 0], coords[source, 1], coords[target, 0], coords[target, 1]); 70 alleles[i] = new Allele(source.ToString() + "-" + target.ToString(), impact); 71 } 72 source = solution[solution.Length - 1]; 73 target = solution[0]; 74 if (source > target) { h = source; source = target; target = h; } 75 impact = dm != null ? dm[source, target] : CalculateLength(coords[source, 0], coords[source, 1], coords[target, 0], coords[target, 1]); 76 alleles[alleles.Length - 1] = new Allele(source.ToString() + "-" + target.ToString(), impact); 61 77 62 78 return alleles; 63 }64 65 private Allele CreateAllele(int source, int target, DoubleMatrix coords) {66 if (source > target) {67 int h = source;68 source = target;69 target = h;70 }71 72 return new Allele(source.ToString() + "-" + target.ToString(),73 CalculateLength(coords[source, 0], coords[source, 1], coords[target, 0], coords[target, 1]));74 79 } 75 80 -
trunk/sources/HeuristicLab.Problems.TravelingSalesman/3.3/TravelingSalesmanProblem.cs
r4825 r4866 351 351 TSPAlleleFrequencyAnalyzer.MaximizationParameter.ActualName = MaximizationParameter.Name; 352 352 TSPAlleleFrequencyAnalyzer.CoordinatesParameter.ActualName = CoordinatesParameter.Name; 353 TSPAlleleFrequencyAnalyzer.DistanceMatrixParameter.ActualName = DistanceMatrixParameter.Name; 353 354 TSPAlleleFrequencyAnalyzer.SolutionParameter.ActualName = SolutionCreator.PermutationParameter.ActualName; 354 355 TSPAlleleFrequencyAnalyzer.QualityParameter.ActualName = Evaluator.QualityParameter.ActualName;
Note: See TracChangeset
for help on using the changeset viewer.