Пример #1
1
 private PathTSPTour(PathTSPTour original, Cloner cloner)
   : base(original, cloner) {
   this.coordinates = cloner.Clone(original.coordinates);
   this.permutation = cloner.Clone(original.permutation);
   this.quality = cloner.Clone(original.quality);
   Initialize();
 }
Пример #2
0
 private PathTSPTour(PathTSPTour original, Cloner cloner)
     : base(original, cloner)
 {
     this.coordinates = cloner.Clone(original.coordinates);
     this.permutation = cloner.Clone(original.permutation);
     this.quality     = cloner.Clone(original.quality);
     Initialize();
 }
        public override IOperation Apply()
        {
            DoubleMatrix            coordinates  = CoordinatesParameter.ActualValue;
            ItemArray <Permutation> permutations = PermutationParameter.ActualValue;
            ItemArray <DoubleValue> qualities    = QualityParameter.ActualValue;
            ResultCollection        results      = ResultsParameter.ActualValue;
            bool        max = MaximizationParameter.ActualValue.Value;
            DoubleValue bestKnownQuality = BestKnownQualityParameter.ActualValue;

            int i = -1;

            if (!max)
            {
                i = qualities.Select((x, index) => new { index, x.Value }).OrderBy(x => x.Value).First().index;
            }
            else
            {
                i = 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();
            }

            PathTSPTour tour = BestSolutionParameter.ActualValue;

            if (tour == null)
            {
                tour = new PathTSPTour(coordinates, (Permutation)permutations[i].Clone(), new DoubleValue(qualities[i].Value));
                BestSolutionParameter.ActualValue = tour;
                results.Add(new Result("Best TSP 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());
        }
    public override IOperation Apply() {
      DoubleMatrix coordinates = CoordinatesParameter.ActualValue;
      ItemArray<Permutation> permutations = PermutationParameter.ActualValue;
      ItemArray<DoubleValue> qualities = QualityParameter.ActualValue;
      ResultCollection results = ResultsParameter.ActualValue;
      bool max = MaximizationParameter.ActualValue.Value;
      DoubleValue bestKnownQuality = BestKnownQualityParameter.ActualValue;

      int i = -1;
      if (!max)
        i = qualities.Select((x, index) => new { index, x.Value }).OrderBy(x => x.Value).First().index;
      else i = 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();
      }

      PathTSPTour tour = BestSolutionParameter.ActualValue;
      if (tour == null) {
        tour = new PathTSPTour(coordinates, (Permutation)permutations[i].Clone(), new DoubleValue(qualities[i].Value));
        BestSolutionParameter.ActualValue = tour;
        results.Add(new Result("Best TSP 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();
    }