Esempio n. 1
0
        /// <summary>
        /// Export route to GRF file.
        /// </summary>
        /// <param name="writer">XMLWriter.</param>
        /// <param name="route">Route to export.</param>
        /// <param name="stops">Route's stops.</param>
        /// <param name="project">Project, which contains this route.</param>
        /// <param name="geocoder">Geocoder.</param>
        /// <param name="solver">Solver.</param>
        /// <param name="orderPropertiesToExport">Collection of order properties, which must be
        /// exported.</param>
        /// <param name="compress">Flag, shows compress result file or not.</param>
        /// <returns>GrfExportResult which contains messages about exporting.</returns>
        public static GrfExportResult ExportToGRF(XmlWriter writer, Route route, ICollection <Stop> stops, Project project,
                                                  IGeocoder geocoder, IVrpSolver solver, ICollection <string> orderPropertiesToExport, bool compress)
        {
            GrfExportResult result = new GrfExportResult();

            writer.WriteStartElement(GRF_DOC_NODE_NAME);
            writer.WriteAttributeString(VERSION_ATTR_NAME, VERSION_VALUE);

            writer.WriteStartElement(ROUTEINFO_NODE_NAME);
            if (stops.Count > 0)
            {
                _SaveStops(
                    writer,
                    route,
                    stops,
                    orderPropertiesToExport,
                    project,
                    geocoder.AddressFields);
            }

            IDataObjectCollection <Barrier> barriers =
                (IDataObjectCollection <Barrier>)project.Barriers.Search(route.StartTime.Value.Date, true);

            _SaveBarriers(writer, barriers, result);
            _SaveRouteResults(writer, route, stops);
            writer.WriteEndElement();
            _SaveRouteSettings(writer, route, solver, result);
            writer.WriteEndElement();

            return(result);
        }
Esempio n. 2
0
        private static void _SaveRouteAttributes(XmlWriter writer, Route route, IVrpSolver solver)
        {
            bool attributesContainsParams = false;

            Debug.Assert(solver.NetworkDescription != null);
            foreach (NetworkAttribute attribute in solver.NetworkDescription.NetworkAttributes)
            {
                foreach (NetworkAttributeParameter parameter in attribute.Parameters)
                {
                    attributesContainsParams = true;
                    break;
                }
                if (attributesContainsParams)
                {
                    break;
                }
            }

            if (attributesContainsParams)
            {
                SolverSettings solverSettings = solver.SolverSettings;

                writer.WriteStartElement(ATTRIBUTE_PARAMS_NODE_NAME);
                foreach (NetworkAttribute attribute in solver.NetworkDescription.NetworkAttributes)
                {
                    bool containsParams = false;
                    foreach (NetworkAttributeParameter parameter in attribute.Parameters)
                    {
                        containsParams = true;
                        break;
                    }

                    if (containsParams)
                    {
                        writer.WriteStartElement(ATTRIBUTE_NODE_NAME);
                        writer.WriteAttributeString(NAME_ATTR_NAME, attribute.Name);
                        foreach (NetworkAttributeParameter parameter in attribute.Parameters)
                        {
                            writer.WriteStartElement(PARAM_NODE_NAME);
                            writer.WriteAttributeString(NAME_ATTR_NAME, parameter.Name);

                            object valueObj = null;
                            if (!solverSettings.GetNetworkAttributeParameterValue(attribute.Name,
                                                                                  parameter.Name,
                                                                                  out valueObj))
                            {
                                valueObj = null;
                            }

                            string value = _ConvertValue2String(valueObj);

                            writer.WriteAttributeString(VALUE_ATTR_NAME, value);
                            writer.WriteEndElement();
                        }
                        writer.WriteEndElement();
                    }
                }
                writer.WriteEndElement();
            }
        }
Esempio n. 3
0
        /// <summary>
        /// React on DataGridCollectionViewSource CommittingEdit.
        /// </summary>
        /// <param name="sender">Ignored.</param>
        /// <param name="e">Data grid item cancel event arguments </param>
        private void DataGridCollectionViewSource_CommittingEdit(object sender,
                                                                 DataGridItemCancelEventArgs e)
        {
            try
            {
                var selectedItem = xceedGrid.CurrentItem as RestrictionDataWrapper;

                IVrpSolver         solver             = App.Current.Solver;
                SolverSettings     solverSettings     = solver.SolverSettings;
                NetworkDescription networkDescription = solver.NetworkDescription;

                ICollection <NetworkAttribute> networkAttributes =
                    networkDescription.NetworkAttributes;
                foreach (NetworkAttribute attribute in networkAttributes)
                {
                    if (selectedItem.Restriction.Name.Equals(attribute.Name,
                                                             StringComparison.OrdinalIgnoreCase))
                    {
                        ICollection <NetworkAttributeParameter> paramColl = attribute.Parameters;
                        Debug.Assert(null != paramColl);
                        _UpdateValue(selectedItem, solverSettings, attribute);
                    }
                }
            }
            catch (Exception ex)
            {
                Logger.Error(ex);
            }

            e.Handled = true;
        }
        /// <summary>
        /// Returns a reference to the <see cref="Tracker"/> class object.
        /// </summary>
        /// <param name="solver">The solver to be used by the returned tracker.</param>
        /// <param name="geocoder">The geocoder to be used by the returned tracker.</param>
        /// <param name="messageReporter">The messageReporter to be used by the returned
        /// tracker.</param>
        /// <returns>A new <see cref="Tracker"/> class instance.</returns>
        /// <exception cref="ArgumentNullException"><paramref name="solver"/>,
        /// <paramref name="geocoder"/> or <paramref name="messageReporter"/> is a null
        /// reference.</exception>
        public Tracker GetTracker(
            IVrpSolver solver,
            IGeocoder geocoder,
            IMessageReporter messageReporter)
        {
            CodeContract.RequiresNotNull("solver", solver);
            CodeContract.RequiresNotNull("geocoder", geocoder);
            CodeContract.RequiresNotNull("messageReporter", messageReporter);

            _CheckSettings(_settings);

            var settings = new TrackingSettings
            {
                BreakTolerance = _settings.TrackingSettings.BreakTolerance ?? 0,
            };

            var uri     = new Uri(_settings.TrackingServiceInfo.RestUrl);
            var service = FeatureService.Create(uri, Server);
            var trackingServiceClient = new TrackingServiceClient(service);

            var trackingService        = new TrackingServiceClient(service);
            var synchronizationService = new SynchronizationService(trackingServiceClient);

            return(new Tracker(
                       settings,
                       trackingService,
                       synchronizationService,
                       solver,
                       geocoder,
                       messageReporter));
        }
        ///////////////////////////////////////////////////////////////////////////////////////////
        ///////////////////////////////////////////////////////////////////////////////////////////
        ///////////////////////////////////////////////////////////////////////////////////////////

        /// <summary>
        /// Gets solver settings.
        /// </summary>
        /// <param name="solver">The reference to the VRP solver.</param>
        /// <returns>Solver settings or NULL.</returns>
        internal static SolverSettings GetSolverSettings(IVrpSolver solver)
        {
            Debug.Assert(solver != null);

            SolverSettings settings = null;

            try
            {
                settings = solver.SolverSettings;
            }
            catch (Exception e)
            {
                if (e is InvalidOperationException ||
                    e is AuthenticationException ||
                    e is CommunicationException ||
                    e is FaultException)
                {
                    Logger.Info(e);
                }
                else
                {
                    throw; // exception
                }
            }

            return(settings);
        }
