public static Graph CreateGraphFromFileData(string data)
        {
            Graph graph = new Graph();
            char[] delimitChars = { ',' };
            data = data.Replace("Graph:", string.Empty).Replace(" ", string.Empty); // Remove unnecessary characters
            string[] edgeData = data.Split(delimitChars); // Split data using delimiter

            foreach (string edgeDatum in edgeData)
            {
                string sourceNode = edgeDatum.Substring(0, 1); // First Char
                string targetNode = edgeDatum.Substring(1, 1); // Second Char
                int weight = Convert.ToInt32(edgeDatum.Substring(2)); // Rest of String
                graph.Edges.Add(new GraphEdge(sourceNode, targetNode, weight));
            }

            return graph;
        }
 private void CreateMatrixWithData(Graph graph)
 {
     CreateDictionaryWithNodeData(graph);
     m_MatrixData = new int?[NodeCount, NodeCount];
     for (int index1 = 0; index1 < m_MatrixData.GetLength(0); index1++) // Initialize All to an Invalid Weight
     {
         for (int index2 = 0; index2 < m_MatrixData.GetLength(1); index2++)
         {
             m_MatrixData[index1, index2] = null;
         }
     }
     foreach (GraphEdge edge in graph.Edges) // Set Edge Weights
     {
         m_MatrixData[(int)GetMatrixIndexFromNode(edge.Source), (int)GetMatrixIndexFromNode(edge.Target)] = edge.Weight;
     }
 }
 public AdvancedMatrix(Graph graph)
 {
     CreateMatrixWithData(graph);
 }
        private void CreateDictionaryWithNodeData(Graph graph)
        {
            m_MatrixIndicesByNodeDictionary = new Dictionary<string, int>();

            int nodeCount = 0;
            foreach (GraphEdge edge in graph.Edges)
            {
                if (!m_MatrixIndicesByNodeDictionary.ContainsKey(edge.Source))
                {
                    m_MatrixIndicesByNodeDictionary.Add(edge.Source, nodeCount);
                    nodeCount++;
                }
                if (!m_MatrixIndicesByNodeDictionary.ContainsKey(edge.Target))
                {
                    m_MatrixIndicesByNodeDictionary.Add(edge.Target, nodeCount);
                    nodeCount++;
                }
            }
        }
 public Matrix(Graph graph)
 {
     CreateMatrixWithData(graph);
 }