// 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(); }
private void IncrementAccordingly(int startTime, int endTime) // increments specified records at appropriate times { int offset = (endTime - startTime) / RecLocs.Count(); int time = startTime; foreach (var recLoc in RecLocs) { recLoc.IncrementSpecified(time); time += offset; } }
// Path handling methods private void SetupPath(PathClass p) // edits RecLocs to point at records specified in path { RecLocs.Clear(); int stationAId, stationBId, lineIndex, recordIndex; stationAId = -1; // prevents first iteration going through foreach (var node in p.Path) { stationBId = node.StationId; lineIndex = node.LineIndex; if (stationAId != -1) // avoids first iteration { recordIndex = LineRecords[lineIndex].GetRecordIndex(stationAId, stationBId); if (recordIndex != -1) { RecLocs.Add(new RecordLocation(lineIndex, recordIndex)); } } stationAId = stationBId; } }