Esempio n. 6
0
        /// <summary>
        /// Does validate.
        /// </summary>
        /// <param name="value">Value to validation.</param>
        /// <param name="culture">Culture info.</param>
        /// <param name="context">Cell validation context.</param>
        /// <returns>Validation result.</returns>
        public override ValidationResult Validate(object value,
                                                  CultureInfo culture,
                                                  CellValidationContext context)
        {
            bool isValid = true;

            string             newValue           = value as string;
            IVrpSolver         solver             = App.Current.Solver;
            NetworkDescription networkDescription = solver.NetworkDescription;

            if (newValue != null && networkDescription != null)
            {
                var wrapper = context.DataItem as RestrictionDataWrapper;

                ICollection <NetworkAttribute> networkAttributes = networkDescription.NetworkAttributes;
                foreach (NetworkAttribute attribute in networkAttributes)
                {
                    // If it is current attribute - find parameter to validate.
                    if (wrapper.Restriction.Name.Equals(attribute.Name,
                                                        StringComparison.OrdinalIgnoreCase))
                    {
                        Debug.Assert(null != attribute.Parameters);
                        NetworkAttributeParameter[] parameters = attribute.Parameters.ToArray();

                        int paramIndex = Parameters.GetIndex(context.Cell.FieldName);

                        // If parameter index was found.
                        if (paramIndex != -1)
                        {
                            var parameter = wrapper.Parameters[paramIndex];

                            // Get corresponding network attribute parameter
                            // and check that value can be converted to parameter type.
                            NetworkAttributeParameter param = parameters.FirstOrDefault(
                                x => x.Name == parameter.Name);

                            // If string is not empty or if parameter doesn't accept empty string -
                            // try to convert value.
                            if ((string)value != string.Empty || !param.IsEmptyStringValid)
                            {
                                try
                                {
                                    Convert.ChangeType(value, param.Type); // NOTE: ignore result
                                }
                                catch
                                {
                                    isValid = false;
                                }
                            }
                        }

                        break;
                    }
                }
            }

            return((isValid) ? ValidationResult.ValidResult :
                   new ValidationResult(false, App.Current.FindString("NotValidValueText")));
        }
Esempio n. 7
0
        /// <summary>
        /// React on is enabled click for CheckBoxCellTemplate. Converts template state
        /// to restriction value.
        /// </summary>
        /// <param name="sender">Ignored.</param>
        /// <param name="e">Ignored.</param>
        private void _IsEnabled_Click(object sender, RoutedEventArgs e)
        {
            RestrictionDataWrapper    selectedItem = xceedGrid.CurrentItem as RestrictionDataWrapper;
            IVrpSolver                solver       = App.Current.Solver;
            ICollection <Restriction> restrictions = solver.SolverSettings.Restrictions;
            Restriction               restriction  = _FindRestriction(selectedItem.Restriction.Name, restrictions);

            restriction.IsEnabled = selectedItem.IsEnabled;
        }
Esempio n. 8
0
        /// <summary>
        /// Saves UTurn settings.
        /// </summary>
        private void _SaveUTurnSettings()
        {
            IVrpSolver     solver   = App.Current.Solver;
            SolverSettings settings = _GetSolverSettings(solver);

            if (settings != null)
            {
                settings.UTurnAtIntersections = MakeUTurnsAtIntersections.IsChecked ?? false;
                settings.UTurnAtDeadEnds      = MakeUTurnsAtDeadEnds.IsChecked ?? false;
            }
        }
Esempio n. 9
0
        /// <summary>
        /// Saves Curb approach settings.
        /// </summary>
        private void _SaveCurbApproachSettings()
        {
            IVrpSolver     solver   = App.Current.Solver;
            SolverSettings settings = _GetSolverSettings(solver);

            if (settings != null)
            {
                settings.UTurnAtStops    = MakeUTurnsAtStops.IsChecked ?? false;
                settings.StopOnOrderSide = StopOnOrderSide.IsChecked ?? false;
            }
        }
