Beispiel #1
0
        private void Application_Startup(object sender, StartupEventArgs e)
        {
            ErrorReportingService.Initialize();

            Trace.WriteLine("App Application_Startup");

            if (!SingleInstanceAppMutex.TakeExclusivity())
            {
                Trace.WriteLine("App Application_Startup TakeExclusivity failed");
                Current.Shutdown();
                return;
            }

            ((ThemeManager)Resources["ThemeManager"]).SetTheme(ThemeData.GetBrushData());

            var deviceManager = DataModelFactory.CreateAudioDeviceManager();

            DiagnosticsService.Advise(deviceManager);

            _viewModel        = new MainViewModel(deviceManager);
            _viewModel.Ready += MainViewModel_Ready;

            _flyoutWindow = new FlyoutWindow(_viewModel, new FlyoutViewModel(_viewModel));
            _trayIcon     = new TrayIcon(new TrayViewModel(_viewModel));

            HotkeyService.Register(SettingsService.Hotkey);
            HotkeyService.KeyPressed += (_, __) => _viewModel.OpenFlyout();

            StartupUWPDialogDisplayService.ShowIfAppropriate();

            Trace.WriteLine($"App Application_Startup Exit");
        }
        public void RemoveRange(IEnumerable <Entities.SearchItemCategory> searchItemCategories)
        {
            if (searchItemCategories == null)
            {
                throw new ArgumentNullException("searchItemCategories");
            }

            base.DbSet.DeleteAllOnSubmit(searchItemCategories.Select(x => DataModelFactory.Create(x)));
        }
        public void InsertRange(IEnumerable <Entities.SearchItemCategory> searchItemCategories)
        {
            if (searchItemCategories == null)
            {
                throw new ArgumentNullException("searchItemCategories");
            }

            base.DbSet.InsertAllOnSubmit(DataModelFactory.Create(searchItemCategories));
        }
        public void RemoveRange(IEnumerable <Entities.PlaceOfInterestCategory> placeOfInterestCategories)
        {
            if (placeOfInterestCategories == null)
            {
                throw new ArgumentNullException("placeOfInterestCategories");
            }

            base.DbSet.DeleteAllOnSubmit(placeOfInterestCategories.Select(x => DataModelFactory.Create(x)));
        }
        public void InsertRange(IEnumerable <Entities.PlaceOfInterestCategory> placeOfInterestCategories)
        {
            if (placeOfInterestCategories == null)
            {
                throw new ArgumentNullException("placeOfInterestCategories");
            }

            base.DbSet.InsertAllOnSubmit(DataModelFactory.Create(placeOfInterestCategories));
        }
Beispiel #6
0
        public void Insert(Entities.Recent recentTrip)
        {
            if (base.DbSet.Any(x => x.Latitude == recentTrip.Point.Latitude && x.Longitude == recentTrip.Point.Longitude))
            {
                Recent existingRecentTrip = base.DbSet.Where(x => x.Latitude == recentTrip.Point.Latitude && x.Longitude == recentTrip.Point.Longitude).FirstOrDefault();

                existingRecentTrip.NumberOfUses += 1;
                existingRecentTrip.LastUsedDate  = recentTrip.LastUsedDate;
            }
            else
            {
                base.DbSet.InsertOnSubmit(DataModelFactory.Create(recentTrip));
            }
        }
        public override void PrintView()
        {
            var metricsPath =
                Path.Combine(Path.Combine(Simulation.Params.CurrentSimulationLoggerPath, @"algorithmMetrics.csv"));
            var algorithmsLogger = new Logger.Logger(new FileRecorder(Path.Combine(Path.Combine(Simulation.Params.CurrentSimulationLoggerPath, @"algorithms.csv"))));
            var dataSetLogger    = new Logger.Logger(new FileRecorder(Path.Combine(Simulation.Params.CurrentSimulationLoggerPath, @"algorithmsDataset.csv"), "DataModelId,CustomersNumber,VehicleNumber,MaxRideTimeDurationInMinutes,MaxAllowedUpperBoundLimitInMinutes,Seed"));
            var vehicleNumber    = 20;
            var count            = 0;

            //var algorithmsMetrics = new AlgorithmMetrics();
            Simulation.Params.VehicleNumber = vehicleNumber;
            for (int customersNumber = 25; customersNumber <= 100; customersNumber = customersNumber + 25)
            {
                Simulation.Params.NumberInitialRequests = customersNumber;
                for (int i = 0; i < 10; i++) // tests 10 different data models
                {
                    bool allowDropNodes = false;
                    RandomNumberGenerator.GenerateNewRandomSeed();
                    var dataModel     = DataModelFactory.Instance().CreateInitialSimulationDataModel(allowDropNodes, Simulation);
                    var printableList = dataModel.GetSettingsPrintableList();
                    ConsoleLogger.Log(printableList);
                    dataSetLogger.Log(dataModel.GetCSVSettingsMessage());
                    for (int searchTime = 5; searchTime <= 90; searchTime = searchTime + 5) //test different same datamodel with different search times
                    {
                        AlgorithmContainer algorithmContainer = new AlgorithmContainer();
                        foreach (var searchAlgorithm in algorithmContainer.SearchAlgorithms)
                        {
                            var algorithm = new SearchAlgorithm(searchAlgorithm, searchTime);
                            algorithm.Test(dataModel, allowDropNodes);
                            ConsoleLogger.Log(algorithm.GetResultPrintableList());

                            if (count == 0)
                            {
                                //logs base message type style
                                algorithmsLogger.Log(algorithm.GetCSVMessageStyle());
                            }
                            algorithmsLogger.Log(algorithm.GetCSVResultsMessage());
                            count++;
                        }
                    }
                }
            }

            //algorithmsMetrics.SaveMetrics(metricsPath);
        }
