コード例 #1
0
ファイル: Break.cs プロジェクト: valuecreation/RoutePlanner
        /// <summary>
        /// Check that both breaks have same types and same duration.
        /// </summary>
        /// <param name="breakObject">Brake to compare with this.</param>
        /// <returns>'True' if second break isnt null and breaks
        /// types and durations are the same, 'false' otherwise.</returns>
        internal virtual bool EqualsByValue(Break breakObject)
        {
            // If second break is null - breaks are not equal.
            if (breakObject == null)
            {
                return(false);
            }

            // Check type and duration.
            return(this.GetType() == breakObject.GetType() && this.Duration == breakObject.Duration);
        }
コード例 #2
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;
            }
        }
コード例 #3
0
        /// <summary>
        /// Method creates time windows from route break.
        /// </summary>
        /// <param name="routeBreak">Route break to get time information.</param>
        /// <returns>Time Window.</returns>
        private TimeWindow _GetBreakTimeWindow(Break routeBreak)
        {
            TimeWindow breakTimeWindow = new TimeWindow
            {
                IsWideOpen = true
            };

            if (routeBreak is TimeWindowBreak)
            {
                var twBreak = routeBreak as TimeWindowBreak;
                breakTimeWindow.From = twBreak.From;
                breakTimeWindow.To = twBreak.To;
                breakTimeWindow.IsWideOpen = false;
            }
            else
            {
                // Do nothing: any another break types have
                // wideopen time windows.
            }

            return breakTimeWindow;
        }
コード例 #4
0
        /// <summary>
        /// Method creates stop from break GP feature.
        /// </summary>
        /// <param name="feature">Break GP feature</param>
        /// <param name="route">Route.</param>
        /// <param name="routeBreak">Break from route.</param>
        /// <param name="stop">Stop data to fill.</param>
        /// <returns>True - if successfully created, otherwise - False.</returns>
        private bool _CreateStopFromBreak(GPFeature feature, Route route,
            Break routeBreak, out StopData stop)
        {
            Debug.Assert(feature != null);
            Debug.Assert(route != null);
            Debug.Assert(routeBreak != null);

            // Check sequence number.
            int sequenceNumber = 0;

            if (!feature.Attributes.TryGet<int>(NAAttribute.SEQUENCE, out sequenceNumber)
                // Sequence always starts from 1. Otherwise: this is empty break.
                || sequenceNumber == 0)
            {
                stop = null;
                return false;
            }

            stop = new StopData();
            stop.SequenceNumber = sequenceNumber;

            // Distance.
            stop.Distance = feature.Attributes.Get<double>(NAAttribute.FROM_PREV_DISTANCE);

            // Wait time.
            stop.WaitTime = feature.Attributes.Get<double>(NAAttribute.WAIT_TIME, 0.0);

            // Service time.
            stop.TimeAtStop = routeBreak.Duration;

            // Travel time.
            stop.TravelTime =
                feature.Attributes.Get<double>(NAAttribute.FROM_PREV_TRAVEL_TIME, 0.0);

            // Time Windows for break stop.
            var breakTimeWindow = _GetBreakTimeWindow(routeBreak);
            var plannedDate = route.Schedule.PlannedDate.Value;

            var timeWindow = breakTimeWindow.ToDateTime(plannedDate);
            stop.TimeWindowStart1 = timeWindow.Item1;
            stop.TimeWindowEnd1 = timeWindow.Item2;

            // Arrive time.
            var arriveTime = _TryGet(feature.Attributes, NAAttribute.ARRIVE_TIME);

            if (!arriveTime.HasValue)
            {
                arriveTime = stop.TimeWindowStart1;
            }

            arriveTime = arriveTime.AddMinutes(stop.WaitTime);

            stop.ArriveTime = arriveTime.Value;

            // Route id.
            stop.RouteId = _AttrToObjectId(NAAttribute.ROUTE_NAME, feature.Attributes);

            // Geometry:
            // There is no geometry for breaks.

            // Curb approach.
            stop.NACurbApproach = NACurbApproachType.esriNAEitherSideOfVehicle;

            // Stop type.
            stop.StopType = StopType.Lunch;

            // Break stop does not have an associated object.
            stop.AssociatedObject = null;

            return true;
        }
コード例 #5
0
 /// <summary>
 /// Check that both breaks have same types and same Duration and TimeInterval values.
 /// </summary>
 /// <param name="breakObject">Brake to compare with this.</param>
 /// <returns>'True' if breaks types and  Duration and TimeInterval
 /// values are the same, 'false' otherwise.</returns>
 internal override bool EqualsByValue(Break breakObject)
 {
     TimeIntervalBreak breakToCompare = breakObject as TimeIntervalBreak;
     return breakToCompare != null && base.EqualsByValue(breakObject) &&
         breakToCompare.TimeInterval == this.TimeInterval;
 }
コード例 #6
0
ファイル: Break.cs プロジェクト: erindm/route-planner-csharp
        /// <summary>
        /// Check that both breaks have same types and same duration.
        /// </summary>
        /// <param name="breakObject">Brake to compare with this.</param>
        /// <returns>'True' if second break isnt null and breaks 
        /// types and durations are the same, 'false' otherwise.</returns>
        internal virtual bool EqualsByValue(Break breakObject)
        {
            // If second break is null - breaks are not equal.
            if (breakObject == null)
                return false;

            // Check type and duration.
            return this.GetType() == breakObject.GetType() && this.Duration == breakObject.Duration;
        }
コード例 #7
0
 /// <summary>
 /// Check that both breaks have same types and same Duration, To and From values.
 /// </summary>
 /// <param name="breakObject">Brake to compare with this.</param>
 /// <returns>'True' if breaks types and  Duration, To and From
 /// values are the same, 'false' otherwise.</returns>
 internal override bool EqualsByValue(Break breakObject)
 {
     TimeWindowBreak breakToCompare = breakObject as TimeWindowBreak;
     return breakToCompare != null && base.EqualsByValue(breakObject) &&
         breakToCompare.From == this.From && breakToCompare.To == this.To;
 }
コード例 #8
0
        /// <summary>
        /// Add break in default breaks collection and select added break.
        /// </summary>
        /// <param name="breakObject"></param>
        private void _AddAndSelect(Break breakObject)
        {
            // Add break and save project.
            App.Current.Project.BreaksSettings.DefaultBreaks.Add(breakObject);
            App.Current.Project.Save();

            // Break added, need to sort breaks.
            _InitDataGridCollection();

            // Selecting added break.
            List<Break> list = new List<Break>();
            list.Add(breakObject);
            _isEditingInProgress = false;
            Select(list);
        }
コード例 #9
0
        /// <summary>
        /// Returns index of Break in breaks collection.
        /// </summary>
        /// <param name="breaks"><c>Breaks</c>.</param>
        /// <param name="br"><c>Break</c>.</param>
        /// <returns>Index of break if break is in Breaks and -1 if not.</returns>
        public static int IndexOf(Breaks breaks, Break br)
        {
            for (int i = 0; i < breaks.Count; i++)
                if (breaks[i] as Break == br)
                    return i;

            // If no such break - return -1.
            return -1;
        }