Esempio n. 10
0
        /// <summary>
        /// Exports specified stops to serializable stop information.
        /// </summary>
        /// <param name="stops">The reference to the collection of stops to be exported.</param>
        /// <param name="capacitiesInfo">The reference to capacities info object to be used
        /// for retrieving custom order properties for stops.</param>
        /// <param name="orderCustomPropertiesInfo">The reference custom order properties info
        /// object.</param>
        /// <param name="addressFields">The reference to address fields object to be used
        /// for retrieving custom order properties for stops.</param>
        /// <param name="solver">The reference to VRPSolver to be used for retrieving
        /// curb approach policies for stops.</param>
        /// <param name="orderPropertiesFilter">Function returning true for custom order
        /// property names which should not be exported.</param>
        /// <returns>A reference to the collection of serializable stop information objects.
        /// </returns>
        public static IEnumerable<StopInfo> ExportStops(
            IEnumerable<Stop> stops,
            CapacitiesInfo capacitiesInfo,
            OrderCustomPropertiesInfo orderCustomPropertiesInfo,
            AddressField[] addressFields,
            IVrpSolver solver,
            Func<string, bool> orderPropertiesFilter = null)
        {
            Debug.Assert(stops != null);
            Debug.Assert(stops.All(stop => stop != null));
            Debug.Assert(stops.All(stop => stop.Route != null));
            Debug.Assert(capacitiesInfo != null);
            Debug.Assert(orderCustomPropertiesInfo != null);
            Debug.Assert(addressFields != null);

            if (!stops.Any())
            {
                return Enumerable.Empty<StopInfo>();
            }

            var capacityProperties = Order.GetPropertiesInfo(capacitiesInfo);
            var addressProperties = Order.GetPropertiesInfo(addressFields);
            var customProperties = Order.GetPropertiesInfo(orderCustomPropertiesInfo);

            var exportOrderProperties = _CreateExportOrderProperties(
                capacitiesInfo,
                orderCustomPropertiesInfo,
                addressFields,
                orderPropertiesFilter);

            // Make a dictionary for mapping routes to collection of sorted route stops.
            var routesSortedStops = stops
                .Select(stop => stop.Route)
                .Distinct()
                .ToDictionary(route => route, route => CommonHelpers.GetSortedStops(route));

            // Prepare result by exporting each stop individually.
            var settings = CommonHelpers.GetSolverSettings(solver);
            var result = stops
                .Select(stop => _ExportStop(
                    stop,
                    routesSortedStops[stop.Route],
                    exportOrderProperties,
                    addressProperties,
                    capacityProperties,
                    customProperties,
                    settings))
                .ToList();

            return result;
        }
Esempio n. 11
0
        /// <summary>
        /// Exports specified stops to serializable stop information.
        /// </summary>
        /// <param name="stops">The reference to the collection of stops to be exported.</param>
        /// <param name="capacitiesInfo">The reference to capacities info object to be used
        /// for retrieving custom order properties for stops.</param>
        /// <param name="orderCustomPropertiesInfo">The reference custom order properties info
        /// object.</param>
        /// <param name="addressFields">The reference to address fields object to be used
        /// for retrieving custom order properties for stops.</param>
        /// <param name="solver">The reference to VRPSolver to be used for retrieving
        /// curb approach policies for stops.</param>
        /// <param name="orderPropertiesFilter">Function returning true for custom order
        /// property names which should not be exported.</param>
        /// <returns>A reference to the collection of serializable stop information objects.
        /// </returns>
        public static IEnumerable <StopInfo> ExportStops(
            IEnumerable <Stop> stops,
            CapacitiesInfo capacitiesInfo,
            OrderCustomPropertiesInfo orderCustomPropertiesInfo,
            AddressField[] addressFields,
            IVrpSolver solver,
            Func <string, bool> orderPropertiesFilter = null)
        {
            Debug.Assert(stops != null);
            Debug.Assert(stops.All(stop => stop != null));
            Debug.Assert(stops.All(stop => stop.Route != null));
            Debug.Assert(capacitiesInfo != null);
            Debug.Assert(orderCustomPropertiesInfo != null);
            Debug.Assert(addressFields != null);

            if (!stops.Any())
            {
                return(Enumerable.Empty <StopInfo>());
            }

            var capacityProperties = Order.GetPropertiesInfo(capacitiesInfo);
            var addressProperties  = Order.GetPropertiesInfo(addressFields);
            var customProperties   = Order.GetPropertiesInfo(orderCustomPropertiesInfo);

            var exportOrderProperties = _CreateExportOrderProperties(
                capacitiesInfo,
                orderCustomPropertiesInfo,
                addressFields,
                orderPropertiesFilter);

            // Make a dictionary for mapping routes to collection of sorted route stops.
            var routesSortedStops = stops
                                    .Select(stop => stop.Route)
                                    .Distinct()
                                    .ToDictionary(route => route, route => CommonHelpers.GetSortedStops(route));

            // Prepare result by exporting each stop individually.
            var settings = CommonHelpers.GetSolverSettings(solver);
            var result   = stops
                           .Select(stop => _ExportStop(
                                       stop,
                                       routesSortedStops[stop.Route],
                                       exportOrderProperties,
                                       addressProperties,
                                       capacityProperties,
                                       customProperties,
                                       settings))
                           .ToList();

            return(result);
        }
