Beispiel #1
0
        public static void testGreedy(String filename, PrioAlg prioalg)
        {
            String outputfile;
            Console.WriteLine("processing " + filename + "...");

            //Greedy Algorithm
            a = createMGraph(filename, prioalg);     //从文件读入数据

            if (a.prioAlg == PrioAlg.orig)
                outputfile = "GreedyOrig.txt";
            else
                outputfile = "GreedyAdv.txt";

            FileStream fs = new FileStream(outputfile, FileMode.Append);
            StreamWriter sw = new StreamWriter(fs);

            //测试RTM solution是否schedulable
            Console.WriteLine("测试RTM solution是否schedulable");
            a.mgrpahSetRTMBuffer();
            a.mgraphSetPrio();      //计算优先级
            a.mgraphResponseTime();     //计算resopnse time
            a.mgraphCalcLateness();     //计算lateness
            if (!a.mgraphSchedulable())
            {
                Console.WriteLine("Not schedulable, unable to perform mapping.");
                Console.ReadKey();
                return;
            }
            else
            {
                Console.WriteLine("RTM solution schedulable.");
            }

            //testPrintBuffer(a);
            //testPrintLateness(a);
            Console.WriteLine("RTM buffers = " + countBuffer(a));
            sw.WriteLine(filename);
            sw.WriteLine("RTM buffer: " + countBuffer(a));
            //Console.ReadKey();

            //计算Greedy Algorithm中得到的buffers上界
            Console.WriteLine("计算Greedy Algorithm中得到的buffers上界");
            a.mgrpahSetNoType2Buffer(); //不加type 2 buffer
            a.mgraphSetPrio();      //计算优先级
            a.mgraphResponseTime();     //计算resopnse time
            a.mgraphCalcLateness();     //计算lateness
            Console.WriteLine(GreedyTaskMapping());

            Console.WriteLine("Greedy buffers = " + countBuffer(a));
            sw.WriteLine("Greedy buffer: " + countBuffer(a));
            a.maxBuff = a.minBuff = countBuffer(a);

            sw.Flush();
            fs.Close();
        }
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;
        }