Пример #1
0
        /// <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;
                }
            }
        }
        /// <summary>
        /// Starts operation process.
        /// </summary>
        /// <param name="args">Command args. Empty there.</param>
        protected override void _Execute(params object[] args)
        {
            // Create command parameters.
            OptimizeAndEditPage schedulePage = (OptimizeAndEditPage)App.Current.MainWindow.GetPage(PagePaths.SchedulePagePath);
            Schedule schedule = schedulePage.CurrentSchedule;
            ICollection<Route> targetRoutes = ViolationsHelper.GetBuildRoutes(schedule);

            // And pass they to call _Execute from base class.
            base._Execute(targetRoutes, (string)App.Current.FindResource(BEST_ROUTE_OPTION_RESOURCE));
        }
Пример #4
0
        public static ICollection <Route> GetRoutingCommandRoutes(Schedule schedule, AsyncOperationInfo info)
        {
            ICollection <Route> routes = null;

            switch (info.OperationType)
            {
            case SolveOperationType.BuildRoutes:
                routes = GetBuildRoutes(schedule);
                break;

            case SolveOperationType.SequenceRoutes:
            {
                Debug.Assert(null != info.InputParams);
                SequenceRoutesParams param = info.InputParams as SequenceRoutesParams;
                routes = param.RoutesToSequence;
                break;
            }

            case SolveOperationType.UnassignOrders:
            {
                UnassignOrdersParams param = info.InputParams as UnassignOrdersParams;
                routes = ViolationsHelper.GetRouteForUnassignOrders(schedule, param.OrdersToUnassign);
                break;
            }

            case SolveOperationType.AssignOrders:
            {
                AssignOrdersParams param = info.InputParams as AssignOrdersParams;
                routes = param.TargetRoutes;
                break;
            }

            case SolveOperationType.GenerateDirections:
            {
                GenDirectionsParams param = info.InputParams as GenDirectionsParams;
                routes = param.Routes;
                break;
            }

            default:
                Debug.Assert(false);     // NOTE: not supported
                break;
            }

            return(routes);
        }
        /// <summary>
        /// Creates violation message for related object collection.
        /// </summary>
        /// <param name="obj">Violation's object (can be any DataObject: Vehicle, Driver and etc).</param>
        /// <param name="relatedObjects">Related object's.</param>
        /// <param name="resourceStringName">Description message format resource name.</param>
        /// <returns>Created message detail.</returns>
        private static MessageDetail _GetRouteViolationMessageStr(DataObject obj, ICollection <DataObject> relatedObjects,
                                                                  string resourceStringName)
        {
            Debug.Assert(obj is Route);

            int paramCount = 1 + relatedObjects.Count; // route + all objects

            DataObject[] param = new DataObject[paramCount];

            int    index        = 0;
            string substitution = "{" + index.ToString() + "}";

            param[index++] = obj;
            string relatedObjFormat = ViolationsHelper.GetObjectListFormat(relatedObjects, ref index, param);
            string format           = App.Current.GetString(resourceStringName, substitution, relatedObjFormat);

            return(new MessageDetail(MessageType.Error, format, param));
        }
        /// <summary>
        /// Creates violation message for related object collection.
        /// </summary>
        /// <param name="obj">Violation's object (can be any DataObject: Vehicle, Driver and etc).</param>
        /// <param name="inputCollectionCount">Collection's object count.</param>
        /// <param name="violatedObjCollection">Violated object collection.</param>
        /// <param name="formatSingle">Description message format for single object.</param>
        /// <param name="formatList">Description message format for object's name list.</param>
        /// <param name="formatAll">Description message format for all object's.</param>
        /// <returns>Created message detail.</returns>
        private static MessageDetail _GetViolationMessageStr <T>(DataObject obj, int inputCollectionCount,
                                                                 ICollection <T> violatedObjCollection,
                                                                 string formatSingle, string formatList,
                                                                 string formatAll)
            where T : DataObject
        {
            bool checkOneRoute = (1 == violatedObjCollection.Count);
            bool checkNotAll   = checkOneRoute ? false : (violatedObjCollection.Count < inputCollectionCount);

            int paramCount = 1;

            if (checkOneRoute)
            {
                ++paramCount;
            }
            else if (checkNotAll)
            {
                paramCount += violatedObjCollection.Count;
            }
            DataObject[] param = new DataObject[paramCount];

            string format = null;
            int    index  = 0;

            if (checkOneRoute)
            {
                param[index++] = violatedObjCollection.First();
                format         = formatSingle;
            }
            else if (checkNotAll)
            {
                string listFormat   = ViolationsHelper.GetObjectListFormat(violatedObjCollection, ref index, param);
                string substitution = "{" + index.ToString() + "}";
                format = string.Format(formatList, listFormat, substitution);
            }
            else
            {
                format = formatAll;
            }
            param[index++] = obj;

            return(new MessageDetail(MessageType.Warning, format, param));
        }
        /// <summary>
        /// Method returns collection of violation message details.
        /// </summary>
        /// <param name="schedule">Schedule to be checked.</param>
        /// <param name="info">Solver's asyncrone operation info.</param>
        /// <param name="violations">Founded violations.</param>
        /// <returns>Message detail with description for violations.</returns>
        public static ICollection <MessageDetail> GetViolationDetails(Schedule schedule,
                                                                      AsyncOperationInfo info,
                                                                      ICollection <Violation> violations)
        {
            Debug.Assert(null != schedule);
            Debug.Assert(0 < violations.Count);

            // special case
            bool  isSpecialCase = false;
            Order orderToAssign = null;

            if (SolveOperationType.AssignOrders == info.OperationType)
            {
                AssignOrdersParams param = (AssignOrdersParams)info.InputParams;
                if (null != param.TargetSequence)
                {
                    isSpecialCase = param.TargetSequence.HasValue;
                }

                if (isSpecialCase)
                {
                    Debug.Assert(1 == param.OrdersToAssign.Count);
                    orderToAssign = param.OrdersToAssign.First();
                }
            }

            ICollection <MessageDetail> details = null;

            if (!isSpecialCase && _IsRouteRelatedViolationPresent(violations))
            {
                details = _GetRouteViolationDetails(violations);
            }
            else
            {
                ICollection <Route> routes = ViolationsHelper.GetRoutingCommandRoutes(schedule, info);
                Debug.Assert((null != routes) && (0 < routes.Count));

                details = _GetViolationDetails(routes, isSpecialCase, orderToAssign, violations);
            }

            return(details);
        }