Esempio n. 12
0
        /// <summary>
        /// Export route to GRF file.
        /// </summary>
        /// <param name="filePath">Path to grf file.</param>
        /// <param name="route">Route to export.</param>
        /// <param name="project">Project, which contains this route.</param>
        /// <param name="geocoder">Geocoder.</param>
        /// <param name="solver">Solver.</param>
        /// <param name="orderPropertiesToExport">Collection of order properties, which must be
        /// exported.</param>
        /// <param name="compress">Flag, shows compress result file or not.</param>
        /// <returns>GrfExportResult which contains messages about exporting.</returns>
        public static GrfExportResult ExportToGRF(string filePath, Route route, Project project,
                                                  IGeocoder geocoder, IVrpSolver solver, ICollection <string> orderPropertiesToExport, bool compress)
        {
            XmlWriterSettings settings = new XmlWriterSettings();

            settings.Indent      = true;
            settings.IndentChars = CommonHelpers.XML_SETTINGS_INDENT_CHARS;

            using (XmlWriter writer = XmlWriter.Create(filePath, settings))
            {
                var result = ExportToGRF(writer, route, route.Stops, project, geocoder, solver, orderPropertiesToExport, compress);
                writer.Flush();
                return(result);
            }
        }
        /// <summary>
        /// Initializes a new instance of the SolveStateTrackingService.
        /// </summary>
        /// <param name="solver">VRP solver to track solves for.</param>
        /// <param name="currentDateProvider">Date/time provider object.</param>
        public SolveStateTrackingService(
            IVrpSolver solver,
            ICurrentDateProvider currentDateProvider)
        {
            Debug.Assert(solver != null);

            _solver = solver;
            _solver.AsyncSolveStarted   += (s, e) => _UpdateState();
            _solver.AsyncSolveCompleted += (s, e) => _UpdateState(e.OperationId);

            _currentDateProvider = currentDateProvider;
            _currentDateProvider.CurrentDateChanged += (s, e) => _UpdateState();

            _UpdateState();
        }
        /// <summary>
        /// Initializes a new instance of the SolveStateTrackingService.
        /// </summary>
        /// <param name="solver">VRP solver to track solves for.</param>
        /// <param name="currentDateProvider">Date/time provider object.</param>
        public SolveStateTrackingService(
            IVrpSolver solver,
            ICurrentDateProvider currentDateProvider)
        {
            Debug.Assert(solver != null);

            _solver = solver;
            _solver.AsyncSolveStarted += (s, e) => _UpdateState();
            _solver.AsyncSolveCompleted += (s, e) => _UpdateState(e.OperationId);

            _currentDateProvider = currentDateProvider;
            _currentDateProvider.CurrentDateChanged += (s, e) => _UpdateState();

            _UpdateState();
        }
Esempio n. 15
0
        /// <summary>
        /// Inits data grid.
        /// </summary>
        private void _InitDataGrid()
        {
            try
            {
                // If active schedule hasn't been set - do it.
                if (App.Current.Project != null &&
                    App.Current.Project.Schedules.ActiveSchedule == null)
                {
                    // Load schedule for current date.
                    var currentSchedule = OptimizeAndEditHelpers.LoadSchedule(
                        App.Current.Project,
                        App.Current.CurrentDate,
                        OptimizeAndEditHelpers.FindScheduleToSelect);

                    // If current date schedule have routes -
                    // select current schedule as active.
                    if (currentSchedule.Routes.Count > 0)
                    {
                        App.Current.Project.Schedules.ActiveSchedule = currentSchedule;
                    }
                }

                _ClearGridSource();

                IVrpSolver                solver         = App.Current.Solver;
                SolverSettings            solverSettings = solver.SolverSettings;
                ICollection <Restriction> restrictions   = solverSettings.Restrictions;
                if (0 < restrictions.Count)
                {
                    NetworkDescription networkDescription = solver.NetworkDescription;

                    // Obtain max "non-restriction" parameters count.
                    int maxParametersCount = _GetNonRestrictionParametersMaximumCount(
                        networkDescription, restrictions);

                    _InitDataGridLayout(maxParametersCount);
                }
            }
            catch (Exception ex)
            {
                Logger.Critical(ex);
            }
        }
Esempio n. 16
0
        protected override void _Execute(params object[] args)
        {
            OptimizeAndEditPage schedulePage = (OptimizeAndEditPage)((MainWindow)App.Current.MainWindow).GetPage(PagePaths.SchedulePagePath);
            IVrpSolver          solver       = App.Current.Solver;

            Debug.Assert(solver != null);

            // get operations for current date
            IList <AsyncOperationInfo> currentOperations = solver.GetAsyncOperations(App.Current.CurrentDate);

            Debug.Assert(currentOperations != null && currentOperations.Count == 1);

            // cancel current operation
            bool isEnabled = !solver.CancelAsyncOperation(currentOperations[0].Id);

            Debug.Assert(!isEnabled);

            // Change status string for current date to "Canceling..." and hide "Cancel" button
            schedulePage.SetCancellingStatus(App.Current.CurrentDate);
        }
Esempio n. 17
0
        /// <summary>
        /// React on NumericTextBox Arrival/Departure Delay TextChanged.
        /// </summary>
        /// <param name="sender">Related NumericTextBox.</param>
        /// <param name="e">Ignored.</param>
        private void numericTextBox_TextChanged(object sender, TextChangedEventArgs e)
        {
            var textBox = sender as NumericTextBox;

            Debug.Assert(null != textBox);

            string text = textBox.Text;

            if (!textBox.HasParsingError &&
                !textBox.HasValidationError &&
                !string.IsNullOrEmpty(text))
            {
                int?value = _ConvertStringToInt(text);
                if (value.HasValue)
                {
                    IVrpSolver solver = App.Current.Solver;
                    Debug.Assert(null != solver);

                    solver.SolverSettings.ArriveDepartDelay = value.Value;
                }
            }
        }
