Esempio n. 1
0
        public Dijkstra(AdjacencyList Graph, int S)
        {
            source = S;
            vertexCount = Graph.getVertexCount();
            adjList = Graph;
            parent = new int[vertexCount];
            vertexCost = new double[vertexCount];

            for (int i = 0; i < vertexCount; ++i)
            {
                parent[i] = -1;
                vertexCost[i] = double.MaxValue;
            }

            parent[source] = -1;
            vertexCost[source] = 0;
        }
        public static AdjacencyList ReadAdjacencyGraph(string inputFile)
        {
            StreamReader sr = new StreamReader(inputFile);
            int vertex_count = int.Parse(sr.ReadLine());
            int edge_count = int.Parse(sr.ReadLine());
            AdjacencyList adjList = new AdjacencyList(vertex_count);

            for (int i = 0; i < edge_count; ++i)
            {
                string[] line = sr.ReadLine().Split(' ');
                int from = int.Parse(line[0]);
                int to = int.Parse(line[1]);
                double cost = double.Parse(line[2]);
                adjList.addEdge(from, to, cost);
            }

            return adjList;
        }