Beispiel #8
0
        public void InitializeFlexibleSimulation(bool allowDropNodes)
        {
            var dataModel = DataModelFactory.Instance().CreateInitialSimulationDataModel(allowDropNodes, this);

            if (dataModel != null)
            {
                RoutingSolver routingSolver = new RoutingSolver(dataModel, false);
                var           printableList = dataModel.GetSettingsPrintableList();
                foreach (var tobePrinted in printableList)
                {
                    Console.WriteLine(tobePrinted);
                }
                //dataModel.PrintDataStructures();
                Assignment timeWindowSolution            = null;
                RoutingSearchParameters searchParameters =
                    operations_research_constraint_solver.DefaultRoutingSearchParameters();
                searchParameters.FirstSolutionStrategy =
                    FirstSolutionStrategy.Types.Value.ParallelCheapestInsertion;
                searchParameters.LocalSearchMetaheuristic = LocalSearchMetaheuristic.Types.Value.TabuSearch;
                searchParameters.TimeLimit = new Duration {
                    Seconds = 20
                };
                timeWindowSolution = routingSolver.TryGetSolution(searchParameters);


                RoutingSolutionObject routingSolutionObject = null;
                if (timeWindowSolution != null)
                {
                    routingSolver.PrintSolution(timeWindowSolution);

                    routingSolutionObject = routingSolver.GetSolutionObject(timeWindowSolution);
                    for (int j = 0; j < routingSolutionObject.VehicleNumber; j++) //Initializes the flexible trips
                    {
                        var solutionVehicle          = routingSolutionObject.IndexToVehicle(j);
                        var solutionVehicleStops     = routingSolutionObject.GetVehicleStops(solutionVehicle);
                        var solutionTimeWindows      = routingSolutionObject.GetVehicleTimeWindows(solutionVehicle);
                        var solutionVehicleCustomers = routingSolutionObject.GetVehicleCustomers(solutionVehicle);
                        InitializeVehicleFlexibleRoute(solutionVehicle, solutionVehicleStops, solutionVehicleCustomers, solutionTimeWindows);
                    }
                }
            }
            Simulate();
        }
Beispiel #9
0
        private void Application_Startup(object sender, StartupEventArgs e)
        {
            ErrorReportingService.Initialize();

            Trace.WriteLine("App Application_Startup");

            if (!SingleInstanceAppMutex.TakeExclusivity())
            {
                Trace.WriteLine("App Application_Startup TakeExclusivity failed");
                Current.Shutdown();
                return;
            }

            ((ThemeManager)Resources["ThemeManager"]).SetTheme(ThemeData.GetBrushData());

            PlaybackDevicesViewModel        = new DeviceCollectionViewModel(DataModelFactory.CreateAudioDeviceManager(AudioDeviceKind.Playback));
            PlaybackDevicesViewModel.Ready += MainViewModel_Ready;

            FlyoutViewModel = new FlyoutViewModel(PlaybackDevicesViewModel);
            FlyoutWindow    = new FlyoutWindow(FlyoutViewModel);

            TrayViewModel              = new TrayViewModel(PlaybackDevicesViewModel);
            TrayViewModel.LeftClick    = new RelayCommand(() => FlyoutViewModel.OpenFlyout(FlyoutShowOptions.Pointer));
            TrayViewModel.OpenMixer    = new RelayCommand(OpenMixer);
            TrayViewModel.OpenSettings = new RelayCommand(OpenSettings);

            _trayIcon = new TrayIcon(TrayViewModel);
            FlyoutWindow.DpiChanged += (_, __) => TrayViewModel.DpiChanged();

            HotkeyManager.Current.Register(SettingsService.Hotkey);
            HotkeyManager.Current.KeyPressed += (hotkey) =>
            {
                if (hotkey.Equals(SettingsService.Hotkey))
                {
                    FlyoutViewModel.OpenFlyout(FlyoutShowOptions.Keyboard);
                }
            };

            StartupUWPDialogDisplayService.ShowIfAppropriate();

            Trace.WriteLine($"App Application_Startup Exit");
        }
