Exemplo n.º 1
0
        ///////////////////////////////////////////////////////////////////////////////////////////
        ///////////////////////////////////////////////////////////////////////////////////////////

        public AssignOrdersOperation(SolverContext context,
                                     Schedule schedule,
                                     AssignOrdersParams inputParams,
                                     SolveOptions options)
            : base(context, schedule, options)
        {
            Debug.Assert(inputParams != null);
            _inputParams = inputParams;
        }
 ///////////////////////////////////////////////////////////////////////////////////////////
 ///////////////////////////////////////////////////////////////////////////////////////////
 public SequenceRoutesOperation(SolverContext context,
     Schedule schedule,
     SequenceRoutesParams inputParams,
     SolveOptions options)
     : base(context, schedule, options)
 {
     Debug.Assert(inputParams != null);
     _inputParams = inputParams;
 }
Exemplo n.º 3
0
        ///////////////////////////////////////////////////////////////////////////////////////////
        ///////////////////////////////////////////////////////////////////////////////////////////

        public SequenceRoutesOperation(SolverContext context,
                                       Schedule schedule,
                                       SequenceRoutesParams inputParams,
                                       SolveOptions options)
            : base(context, schedule, options)
        {
            Debug.Assert(inputParams != null);
            _inputParams = inputParams;
        }
 ///////////////////////////////////////////////////////////////////////////////////////////
 ///////////////////////////////////////////////////////////////////////////////////////////
 public BuildRoutesOperation(SolverContext context,
     Schedule schedule,
     SolveOptions options,
     BuildRoutesParameters inputParams)
     : base(context, schedule, options)
 {
     Debug.Assert(inputParams != null);
     _inputParams = inputParams;
 }
Exemplo n.º 5
0
        ///////////////////////////////////////////////////////////////////////////////////////////
        ///////////////////////////////////////////////////////////////////////////////////////////

        public BuildRoutesOperation(SolverContext context,
                                    Schedule schedule,
                                    SolveOptions options,
                                    BuildRoutesParameters inputParams)
            : base(context, schedule, options)
        {
            Debug.Assert(inputParams != null);
            _inputParams = inputParams;
        }
Exemplo n.º 6
0
        /// <summary>
        /// Asynchronously builds routes for specified schedule.
        /// </summary>
        /// <param name="schedule">Schedule object.</param>
        /// <param name="options">Solve options.</param>
        /// <param name="inputParams">Input parameters for build route operation.</param>
        /// <returns>
        /// Operation id.
        /// </returns>
        public Guid BuildRoutesAsync(Schedule schedule,
                                     SolveOptions options,
                                     BuildRoutesParameters inputParams)
        {
            BuildRoutesOperation operation = new BuildRoutesOperation(_context,
                                                                      schedule,
                                                                      options,
                                                                      inputParams);

            return(_RunAsync(operation));
        }
Exemplo n.º 7
0
        public Guid UnassignOrdersAsync(Schedule schedule,
                                        ICollection <Order> ordersToUnassign,
                                        SolveOptions options)
        {
            UnassignOrdersOperation operation = new UnassignOrdersOperation(
                _context,
                schedule,
                new UnassignOrdersParams(ordersToUnassign),
                options);

            return(_RunAsync(operation));
        }
Exemplo n.º 8
0
        public Guid SequenceRoutesAsync(Schedule schedule,
                                        ICollection <Route> routesToSequence,
                                        SolveOptions options)
        {
            SequenceRoutesOperation operation = new SequenceRoutesOperation(
                _context,
                schedule,
                new SequenceRoutesParams(routesToSequence),
                options);

            return(_RunAsync(operation));
        }
 ///////////////////////////////////////////////////////////////////////////////////////////
 ///////////////////////////////////////////////////////////////////////////////////////////
 public AssignOrdersStep2(SolverContext context,
     Schedule schedule,
     SolveRequestData reqData,
     AssignOrdersParams inputParams,
     IList<RouteResult> prevRouteResults,
     IList<Violation> prevViolations,
     SolveOptions options)
     : base(context, schedule, options)
 {
     _reqData = reqData;
     _inputParams = inputParams;
     _prevRouteResults = prevRouteResults;
     _prevViolations = prevViolations;
 }
