Пример #1
0
        /// <summary>
        /// Reads the file and creates graph edges.
        /// </summary>
        /// <param name="szFileName">Name of the file.</param>
        /// <param name="oGraph">The graph object.</param>
        public static void readFileForEdges(String szFileName, ref Graph oGraph)
        {
            // file should have Rows as
            // "<from-node> <to-node> <traffic in kbps>"
            StreamReader oFile = new StreamReader(szFileName);

            if (oFile != null)
            {
                String szLine;

                UInt32 uStartIdx = (UInt32) oGraph.m_listEdges.Count;

                while (!oFile.EndOfStream)
                {
                    szLine = oFile.ReadLine();
                    if (szLine.Trim().Length != 0)
                    {
                        String[] listN = szLine.Split(new char[] { ' ', '\t' });
                        oGraph.addEdge(++uStartIdx,
                                       UInt32.Parse(listN[0]),
                                       UInt32.Parse(listN[1]),
                                       UInt32.Parse(listN[2]));
                    }
                }

            }
        }
Пример #2
0
        // main method
        static void Main(string[] args)
        {
            // we will create a graph.
            oGraph = new Graph();
            // we will read following files to get node locations & traffic
            String szNodeFile = @"..\..\nodelocations.txt";
            String szEdgeFile = @"..\..\traffictable.txt";

            // read node list & add them into graph.
            Util.readFileForNodes(szNodeFile, ref oGraph);
            // read edge list & add them into graph.
            Util.readFileForEdges(szEdgeFile, ref oGraph);

            // init MST edges data structure
            listMSTEdges = new SortedEdgeList();
            // init Path list
            listPaths = new List<PathListEntry>();
            // lets run kruskal
            oGraph.runKruskal(out listMSTEdges);

            Console.Clear();

            // TASK 1: print loc1, loc2, distance, with a total dist
            taskPrintMST();
            Console.WriteLine("----------------------------------------------------");
            // TASK 2: Utilization\
            taskCalcNPrintUtilization();
            Console.WriteLine("----------------------------------------------------");
            // TASK 3: Average hops
            taskAvgHop();
            Console.WriteLine("----------------------------------------------------");
            // TASK 4: average delay
            taskAvgDelay();
        }
Пример #3
0
        /// <summary>
        /// Reads the file and creates graph nodes.
        /// </summary>
        /// <param name="szFileName">Name of the file.</param>
        /// <param name="oGraph">The graph object</param>
        public static void readFileForNodes(String szFileName, ref Graph oGraph)
        {
            // file should have Rows as
            // "<node id> <X-co-ordinate> <Y-co-ordinate>"
            StreamReader oFile = new StreamReader(szFileName);

            if (oFile != null)
            {
                String szLine;

                while (!oFile.EndOfStream)
                {
                    szLine = oFile.ReadLine();
                    if (szLine.Trim().Length != 0)
                    {
                        String[] listN = szLine.Split(new char[] { ' ', '\t' });
                        GraphNode oNode = new GraphNode(UInt32.Parse(listN[0]),
                                                        Int32.Parse(listN[1]),
                                                        Int32.Parse(listN[2]));
                        oGraph.addNode(oNode);
                    }
                }

            }
        }