示例#1
0
        public int FindBestInsertionPlace(Tour tour, int city, int positionToAvoid = -1)
        {
            if (tour.Stops.Count == 0)
            {
                return(0);
            }

            int    place      = -1;
            double minQuality = -1;

            VRPEvaluation eval = ProblemInstance.EvaluateTour(tour, this);

            for (int i = 0; i <= tour.Stops.Count; i++)
            {
                if (positionToAvoid != i)
                {
                    bool   feasible;
                    double quality = ProblemInstance.GetInsertionCosts(eval, this, city, 0, i, out feasible);
                    if (place < 0 || quality < minQuality)
                    {
                        place      = i;
                        minQuality = quality;
                    }
                }
            }

            if (place == -1)
            {
                place = 0;
            }

            return(place);
        }
示例#2
0
        public bool FindInsertionPlace(int city, int routeToAvoid, bool allowInfeasible, out int route, out int place)
        {
            route = -1;
            place = -1;
            double minDetour = double.MaxValue;

            VRPEvaluation eval             = ProblemInstance.Evaluate(this);
            bool          originalFeasible = ProblemInstance.Feasible(eval);

            for (int tour = 0; tour < Tours.Count; tour++)
            {
                if (tour != routeToAvoid)
                {
                    double length = eval.Quality;

                    for (int i = 0; i <= Tours[tour].Stops.Count; i++)
                    {
                        bool   feasible;
                        double detour = ProblemInstance.GetInsertionCosts(eval, this, city, tour, i, out feasible);

                        if (feasible || allowInfeasible)
                        {
                            if (route < 0 || detour < minDetour)
                            {
                                route     = tour;
                                place     = i;
                                minDetour = detour;
                            }
                        }
                    }
                }
            }

            return(route >= 0 && place >= 0);
        }
        private bool FindRouteInsertionPlace(
            PotvinEncoding individual,
            Tour tour,
            int city, bool allowInfeasible, out int place)
        {
            place = -1;

            if (tour.Stops.Contains(city))
            {
                return(false);
            }

            if (tour.Stops.Count == 0)
            {
                place = 0;
                return(true);
            }

            double        minDetour        = 0;
            VRPEvaluation eval             = ProblemInstance.EvaluateTour(tour, individual);
            bool          originalFeasible = ProblemInstance.Feasible(eval);

            for (int i = 0; i <= tour.Stops.Count; i++)
            {
                bool   feasible;
                double detour = ProblemInstance.GetInsertionCosts(eval, individual, city, 0, i, out feasible);
                if (feasible || allowInfeasible)
                {
                    if (place < 0 || detour < minDetour)
                    {
                        place     = i;
                        minDetour = detour;
                    }
                }
            }

            return(place >= 0);
        }