Exemplo n.º 10
0
        ///////////////////////////////////////////////////////////////////////////////////////////
        ///////////////////////////////////////////////////////////////////////////////////////////

        public AssignOrdersStep2(SolverContext context,
                                 Schedule schedule,
                                 SolveRequestData reqData,
                                 AssignOrdersParams inputParams,
                                 IList <RouteResult> prevRouteResults,
                                 IList <Violation> prevViolations,
                                 SolveOptions options)
            : base(context, schedule, options)
        {
            _reqData          = reqData;
            _inputParams      = inputParams;
            _prevRouteResults = prevRouteResults;
            _prevViolations   = prevViolations;
        }
 public BuildRoutesOperation(SolverContext context,
     Schedule schedule,
     SolveOptions options,
     SolveRequestData reqData,
     List<Violation> violations,
     BuildRoutesParameters inputParams)
     : base(context, schedule, options)
 {
     Debug.Assert(reqData != null);
     Debug.Assert(violations != null);
     Debug.Assert(inputParams != null);
     _reqData = reqData;
     _violations = violations;
     _inputParams = inputParams;
 }
Exemplo n.º 12
0
 public BuildRoutesOperation(SolverContext context,
                             Schedule schedule,
                             SolveOptions options,
                             SolveRequestData reqData,
                             List <Violation> violations,
                             BuildRoutesParameters inputParams)
     : base(context, schedule, options)
 {
     Debug.Assert(reqData != null);
     Debug.Assert(violations != null);
     Debug.Assert(inputParams != null);
     _reqData     = reqData;
     _violations  = violations;
     _inputParams = inputParams;
 }
Exemplo n.º 13
0
        public AssignOrdersOperation(SolverContext context,
                                     Schedule schedule,
                                     AssignOrdersParams inputParams,
                                     SolveOptions options,
                                     SolveRequestData reqData,
                                     AssignOrdersReqBuilder reqBuilder,
                                     List <Violation> violations)
            : base(context, schedule, options)
        {
            Debug.Assert(inputParams != null);
            Debug.Assert(reqData != null);
            Debug.Assert(reqBuilder != null);
            Debug.Assert(violations != null);

            _inputParams = inputParams;
            _reqData     = reqData;
            _reqBuilder  = reqBuilder;
            _violations  = violations;
        }
