Beispiel #1
0
        /// <summary>
        /// 复制一个MGraph
        /// </summary>
        /// <param name="s"></param>
        /// <returns></returns>
        public static MGraph copyMGraph(MGraph s)
        {
            int vexnum = s.mgraphVexnum;
            int arcnum = s.mgraphArcnum;
            MGraph b = new MGraph(s.mgraphVexnum, s.mgraphArcnum);
            for (int i = 0; i < vexnum; i++)
            {
                b.mgraphSetPointArgs(i, s.vexs[i].pointPeriod, s.vexs[i].pointComptime);

                for (int j = 0; j < vexnum; j++)
                {
                    b.arcs[i, j] = new ArcCell(s.arcs[i, j].arcAdj, s.arcs[i, j].arcBuf, s.arcs[i, j].arcAdjCount);
                }
            }

            b.LSlist = new ArrayList();
            for (int i = 0; i < s.LSlist.Count; i++)
            {
                LS t = (LS)s.LSlist[i];
                LS sp = new LS(t.src, t.des, t.buffcount);
                b.LSlist.Add(sp);
            }

            b.maxBuff = s.maxBuff;
            b.minBuff = s.minBuff;
            b.prioAlg = s.prioAlg;

            return b;
        }
Beispiel #2
0
        /// <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;
        }