Ejemplo n.º 1
0
 private PathPTSPTour(PathPTSPTour original, Cloner cloner)
     : base(original, cloner)
 {
     this.coordinates   = cloner.Clone(original.coordinates);
     this.probabilities = cloner.Clone(original.probabilities);
     this.permutation   = cloner.Clone(original.permutation);
     this.quality       = cloner.Clone(original.quality);
     Initialize();
 }
        public override IOperation Apply()
        {
            var coordinates      = CoordinatesParameter.ActualValue;
            var permutations     = PermutationParameter.ActualValue;
            var qualities        = QualityParameter.ActualValue;
            var probabilities    = ProbabilitiesParameter.ActualValue;
            var results          = ResultsParameter.ActualValue;
            var max              = MaximizationParameter.ActualValue.Value;
            var bestKnownQuality = BestKnownQualityParameter.ActualValue;

            var i = !max?qualities.Select((x, index) => new { index, x.Value }).OrderBy(x => x.Value).First().index
                    : qualities.Select((x, index) => new { index, x.Value }).OrderByDescending(x => x.Value).First().index;

            if (bestKnownQuality == null ||
                max && qualities[i].Value > bestKnownQuality.Value ||
                !max && qualities[i].Value < bestKnownQuality.Value)
            {
                BestKnownQualityParameter.ActualValue  = new DoubleValue(qualities[i].Value);
                BestKnownSolutionParameter.ActualValue = (Permutation)permutations[i].Clone();
            }

            var tour = BestSolutionParameter.ActualValue;

            if (tour == null)
            {
                tour = new PathPTSPTour(coordinates, probabilities, (Permutation)permutations[i].Clone(), new DoubleValue(qualities[i].Value));
                BestSolutionParameter.ActualValue = tour;
                results.Add(new Result("Best PTSP Solution", tour));
            }
            else
            {
                if (max && tour.Quality.Value < qualities[i].Value ||
                    !max && tour.Quality.Value > qualities[i].Value)
                {
                    tour.Coordinates   = coordinates;
                    tour.Permutation   = (Permutation)permutations[i].Clone();
                    tour.Quality.Value = qualities[i].Value;
                }
            }

            return(base.Apply());
        }
Ejemplo n.º 3
0
 private PathPTSPTour(PathPTSPTour original, Cloner cloner)
   : base(original, cloner) {
   this.coordinates = cloner.Clone(original.coordinates);
   this.probabilities = cloner.Clone(original.probabilities);
   this.permutation = cloner.Clone(original.permutation);
   this.quality = cloner.Clone(original.quality);
   Initialize();
 }
Ejemplo n.º 4
0
    public override IOperation Apply() {
      var coordinates = CoordinatesParameter.ActualValue;
      var permutations = PermutationParameter.ActualValue;
      var qualities = QualityParameter.ActualValue;
      var probabilities = ProbabilitiesParameter.ActualValue;
      var results = ResultsParameter.ActualValue;
      var max = MaximizationParameter.ActualValue.Value;
      var bestKnownQuality = BestKnownQualityParameter.ActualValue;

      var i = !max ? qualities.Select((x, index) => new { index, x.Value }).OrderBy(x => x.Value).First().index
                   : qualities.Select((x, index) => new { index, x.Value }).OrderByDescending(x => x.Value).First().index;

      if (bestKnownQuality == null ||
          max && qualities[i].Value > bestKnownQuality.Value ||
          !max && qualities[i].Value < bestKnownQuality.Value) {
        BestKnownQualityParameter.ActualValue = new DoubleValue(qualities[i].Value);
        BestKnownSolutionParameter.ActualValue = (Permutation)permutations[i].Clone();
      }

      var tour = BestSolutionParameter.ActualValue;
      if (tour == null) {
        tour = new PathPTSPTour(coordinates, probabilities, (Permutation)permutations[i].Clone(), new DoubleValue(qualities[i].Value));
        BestSolutionParameter.ActualValue = tour;
        results.Add(new Result("Best PTSP Solution", tour));
      } else {
        if (max && tour.Quality.Value < qualities[i].Value ||
          !max && tour.Quality.Value > qualities[i].Value) {
          tour.Coordinates = coordinates;
          tour.Permutation = (Permutation)permutations[i].Clone();
          tour.Quality.Value = qualities[i].Value;
        }
      }

      return base.Apply();
    }