Exemplo n.º 14
0
        public Guid AssignOrdersAsync(Schedule schedule,
                                      ICollection <Order> ordersToAssign,
                                      ICollection <Route> targetRoutes,
                                      int?targetSequence,
                                      bool keepViolatedOrdersUnassigned,
                                      SolveOptions options)
        {
            AssignOrdersParams inputParams = new AssignOrdersParams(
                ordersToAssign,
                targetRoutes,
                targetSequence,
                keepViolatedOrdersUnassigned);

            AssignOrdersOperation operation = new AssignOrdersOperation(
                _context,
                schedule,
                inputParams,
                options);

            return(_RunAsync(operation));
        }
        ///////////////////////////////////////////////////////////////////////////////////////////
        ///////////////////////////////////////////////////////////////////////////////////////////
        /// <summary>
        /// Method collect information from solve request data for planned date and build request
        /// object.
        /// </summary>
        /// <param name="schedule">Current schedule.</param>
        /// <param name="reqData">Request data to get information.</param>
        /// <param name="options">Request options.</param>
        /// <param name="solveOptions">The reference to to the solve options object.</param>
        /// <returns>Request object with filled information for request.</returns>
        /// <exception cref="RouteException">If Fuel Economy in some of routes is 0.0,
        /// If unassigned order or location is not geocoded.</exception>
        public SubmitVrpJobRequest BuildRequest(Schedule schedule, SolveRequestData reqData,
            SolveRequestOptions options, SolveOptions solveOptions)
        {
            Debug.Assert(schedule != null);
            Debug.Assert(reqData != null);
            Debug.Assert(options != null);
            Debug.Assert(solveOptions != null);

            _plannedDate = (DateTime)schedule.PlannedDate;
            _orderRevenue = Math.Min(_CalcMaxRoutesCost(reqData.Routes),
                MAX_REVENUE);

            _BuildDepotsColl(reqData.Routes);

            SubmitVrpJobRequest req = new SubmitVrpJobRequest();

            // Get depots.
            req.Depots = _ConvertDepots();

            // Get orders.
            req.Orders = _ConvertOrders(reqData.Orders, reqData.Routes,
                options.ConvertUnassignedOrders);

            // Get order pairs.
            req.OrderPairs = _ConvertOrderPairs(reqData.Orders);

            // Get routes.
            req.Routes = _ConvertRoutes(reqData.Routes);

            // Get route zones.
            var zoneInfo = _ConvertZones(reqData.Routes);
            req.RouteZones = zoneInfo.Zones;
            req.SpatiallyClusterRoutes = zoneInfo.UseSpatialClustering;

            // Get renewals.
            req.Renewals = _ConvertRenewals(reqData.Routes);

            // Get breaks.
            req.Breaks = ConvertBreaks(reqData.Routes);

            // Get barriers of all types.
            var typedBarriers = reqData.Barriers.ToLookup(BarriersConverter.DetermineBarrierType);
            req.PointBarriers = _ConvertBarriers(typedBarriers, BarrierGeometryType.Point,
                _context.NetworkDescription.NetworkAttributes);
            req.PolygonBarriers = _ConvertBarriers(typedBarriers, BarrierGeometryType.Polygon,
                _context.NetworkDescription.NetworkAttributes);
            req.LineBarriers = _ConvertBarriers(typedBarriers, BarrierGeometryType.Polyline,
                _context.NetworkDescription.NetworkAttributes);

            // Get network attribute parameters.
            req.NetworkParams = _ConvertNetworkParams();

            // Get analysis region.
            req.AnalysisRegion = _context.RegionName;

            // Get restrictions.
            req.Restrictions = _FormatRestrictions();

            // Get u-turn policy.
            req.UTurnPolicy = _GetUTurnPolicy();

            req.Date = GPObjectHelper.DateTimeToGPDateTime(_plannedDate);
            req.UseHierarchyInAnalysis = true;
            req.PopulateRouteLines = false;
            req.EnvOutSR = solverSR.WKID;
            req.EnvProcessSR = solverSR.WKID;
            req.TWPreference = _context.SolverSettings.TWPreference;
            req.ExcludeRestrictedStreets = _context.SolverSettings.ExcludeRestrictedStreets;
            req.OutputFormat = NAOutputFormat.JSON;

            req.DirectionsLanguage = RequestBuildingHelper.GetDirectionsLanguage();
            req.PopulateDirections = options.PopulateRouteLines;
            req.SaveOutputLayer = _context.SolverSettings.SaveOutputLayer;

            req.ReturnM = true;

            return req;
        }
        /// <summary>
        /// Excecutes command.
        /// </summary>
        /// <param name="args"></param>
        protected override void _Execute(params object[] args)
        {
            try
            {
                OptimizeAndEditPage schedulePage = (OptimizeAndEditPage)App.Current.MainWindow.GetPage(PagePaths.SchedulePagePath);
                Schedule schedule = schedulePage.CurrentSchedule;

                // Get selected orders.
                Collection<Order> selectedOrders = _GetOrdersWhichCanBeMovedFromSelection(schedulePage.SelectedItems);
                selectedOrders = RoutingCmdHelpers.GetOrdersIncludingPairs(schedule, selectedOrders) as Collection<Order>;
                bool keepViolOrdrsUnassigned = false;

                Debug.Assert(args[0] != null);
                ICollection<Route> targetRoutes = args[0] as ICollection<Route>;
                Debug.Assert(targetRoutes != null);

                string routeName = args[1] as string;

                if (_CheckRoutingParams(schedule, targetRoutes, selectedOrders))
                {
                    SolveOptions options = new SolveOptions();
                    options.GenerateDirections = App.Current.MapDisplay.TrueRoute;
                    options.FailOnInvalidOrderGeoLocation = false;

                    _SetOperationStartedStatus((string)App.Current.FindResource(ASSIGN_ORDERS), (DateTime)schedule.PlannedDate);

                    // Start "Assign to best other route" operation.
                    OperationsIds.Add(App.Current.Solver.AssignOrdersAsync(schedule, selectedOrders,
                                                                           targetRoutes, null,
                                                                           keepViolOrdrsUnassigned,
                                                                           options));
                    // Set solve started message
                    string infoMessage = RoutingMessagesHelper.GetAssignOperationStartedMessage(selectedOrders, routeName);

                    if (!string.IsNullOrEmpty(infoMessage))
                        App.Current.Messenger.AddInfo(infoMessage);
                }
            }
            catch (RouteException e)
            {
                if (e.InvalidObjects != null) // If exception throw because any Routes or Orders are invalid
                    _ShowSolveValidationResult(e.InvalidObjects);
                else
                    _ShowErrorMsg(RoutingCmdHelpers.FormatRoutingExceptionMsg(e));
            }
            catch (Exception e)
            {
                Logger.Error(e);
                if ((e is LicenseException) || (e is AuthenticationException) || (e is CommunicationException))
                    CommonHelpers.AddRoutingErrorMessage(e);
                else
                    throw;
            }
        }
