// Reading Methods public void FillInNetwork(string outFile, Sorting S, BackgroundWorker bgw, List <string> cutEdges) // iterates through data and fills in edge loadings accordingly { List <FinalLine> data = S.GetRecordsList(); FinalLine newRec = new FinalLine(); FinalLine oldRec = new FinalLine(); PathClass path; // just used as alias oldRec = data.First(); RouteFinding rf = new RouteFinding(NodeNumber); rf.SetupFresh(oldRec.StartStn); path = rf.Retrace(oldRec.EndStn); SetupPath(path); //debugging variables List <string> droppedStations = new List <string>(); string dropName; // end debugging variables foreach (var record in data) { newRec.CopyFrom(record); if (newRec.StartStn != oldRec.StartStn) // need to repeat dijkstra forward and backwards { OriginChange(newRec, bgw); // report progress rf.SetupFresh(newRec.StartStn); // redefines origin and performs dijkstra forwards path = rf.Retrace(newRec.EndStn); // gets path between origin and destination SetupPath(path); // alters RecLocs for fast access to desired records } else if (newRec.EndStn != oldRec.EndStn) // need only repeat dijkstra backwards { path = rf.Retrace(newRec.EndStn); // gets path SetupPath(path); // alters RecLocs } if (RecLocs.Any()) { IncrementAccordingly(newRec.StartTime, newRec.EndTime); // increment desired records } else // debugging purposes only { dropName = Backend.StationDiction.GetValue(newRec.EndStn); if (!droppedStations.Contains(dropName)) { droppedStations.Add(dropName); } DroppedRecords++; } oldRec.CopyFrom(newRec); } WriteFile(outFile, cutEdges); SetMaximumLoading(); }
public void CorrectReadingTest() { string line = "4,Wed,LUL,Richmond,Lancaster Gate,0,00:00,10,00:10,Z0110,TKT,N,0,0,XX,Freedom Pass (Elderly)"; FinalLine f = new FinalLine(); f.TryInitialise(line, sd); Assert.AreEqual(sd.GetKey("Richmond"), f.StartStn); Assert.AreEqual(sd.GetKey("Lancaster Gate"), f.EndStn); Assert.AreEqual(0, f.StartTime); Assert.AreEqual(10, f.EndTime); }
public void SortednessTest() { // WARNING: this test takes a long time ~ 15 seconds BackgroundWorker bgw = new BackgroundWorker(); bgw.WorkerReportsProgress = true; Sorting s = new Sorting(@"C:\Users\ltray\Documents\Computing\Project Code\User Interface\bin\Debug\SourceData.csv"); s.Sort(sd, bgw); List <FinalLine> recs = s.GetRecordsList(); FinalLine oldRec = recs[0]; foreach (var rec in recs) { if (oldRec.StartStn < rec.StartStn) // primary ordering { // all good } else if (oldRec.StartStn == rec.StartStn) { if (oldRec.EndStn < rec.EndStn) // secondary ordering { // all good } else if (oldRec.EndStn == rec.EndStn) { if (oldRec.StartTime <= rec.StartTime) // tertiary ordering { // is passing so far } else { Assert.Fail(); } } } else { Assert.Fail(); } oldRec = rec; } Assert.AreEqual(1, 1); }
// progress reports private void OriginChange(FinalLine f, BackgroundWorker bgw) // outputs current data record when origin station changes { int percentProgress = (f.StartStn * 100) / NodeNumber; bgw.ReportProgress(percentProgress); }