Пример #8
0
        /// <summary>
        /// Gets build routes operation parameters for the specified schedule.
        /// </summary>
        /// <param name="schedule">The schedule to get build routes operation
        /// parameters for.</param>
        /// <returns>Build routes operation parameters.</returns>
        private BuildRoutesParameters _GetBuildRoutesParameters(Schedule schedule)
        {
            var routes = ViolationsHelper.GetBuildRoutes(schedule);

            // get orders planned on schedule's date
            var day = (DateTime)schedule.PlannedDate;

            var orders =
                from order in App.Current.Project.Orders.Search(day)
                where !ConstraintViolationsChecker.IsOrderRouteLocked(order, schedule)
                select order;

            var parameters = new BuildRoutesParameters()
            {
                TargetRoutes   = routes,
                OrdersToAssign = orders.ToList()
            };

            return(parameters);
        }
        private static List <MessageDetail> _CheckDriverSpecialties(ICollection <Route> routes, ICollection <Order> orders)
        {
            List <MessageDetail> details = new List <MessageDetail>();

            bool checkOneRoute = (1 == routes.Count);

            string format = App.Current.FindString((checkOneRoute)? "ConstraintsCheckerDriverSpecRouteMessageFmt" :
                                                   "ConstraintsCheckerDriverSpecRoutesMessageFmt");

            foreach (Order order in orders)
            {
                ICollection <DriverSpecialty> specialties = (checkOneRoute)?
                                                            _CanAccommodateOrderSpecialties(routes.First().Driver.Specialties, order.DriverSpecialties) :
                                                            _CanAccommodateOrderDriverSpecialties(routes, order);;
                if (null != specialties)
                {
                    int paramCount = 1 + specialties.Count;
                    if (checkOneRoute)
                    {
                        ++paramCount;
                    }
                    AppData.DataObject[] param = new AppData.DataObject[paramCount];

                    int index = 0;
                    if (checkOneRoute)
                    {
                        param[index++] = routes.First().Driver;
                    }
                    param[index++] = order;

                    string specialtiesFormat = ViolationsHelper.GetObjectListFormat(specialties, ref index, param);
                    string messageFormat     = (checkOneRoute) ? string.Format(format, "{0}", "{1}", specialtiesFormat) :
                                               string.Format(format, "{0}", specialtiesFormat);
                    details.Add(new MessageDetail(MessageType.Warning, messageFormat, param));
                }
            }

            return(details);
        }
Пример #10
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);
                }
            }
        }