/// <summary> /// 从文件读入参数构建MGraph /// </summary> /// <returns></returns> public static MGraph createMGraph(String filename, PrioAlg prioalg) { Console.WriteLine("Starting reading the graph parameter..."); StreamReader sr = new StreamReader(filename); String line; //first line: read vexnum & arcnum line = sr.ReadLine(); String[] temp = new String[2]; temp = line.Split(' '); MGraph a = new MGraph(Int32.Parse(temp[0]), Int32.Parse(temp[1])); //next vexnum lines: read vexs info for (int i = 0; i < a.mgraphVexnum; i++) { line = sr.ReadLine(); temp = line.Split(' '); a.mgraphSetPointArgs(i, Int32.Parse(temp[0]), Double.Parse(temp[1])); } //next vexnum lines: read adj matrix String[,] temp2 = new String[a.mgraphVexnum, a.mgraphVexnum]; for (int i = 0; i < a.mgraphVexnum; i++) { line = sr.ReadLine(); String[] temp3 = new String[a.mgraphVexnum]; temp3 = line.Split(' '); for (int j = 0; j < a.mgraphVexnum; j++) temp2[i, j] = temp3[j]; } a.mgraphSetAdjMatrix(a.mgraphVexnum, temp2); String[,] temp4 = new String[a.mgraphVexnum, a.mgraphVexnum]; for (int i = 0; i < a.mgraphVexnum; i++) { line = sr.ReadLine(); String[] temp5 = new String[a.mgraphVexnum]; temp5 = line.Split(' '); for (int j = 0; j < a.mgraphVexnum; j++) temp4[i, j] = temp5[j]; } a.mgraphSetAdjCountMatirx(a.mgraphVexnum, temp4); a.prioAlg = prioalg; sr.Close(); Console.WriteLine("Graph paremeters read complete.\n"); return a; }