Esempio n. 18
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Tracker"/> class.
        /// </summary>
        /// <param name="settings">Settings to be used by the tracker.</param>
        /// <param name="trackingService">The tracking service client to be used to communicate
        /// with the tracking server.</param>
        /// <param name="synchronizationService">The synchronization service to be used for
        /// synchronizing data in the project and at the tracking service.</param>
        /// <param name="solver">The VRP solver to be used by the tracker.</param>
        /// <param name="geocoder">The geocoder to be used by the tracker.</param>
        /// <param name="messageReporter">The message reporter to be used for reporting
        /// tracking errors.</param>
        /// <exception cref="ArgumentNullException"><paramref name="settings"/>,
        /// <paramref name="trackingService"/>, <paramref name="synchronizationService"/>,
        /// <paramref name="solver"/>, <paramref name="geocoder"/> or
        /// <paramref name="messageReporter"/> is a null reference.</exception>
        internal Tracker(
            TrackingSettings settings,
            ITrackingService trackingService,
            ISynchronizationService synchronizationService,
            IVrpSolver solver,
            IGeocoder geocoder,
            IMessageReporter messageReporter)
        {
            CodeContract.RequiresNotNull("settings", settings);
            CodeContract.RequiresNotNull("trackingService", trackingService);
            CodeContract.RequiresNotNull("synchronizationService", synchronizationService);
            CodeContract.RequiresNotNull("solver", solver);
            CodeContract.RequiresNotNull("geocoder", geocoder);
            CodeContract.RequiresNotNull("messageReporter", messageReporter);

            _settings               = settings;
            _trackingService        = trackingService;
            _synchronizationService = synchronizationService;

            _solver = solver;

            _geocoder        = geocoder;
            _messageReporter = messageReporter;
        }
        /// <summary>
        /// Gets solver settings.
        /// </summary>
        /// <param name="solver">The reference to the VRP solver.</param>
        /// <returns>Solver settings or NULL.</returns>
        private SolverSettings _GetSolverSettings(IVrpSolver solver)
        {
            Debug.Assert(solver != null);

            SolverSettings settings = null;
            try
            {
                settings = solver.SolverSettings;
            }
            catch (Exception e)
            {
                if (e is InvalidOperationException ||
                    e is AuthenticationException ||
                    e is CommunicationException)
                {
                    Logger.Info(e);
                }
                else
                {
                    throw; // exception
                }
            }

            return settings;
        }
Esempio n. 20
0
        /// <summary>
        /// Inits page controls.
        /// </summary>
        private void _InitPageContent()
        {
            App.Current.MainWindow.StatusBar.SetStatus(this, null);

            checkConstraintButton.IsChecked =
                Properties.Settings.Default.IsRoutingConstraintCheckEnabled;
            alwaysRouteButton.IsChecked = !checkConstraintButton.IsChecked;

            checkConstraintButton.Checked += new RoutedEventHandler(_CheckConstraintButton_Checked);
            alwaysRouteButton.Checked     += new RoutedEventHandler(_AlwaysRouteButton_Checked);

            _InitDataGrid();

            IVrpSolver     solver   = App.Current.Solver;
            SolverSettings settings = _GetSolverSettings(solver);

            if (null == settings)
            {
                textBoxArriveDepartDelay.Text      = string.Empty;
                textBoxArriveDepartDelay.IsEnabled = false;

                MakeUTurnsAtIntersections.IsEnabled = false;
                MakeUTurnsAtDeadEnds.IsEnabled      = false;
                MakeUTurnsAtStops.IsEnabled         = false;
                StopOnOrderSide.IsEnabled           = false;
            }
            else
            {
                textBoxArriveDepartDelay.Text      = settings.ArriveDepartDelay.ToString();
                textBoxArriveDepartDelay.IsEnabled = true;

                textBoxArriveDepartDelay.KeyDown +=
                    new System.Windows.Input.KeyEventHandler(numericTextBox_KeyDown);
                textBoxArriveDepartDelay.TextChanged +=
                    new TextChangedEventHandler(numericTextBox_TextChanged);
                textBoxArriveDepartDelay.MouseWheel +=
                    new MouseWheelEventHandler(numericTextBox_MouseWheel);

                // Enable all check boxes.
                MakeUTurnsAtIntersections.IsEnabled = true;
                MakeUTurnsAtDeadEnds.IsEnabled      = true;
                MakeUTurnsAtStops.IsEnabled         = true;
                StopOnOrderSide.IsEnabled           = true;

                // U-Turn policies.
                MakeUTurnsAtIntersections.Checked   += _MakeUTurnsAtIntersectionsChecked;
                MakeUTurnsAtIntersections.Unchecked += _MakeUTurnsAtIntersectionsUnchecked;
                MakeUTurnsAtDeadEnds.Checked        += _MakeUTurnsAtDeadEndsChecked;
                MakeUTurnsAtDeadEnds.Unchecked      += _MakeUTurnsAtDeadEndsUnchecked;
                MakeUTurnsAtStops.Checked           += _MakeUTurnsAtStopsChecked;
                MakeUTurnsAtStops.Unchecked         += _MakeUTurnsAtStopsUnchecked;
                StopOnOrderSide.Checked             += _StopOnOrderSideChecked;
                StopOnOrderSide.Unchecked           += _StopOnOrderSideUnchecked;

                // Initialize U-Turn policies.
                MakeUTurnsAtIntersections.IsChecked = settings.UTurnAtIntersections;
                MakeUTurnsAtDeadEnds.IsChecked      = settings.UTurnAtDeadEnds;
                MakeUTurnsAtStops.IsChecked         = settings.UTurnAtStops;
                StopOnOrderSide.IsChecked           = settings.StopOnOrderSide;
            }
        }
