Example #1
0
        private static Way createWay(MiddleWay middleWay, double walkSpeedMps)
        {
            Way way = new Way();

            way.TotalTime          = TimeSpan.FromMinutes(middleWay.TotalTime);
            way.TotalTransferCount = middleWay.TotalTransfers;
            way.TotalWalkDistance  = middleWay.TotalWalk;
            way.LastWalkDistance   = middleWay.LastWalkDistance;
            way.walkSpeedMps       = walkSpeedMps;

            if (middleWay.Entries != null)
            {
                way.AddRange(middleWay.Entries.Select(
                                 mw => new Way.Entry(mw.Stops.Select(sID => App.TB.Stops[sID]))
                {
                    Route            = App.TB.Routes[mw.RouteID],
                    TripType         = App.TB.TripTypes[mw.TripTypeID],
                    StartStop        = App.TB.Stops[mw.StartStopID],
                    EndStop          = App.TB.Stops[mw.EndStopID],
                    StartTime        = TimeSpan.FromMinutes(mw.StartTimeMinutes),
                    EndTime          = TimeSpan.FromMinutes(mw.EndTimeMinutes),
                    WaitMinutes      = mw.WaitMinutes,
                    WalkBeforeMeters = mw.WalkBeforeMeters,
                    StopCount        = mw.Stops.Length - 1
                }
                                 ));
            }

            return(way);
        }
Example #2
0
        private async Task planning()
        {
            if (SourceText.Selected == null)
            {
                new MessageDialog(App.Common.Services.Resources.LocalizedStringOf("PlanningSourceEmpty")).ShowAsync();
                return;
            }
            if (TargetText.Selected == null)
            {
                new MessageDialog(App.Common.Services.Resources.LocalizedStringOf("PlanningTargetEmpty")).ShowAsync();
                return;
            }

            var source         = SourceText.Selected;
            var target         = TargetText.Selected;
            var pickedDateTime = DateTimePicker.Time;


            App.UB.History.AddPlanningHistory(source, true);
            App.UB.History.AddPlanningHistory(target, false);

            ResultList.ItemsSource().Clear();
            ResultBorder.Height         = 0;
            ProgressBar.IsIndeterminate = true;

            await App.TB.UsingFiles;

            Stopwatch watch = Stopwatch.StartNew();

            await Task.Run(() =>
            {
                try
                {
                    App.Planner.SetParams(new PlanningArgs
                    {
                        Type         = DateTimePicker.TimeType,
                        EnabledTypes = Convert(new bool[] { PlanSettingsModel.TramAllowed, PlanSettingsModel.MetroAllowed, PlanSettingsModel.UrbanTrainAllowed, PlanSettingsModel.BusAllowed, true, true, true, true }),
                        OnlyWheelchairAccessibleTrips = PlanSettingsModel.WheelchairAccessibleTrips,
                        OnlyWheelchairAccessibleStops = PlanSettingsModel.WheelchairAccessibleStops,
                        LatitudeDegreeDistance        = App.Config.LatitudeDegreeDistance,
                        LongitudeDegreeDistance       = App.Config.LongitudeDegreeDistance,
                        WalkSpeedRate = PlanSettingsModel.WalkingSpeed / 3.6 * 60
                    });
                }
                catch (Exception e)
                {
                    Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () => new MessageDialog(App.Common.Services.Resources.LocalizedStringOf("PlanningError")).ShowAsync());
                }
            });

            IEnumerable <PlanningAspect> aspects = new PlanningAspect[] { PlanningAspect.Time, PlanningAspect.TransferCount, PlanningAspect.WalkDistance };
            //aspects = aspects.Take(App.Config.PlanningAspectsCount);
            //aspects = aspects.Take(1);

            await Task.WhenAll(aspects.Select(async aspect =>
            {
                MiddleWay middleResult = await Task.Run(() =>
                {
                    try
                    {
                        return(App.Planner.CalculatePlanning(source.ID, target.ID, pickedDateTime.ToString(CultureInfo.InvariantCulture), aspect));
                    }
                    catch (Exception e)
                    {
                        Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () => new MessageDialog(App.Common.Services.Resources.LocalizedStringOf("PlanningError")).ShowAsync());
                        return(null);
                    }
                });
                if (middleResult != null)
                {
                    //new MessageDialog(middleResult.Message).ShowAsync();
                    Way result     = createWay(middleResult, PlanSettingsModel.WalkingSpeedInMps);
                    var resultList = ResultList.ItemsSource as ObservableCollection <WayModel>;
                    if (resultList.All(x => !x.Way.Equals(result)))
                    {
                        int i = 0;
                        while (i < resultList.Count && resultList[i].Way < result)
                        {
                            i++;
                        }
                        resultList.Insert(i, new WayModel(result, source, target, pickedDateTime));
                        ResultBorder.Height = double.NaN;
                    }
                }
            }));

            ProgressBar.IsIndeterminate = false;
            if (ResultList.ItemsSource().Count == 0)
            {
                new MessageDialog(App.Common.Services.Resources.LocalizedStringOf("PlanningNoResult")).ShowAsync();
            }
            else
            {
                TimeText.Text = string.Format("{0} ({1:0.##} sec)", App.Common.Services.Resources.LocalizedStringOf("PlanningTimeLabel"), watch.ElapsedMilliseconds / 1000.0);
                await Task.Delay(3000);

                TimeText.Text = "";
            }
        }