public bool SortMovingTrams(TramLocation location) { SortingAlgoritm sorter = new SortingAlgoritm(AllTracks, repo); List <Tram> movingTrams = repo.GetAllTramsWithLocation(location); if (movingTrams.Count != 0) { for (int i = 0; i < movingTrams.Count; i++) { BeheerTram beheerTram = BeheerTram.ToBeheerTram(movingTrams[i]); if (location == TramLocation.ComingIn) { if (movingTrams[i].DepartureTime == null) { GetExitTime(beheerTram); } SortTram(sorter, beheerTram); } else if (location == TramLocation.GoingOut) { beheerTram.EditTramLocation(TramLocation.Out); movingTrams[i] = beheerTram; repo.EditTram(movingTrams[i]); repo.WipeSectorByTramId(movingTrams[i].Number); } } FetchUpdates(); return(true); } return(false); }
public void Simulation() { SortingAlgoritm sorter = new SortingAlgoritm(AllTracks, repo); //De schema moet op volgorde van eerst binnenkomende worden gesorteerd schema.Sort((x, y) => x.EntryTime.CompareTo(y.EntryTime)); //Voor iedere inrijtijd een tram eraan koppellen foreach (InUitRijSchema entry in schema.Where(x => x.TramNumber == null)) { foreach (BeheerTram tram in AllTrams.Where(x => x.DepartureTime == null && x.Line == entry.Line)) { entry.TramNumber = tram.Number; tram.EditTramDepartureTime(entry.ExitTime); break; } } //Too little linebound trams to fill each entry so overflow to other types of trams foreach (InUitRijSchema entry in schema.Where(x => x.TramNumber == null)) { foreach (BeheerTram tram in AllTrams.Where(x => x.DepartureTime == null)) { if ((entry.Line == 5 || entry.Line == 1624) && (tram.Model == TramModel.Dubbel_Kop_Combino || tram.Model == TramModel.TwaalfG)) //No driver lines { entry.TramNumber = tram.Number; tram.EditTramDepartureTime(entry.ExitTime); break; } else if ((entry.Line != 5 || entry.Line != 1624) && tram.Model == TramModel.Combino) //Driver lines { entry.TramNumber = tram.Number; tram.EditTramDepartureTime(entry.ExitTime); break; } } } //Het schema afgaan voor de simulatie foreach (InUitRijSchema entry in schema) { BeheerTram tram = AllTrams.Find(x => x.Number == entry.TramNumber); SortTram(sorter, tram); form.Invalidate(); Thread.Sleep(simulationSpeed); } foreach (BeheerTram tram in AllTrams.Where(x => x.DepartureTime == null)) { SortTram(sorter, tram); form.Invalidate(); Thread.Sleep(simulationSpeed); } schema = csv.getSchema(); Update(); }
public void SortTram(SortingAlgoritm sorter, BeheerTram tram) { if (tram != null) { BackupAllTracks = AllTracks; AllTracks = sorter.AssignTramLocation(tram); if (AllTracks == null) { AllTracks = BackupAllTracks; } } }