forked from YaccConstructor/QuickGraph
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
67 lines (64 loc) · 2.44 KB
/
Program.cs
File metadata and controls
67 lines (64 loc) · 2.44 KB
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using QuickGraph.Algorithms.ShortestPath;
using QuickGraph.Tests.Algorithms;
using QuickGraph.Tests.Algorithms.MinimumSpanningTree;
using QuickGraph.Serialization;
using QuickGraph.Algorithms.Observers;
using QuickGraph.Collections;
using QuickGraph.Algorithms;
using QuickGraph.Algorithms.Search;
namespace QuickGraph.Perf
{
class Program
{
static void Main(string[] args)
{
// new TarjanOfflineLeastCommonAncestorAlgorithmTest().TarjanOfflineLeastCommonAncestorAlgorithmAll();
// new DijkstraShortestPathAlgorithmTest().DijkstraAll();
// new MinimumSpanningTreeTest().PrimKruskalMinimumSpanningTreeAll();
var g = TestGraphFactory.LoadBidirectionalGraph(@"graphml\repro12359.graphml");
var distances = new Dictionary<Edge<string>, double>(g.EdgeCount);
foreach (var e in g.Edges)
distances[e] = g.OutDegree(e.Source) + 1;
var root = Enumerable.First(g.Vertices);
foreach (var v in g.Vertices)
{
FrontierDijkstra(g, distances, root, v);
}
}
static void Dijkstra<TVertex, TEdge>(
IVertexAndEdgeListGraph<TVertex, TEdge> g,
Dictionary<TEdge, double> distances,
TVertex root)
where TEdge : IEdge<TVertex>
{
var algo = new DijkstraShortestPathAlgorithm<TVertex, TEdge>(
g,
AlgorithmExtensions.GetIndexer(distances)
);
var predecessors = new VertexPredecessorRecorderObserver<TVertex, TEdge>();
using (predecessors.Attach(algo))
algo.Compute(root);
}
static void FrontierDijkstra<TVertex, TEdge>(
IBidirectionalGraph<TVertex, TEdge> g,
Dictionary<TEdge, double> distances,
TVertex root,
TVertex target)
where TEdge : IEdge<TVertex>
{
var algo = new BestFirstFrontierSearchAlgorithm<TVertex, TEdge>(
null,
g,
AlgorithmExtensions.GetIndexer(distances),
DistanceRelaxers.ShortestDistance
);
var predecessors = new VertexPredecessorRecorderObserver<TVertex, TEdge>();
using (predecessors.Attach(algo))
algo.Compute(root, target);
}
}
}