示例#1
0
 private AttDistance(AttDistance original, Cloner cloner) : base(original, cloner)
 {
 }
示例#2
0
        public virtual void Load(PTSPData data)
        {
            try {
                SuppressEvents = true;
                if (data.Coordinates == null && data.Distances == null)
                {
                    throw new System.IO.InvalidDataException("The given instance specifies neither coordinates nor distances!");
                }
                if (data.Dimension > DistanceMatrixSizeLimit && (data.Coordinates == null || data.Coordinates.GetLength(0) != data.Dimension || data.Coordinates.GetLength(1) != 2))
                {
                    throw new System.IO.InvalidDataException("The given instance is too large for using a distance matrix and there is a problem with the coordinates.");
                }
                if (data.Coordinates != null && (data.Coordinates.GetLength(0) != data.Dimension || data.Coordinates.GetLength(1) != 2))
                {
                    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 respectively.");
                }

                switch (data.DistanceMeasure)
                {
                case DistanceMeasure.Direct:
                    DistanceCalculator = null;
                    if (data.Dimension > DistanceMatrixSizeLimit && Coordinates != null)
                    {
                        DistanceCalculator = new EuclideanDistance();
                        UseDistanceMatrix  = false;
                    }
                    else
                    {
                        UseDistanceMatrix = true;
                    }
                    break;

                case DistanceMeasure.Att: DistanceCalculator = new AttDistance(); break;

                case DistanceMeasure.Euclidean: DistanceCalculator = new EuclideanDistance(); break;

                case DistanceMeasure.Geo: DistanceCalculator = new GeoDistance(); break;

                case DistanceMeasure.Manhattan: DistanceCalculator = new ManhattanDistance(); break;

                case DistanceMeasure.Maximum: DistanceCalculator = new MaximumDistance(); break;

                case DistanceMeasure.RoundedEuclidean: DistanceCalculator = new RoundedEuclideanDistance(); break;

                case DistanceMeasure.UpperEuclidean: DistanceCalculator = new UpperEuclideanDistance(); break;

                default: throw new ArgumentException("Distance measure is unknown");
                }

                Name        = data.Name;
                Description = data.Description;

                Probabilities     = new DoubleArray(data.Probabilities);
                BestKnownSolution = data.BestKnownTour != null ? new Permutation(PermutationTypes.RelativeUndirected, data.BestKnownTour) : null;
                Coordinates       = data.Coordinates != null && data.Coordinates.GetLength(0) > 0 ? new DoubleMatrix(data.Coordinates) : null;
                DistanceMatrix    = data.Dimension <= DistanceMatrixSizeLimit && UseDistanceMatrix ? new DistanceMatrix(data.GetDistanceMatrix()) : null;

                Encoding.Length = data.Dimension;
            } finally { SuppressEvents = false; }
            OnReset();
        }
示例#3
0
 private AttDistance(AttDistance original, Cloner cloner) : base(original, cloner) { }