Beispiel #10
0
        public bool Insert(Entities.Favourite favourite)
        {
            if (Exists(favourite))
            {
                return(false);
            }

            Recent existingRecentTrip = base.DbSet.Where(x => x.Latitude == favourite.Point.Latitude && x.Longitude == favourite.Point.Longitude).FirstOrDefault();

            if (existingRecentTrip != null)
            {
                existingRecentTrip.IsFavourite = true;
            }
            else
            {
                base.DbSet.InsertOnSubmit(DataModelFactory.Create(favourite));
            }

            return(true);
        }
Beispiel #11
0
        public static void DumpAndShowData()
        {
            var allText = DumpDevices(DataModelFactory.CreateAudioDeviceManager(AudioDeviceKind.Playback));

            allText += DumpDevices(DataModelFactory.CreateAudioDeviceManager(AudioDeviceKind.Recording));
            allText += Environment.NewLine;
            allText += $"App: {(App.Current.HasIdentity() ? Package.Current.Id.Version.ToVersionString() : "dev")}" + Environment.NewLine;
            allText += $"BuildLabel: {SystemSettings.BuildLabel}" + Environment.NewLine;
            allText += $"First Party Addons: {string.Join(" ", Extensibility.Hosting.AddonManager.Current.BuiltIn.Select(a => a.DisplayName))}" + Environment.NewLine;
            allText += $"Third Party Addons: {string.Join(" ", Extensibility.Hosting.AddonManager.Current.ThirdParty.Select(a => a.DisplayName))}" + Environment.NewLine;
            allText += $"IsLightTheme: {SystemSettings.IsLightTheme}" + Environment.NewLine;
            allText += $"RTL: {SystemSettings.IsRTL}" + Environment.NewLine;
            allText += $"IsTransparencyEnabled: {SystemSettings.IsTransparencyEnabled}" + Environment.NewLine;
            allText += $"UseAccentColor: {SystemSettings.UseAccentColor}" + Environment.NewLine;
            allText += $"AnimationsEnabled: {SystemParameters.MenuAnimation}" + Environment.NewLine;
            allText += Environment.NewLine;
            allText += AppTrace.GetLogText();

            var fileName = $"{Path.GetTempFileName()}.txt";

            File.WriteAllText(fileName, allText);
            ProcessHelper.StartNoThrow(fileName);
        }