Esempio n. 21
0
        /// <summary>
        /// Inits grid source.
        /// </summary>
        /// <param name="maxParametersCount">Maximum number of attribute parameters.</param>
        /// <param name="collectionSource">Data grid collection source.</param>
        private void _InitGridSource(int maxParametersCount,
                                     DataGridCollectionViewSource collectionSource)
        {
            IVrpSolver                solver             = App.Current.Solver;
            SolverSettings            solverSettings     = solver.SolverSettings;
            NetworkDescription        networkDescription = solver.NetworkDescription;
            ICollection <Restriction> restrictions       = solverSettings.Restrictions;

            var restrictionWrappers = new List <RestrictionDataWrapper>();

            var networkAttributes = networkDescription.NetworkAttributes;

            foreach (NetworkAttribute attribute in networkAttributes)
            {
                if (attribute.UsageType == NetworkAttributeUsageType.Restriction)
                {
                    Restriction restriction = _FindRestriction(attribute.Name, restrictions);
                    if (restriction.IsEditable)
                    {
                        Debug.Assert(null != attribute.Parameters);

                        // Create collection of all non "restriction usage" attribute parameters.
                        IList <NetworkAttributeParameter> attrParams;
                        if (attribute.RestrictionUsageParameter != null)
                        {
                            attrParams = attribute.Parameters.Where(
                                param => param.Name != attribute.RestrictionUsageParameter.Name).ToList();
                        }
                        else
                        {
                            attrParams = attribute.Parameters.ToList();
                        }

                        var parameters = new Parameters(maxParametersCount);
                        for (int index = 0; index < maxParametersCount; ++index)
                        {
                            string value = null;
                            if (index < attrParams.Count())
                            {
                                NetworkAttributeParameter param = attrParams.ElementAt(index);
                                value             = _GetParameterValue(attribute.Name, param.Name, solverSettings);
                                parameters[index] = new Parameter(param.Name, value);
                            }
                            else
                            {
                                parameters[index] = new Parameter();
                            }
                        }

                        // Create wrapper for restriction.
                        var wrapper = new RestrictionDataWrapper(restriction.IsEnabled,
                                                                 restriction.NetworkAttributeName,
                                                                 restriction.Description, parameters);

                        // If attribute has restriction usage parameter - add this parameter
                        // to wrapper.
                        if (attribute.RestrictionUsageParameter != null)
                        {
                            var restrictionUsageParameterValue = _GetParameterValue(attribute.Name,
                                                                                    attribute.RestrictionUsageParameter.Name, solverSettings);
                            var restrictionParameter = new Parameter(attribute.RestrictionUsageParameter.Name,
                                                                     restrictionUsageParameterValue);
                            wrapper.RestrictionUsageParameter = restrictionParameter;
                        }

                        restrictionWrappers.Add(wrapper);
                    }
                }
            }

            collectionSource.Source = restrictionWrappers;
        }
Esempio n. 22
0
        /// <summary>
        /// Export route to GRF file.
        /// </summary>
        /// <param name="filePath">Path to grf file.</param>
        /// <param name="route">Route to export.</param>
        /// <param name="project">Project, which contains this route.</param>
        /// <param name="geocoder">Geocoder.</param>
        /// <param name="solver">Solver.</param>
        /// <param name="orderPropertiesToExport">Collection of order properties, which must be
        /// exported.</param>
        /// <param name="compress">Flag, shows compress result file or not.</param>
        /// <returns>GrfExportResult which contains messages about exporting.</returns>
        public static GrfExportResult ExportToGRF(string filePath, Route route, Project project,
            IGeocoder geocoder, IVrpSolver solver, ICollection<string> orderPropertiesToExport, bool compress)
        {
            XmlWriterSettings settings = new XmlWriterSettings();
            settings.Indent = true;
            settings.IndentChars = CommonHelpers.XML_SETTINGS_INDENT_CHARS;

            using (XmlWriter writer = XmlWriter.Create(filePath, settings))
            {
                var result = ExportToGRF(writer, route, route.Stops, project, geocoder, solver, orderPropertiesToExport, compress);
                writer.Flush();
                return result;
            }
        }
Esempio n. 23
0
        private static void _SaveRouteSettings(XmlWriter writer, Route route, IVrpSolver solver,
                                               GrfExportResult result)
        {
            SolverSettings settings = solver.SolverSettings;

            writer.WriteStartElement(ROUTE_SETTINGS_NODE_NAME);

            writer.WriteStartElement(UTURNPOLICY_NODE_NAME);
            string uTurnPolicy = "";

            switch (settings.GetUTurnPolicy())
            {
            case UTurnPolicy.Nowhere:
                uTurnPolicy = UTurnNowhere;
                break;

            case UTurnPolicy.AtDeadEnds:
                uTurnPolicy = UTurnAtDeadEnds;
                break;

            case UTurnPolicy.AtDeadEndsAndIntersections:
                // GRF doesnt support "U-Turns at Dead Ends and Intersections" UTurnPolicy,
                // so replace it with "U-Turns at Dead Ends".
                //fjk: updated so UTurnEverywhere respected
                uTurnPolicy = UTurnEverywhere;

                //fjk: commented out b/c of the above change
                // Add warning message
                //result.Warnings.Add(Properties.Messages.Warning_UTurnPolicyNotSupported);
                break;

            default:
                Debug.Assert(false);     // NOTE: not supported
                break;
            }
            writer.WriteAttributeString(VALUE_ATTR_NAME, uTurnPolicy);
            writer.WriteEndElement();

            writer.WriteStartElement(IMPEDANCE_ATTR_NODE_NAME);
            writer.WriteAttributeString(NAME_ATTR_NAME, "Time");
            writer.WriteEndElement();

            writer.WriteStartElement(RESTRICTIONS_ATTR_NODE_NAME);

            ICollection <string> restrictions = SolveHelper.GetEnabledRestrictionNames(
                solver.SolverSettings.Restrictions);

            foreach (string name in restrictions)
            {
                writer.WriteStartElement(RESTRICTION_NODE_NAME);
                writer.WriteAttributeString(NAME_ATTR_NAME, name);
                writer.WriteAttributeString(TYPE_ATTR_NAME, STRICT_ATTR_NAME);
                writer.WriteAttributeString(STATUS_ATTR_NAME, ON_ATTR);
                writer.WriteEndElement();
            }
            writer.WriteEndElement();

            _SaveRouteAttributes(writer, route, solver);

            writer.WriteStartElement(TRIPPLANSETTINGS_NODE_NAME);
            writer.WriteStartElement(TRIP_START_NODE_NAME);
            string startTime = route.StartTime.Value.ToString("yyyy-MM-ddTHH:mm:ss");

            writer.WriteAttributeString(VALUE_ATTR_NAME, startTime);
            writer.WriteEndElement();
            writer.WriteEndElement();

            writer.WriteStartElement(DIRECTIONS_LENGTH_UNITS_NODE_NAME);
            string     lengthUnits;
            RegionInfo ri = new RegionInfo(System.Threading.Thread.CurrentThread.CurrentCulture.LCID);

            if (ri.IsMetric)
            {
                lengthUnits = KILOMETERS;
            }
            else
            {
                lengthUnits = MILES;
            }
            writer.WriteAttributeString(VALUE_ATTR_NAME, lengthUnits);
            writer.WriteEndElement();

            writer.WriteStartElement(DIRECTIONS_CONTENT_NODE_NAME);
            writer.WriteAttributeString(VALUE_ATTR_NAME, "all");
            writer.WriteEndElement();

            writer.WriteEndElement();
        }
