コード例 #1
0
        /// <summary>
        /// Comparison for two Brakes.
        /// </summary>
        /// <param name="break1">First <c>Brake</c>.</param>
        /// <param name="break2">Second <c>Brake</c>.</param>
        /// <returns>-1 if first break less then second, 0 if they are equal
        /// and 1 if first break more then second. </returns>
        public static int Compare(Break break1, Break break2)
        {
            // If first break == null.
            if (break1 == null)
            {
                if (break2 == null)
                {
                    return(0);
                }
                else
                {
                    return(-1);
                }
            }
            else if (break2 == null)
            {
                return(1);
            }

            // If both not null.
            if (break1.GetType() != break2.GetType())
            {
                return(0); // Breaks are not of the same type, cant compare.
            }
            else if (break1.GetType() == typeof(TimeWindowBreak))
            {
                TimeWindowBreak br1 = break1 as TimeWindowBreak;
                TimeWindowBreak br2 = break2 as TimeWindowBreak;

                return(_TimeWindowBreakComparer(br1, br2));
            }
            else if (break1.GetType() == typeof(WorkTimeBreak))
            {
                WorkTimeBreak br1 = break1 as WorkTimeBreak;
                WorkTimeBreak br2 = break2 as WorkTimeBreak;

                return(_WorkTimeBreakComparer(br1, br2));
            }
            else if (break1.GetType() == typeof(DriveTimeBreak))
            {
                DriveTimeBreak br1 = break1 as DriveTimeBreak;
                DriveTimeBreak br2 = break2 as DriveTimeBreak;

                return(_DriveTimeBreakComparer(br1, br2));
            }
            else
            {
                // Breaks are of unknown type, cant compare them.
                Debug.Assert(false);
                return(0);
            }
        }
コード例 #2
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);
        }
コード例 #3
0
 /// <summary>
 /// Comparer for two <c>WorkTimeBrakes</c>.
 /// </summary>
 /// <param name="break1">First <c>Brake</c>.</param>
 /// <param name="break2">Second <c>Brake</c>.</param>
 /// <returns>Result of comapring. Breaks are comapred by timeinterval.</returns>
 private static int _WorkTimeBreakComparer(WorkTimeBreak break1, WorkTimeBreak break2)
 {
     if (break1.TimeInterval > break2.TimeInterval)
     {
         return(1);
     }
     else if (break1.TimeInterval < break2.TimeInterval)
     {
         return(-1);
     }
     else
     {
         return(0);
     }
 }
コード例 #4
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);
        }