private OrienteeringSolution(OrienteeringSolution original, Cloner cloner)
     : base(original, cloner)
 {
     this.integerVector = cloner.Clone(original.integerVector);
     this.coordinates   = cloner.Clone(original.coordinates);
     this.quality       = cloner.Clone(original.quality);
     this.penalty       = cloner.Clone(original.penalty);
     Initialize();
 }
        public override IOperation Apply()
        {
            var solutions        = IntegerVector.ActualValue;
            var qualities        = QualityParameter.ActualValue;
            var penalties        = PenaltyParameter.ActualValue;
            var results          = ResultsParameter.ActualValue;
            var bestKnownQuality = BestKnownQualityParameter.ActualValue;

            int bestIndex = qualities.Select((quality, index) => new { index, quality.Value }).OrderByDescending(x => x.Value).First().index;

            if (bestKnownQuality == null || qualities[bestIndex].Value > bestKnownQuality.Value)
            {
                BestKnownQualityParameter.ActualValue  = new DoubleValue(qualities[bestIndex].Value);
                BestKnownSolutionParameter.ActualValue = (IntegerVector)solutions[bestIndex].Clone();
            }

            var    solution           = BestSolutionParameter.ActualValue;
            var    coordinates        = CoordinatesParameter.ActualValue;
            var    startingPoint      = StartingPointParameter.ActualValue;
            var    terminalPoint      = TerminalPointParameter.ActualValue;
            var    scores             = ScoresParameter.ActualValue;
            var    pointVisitingCosts = PointVisitingCostsParameter.ActualValue;
            var    distances          = DistanceMatrixParameter.ActualValue;
            double distance           = distances.CalculateTourLength(solutions[bestIndex].ToList(), pointVisitingCosts.Value);

            if (solution == null)
            {
                solution = new OrienteeringSolution(
                    (IntegerVector)solutions[bestIndex].Clone(),
                    coordinates,
                    startingPoint,
                    terminalPoint,
                    scores,
                    new DoubleValue(qualities[bestIndex].Value),
                    new DoubleValue(penalties[bestIndex].Value),
                    new DoubleValue(distance));
                BestSolutionParameter.ActualValue = solution;
                results.Add(new Result("Best Orienteering Solution", solution));
            }
            else
            {
                if (solution.Quality.Value < qualities[bestIndex].Value)
                {
                    solution.Coordinates    = coordinates;
                    solution.Scores         = scores;
                    solution.IntegerVector  = (IntegerVector)solutions[bestIndex].Clone();
                    solution.Quality.Value  = qualities[bestIndex].Value;
                    solution.Penalty.Value  = penalties[bestIndex].Value;
                    solution.Distance.Value = distance;
                }
            }

            return(base.Apply());
        }
    public override IOperation Apply() {
      var solutions = IntegerVector.ActualValue;
      var qualities = QualityParameter.ActualValue;
      var penalties = PenaltyParameter.ActualValue;
      var results = ResultsParameter.ActualValue;
      var bestKnownQuality = BestKnownQualityParameter.ActualValue;

      int bestIndex = qualities.Select((quality, index) => new { index, quality.Value }).OrderByDescending(x => x.Value).First().index;

      if (bestKnownQuality == null || qualities[bestIndex].Value > bestKnownQuality.Value) {
        BestKnownQualityParameter.ActualValue = new DoubleValue(qualities[bestIndex].Value);
        BestKnownSolutionParameter.ActualValue = (IntegerVector)solutions[bestIndex].Clone();
      }

      var solution = BestSolutionParameter.ActualValue;
      var coordinates = CoordinatesParameter.ActualValue;
      var startingPoint = StartingPointParameter.ActualValue;
      var terminalPoint = TerminalPointParameter.ActualValue;
      var scores = ScoresParameter.ActualValue;
      var pointVisitingCosts = PointVisitingCostsParameter.ActualValue;
      var distances = DistanceMatrixParameter.ActualValue;
      double distance = distances.CalculateTourLength(solutions[bestIndex].ToList(), pointVisitingCosts.Value);

      if (solution == null) {
        solution = new OrienteeringSolution(
          (IntegerVector)solutions[bestIndex].Clone(),
          coordinates,
          startingPoint,
          terminalPoint,
          scores,
          new DoubleValue(qualities[bestIndex].Value),
          new DoubleValue(penalties[bestIndex].Value),
          new DoubleValue(distance));
        BestSolutionParameter.ActualValue = solution;
        results.Add(new Result("Best Orienteering Solution", solution));
      } else {
        if (solution.Quality.Value < qualities[bestIndex].Value) {
          solution.Coordinates = coordinates;
          solution.Scores = scores;
          solution.IntegerVector = (IntegerVector)solutions[bestIndex].Clone();
          solution.Quality.Value = qualities[bestIndex].Value;
          solution.Penalty.Value = penalties[bestIndex].Value;
          solution.Distance.Value = distance;
        }
      }

      return base.Apply();
    }
Exemplo n.º 4
0
 private OrienteeringSolution(OrienteeringSolution original, Cloner cloner)
   : base(original, cloner) {
   this.integerVector = cloner.Clone(original.integerVector);
   this.coordinates = cloner.Clone(original.coordinates);
   this.quality = cloner.Clone(original.quality);
   this.penalty = cloner.Clone(original.penalty);
   Initialize();
 }