Esempio n. 24
0
        /// <summary>
        /// Export route to GRF file.
        /// </summary>
        /// <param name="writer">XMLWriter.</param>
        /// <param name="route">Route to export.</param>
        /// <param name="stops">Route's stops.</param>
        /// <param name="project">Project, which contains this route.</param>
        /// <param name="geocoder">Geocoder.</param>
        /// <param name="solver">Solver.</param>
        /// <param name="orderPropertiesToExport">Collection of order properties, which must be
        /// exported.</param>
        /// <param name="compress">Flag, shows compress result file or not.</param>
        /// <returns>GrfExportResult which contains messages about exporting.</returns>
        public static GrfExportResult ExportToGRF(XmlWriter writer, Route route, ICollection<Stop> stops, Project project,
            IGeocoder geocoder, IVrpSolver solver, ICollection<string> orderPropertiesToExport, bool compress)
        {
            GrfExportResult result = new GrfExportResult();

            writer.WriteStartElement(GRF_DOC_NODE_NAME);
            writer.WriteAttributeString(VERSION_ATTR_NAME, VERSION_VALUE);

            writer.WriteStartElement(ROUTEINFO_NODE_NAME);
            if (stops.Count > 0)
            {
                _SaveStops(
                    writer,
                    route,
                    stops,
                    orderPropertiesToExport,
                    project,
                    geocoder.AddressFields);
            }

            IDataObjectCollection<Barrier> barriers =
                (IDataObjectCollection<Barrier>)project.Barriers.Search(route.StartTime.Value.Date, true);
            _SaveBarriers(writer, barriers, result);
            _SaveRouteResults(writer, route, stops);
            writer.WriteEndElement();
            _SaveRouteSettings(writer, route, solver, result);
            writer.WriteEndElement();

            return result;
        }
Esempio n. 25
0
        private static void _SaveRouteSettings(XmlWriter writer, Route route, IVrpSolver solver,
            GrfExportResult result )
        {
            SolverSettings settings = solver.SolverSettings;
            writer.WriteStartElement(ROUTE_SETTINGS_NODE_NAME);

            writer.WriteStartElement(UTURNPOLICY_NODE_NAME);
            string uTurnPolicy = "";
            switch (settings.GetUTurnPolicy())
            {
                case UTurnPolicy.Nowhere:
                    uTurnPolicy = UTurnNowhere;
                    break;
                case UTurnPolicy.AtDeadEnds:
                    uTurnPolicy = UTurnAtDeadEnds;
                    break;
                case UTurnPolicy.AtDeadEndsAndIntersections:
                    // GRF doesnt support "U-Turns at Dead Ends and Intersections" UTurnPolicy,
                    // so replace it with "U-Turns at Dead Ends".
                    uTurnPolicy = UTurnAtDeadEnds;

                    // Add warning message
                    result.Warnings.Add(Properties.Messages.Warning_UTurnPolicyNotSupported);
                    break;
                default:
                    Debug.Assert(false); // NOTE: not supported
                    break;
            }
            writer.WriteAttributeString(VALUE_ATTR_NAME, uTurnPolicy);
            writer.WriteEndElement();

            writer.WriteStartElement(IMPEDANCE_ATTR_NODE_NAME);
            writer.WriteAttributeString(NAME_ATTR_NAME, solver.NetworkDescription.ImpedanceAttributeName);
            writer.WriteEndElement();

            writer.WriteStartElement(RESTRICTIONS_ATTR_NODE_NAME);

            ICollection<string> restrictions = SolveHelper.GetEnabledRestrictionNames(
                solver.SolverSettings.Restrictions);

            foreach (string name in restrictions)
            {
                writer.WriteStartElement(RESTRICTION_NODE_NAME);
                writer.WriteAttributeString(NAME_ATTR_NAME, name);
                writer.WriteAttributeString(TYPE_ATTR_NAME, STRICT_ATTR_NAME);
                writer.WriteAttributeString(STATUS_ATTR_NAME, ON_ATTR);
                writer.WriteEndElement();
            }
            writer.WriteEndElement();

            _SaveRouteAttributes(writer, route, solver);

            writer.WriteStartElement(TRIPPLANSETTINGS_NODE_NAME);
            writer.WriteStartElement(TRIP_START_NODE_NAME);
            string startTime = route.StartTime.Value.ToString("yyyy-MM-ddTHH:mm:ss");
            writer.WriteAttributeString(VALUE_ATTR_NAME, startTime);
            writer.WriteEndElement();
            writer.WriteEndElement();

            writer.WriteStartElement(DIRECTIONS_LENGTH_UNITS_NODE_NAME);
            string lengthUnits;
            RegionInfo ri = new RegionInfo(System.Threading.Thread.CurrentThread.CurrentCulture.LCID);
            if (ri.IsMetric)
                lengthUnits = KILOMETERS;
            else
                lengthUnits = MILES;
            writer.WriteAttributeString(VALUE_ATTR_NAME, lengthUnits);
            writer.WriteEndElement();

            writer.WriteStartElement(DIRECTIONS_CONTENT_NODE_NAME);
            writer.WriteAttributeString(VALUE_ATTR_NAME, "all");
            writer.WriteEndElement();

            writer.WriteEndElement();
        }
