Exemplo n.º 1
0
        /// <summary>
        /// Method gets Drive Time break attributes.
        /// </summary>
        /// <param name="driveTimeBreak">Break.</param>
        /// <param name="cumulServiceTime">Accumulated breaks service time.</param>
        /// <returns>Attributes of Drive Time break.</returns>
        private AttrDictionary _GetDriveTimeBreakAttributes(
            DriveTimeBreak driveTimeBreak, ref double cumulServiceTime)
        {
            Debug.Assert(driveTimeBreak != null);

            AttrDictionary attrs = new AttrDictionary();

            // Convert to Time units.
            double timeInUnits = _ConvertTimeInterval(driveTimeBreak.TimeInterval);

            // Consider accumulated breaks service time for current break.
            double actualTravelTime = timeInUnits - cumulServiceTime;

            cumulServiceTime += actualTravelTime;

            // The maximum amount of drive time that can be
            // accumulated before the break is taken.
            if (actualTravelTime > 0)
            {
                attrs.Add(NAAttribute.MaxTravelTimeBetweenBreaks, actualTravelTime);
            }

            attrs.Add(NAAttribute.SERVICE_TIME, driveTimeBreak.Duration);

            return(attrs);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Method gets attributes for barriers.
        /// </summary>
        /// <param name="barrier">Barrier to set attributes for.</param>
        /// <param name="barrierType">Barrier type.</param>
        /// <returns>Attributes for barrier.</returns>
        private AttrDictionary _GetAttributes(Barrier barrier,
                                              BarrierGeometryType barrierType)
        {
            // Fill common barriers attributes.
            var attr = new AttrDictionary();

            attr.Add(NAAttribute.NAME, barrier.Id.ToString());

            // Adjust type and time attributes for Polygon barriers.
            if (barrierType == BarrierGeometryType.Polygon)
            {
                if (barrier.BarrierEffect.BlockTravel == false)
                {
                    attr.Add(NAAttribute.BarrierType, (int)NABarrierType.esriBarrierScaledCost);
                }
                else
                {
                    attr.Add(NAAttribute.BarrierType, (int)NABarrierType.esriBarrierRestriction);
                }

                double timeFactor = _GetTimeFactor(barrier.BarrierEffect.SpeedFactorInPercent);

                attr.Add(NAAttribute.AttributeTimeScale, timeFactor);
            }
            // Adjust type and time attributes for Polyline barriers.
            else if (barrierType == BarrierGeometryType.Polyline)
            {
                attr.Add(NAAttribute.BarrierType, (int)NABarrierType.esriBarrierRestriction);
            }
            // Adjust type and time attributes for Point barriers.
            else if (barrierType == BarrierGeometryType.Point)
            {
                if (barrier.BarrierEffect.BlockTravel == false)
                {
                    attr.Add(NAAttribute.BarrierType, (int)NABarrierType.esriBarrierAddedCost);
                }
                else
                {
                    attr.Add(NAAttribute.BarrierType, (int)NABarrierType.esriBarrierRestriction);
                }

                attr.Add(NAAttribute.FullEdge, false);
                attr.Add(NAAttribute.CURB_APPROACH,
                         (int)NACurbApproachType.esriNAEitherSideOfVehicle);

                attr.Add(NAAttribute.AttributeTimeDelay, barrier.BarrierEffect.DelayTime);
            }
            else
            {
                // Not supported type of barrier.
                Debug.Assert(false);
            }

            return(attr);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Method gets Common breaks attributes.
        /// </summary>
        /// <param name="routeId">Route id to be appointed break.</param>
        /// <param name="precedence">Break precedence.</param>
        /// <param name="attrs">Attributes to fill in.</param>
        private void _FillCommonGPBreakAttributes(Guid routeId,
                                                  int precedence, AttrDictionary attrs)
        {
            Debug.Assert(routeId != null);
            Debug.Assert(precedence >= 1);

            attrs.Add(NAAttribute.ROUTE_NAME, routeId.ToString());
            attrs.Add(NAAttribute.Precedence, precedence);

            // Paid break flag is not used in ALR, the breaks are treated as paid.
            attrs.Add(NAAttribute.IsPaid, (int)NABool.True);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Method gets Work Time break attributes.
        /// </summary>
        /// <param name="workTimeBreak">Break.</param>
        /// <returns>Attributes of Work Time break.</returns>
        private AttrDictionary _GetWorkTimeBreakAttributes(WorkTimeBreak workTimeBreak)
        {
            Debug.Assert(workTimeBreak != null);

            AttrDictionary attrs = new AttrDictionary();

            attrs.Add(NAAttribute.MaxCumulWorkTime,
                      _ConvertTimeInterval(workTimeBreak.TimeInterval));

            attrs.Add(NAAttribute.SERVICE_TIME, workTimeBreak.Duration);

            return(attrs);
        }
Exemplo n.º 5
0
        /// <summary>
        /// Method gets Time Window break attributes.
        /// </summary>
        /// <param name="currentBreak">Current break.</param>
        /// <returns>Attributes of Time Window break.</returns>
        private AttrDictionary _GetTimeWindowBreakAttributes(Break currentBreak)
        {
            Debug.Assert(currentBreak != null);

            AttrDictionary attrs = new AttrDictionary();

            // Break Time Window.
            _SetTimeWindowAttribute(currentBreak, NAAttribute.TW_START,
                                    NAAttribute.TW_END, attrs);

            // Max violation time is 0, which means route has a hard Time Window.
            attrs.Add(NAAttribute.MAX_VIOLATION_TIME, 0.0);

            attrs.Add(NAAttribute.SERVICE_TIME, currentBreak.Duration);

            return(attrs);
        }
        /// <summary>
        /// Sets time window attributes with specified names in the specified attributes dictionary.
        /// </summary>
        /// <param name="dictionary">The dictionary to set attributes for.</param>
        /// <param name="window">The time window to get attribute values from.</param>
        /// <param name="plannedDate">The date/time when time window should be applied.</param>
        /// <param name="timeWindowStartAttribute">The name of the time window start
        /// attribute.</param>
        /// <param name="timeWindowEndAttribute">The name of the time window end
        /// attribute.</param>
        public static void SetTimeWindow(
            this AttrDictionary dictionary,
            TimeWindow window,
            DateTime plannedDate,
            string timeWindowStartAttribute,
            string timeWindowEndAttribute)
        {
            Debug.Assert(dictionary != null);
            Debug.Assert(window != null);
            Debug.Assert(!string.IsNullOrEmpty(timeWindowStartAttribute));
            Debug.Assert(!string.IsNullOrEmpty(timeWindowEndAttribute));

            if (window.IsWideOpen)
            {
                dictionary.Set(timeWindowStartAttribute, null);
                dictionary.Set(timeWindowEndAttribute, null);

                return;
            }

            // Time window is not wide-open so we apply it to the specified planned date and
            // attribute values in the dictionary.
            var dates = window.ToDateTime(plannedDate);

            var from = dates.Item1.Value;

            dictionary.Add(
                timeWindowStartAttribute,
                GPObjectHelper.DateTimeToGPDateTime(from));

            var to = dates.Item2.Value;

            dictionary.Add(
                timeWindowEndAttribute,
                GPObjectHelper.DateTimeToGPDateTime(to));
        }
Exemplo n.º 7
0
        /// <summary>
        /// Gets properties dictionary for the specified stop built of the specified order property
        /// info objects.
        /// </summary>
        /// <param name="stop">The reference to the stop object to get properties for.</param>
        /// <param name="orderPropertiesToExport">The reference to the collection
        /// of custom order properties to be exported.</param>
        /// <returns>A dictionary with properties for an order associated with the specified
        /// stop.</returns>
        private static AttrDictionary _GetOrderProperties(
            Stop stop,
            IEnumerable <OrderPropertyInfo> orderPropertiesToExport)
        {
            Debug.Assert(stop != null);
            Debug.Assert(orderPropertiesToExport != null);
            Debug.Assert(orderPropertiesToExport.All(info => info != null));

            var properties = new AttrDictionary();
            var order      = stop.AssociatedObject as Order;

            if (order == null)
            {
                return(properties);
            }

            object value = null;

            foreach (var info in orderPropertiesToExport)
            {
                if (info.Name == Order.PropertyNamePlannedDate)
                {
                    value = stop.ArriveTime;
                }
                else
                {
                    value = Order.GetPropertyValue(order, info.Name);
                }

                if (value != null && value.ToString().Length > 0)
                {
                    properties.Add(info.Title, value);
                }
            }

            return(properties);
        }
Exemplo n.º 8
0
        /// <summary>
        /// Method do conversion of separate route Breaks to GP Breaks collection.
        /// </summary>
        /// <param name="routeBreaks">Route breaks.</param>
        /// <param name="route">Route, to which breaks belong to.</param>
        /// <param name="addSequence">Flag, showing that we must add
        /// sequence attribute to break GP feature.</param>
        /// <returns>GP Breaks collection.</returns>
        private List <GPFeature> _ConvertToGPBreaks(Breaks routeBreaks, Route route, bool addSequence)
        {
            Debug.Assert(routeBreaks != null);
            Debug.Assert(route != null);

            List <GPFeature> features = new List <GPFeature>();

            routeBreaks.Sort();

            // Precedence should always start from 1.
            int    precedence            = 1;
            double cumulBreakServiceTime = 0;

            // Get feature collections of route breaks.
            foreach (Break currentBreak in routeBreaks)
            {
                GPFeature      feature = new GPFeature();
                AttrDictionary attrs   = new AttrDictionary();

                if ((currentBreak != null) && (currentBreak.Duration > 0.0))
                {
                    // Get specific attributes for every break type.
                    if (currentBreak is TimeWindowBreak)
                    {
                        attrs = _GetTimeWindowBreakAttributes(currentBreak);
                    }
                    else if (currentBreak is DriveTimeBreak)
                    {
                        DriveTimeBreak driveTimeBreak = currentBreak as DriveTimeBreak;
                        attrs = _GetDriveTimeBreakAttributes(driveTimeBreak,
                                                             ref cumulBreakServiceTime);
                    }
                    else if (currentBreak is WorkTimeBreak)
                    {
                        WorkTimeBreak workTimeBreak = currentBreak as WorkTimeBreak;
                        attrs = _GetWorkTimeBreakAttributes(workTimeBreak);
                    }
                    else
                    {
                        // Unsupported breaks type.
                        Debug.Assert(false);
                    }

                    // Get common attributes.
                    _FillCommonGPBreakAttributes(route.Id, precedence++, attrs);

                    // Add sequence atribute if we must to.
                    if (addSequence)
                    {
                        var sequenceNumber = _GetSequenceNumber(route, currentBreak);
                        attrs.Add(NAAttribute.SEQUENCE, sequenceNumber);
                    }

                    feature.Attributes = attrs;
                }

                features.Add(feature);
            }

            return(features);
        }