Exemple #1
0
        ///////////////////////////////////////////////////////////////////////////////////////////
        ///////////////////////////////////////////////////////////////////////////////////////////

        protected override void SetOrderAssignment(AttrDictionary attrs,
                                                   AssignedOrder assignedOrder)
        {
            if (assignedOrder.Route.IsLocked)
            {
                // order is assigned to a locked route
                attrs.Set(NAAttribute.ASSIGNMENT_RULE,
                          (int)NAOrderAssignmentRule.esriNAOrderExcludeFromSolve);
            }
            else if (assignedOrder.Stop.IsLocked)
            {
                // order is locked itself
                attrs.Set(NAAttribute.ROUTE_NAME, assignedOrder.Route.Id.ToString());
                attrs.Set(NAAttribute.SEQUENCE, assignedOrder.SequenceNumber);
                attrs.Set(NAAttribute.ASSIGNMENT_RULE,
                          (int)NAOrderAssignmentRule.esriNAOrderPreserveRouteAndRelativeSequence);
            }
            else
            {
                attrs.Set(NAAttribute.ROUTE_NAME, "");
                attrs.Set(NAAttribute.SEQUENCE, null);
                attrs.Set(NAAttribute.ASSIGNMENT_RULE,
                          (int)NAOrderAssignmentRule.esriNAOrderOverride);
            }
        }
Exemple #2
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);
        }
Exemple #3
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);
        }
Exemple #4
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);
        }
Exemple #5
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);
        }
Exemple #6
0
        private static bool _AttrToObjectId(string attrName, AttrDictionary attrs, out Guid id)
        {
            id = Guid.Empty;

            bool res = false;

            try
            {
                id  = new Guid(attrs.Get <string>(attrName));
                res = true;
            }
            catch { }

            return(res);
        }
        /// <summary>
        /// Tries to get value from the specified attribute dictionary for the
        /// specified key.
        /// </summary>
        /// <typeparam name="TValue">The type of the value to get from dictionary.</typeparam>
        /// <param name="dictionary">The reference to the attribute dictionary
        /// to get value from.</param>
        /// <param name="key">The key to get value for.</param>
        /// <returns>Value for the specified key or null if there is no such key
        /// in the dictionary.</returns>
        public static TValue?TryGet <TValue>(
            this AttrDictionary dictionary,
            string key)
            where TValue : struct
        {
            Debug.Assert(dictionary != null);

            TValue result;

            if (dictionary.TryGet(key, out result))
            {
                return(result);
            }

            return(null);
        }
        /// <summary>
        /// Gets comments for the specified stop built of the specified custom order properties.
        /// </summary>
        /// <param name="stop">The reference to the stop object to get comments for.</param>
        /// <param name="orderPropertiesToExport">The reference to the collection
        /// of custom order properties to be exported.</param>
        /// <returns>A string with comments for the specified stop or empty string if
        /// stop is not associated with an order.</returns>
        private static string _GetOrderComments(AttrDictionary commentsProperties)
        {
            Debug.Assert(commentsProperties != null);

            StringBuilder comments = new StringBuilder();

            foreach (var item in commentsProperties)
            {
                var value = item.Value;
                if (value != null && !string.IsNullOrEmpty(value.ToString()))
                {
                    comments.AppendLine(string.Format("{0}: {1}", item.Key, value));
                }
            }

            return(comments.ToString());
        }
Exemple #9
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);
        }
Exemple #10
0
        ///////////////////////////////////////////////////////////////////////////////////////////
        ///////////////////////////////////////////////////////////////////////////////////////////

        protected override void SetOrderAssignment(AttrDictionary attrs,
                                                   AssignedOrder assignedOrder)
        {
            if (!_unlockedOrdersToAssign.Contains(assignedOrder.Order))
            {
                attrs.Set(NAAttribute.ROUTE_NAME, assignedOrder.Route.Id.ToString());
                attrs.Set(NAAttribute.SEQUENCE, assignedOrder.SequenceNumber);
                attrs.Set(NAAttribute.ASSIGNMENT_RULE,
                          (int)NAOrderAssignmentRule.esriNAOrderPreserveRouteAndRelativeSequence);
            }
            else
            {
                attrs.Set(NAAttribute.ROUTE_NAME, "");
                attrs.Set(NAAttribute.SEQUENCE, null);
                attrs.Set(NAAttribute.ASSIGNMENT_RULE,
                          (int)NAOrderAssignmentRule.esriNAOrderOverride);
            }
        }
Exemple #11
0
        ///////////////////////////////////////////////////////////////////////////////////////////
        ///////////////////////////////////////////////////////////////////////////////////////////

        protected override void SetOrderAssignment(AttrDictionary attrs,
                                                   AssignedOrder assignedOrder)
        {
            if (assignedOrder.Route.IsLocked ||
                assignedOrder.Stop.IsLocked)
            {
                attrs.Set(NAAttribute.ROUTE_NAME, assignedOrder.Route.Id.ToString());
                attrs.Set(NAAttribute.SEQUENCE, assignedOrder.SequenceNumber);
                attrs.Set(NAAttribute.ASSIGNMENT_RULE,
                          (int)NAOrderAssignmentRule.esriNAOrderPreserveRouteAndRelativeSequence);
            }
            else
            {
                attrs.Set(NAAttribute.ROUTE_NAME, assignedOrder.Route.Id.ToString());
                attrs.Set(NAAttribute.SEQUENCE, assignedOrder.SequenceNumber);
                attrs.Set(NAAttribute.ASSIGNMENT_RULE,
                          (int)NAOrderAssignmentRule.esriNAOrderPreserveRoute);
            }
        }
Exemple #12
0
        /// <summary>
        /// Method fills TimeWindow attributes in correct format.
        /// </summary>
        /// <param name="routeBreak">Route break.</param>
        /// <param name="attrNameStart">Format string for Start TW.</param>
        /// <param name="attrNameEnd">Format string for End TW</param>
        /// <param name="attributes">Attributes to fill in.</param>
        private void _SetTimeWindowAttribute(Break routeBreak, string attrNameStart,
                                             string attrNameEnd, AttrDictionary attributes)
        {
            Debug.Assert(routeBreak != null);
            Debug.Assert(!string.IsNullOrEmpty(attrNameStart));
            Debug.Assert(!string.IsNullOrEmpty(attrNameEnd));

            var twBreak = routeBreak as TimeWindowBreak;

            var window = new TimeWindow
            {
                IsWideOpen = false,
                From       = twBreak.From,
                To         = twBreak.To,
                Day        = twBreak.Day
            };

            attributes.SetTimeWindow(window, _plannedDate, attrNameStart, attrNameEnd);
        }
        /// <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);
        }
        /// <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));
        }
Exemple #15
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);
        }