Esempio n. 26
0
        private static void _SaveRouteAttributes(XmlWriter writer, Route route, IVrpSolver solver)
        {
            bool attributesContainsParams = false;
            Debug.Assert(solver.NetworkDescription != null);
            foreach (NetworkAttribute attribute in solver.NetworkDescription.NetworkAttributes)
            {
                foreach (NetworkAttributeParameter parameter in attribute.Parameters)
                {
                    attributesContainsParams = true;
                    break;
                }
                if (attributesContainsParams)
                    break;
            }

            if (attributesContainsParams)
            {
                SolverSettings solverSettings = solver.SolverSettings;

                writer.WriteStartElement(ATTRIBUTE_PARAMS_NODE_NAME);
                foreach (NetworkAttribute attribute in solver.NetworkDescription.NetworkAttributes)
                {
                    bool containsParams = false;
                    foreach (NetworkAttributeParameter parameter in attribute.Parameters)
                    {
                        containsParams = true;
                        break;
                    }

                    if (containsParams)
                    {
                        writer.WriteStartElement(ATTRIBUTE_NODE_NAME);
                        writer.WriteAttributeString(NAME_ATTR_NAME, attribute.Name);
                        foreach (NetworkAttributeParameter parameter in attribute.Parameters)
                        {
                            writer.WriteStartElement(PARAM_NODE_NAME);
                            writer.WriteAttributeString(NAME_ATTR_NAME, parameter.Name);

                            object valueObj = null;
                            if (!solverSettings.GetNetworkAttributeParameterValue(attribute.Name,
                                                                                  parameter.Name,
                                                                                  out valueObj))
                                valueObj = null;

                            string value = _ConvertValue2String(valueObj);

                            writer.WriteAttributeString(VALUE_ATTR_NAME, value);
                            writer.WriteEndElement();
                        }
                        writer.WriteEndElement();
                    }
                }
                writer.WriteEndElement();
            }
        }
        /// <summary>
        /// Returns a reference to the <see cref="Tracker"/> class object.
        /// </summary>
        /// <param name="solver">The solver to be used by the returned tracker.</param>
        /// <param name="geocoder">The geocoder to be used by the returned tracker.</param>
        /// <param name="messageReporter">The messageReporter to be used by the returned
        /// tracker.</param>
        /// <returns>A new <see cref="Tracker"/> class instance.</returns>
        /// <exception cref="ArgumentNullException"><paramref name="solver"/>,
        /// <paramref name="geocoder"/> or <paramref name="messageReporter"/> is a null
        /// reference.</exception>
        public Tracker GetTracker(
            IVrpSolver solver,
            IGeocoder geocoder,
            IMessageReporter messageReporter)
        {
            CodeContract.RequiresNotNull("solver", solver);
            CodeContract.RequiresNotNull("geocoder", geocoder);
            CodeContract.RequiresNotNull("messageReporter", messageReporter);

            _CheckSettings(_settings);

            var settings = new TrackingSettings
            {
                BreakTolerance = _settings.TrackingSettings.BreakTolerance ?? 0,
            };

            var uri = new Uri(_settings.TrackingServiceInfo.RestUrl);
            var service = FeatureService.Create(uri, Server);
            var trackingServiceClient = new TrackingServiceClient(service);

            var trackingService = new TrackingServiceClient(service);
            var synchronizationService = new SynchronizationService(trackingServiceClient);

            return new Tracker(
                settings,
                trackingService,
                synchronizationService,
                solver,
                geocoder,
                messageReporter);
        }
Esempio n. 28
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Tracker"/> class.
        /// </summary>
        /// <param name="settings">Settings to be used by the tracker.</param>
        /// <param name="trackingService">The tracking service client to be used to communicate
        /// with the tracking server.</param>
        /// <param name="synchronizationService">The synchronization service to be used for
        /// synchronizing data in the project and at the tracking service.</param>
        /// <param name="solver">The VRP solver to be used by the tracker.</param>
        /// <param name="geocoder">The geocoder to be used by the tracker.</param>
        /// <param name="messageReporter">The message reporter to be used for reporting
        /// tracking errors.</param>
        /// <exception cref="ArgumentNullException"><paramref name="settings"/>,
        /// <paramref name="trackingService"/>, <paramref name="synchronizationService"/>,
        /// <paramref name="solver"/>, <paramref name="geocoder"/> or
        /// <paramref name="messageReporter"/> is a null reference.</exception>
        internal Tracker(
            TrackingSettings settings,
            ITrackingService trackingService,
            ISynchronizationService synchronizationService,
            IVrpSolver solver,
            IGeocoder geocoder,
            IMessageReporter messageReporter)
        {
            CodeContract.RequiresNotNull("settings", settings);
            CodeContract.RequiresNotNull("trackingService", trackingService);
            CodeContract.RequiresNotNull("synchronizationService", synchronizationService);
            CodeContract.RequiresNotNull("solver", solver);
            CodeContract.RequiresNotNull("geocoder", geocoder);
            CodeContract.RequiresNotNull("messageReporter", messageReporter);

            _settings = settings;
            _trackingService = trackingService;
            _synchronizationService = synchronizationService;

            _solver = solver;

            _geocoder = geocoder;
            _messageReporter = messageReporter;
        }