コード例 #1
0
    protected override void Manipulate(IRandom random, GVREncoding individual) {
      int customer = random.Next(1, individual.Cities + 1);
      Tour tour;
      int position;
      individual.FindCustomer(customer, out tour, out position);

      tour.Stops.RemoveAt(position);

      //with a probability of 1/(2*V) create a new tour, else insert at another position
      if (individual.GetTours().Count > 0 &&
        individual.GetTours().Count < ProblemInstance.Vehicles.Value &&
        random.Next(individual.GetTours().Count * 2) == 0) {
        Tour newTour = new Tour();
        newTour.Stops.Add(customer);

        individual.Tours.Add(newTour);
      } else {
        Tour newTour = individual.Tours[random.Next(individual.Tours.Count)];
        int newPosition = random.Next(newTour.Stops.Count + 1);

        newTour.Stops.Insert(newPosition, customer);
      }

      if (tour.Stops.Count == 0)
        individual.Tours.Remove(tour);
    }
コード例 #2
0
    protected override void Manipulate(IRandom random, GVREncoding individual) {
      Tour tour = individual.Tours[random.Next(individual.Tours.Count)];
      int breakPoint1 = random.Next(tour.Stops.Count);
      int length = random.Next(1, tour.Stops.Count - breakPoint1 + 1);

      List<int> displaced = tour.Stops.GetRange(breakPoint1, length);
      tour.Stops.RemoveRange(breakPoint1, length);
      //with a probability of 1/(2*V) create a new tour, else insert at another position
      if (individual.GetTours().Count > 0 &&
        individual.GetTours().Count < ProblemInstance.Vehicles.Value &&
        random.Next(individual.GetTours().Count * 2) == 0) {
        Tour newTour = new Tour();
        newTour.Stops.InsertRange(0, displaced);

        individual.Tours.Add(newTour);
      } else {
        Tour newTour = individual.Tours[random.Next(individual.Tours.Count)];
        int newPosition = newTour.Stops.Count;

        newTour.Stops.InsertRange(newPosition, displaced);
      }

      if (tour.Stops.Count == 0)
        individual.Tours.Remove(tour);
    }
コード例 #3
0
        protected override void Manipulate(IRandom random, GVREncoding individual)
        {
            int  customer = random.Next(1, individual.Cities + 1);
            Tour tour;
            int  position;

            individual.FindCustomer(customer, out tour, out position);

            tour.Stops.RemoveAt(position);

            //with a probability of 1/(2*V) create a new tour, else insert at another position
            if (individual.GetTours().Count > 0 &&
                individual.GetTours().Count < ProblemInstance.Vehicles.Value &&
                random.Next(individual.GetTours().Count * 2) == 0)
            {
                Tour newTour = new Tour();
                newTour.Stops.Add(customer);

                individual.Tours.Add(newTour);
            }
            else
            {
                Tour newTour     = individual.Tours[random.Next(individual.Tours.Count)];
                int  newPosition = random.Next(newTour.Stops.Count + 1);

                newTour.Stops.Insert(newPosition, customer);
            }

            if (tour.Stops.Count == 0)
            {
                individual.Tours.Remove(tour);
            }
        }
コード例 #4
0
        protected override void Manipulate(IRandom random, GVREncoding individual)
        {
            Tour tour        = individual.Tours[random.Next(individual.Tours.Count)];
            int  breakPoint1 = random.Next(tour.Stops.Count);
            int  length      = random.Next(1, tour.Stops.Count - breakPoint1 + 1);

            List <int> displaced = tour.Stops.GetRange(breakPoint1, length);

            tour.Stops.RemoveRange(breakPoint1, length);
            //with a probability of 1/(2*V) create a new tour, else insert at another position
            if (individual.GetTours().Count > 0 &&
                individual.GetTours().Count < ProblemInstance.Vehicles.Value &&
                random.Next(individual.GetTours().Count * 2) == 0)
            {
                Tour newTour = new Tour();
                newTour.Stops.InsertRange(0, displaced);

                individual.Tours.Add(newTour);
            }
            else
            {
                Tour newTour     = individual.Tours[random.Next(individual.Tours.Count)];
                int  newPosition = newTour.Stops.Count;

                newTour.Stops.InsertRange(newPosition, displaced);
            }

            if (tour.Stops.Count == 0)
            {
                individual.Tours.Remove(tour);
            }
        }