Exemple #1
0
        /// <summary>
        /// Solves the problem.
        /// </summary>
        /// <returns></returns>
        protected override IRoute DoSolve(IProblem problem)
        {
            bool is_round;
            int  first;

            if (problem.First.HasValue)
            { // the first customer is set.
                // test if the last customer is the same.
                if (problem.Last == problem.First)
                { // the route is a round.
                    is_round = true;
                    first    = problem.First.Value;
                }
                else
                { // the route is not a round.
                    is_round = false;
                    first    = problem.First.Value;
                }
            }
            else
            { // the first and last customer can be choosen randomly.
                is_round = false;
                first    = -1;
            }

            // convert the problem to another problem with a virtual depot if needed.
            IProblem converted_problem;

            if (!is_round && first < 0)
            { // the end points can both vary.
                converted_problem = problem.AddVirtualDepot();
            }
            else
            { // the problem does not need to be converted.
                converted_problem = problem;
            }

            // do the RAI.
            IRoute route = RandomizedArbitraryInsertionSolver.DoSolve(this, converted_problem, _route);

            // convert the route again if needed.
            if (!is_round && first < 0)
            { // the end points could both vary so a virtual one was added. Remove it again here.
                List <int> route_list     = new List <int>(route);
                List <int> new_route_list = new List <int>();
                for (int idx = 0; idx < route_list.Count; idx++)
                { // remove customer zero.
                    if (route_list[idx] > 0)
                    {
                        new_route_list.Add(route_list[idx] - 1);
                    }
                }
                route = DynamicAsymmetricRoute.CreateFrom(new_route_list, false);
            }
            return(route);
        }
        /// <summary>
        /// Solves the problem.
        /// </summary>
        /// <returns></returns>
        protected override IRoute DoSolve(IProblem problem)
        {
            bool is_round;
            int first;
            if (problem.First.HasValue)
            { // the first customer is set.
                // test if the last customer is the same.
                if (problem.Last == problem.First)
                { // the route is a round.
                    is_round = true;
                    first = problem.First.Value;
                }
                else
                { // the route is not a round.
                    is_round = false;
                    first = problem.First.Value;
                }
            }
            else
            { // the first and last customer can be choosen randomly.
                is_round = false;
                first = -1;
            }

            // convert the problem to another problem with a virtual depot if needed.
            IProblem converted_problem;
            if (!is_round && first < 0)
            { // the end points can both vary.
                converted_problem = problem.AddVirtualDepot();
            }
            else
            { // the problem does not need to be converted.
                converted_problem = problem;
            }

            // do the RAI.
            IRoute route = RandomizedArbitraryInsertionSolver.DoSolve(this, converted_problem, _route);

            // convert the route again if needed.
            if (!is_round && first < 0)
            { // the end points could both vary so a virtual one was added. Remove it again here.
                List<int> route_list = new List<int>(route);
                List<int> new_route_list = new List<int>();
                for (int idx = 0; idx < route_list.Count; idx++)
                { // remove customer zero.
                    if (route_list[idx] > 0)
                    {
                        new_route_list.Add(route_list[idx] - 1);
                    }
                }
                route = DynamicAsymmetricRoute.CreateFrom(new_route_list, false);
            }
            return route;
        }