Класс DijkstraAllPairsSP
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace WOrGraph { class DijkstraAllPairsSP { private DijkstraSP[] all; public DijkstraAllPairsSP(EdgeWeightedDigraph G) { all = new DijkstraSP[G.GetVertices()]; for (int v = 0; v < G.GetVertices(); v++) all[v] = new DijkstraSP(G, v); } public IEnumerable<DirectedEdge> GetPath(int s, int t) { ValidateVertex(s); ValidateVertex(t); return all[s].GetPathTo(t); } private void ValidateVertex(int v) { int V = all.Length; if (v < 0 || v >= V) throw new ArgumentException("vertex " + v + " is not between 0 and " + (V - 1)); } public double Dist(int s, int t) { ValidateVertex(s); ValidateVertex(t); return all[s].GetDistTo(t); } } } |