Пример #1
0
        /// <summary>
        /// Method gets stops date from route.
        /// </summary>
        /// <param name="route">Route to get information.</param>
        /// <returns>Collection of stops data.</returns>
        private List <StopData> _GetStops(Route route)
        {
            Debug.Assert(route != null);

            IDataObjectCollection <Stop> stops = route.Stops;
            int stopsCount = stops.Count;

            var stopDatas = new List <StopData>(stopsCount);

            for (int index = 0; index < stopsCount; ++index)
            {
                Stop stop = stops[index];

                StopData sd = new StopData();
                sd.SequenceNumber = stop.SequenceNumber;
                sd.Distance       = stop.Distance;
                sd.WaitTime       = stop.WaitTime;
                sd.TimeAtStop     = stop.TimeAtStop;
                sd.TravelTime     = stop.TravelTime;
                sd.ArriveTime     = (DateTime)stop.ArriveTime;

                if (stop.StopType == StopType.Lunch)
                {
                    // Break.

                    // ToDo - need update logic - now find only first TWBreak.
                    var twBreaks =
                        from currBreak in route.Breaks
                        where
                        currBreak is TimeWindowBreak
                        select currBreak;

                    TimeWindowBreak rtBreak = twBreaks.FirstOrDefault() as TimeWindowBreak;
                    if (rtBreak != null && rtBreak.Duration > 0.0)
                    {
                        // TODO Break

                        //// Time window.
                        //DateTime? twStart = null;
                        //DateTime? twEnd = null;
                        //if (rtBreak.TimeWindow != null)
                        //    _ConvertTW(rtBreak.TimeWindow, out twStart, out twEnd);
                        sd.TimeWindowStart1 = _TSToDate(rtBreak.From);
                        sd.TimeWindowEnd1   = _TSToDate(rtBreak.To);
                    }
                }
                else
                {
                    Debug.Assert(stop.AssociatedObject != null);

                    // Associated object id.
                    sd.AssociatedObject = stop.AssociatedObject;

                    // Geometry.
                    Point pt = _GetStopPoint(stop);
                    sd.Geometry = GPObjectHelper.PointToGPPoint(pt);

                    // Time windows.
                    DateTime?twStart1 = null;
                    DateTime?twStart2 = null;
                    DateTime?twEnd1   = null;
                    DateTime?twEnd2   = null;

                    // Type-specific data.
                    if (stop.StopType == StopType.Order)
                    {
                        Order order = stop.AssociatedObject as Order;
                        Debug.Assert(order != null);

                        // Curbapproach.
                        sd.NACurbApproach =
                            CurbApproachConverter.ToNACurbApproach(
                                _context.SolverSettings.GetDepotCurbApproach());

                        // Time window 1.
                        if (order.TimeWindow != null)
                        {
                            _ConvertTW(order.TimeWindow, out twStart1, out twEnd1);
                        }

                        // Time window 2.
                        if (order.TimeWindow2 != null)
                        {
                            _ConvertTW(order.TimeWindow2, out twStart2, out twEnd2);
                        }
                    }
                    else if (stop.StopType == StopType.Location)
                    {
                        Location loc = stop.AssociatedObject as Location;
                        Debug.Assert(loc != null);

                        // Time window.
                        if (loc.TimeWindow != null)
                        {
                            _ConvertTW(loc.TimeWindow, out twStart1, out twEnd1);
                        }
                    }

                    sd.TimeWindowStart1 = twStart1;
                    sd.TimeWindowStart2 = twStart2;
                    sd.TimeWindowEnd1   = twEnd1;
                    sd.TimeWindowEnd2   = twEnd2;
                }

                sd.RouteId  = route.Id;
                sd.StopType = stop.StopType;
                stopDatas.Add(sd);
            }

            SolveHelper.ConsiderArrivalDelayInStops(
                _context.SolverSettings.ArriveDepartDelay, stopDatas);

            return(stopDatas);
        }
Пример #2
0
        ///////////////////////////////////////////////////////////////////////////////////////////
        ///////////////////////////////////////////////////////////////////////////////////////////
        ///////////////////////////////////////////////////////////////////////////////////////////

        /// <summary>
        /// Builds stop features.
        /// </summary>
        /// <param name="stops">Stops.</param>
        /// <returns>Created route stops recordset for stops.</returns>
        private RouteStopsRecordSet _BuildStopFeatures(IList <StopData> stops)
        {
            Debug.Assert(stops != null);

            // Sort stops respecting sequence.
            var sortedStops = new List <StopData>(stops);

            SolveHelper.SortBySequence(sortedStops);

            Debug.Assert(_context != null);

            SolveHelper.ConsiderArrivalDelayInStops(
                _context.SolverSettings.ArriveDepartDelay, sortedStops);

            // Format impedance attribute name.
            string impedanceAttrName = null;

            if (!string.IsNullOrEmpty(_context.NetworkDescription.ImpedanceAttributeName))
            {
                impedanceAttrName = string.Format(IMPEDANCE_ATTR_FORMAT,
                                                  _context.NetworkDescription.ImpedanceAttributeName);
            }

            var features = new List <GPFeature>();

            for (int index = 0; index < sortedStops.Count; ++index)
            {
                var feature = new GPFeature();

                // Attributes.
                feature.Attributes = new AttrDictionary();

                StopData sd = sortedStops[index];

                Guid objectId = Guid.Empty;
                if (sd.AssociatedObject != null)
                {
                    objectId = sd.AssociatedObject.Id;
                }

                feature.Attributes.Add(NAAttribute.NAME, objectId.ToString());
                feature.Attributes.Add(NAAttribute.ROUTE_NAME, sd.RouteId.ToString());

                // Effective time window.
                DateTime?twStart = null;
                DateTime?twEnd   = null;
                _GetEffectiveTW(sd, out twStart, out twEnd); // NOTE: ignore result
                feature.Attributes.Add(NAAttribute.TW_START, _FormatStopTime(twStart));
                feature.Attributes.Add(NAAttribute.TW_END, _FormatStopTime(twEnd));

                // Service time.
                if (impedanceAttrName != null)
                {
                    feature.Attributes.Add(impedanceAttrName, sd.TimeAtStop);
                }

                var geometry = new GeometryHolder();
                geometry.Value = sd.Geometry;

                if (sd.StopType == StopType.Lunch)
                {
                    var actualStop = SolveHelper.GetActualLunchStop(sortedStops, index);
                    geometry.Value = actualStop.Geometry;
                }

                // Set curb approach.
                var curbApproach = CurbApproachConverter.ToNACurbApproach(
                    _context.SolverSettings.GetOrderCurbApproach());
                if (sd.StopType == StopType.Location)
                {
                    curbApproach = CurbApproachConverter.ToNACurbApproach(
                        _context.SolverSettings.GetDepotCurbApproach());
                }

                feature.Attributes.Add(NAAttribute.CURB_APPROACH, (int)curbApproach);
                feature.Geometry = geometry;

                features.Add(feature);
            }

            var rs = new RouteStopsRecordSet();

            rs.Features = features.ToArray();

            // TODO: will be changed later when support custom AddLocations tool
            rs.DoNotLocateOnRestrictedElements = _context.SolverSettings.ExcludeRestrictedStreets;

            return(rs);
        }