Changeset 12228 for branches/PTSP/HeuristicLab.Problems.PTSP/3.3/PTSP.cs
- Timestamp:
- 03/19/15 17:16:39 (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/PTSP/HeuristicLab.Problems.PTSP/3.3/PTSP.cs
r12219 r12228 40 40 public abstract class ProbabilisticTravelingSalesmanProblem : SingleObjectiveBasicProblem<PermutationEncoding>, IStorableContent, 41 41 IProblemInstanceConsumer<TSPData> { 42 private static readonly int DistanceMatrixSizeLimit = 1000; 43 42 44 #region Parameter Properties 43 45 public OptionalValueParameter<DoubleMatrix> CoordinatesParameter { … … 53 55 get { return (OptionalValueParameter<Permutation>)Parameters["BestKnownSolution"]; } 54 56 } 55 public OptionalValueParameter<ItemList<DoubleValue>> ProbabilityMatrixParameter {56 get { return ( OptionalValueParameter<ItemList<DoubleValue>>)Parameters["ProbabilityMatrix"]; }57 public ValueParameter<DoubleArray> ProbabilityMatrixParameter { 58 get { return (ValueParameter<DoubleArray>)Parameters["ProbabilityMatrix"]; } 57 59 } 58 60 public ValueParameter<IntValue> SampleSizeParameter { … … 79 81 set { BestKnownSolutionParameter.Value = value; } 80 82 } 81 public ItemList<DoubleValue>ProbabilityMatrix {83 public DoubleArray ProbabilityMatrix { 82 84 get { return ProbabilityMatrixParameter.Value; } 83 85 set { ProbabilityMatrixParameter.Value = value; } … … 105 107 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))); 106 108 Parameters.Add(new OptionalValueParameter<Permutation>("BestKnownSolution", "The best known solution of this TSP instance.")); 107 Parameters.Add(new OptionalValueParameter<ItemList<DoubleValue>>("ProbabilityMatrix", "The matrix which contains the probabilities of each of the cities.")); 109 Parameters.Add(new ValueParameter<DoubleArray>("ProbabilityMatrix", "The matrix which contains the probabilities of each of the cities.")); 110 111 Coordinates = new DoubleMatrix(new double[,] { 112 { 100, 100 }, { 100, 200 }, { 100, 300 }, { 100, 400 }, 113 { 200, 100 }, { 200, 200 }, { 200, 300 }, { 200, 400 }, 114 { 300, 100 }, { 300, 200 }, { 300, 300 }, { 300, 400 }, 115 { 400, 100 }, { 400, 200 }, { 400, 300 }, { 400, 400 } 116 }); 117 118 ProbabilityMatrix = new DoubleArray(new double[] {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}); 108 119 109 120 } 110 121 111 122 public virtual void Load(TSPData data) { 123 if (data.Coordinates == null && data.Distances == null) 124 throw new System.IO.InvalidDataException("The given instance specifies neither coordinates nor distances!"); 125 if (data.Dimension > DistanceMatrixSizeLimit && (data.DistanceMeasure == DistanceMeasure.Att 126 || data.DistanceMeasure == DistanceMeasure.Manhattan 127 || data.DistanceMeasure == DistanceMeasure.Maximum)) 128 throw new System.IO.InvalidDataException("The given instance uses an unsupported distance measure and is too large for using a distance matrix."); 129 if (data.Coordinates != null && data.Coordinates.GetLength(1) != 2) 130 throw new System.IO.InvalidDataException("The coordinates of the given instance are not in the right format, there need to be one row for each customer and two columns for the x and y coordinates."); 131 132 Name = data.Name; 133 Description = data.Description; 134 135 bool clearCoordinates = false, clearDistanceMatrix = false; 136 if (data.Coordinates != null && data.Coordinates.GetLength(0) > 0) 137 Coordinates = new DoubleMatrix(data.Coordinates); 138 else clearCoordinates = true; 139 140 // reset them after assigning the evaluator 141 if (clearCoordinates) Coordinates = null; 142 if (clearDistanceMatrix) DistanceMatrix = null; 143 112 144 DistanceMatrix = new DistanceMatrix(data.GetDistanceMatrix()); 113 145 // Get Probabilities of cities using random with seed from hash function on the Name of the instance 114 ProbabilityMatrix = new ItemList<DoubleValue>(data.Dimension);146 ProbabilityMatrix = new DoubleArray(data.Dimension); 115 147 Random r = new Random(data.Name.GetHashCode()); 116 148 for (int i = 0; i < data.Dimension; i++) { 117 ProbabilityMatrix .Add(new DoubleValue(r.NextDouble()));149 ProbabilityMatrix[i] = r.NextDouble(); 118 150 } 119 151 Encoding.Length = data.Dimension; 152 153 OnReset(); 120 154 } 121 155 }
Note: See TracChangeset
for help on using the changeset viewer.