public TopologicalGraph ReadGraphFile(string fileName) { _graph = new TopologicalGraph(); if (!File.Exists(fileName)) { throw new FileNotFoundException(); } using (var streamReader = new StreamReader(File.OpenRead(fileName))) { string newLine = Environment.NewLine; string nextLine = null; var sb = new StringBuilder(); while (!streamReader.EndOfStream) { nextLine = streamReader.ReadLine(); sb.Append(nextLine) .Append(newLine); if (_state == PARSE_NOTHING) { if (nextLine.Contains("Nodes:")) { _state = PARSE_NODES; } } else if (_state == PARSE_NODES) { ParseNodeString(nextLine); } else if (_state == PARSE_EDGES) { ParseEdgesString(nextLine); } } } return(_graph); }
private void CreateDelayMatrix(TopologicalGraph graph, bool directed) { _totalNodeNum = graph.NumberOfNodes; _delayMatrix = new float[_totalNodeNum][]; for (var i = 0; i < _totalNodeNum; i++) { _delayMatrix[i] = new float[_totalNodeNum]; } for (int row = 0; row < _totalNodeNum; ++row) { for (int col = 0; col < _totalNodeNum; ++col) { _delayMatrix[row][col] = float.MaxValue; } } IEnumerator <TopologicalLink> itr = graph.GetLinkEnumerator(); TopologicalLink edge; do { edge = itr.Current; if (edge != null) { _delayMatrix[edge.SrcNodeId][edge.DestNodeId] = edge.LinkDelay; if (!directed) { // according to aproximity of symmetry to all communication-paths _delayMatrix[edge.DestNodeId][edge.SrcNodeId] = edge.LinkDelay; } } } while (itr.MoveNext()); }
public DelayMatrixFloat(TopologicalGraph graph, bool directed) { CreateDelayMatrix(graph, directed); CalculateShortestPath(); }