protected override double[] GetProbabilities(IDataDescriptor descriptor, PTSPData instance)
        {
            var ptspDesc = descriptor as TSPLIBHomogeneousPTSPDataDescriptor;

            return(ptspDesc != null?Enumerable.Range(0, instance.Dimension).Select(_ => ptspDesc.Probability).ToArray()
                       : Enumerable.Range(0, instance.Dimension).Select(_ => 0.5).ToArray());
        }
Exemplo n.º 2
0
        public override void Load(PTSPData data)
        {
            base.Load(data);
            UpdateRealizations();

            foreach (var op in Operators.OfType <IEstimatedPTSPOperator>())
            {
                op.RealizationsParameter.ActualName = RealizationsParameter.Name;
            }
        }
 protected override double[] GetProbabilities(IDataDescriptor descriptor, PTSPData instance) {
   var random = new MarsagliaRandom(GetInstanceHash(instance.Name));
   return Enumerable.Range(0, instance.Dimension).Select(_ => (int)Math.Round((0.1 + 0.9 * random.NextDouble()) * 100) / 100.0).ToArray();
 }
Exemplo n.º 4
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();
        }
        protected override double[] GetProbabilities(IDataDescriptor descriptor, PTSPData instance)
        {
            var random = new MarsagliaRandom(GetInstanceHash(instance.Name));

            return(Enumerable.Range(0, instance.Dimension).Select(_ => (int)Math.Round((0.1 + 0.9 * random.NextDouble()) * 100) / 100.0).ToArray());
        }
 protected override double[] GetProbabilities(IDataDescriptor descriptor, PTSPData instance) {
   var ptspDesc = descriptor as TSPLIBHomogeneousPTSPDataDescriptor;
   return ptspDesc != null ? Enumerable.Range(0, instance.Dimension).Select(_ => ptspDesc.Probability).ToArray()
                           : Enumerable.Range(0, instance.Dimension).Select(_ => 0.5).ToArray();
 }