Exemplo n.º 17
0
        ///////////////////////////////////////////////////////////////////////////////////////////
        ///////////////////////////////////////////////////////////////////////////////////////////

        /// <summary>
        /// Create a new instance of the <c>VrpOperation</c> class.
        /// </summary>
        /// <param name="context">Solver context.</param>
        /// <param name="schedule">Current schedule.</param>
        /// <param name="options">Solve options.</param>
        public VrpOperation(SolverContext context, Schedule schedule, SolveOptions options)
        {
            _context  = context;
            _schedule = schedule;
            _options  = options;
        }
        /// <summary>
        /// Starts operation process.
        /// </summary>
        /// <param name="args">Operation args.</param>
        /// <exception cref="Exception">Throws if any unhandles exception occurs in method.</exception>
        protected override void _Execute(params object[] args)
        {
            try
            {
                // Get current schedule.
                if (_schedulePage == null)
                    _schedulePage = (OptimizeAndEditPage)App.Current.MainWindow.GetPage(PagePaths.SchedulePagePath);

                Schedule schedule = _schedulePage.CurrentSchedule;

                ICollection<Order> selectedOrders = _GetOrdersWhichCanBeUnassignedFromSelection(_schedulePage.SelectedItems);
                ICollection<Order> orders = RoutingCmdHelpers.GetOrdersIncludingPairs(schedule, selectedOrders);
                ICollection<Route> routes = ViolationsHelper.GetRouteForUnassignOrders(schedule, orders);

                if (_CheckRoutingParams(schedule, routes, orders))
                {
                    SolveOptions options = new SolveOptions();
                    options.GenerateDirections = App.Current.MapDisplay.TrueRoute;
                    options.FailOnInvalidOrderGeoLocation = false;

                    _SetOperationStartedStatus((string)App.Current.FindResource(UNASSIGN_ORDERS), (DateTime)schedule.PlannedDate);

                    OperationsIds.Add(App.Current.Solver.UnassignOrdersAsync(schedule, orders, options));

                    // set solve started message
                    string infoMessage = RoutingMessagesHelper.GetUnassignOperationStartedMessage(orders);

                    if (!string.IsNullOrEmpty(infoMessage))
                        App.Current.Messenger.AddInfo(infoMessage);
                }
            }
            catch (RouteException e)
            {
                if (e.InvalidObjects != null) // if exception throw because any Routes or Orders are invalid
                    _ShowSolveValidationResult(e.InvalidObjects);
                else
                    _ShowErrorMsg(RoutingCmdHelpers.FormatRoutingExceptionMsg(e));
            }
            catch (Exception e)
            {
                Logger.Error(e);
                if ((e is LicenseException) || (e is AuthenticationException) || (e is CommunicationException))
                    CommonHelpers.AddRoutingErrorMessage(e);
                else
                    throw;
            }
        }
        /// <summary>
        /// Method unassignes orders from schedule
        /// </summary>
        /// <param name="orders"></param>
        /// <param name="schedule"></param>
        private void _UnassignOrdersFromSchedule(Schedule schedule, ICollection<Order> orders)
        {
            try
            {
                ICollection<Order> ordersWithPairs = RoutingCmdHelpers.GetOrdersIncludingPairs(schedule, orders);

                // Create routes collection.
                ICollection<Route> routes = ViolationsHelper.GetRouteForUnassignOrders(schedule, ordersWithPairs);

                if (_CheckRoutingParams(schedule, ordersWithPairs, routes))
                {
                    SolveOptions options = new SolveOptions();
                    options.GenerateDirections = App.Current.MapDisplay.TrueRoute;
                    options.FailOnInvalidOrderGeoLocation = false;

                    string infoMessage = _FormatSuccessUnassigningStartedMessage(schedule, _schedulesToUnassign);

                    // Set operation info status.
                    _SetOperationStartedStatus(infoMessage, (DateTime)schedule.PlannedDate);

                    // Start solve operation.
                    App.Current.Solver.UnassignOrdersAsync(schedule, ordersWithPairs, options);
                }
                else // If routing operation was not started - clean collections and unlock UI.
                {
                    _CleanUp();
                    _UnlockUI();
                }
            }
            catch (RouteException e)
            {
                App.Current.Messenger.AddError(RoutingCmdHelpers.FormatRoutingExceptionMsg(e));
                App.Current.Messenger.AddError(string.Format(OperationIsFailedMessage, schedule));

                // Save already edited schedules.
                _UpdateOptimizeAndEditPageSchedules();
                _CleanUp();
                _UnlockUI();
            }
            catch (Exception ex)
            {
                // Save already edited schedules.
                _UpdateOptimizeAndEditPageSchedules();
                _CleanUp();
                _UnlockUI();

                if ((ex is LicenseException) || (ex is AuthenticationException) || (ex is CommunicationException))
                    CommonHelpers.AddRoutingErrorMessage(ex);
                else
                    throw;
            }
        }
