Beispiel #1
0
        /// <summary>
        /// Returns true if the point at the given original location index is in error.
        /// </summary>
        public static bool IsInError <T>(this IWeightMatrixAlgorithm <T> algorithm, int locationIdx)
        {
            LocationError    le;
            RouterPointError rpe;

            return(algorithm.TryGetError(locationIdx, out le, out rpe));
        }
Beispiel #2
0
 /// <summary>
 /// Creates a new TSP router.
 /// </summary>
 public TSPRouter(IWeightMatrixAlgorithm <float> weightMatrixAlgorithm, int first = 0, int?last = null,
                  SolverBase <float, TSProblem, TSPObjective, Itinero.Optimization.Tours.Tour, float> solver = null)
 {
     _first = first;
     _last  = last;
     _weightMatrixAlgorithm = weightMatrixAlgorithm;
     _solver = solver;
 }
Beispiel #3
0
 /// <summary>
 /// Creates a new TSP router.
 /// </summary>
 public STSPRouter(IWeightMatrixAlgorithm <float> weightMatrixAlgorithm, float max, int first = 0, int?last = null,
                   SolverBase <float, STSProblem, STSPObjective, Tour, STSPFitness> solver    = null)
 {
     _first = first;
     _last  = last;
     _max   = max;
     _weightMatrixAlgorithm = weightMatrixAlgorithm;
     _solver = solver;
 }
Beispiel #4
0
        /// <summary>
        /// Gets the orginal location index for the given corrected routerpoint index.
        /// </summary>
        public static int OriginalLocationIndex <T>(this IWeightMatrixAlgorithm <T> algorithm, int correctedIdx)
        {
            var resolvedIndex = algorithm.OriginalIndexOf(correctedIdx);

            if (resolvedIndex != -1)
            {
                return(algorithm.MassResolver.LocationIndexOf(resolvedIndex));
            }
            return(-1);
        }
Beispiel #5
0
        /// <summary>
        /// Gets the index in the weight matrix, given the orginal location index.
        /// </summary>
        public static int WeightIndex <T>(this IWeightMatrixAlgorithm <T> algorithm, int locationIdx)
        {
            var resolvedIndex = algorithm.MassResolver.ResolvedIndexOf(locationIdx);

            if (resolvedIndex != -1)
            {
                return(algorithm.CorrectedIndexOf(resolvedIndex));
            }
            return(-1);
        }
Beispiel #6
0
        /// <summary>
        /// Creates a new TSP router.
        /// </summary>
        public TSPTWRouter(IWeightMatrixAlgorithm <float> weightMatrixAlgorithm, TimeWindow[] windows, int first           = 0, int?last = null,
                           SolverBase <float, TSPTWProblem, TSPTWObjective, Itinero.Optimization.Tours.Tour, float> solver = null)
        {
            _weightMatrixAlgorithm = weightMatrixAlgorithm;
            _windows = windows;
            _first   = first;
            _last    = last;

            _weightMatrixAlgorithm = weightMatrixAlgorithm;
            _solver = solver;
        }
Beispiel #7
0
        /// <summary>
        /// Builds the routes in segments divided by routes between customers in the given tour.
        /// </summary>
        /// <returns></returns>
        public static List <Result <Route> > TryBuildRoutes <T>(this IWeightMatrixAlgorithm <T> algorithm, Tour tour)
        {
            var routes = new List <Result <Route> >();

            foreach (var pair in tour.Pairs())
            {
                routes.Add(algorithm.Router.TryCalculate(algorithm.Profile, algorithm.RouterPoints[pair.From],
                                                         algorithm.RouterPoints[pair.To]));
            }
            return(routes);
        }
Beispiel #8
0
        /// <summary>
        /// Tries to get an error for the given original location index.
        /// </summary>
        public static bool TryGetError <T>(this IWeightMatrixAlgorithm <T> algorithm, int locationIdx, out LocationError locationError,
                                           out RouterPointError routerPointError)
        {
            locationError    = null;
            routerPointError = null;
            if (algorithm.MassResolver.Errors.TryGetValue(locationIdx, out locationError))
            {
                return(true);
            }
            var resolvedIndex = algorithm.MassResolver.ResolvedIndexOf(locationIdx);

            if (algorithm.Errors.TryGetValue(resolvedIndex, out routerPointError))
            {
                return(true);
            }
            return(false);
        }
Beispiel #9
0
        /// <summary>
        /// Builds a route from a given tour.
        /// </summary>
        /// <returns></returns>
        public static Route BuildRoute <T>(this IWeightMatrixAlgorithm <T> algorithm, Tour tour)
        {
            Route route = null;

            foreach (var pair in tour.Pairs())
            {
                var localRoute = algorithm.Router.Calculate(algorithm.Profile, algorithm.RouterPoints[pair.From],
                                                            algorithm.RouterPoints[pair.To]);
                if (route == null)
                {
                    route = localRoute;
                }
                else
                {
                    route = route.Concatenate(localRoute);
                }
            }
            return(route);
        }
Beispiel #10
0
        /// <summary>
        /// Builds the result route in segments divided by routes between customers.
        /// </summary>
        /// <returns></returns>
        public static List <Route> BuildRoutes <T>(this IWeightMatrixAlgorithm <T> algorithm, Tour tour)
        {
            var routes = new List <Route>();

            foreach (var pair in tour.Pairs())
            {
                var from = algorithm.RouterPoints[pair.From];
                var to   = algorithm.RouterPoints[pair.To];

                var result = algorithm.Router.TryCalculate(algorithm.Profile, from, to);
                if (result.IsError)
                {
                    throw new Itinero.Exceptions.RouteNotFoundException(
                              string.Format("Part of the tour was not found: {0}[{1}] -> {2}[{3}] - {4}.",
                                            pair.From, from, pair.To, to, result.ErrorMessage));
                }
                routes.Add(result.Value);
            }
            return(routes);
        }