protected override void Manipulate(IRandom random, PrinsEncoding individual) {
      List<Tour> tours = individual.GetTours();
      bool improvement = false;
      int iterations = 0;

      do {
        improvement = false;
        double originalQuality = GetQuality(individual);
        PrinsEncoding child = null;

        int samples = 0;
        while (!improvement &&
          samples < SampleSize.Value.Value) {
          int u = random.Next(ProblemInstance.Cities.Value);
          int v = random.Next(ProblemInstance.Cities.Value);

          child = Manipulate(individual,
                originalQuality, u, v);

          improvement = child != null;

          samples++;
        }

        if (improvement) {
          for (int i = 0; i < child.Length; i++) {
            individual[i] = child[i];
          }
        }

        iterations++;
      } while (improvement &&
        iterations < Iterations.Value.Value);
    }
Пример #2
0
    private Tour FindTour(PrinsEncoding individual, int city) {
      Tour found = null;

      List<Tour> tours = individual.GetTours();
      int i = 0;

      while (found == null && i < tours.Count) {
        if (tours[i].Stops.Contains(city))
          found = tours[i];

        i++;
      }

      return found;
    }
        protected override void Manipulate(IRandom random, PrinsEncoding individual)
        {
            List <Tour> tours       = individual.GetTours();
            bool        improvement = false;
            int         iterations  = 0;

            do
            {
                int u = depot;
                improvement = false;
                double        originalQuality = GetQuality(individual);
                PrinsEncoding child           = null;

                while (!improvement && u < ProblemInstance.Cities.Value)
                {
                    int v = depot;
                    while (!improvement && v < ProblemInstance.Cities.Value)
                    {
                        if (u != v)
                        {
                            child = Manipulate(individual,
                                               originalQuality, u, v);

                            improvement = child != null;
                        }
                        v++;
                    }
                    u++;
                }

                if (improvement)
                {
                    for (int i = 0; i < child.Length; i++)
                    {
                        individual[i] = child[i];
                    }
                }

                iterations++;
            } while (improvement &&
                     iterations < Iterations.Value.Value);
        }