Exemplo n.º 20
0
        /// <summary>
        /// Method starts moving orders.
        /// </summary>
        /// <param name="ordersToAssign">Collection of orders to move.</param>
        /// <param name="targetRoutes">Target routes.</param>
        /// <param name="sequence">Order sequence. Can be null.</param>
        private void _MoveOrders(Collection<Order> ordersToAssign, ICollection<Route> targetRoutes, int? sequence)
        {
            _RemoveRedundantOrders(ref ordersToAssign, targetRoutes, sequence);

            // if collection of dropping orders is empty - return
            if (ordersToAssign.Count == 0)
                return;

            // get current schedule
            OptimizeAndEditPage schedulePage = (OptimizeAndEditPage)(App.Current.MainWindow).GetPage(PagePaths.SchedulePagePath);
            Schedule schedule = schedulePage.CurrentSchedule;

            if (_CheckRoutingParams(schedule, targetRoutes, ordersToAssign))
            {
                SolveOptions options = new SolveOptions();
                options.GenerateDirections = App.Current.MapDisplay.TrueRoute;
                options.FailOnInvalidOrderGeoLocation = false;

                // Update status.
                _SetOperationStartedStatus((string)App.Current.FindResource("AssignOrders"), (DateTime)schedule.PlannedDate);

                // Start solve.
                OperationsIds.Add(App.Current.Solver.AssignOrdersAsync(schedule, ordersToAssign,
                                                                       targetRoutes, sequence,
                                                                       false, options));

                IEnumerator<Route> rtEnum = targetRoutes.GetEnumerator();
                rtEnum.MoveNext();

                // Set solve started message.
                string infoMessage = RoutingMessagesHelper.GetAssignOperationStartedMessage(
                    ordersToAssign, rtEnum.Current.Name);

                if (!string.IsNullOrEmpty(infoMessage))
                    App.Current.Messenger.AddInfo(infoMessage);
            }
        }
Exemplo n.º 21
0
        /// <summary>
        /// Method starts unassigning orders.
        /// </summary>
        /// <param name="ordersToAssign">Collection of orders to unassign.</param>
        private void _UnassignOrders(Collection<Order> ordersToUnassign)
        {
            // Get current schedule.
            OptimizeAndEditPage schedulePage = (OptimizeAndEditPage)(App.Current.MainWindow).GetPage(PagePaths.SchedulePagePath);
            Schedule schedule = schedulePage.CurrentSchedule;

            // Remove unassigned orders from collection of orders to unassign.
            _RemoveUnassignedOrders(ref ordersToUnassign, schedule);

            // If all orders in selection are unassigned - just return.
            if (ordersToUnassign.Count == 0)
                return;

            ICollection<Route> routes = ViolationsHelper.GetRouteForUnassignOrders(schedule, ordersToUnassign);

            if (_CheckRoutingParams(schedule, routes, ordersToUnassign))
            {
                SolveOptions options = new SolveOptions();
                options.GenerateDirections = App.Current.MapDisplay.TrueRoute;
                options.FailOnInvalidOrderGeoLocation = false;

                // Update status.
                _SetOperationStartedStatus((string)App.Current.FindResource(UNASSIGN_ORDERS), (DateTime)schedule.PlannedDate);

                // Start solve.
                OperationsIds.Add(App.Current.Solver.UnassignOrdersAsync(schedule, ordersToUnassign, options));

                // Set solve started message
                string infoMessage = RoutingMessagesHelper.GetUnassignOperationStartedMessage(ordersToUnassign);

                if (!string.IsNullOrEmpty(infoMessage))
                    App.Current.Messenger.AddInfo(infoMessage);
            }
        }