Beispiel #12
0
 public void Insert(Entities.OperatorSetting operatorSetting)
 {
     base.DbSet.InsertOnSubmit(DataModelFactory.Create(operatorSetting));
 }
 public void InsertRange(IEnumerable <Entities.PublicStop> publicStops)
 {
     base.DbSet.InsertAllOnSubmit(DataModelFactory.Create(publicStops));
 }
 public void Insert(DrumbleApp.Shared.Entities.UberTrip uberTrip)
 {
     base.DbSet.InsertOnSubmit(DataModelFactory.Create(uberTrip));
 }
 public void Insert(DrumbleApp.Shared.Entities.TransportMode transportMode)
 {
     base.DbSet.InsertOnSubmit(DataModelFactory.Create(transportMode));
 }
        public override void Handle(Event evt)
        {  //INSERTION OF EVENTS FOR THE NEWLY GENERATED ROUTE ( after a dynamic request has been accepted)
            if (evt.Category == 4 && evt is CustomerRequestEvent customerRequestEvent)
            {
                Log(evt);
                evt.AlreadyHandled = true;
                _consoleLogger.Log("New Customer (dynamic) request:" + customerRequestEvent.Customer + " - " + customerRequestEvent.Customer.PickupDelivery[0] + " -> " + customerRequestEvent.Customer.PickupDelivery[1] + ", TimeWindows: {" + customerRequestEvent.Customer.DesiredTimeWindow[0] + "," + customerRequestEvent.Customer.DesiredTimeWindow[1] + "} at " + TimeSpan.FromSeconds(evt.Time).ToString());
                //Check if request can be served, if so the
                Simulation.Stats.TotalDynamicRequests++;
                var newCustomer = customerRequestEvent.Customer;
                RoutingSolutionObject solutionObject = null;
                if (Simulation.Context.VehicleFleet.FindAll(v => v.FlexibleRouting).Count > 0 && newCustomer != null)
                {
                    var dataModel = DataModelFactory.Instance().CreateCurrentSimulationDataModel(Simulation, newCustomer, evt.Time);
                    var solver    = new RoutingSolver(dataModel, false);
                    RoutingSearchParameters searchParameters =
                        operations_research_constraint_solver.DefaultRoutingSearchParameters();
                    searchParameters.FirstSolutionStrategy =
                        FirstSolutionStrategy.Types.Value.ParallelCheapestInsertion;
                    searchParameters.LocalSearchMetaheuristic = LocalSearchMetaheuristic.Types.Value.TabuSearch;
                    searchParameters.TimeLimit = new Duration {
                        Seconds = 5
                    };                                                        //change
                    _consoleLogger.Log("Generating new Routing Solution...");
                    var solution = solver.TryGetSolution(searchParameters);
                    if (solution != null)
                    {
                        //solver.PrintSolution(solution);
                        Simulation.Stats.TotalServedDynamicRequests++;
                        _consoleLogger.Log(newCustomer.ToString() + " request was inserted into a vehicle route at " + TimeSpan.FromSeconds(customerRequestEvent.Time).ToString());

                        solutionObject = solver.GetSolutionObject(solution);
                    }
                    else
                    {
                        _consoleLogger.Log(newCustomer.ToString() + " will not be able to be served by any of the available vehicles at " + TimeSpan.FromSeconds(customerRequestEvent.Time).ToString());
                    }
                }

                if (!Simulation.Context.DynamicCustomers.Contains(newCustomer))
                {
                    Simulation.Context.DynamicCustomers.Add(newCustomer);
                }

                if (solutionObject != null)
                {
                    //solutionObject.MetricsContainer.PrintMetrics();
                    var vehicleFlexibleRouting = Simulation.Context.VehicleFleet.FindAll(v => v.FlexibleRouting);
                    foreach (var vehicle in vehicleFlexibleRouting)
                    {
                        var solutionRoute       = solutionObject.GetVehicleStops(vehicle);
                        var solutionTimeWindows = solutionObject.GetVehicleTimeWindows(vehicle);
                        var solutionCustomers   = solutionObject.GetVehicleCustomers(vehicle);
                        if (solutionRoute.Count >= 2 && solutionRoute[0] != solutionRoute[1])//check if current vehicle route is valid
                        {
                            if (vehicle.VisitedStops.Count > 1 && vehicle.CurrentStop == Simulation.Context.Depot)
                            {
                                _consoleLogger.Log("Vehicle " + vehicle.Id + " already performed a route and is currently idle at depot.");//debug
                            }
                            if (vehicle.TripIterator?.Current != null)
                            {
                                var           currentStopIndex   = vehicle.TripIterator.Current.StopsIterator.CurrentIndex;
                                var           customers          = solutionObject.GetVehicleCustomers(vehicle); //contains all customers (already inside and not yet in vehicle)
                                List <Stop>   visitedStops       = new List <Stop>(vehicle.VisitedStops);
                                List <long[]> visitedTimeWindows = new List <long[]>(vehicle.StopsTimeWindows);


                                if (currentStopIndex < vehicle.VisitedStops.Count)
                                {
                                    visitedStops.RemoveAt(currentStopIndex);       //remove current stop from the visitedStops list
                                    visitedTimeWindows.RemoveAt(currentStopIndex); //remove current timeWindow from the visitedTimeWindows list
                                }

                                //inserts the already visited stops at the beginning of the solutionRoute list
                                for (int e = visitedStops.Count - 1; e >= 0; e--)
                                {
                                    solutionRoute.Insert(0, visitedStops[e]);
                                    solutionTimeWindows.Insert(0, visitedTimeWindows[e]);
                                }

                                vehicle.TripIterator.Current.AssignStops(solutionRoute, solutionTimeWindows, currentStopIndex);
                                vehicle.TripIterator.Current.ExpectedCustomers = customers.FindAll(c => !c.IsInVehicle);                                                                                                                                                                                  //the expected customers for the current vehicle are the ones that are not in that vehicle

                                var vehicleEvents = Simulation.Events.FindAll(e => (e is VehicleStopEvent vse && vse.Vehicle == vehicle && e.Time >= evt.Time) || (e is CustomerVehicleEvent cve && cve.Vehicle == vehicle && e.Time >= evt.Time)).OrderBy(e => e.Time).ThenBy(e => e.Category).ToList(); //gets all next vehicle depart or arrive events
                                if (vehicleEvents.Count > 0)
                                {
                                    foreach (var vEvent in vehicleEvents)
                                    {
                                        if (vEvent is VehicleStopEvent vehicleStopArriveEvent && vEvent.Category == 0
                                            ) //vehicle arrive stop event
                                        {
                                            //_consoleLogger.Log(vehicleStopArriveEvent.GetTraceMessage());
                                        }

                                        if (vEvent is VehicleStopEvent vehicleStopDepartEvent && vEvent.Category == 1
                                            ) //vehicle depart stop event
                                        {
                                            var departTime = vEvent.Time;

                                            if (vehicleStopDepartEvent.Stop == vehicle.CurrentStop)
                                            {
                                                departTime =
                                                    (int)vehicle.TripIterator.Current.ScheduledTimeWindows[
                                                        vehicle.TripIterator.Current.StopsIterator.CurrentIndex][1] +
                                                    2; //recalculates new event depart time;


                                                vEvent.Time = departTime;
                                            }

                                            var allEnterLeaveEventsForCurrentVehicle = Simulation.Events
                                                                                       .FindAll(e =>
                                                                                                e.Time >= evt.Time &&
                                                                                                (e is CustomerVehicleEvent cve && cve.Vehicle == vehicle))
                                                                                       .OrderBy(e => e.Time).ThenBy(e => e.Category).ToList();

                                            foreach (var enterOrLeaveEvt in allEnterLeaveEventsForCurrentVehicle)
                                            {
                                                if (enterOrLeaveEvt.Time > departTime
                                                    ) //if the event time is greater than the depart time removes those events, otherwise maintain the enter and leave events for current stop
                                                {
                                                    Simulation.Events.Remove(enterOrLeaveEvt);
                                                }
                                            }
                                        }
                                    }
                                }
                                else
                                {
                                    //if vehicle events is 0 it means the vehicle has no more generated events for it, need to generate a new depart event for the vehicle
                                    vehicle.TripIterator.Current.IsDone = false; //current trip is no longer completed
                                    var currentDepartureTime = (int)solutionTimeWindows[currentStopIndex][1];
                                    if (currentDepartureTime == evt.Time)        //if departure time is the same time as the event being handled adds 1 to its time
                                    {
                                        currentDepartureTime++;
                                    }
                                    var departEvt = Simulation.EventGenerator.GenerateVehicleDepartEvent(vehicle, currentDepartureTime);
                                    Simulation.Events.Add(departEvt);
                                }
                            }
                            else
                            {
                                //trip assignment for vehicles that are have not yet performed a route
                                Simulation.InitializeVehicleFlexibleRoute(vehicle, solutionRoute, solutionCustomers, solutionTimeWindows);
                            }
                        }
                    }
                }
            }
            else
            {
                Successor?.Handle(evt);
            }
        }
 public void Insert(Entities.User user)
 {
     base.DbSet.InsertOnSubmit(DataModelFactory.Create(user));
 }
 public void Insert(DrumbleApp.Shared.Entities.CacheSetting cacheSetting)
 {
     base.DbSet.InsertOnSubmit(DataModelFactory.Create(cacheSetting));
 }
 public void Insert(DrumbleApp.Shared.Entities.Weather weather)
 {
     base.DbSet.InsertOnSubmit(DataModelFactory.Create(weather));
 }
 public void Insert(DrumbleApp.Shared.Entities.Path path)
 {
     base.DbSet.InsertOnSubmit(DataModelFactory.Create(path));
 }
 public void Insert(Entities.PublicStop publicStop)
 {
     base.DbSet.InsertOnSubmit(DataModelFactory.Create(publicStop));
 }
Beispiel #22
0
 public void InsertRange(IEnumerable <DrumbleApp.Shared.Entities.PublicTransportOperator> publicTransportOperators)
 {
     base.DbSet.InsertAllOnSubmit(DataModelFactory.Create(publicTransportOperators));
 }
Beispiel #23
0
 public void Insert(DrumbleApp.Shared.Entities.PublicTransportOperator publicTransportOperator)
 {
     base.DbSet.InsertOnSubmit(DataModelFactory.Create(publicTransportOperator));
 }