Skip to content

Commit 949da17

Browse files
committed
i-20: Merge remote-tracking branch 'origin/master' into feature/i20-page-rank
# Conflicts: # src/Dijkstra.NET/Graph/Node.cs
2 parents 5174535 + 10ac290 commit 949da17

File tree

4 files changed

+61
-25
lines changed

4 files changed

+61
-25
lines changed

README.md

Lines changed: 31 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Dijkstra.NET Dijkstra algorithm in C# [![NuGet Version](https://img.shields.io/badge/Dijkstra.NET-1.1.0-blue.svg)](https://www.nuget.org/packages/Dijkstra.NET)
1+
# Dijkstra.NET [![NuGet Version](https://img.shields.io/badge/Dijkstra.NET-1.2.0-blue.svg)](https://www.nuget.org/packages/Dijkstra.NET)
22

33
Dijkstra algorithm which use priority queue thus complexity is equal O(ElogV) where E is number of edges and V is number of vertices. Used data structures are based on interfaces so you can implement your own or reused present. Simply example below. More information about algorithm you can find on [Wikipedia](https://en.wikipedia.org/wiki/Dijkstra%27s_algorithm).
44

@@ -12,39 +12,56 @@ Install the latest version from NuGet
1212
## Simple example
1313

1414
```c#
15-
using Dijkstra.NET.Extensions;
15+
using Dijkstra.NET.Graph;
16+
using Dijkstra.NET.ShortestPath;
1617

1718
var graph = new Graph<int, string>();
1819

1920
graph.AddNode(1);
2021
graph.AddNode(2);
2122

22-
graph.Connect(0, 1, 5, "some custom information in edge"); //First node has key equal 0
23+
graph.Connect(1, 2, 5, "some custom information in edge"); //First node has key equal 1
2324
24-
ShortestPathResult result = graph.Dijkstra(0, 1); //result contains the shortest path
25+
ShortestPathResult result = graph.Dijkstra(1, 2); //result contains the shortest path
2526
26-
result.GetPath();
27+
var path = result.GetPath();
28+
```
29+
or
30+
31+
```c#
32+
using Dijkstra.NET.Graph;
33+
using Dijkstra.NET.ShortestPath;
34+
35+
var graph = new Graph<int, string>() + 1 + 2;
36+
37+
bool connected = graph >> 1 >> 2 >> 5 ^ "custome edge information";
38+
39+
ShortestPathResult result = graph.Dijkstra(1, 2); //result contains the shortest path
40+
41+
var path = result.GetPath();
2742
```
2843

2944
## Benchmark
3045

31-
For Graph where number of nodes is 10 000 000 and connections between them 1 000 000. The length of path is minimum 10.
46+
For Graph where number of nodes is 1 000 000 and connections between them 1 000 000. The length of path is minimum 10.
3247

3348
``` ini
3449

35-
BenchmarkDotNet=v0.10.10, OS=Windows 7 SP1 (6.1.7601.0)
36-
Processor=Intel Core i7-6600U CPU 2.60GHz (Skylake), ProcessorCount=4
37-
Frequency=2742363 Hz, Resolution=364.6490 ns, Timer=TSC
38-
[Host] : .NET Framework 4.7 (CLR 4.0.30319.42000), 32bit LegacyJIT-v4.7.2563.0
39-
Job-XQYAYC : .NET Framework 4.7 (CLR 4.0.30319.42000), 32bit LegacyJIT-v4.7.2563.0
50+
BenchmarkDotNet=v0.10.10, OS=Windows 10.0.17134
51+
Processor=Intel Core i7-4700HQ CPU 2.40GHz (Haswell), ProcessorCount=8
52+
Frequency=2338342 Hz, Resolution=427.6534 ns, Timer=TSC
53+
[Host] : .NET Framework 4.6.1 (CLR 4.0.30319.42000), 32bit LegacyJIT-v4.7.3260.0
54+
Job-XQYAYC : .NET Framework 4.6.1 (CLR 4.0.30319.42000), 32bit LegacyJIT-v4.7.3260.0
4055

4156
LaunchCount=1 RunStrategy=Monitoring TargetCount=3
4257
WarmupCount=2
4358

4459
```
45-
| Method | Mean | Error | StdDev | Scaled | Allocated |
46-
|--------------------------- |---------:|---------:|---------:|-------:|----------:|
47-
| Dijkstra | 5.348 us | 24.43 us | 1.381 us | 1.00 | 16 KB |
60+
| Method | Mean | Error | StdDev | Scaled | ScaledSD | Gen 0 | Gen 1 | Allocated |
61+
|--------------------------- |-------------:|-----------:|-----------:|-------:|---------:|-----------:|-----------:|------------:|
62+
| Dijkstra | 7.515 ms | 3.845 ms | 0.2173 ms | 1.00 | 0.00 | - | - | 48 KB |
63+
| PageRank | 1,139.983 ms | 762.417 ms | 43.0780 ms | 151.77 | 5.86 | 40000 | 40000 | 272365.8 KB |
64+
4865

4966
## License
5067

src/Dijkstra.NET.Tests/EdgeTest.cs

Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@ namespace Dijkstra.NET.Tests
55
{
66
public class EdgeTest
77
{
8-
8+
99
[Fact]
1010
public void Two_Edges_Should_Be_Equal()
1111
{
1212
var g = new Graph<string, int>() + "node1";
1313
var n = g >> 1;
14-
14+
1515
var a = new Edge<string, int>(n, 1, 1);
1616
var b = new Edge<string, int>(n,1, 1);
1717

@@ -25,7 +25,7 @@ public void Two_Edges_Should_Be_Equal_With_Null_References()
2525
{
2626
var g = new Graph<string, string>() + "node1";
2727
var n = g >> 1;
28-
28+
2929
var a = new Edge<string, string>(n, 1, null);
3030
var b = new Edge<string, string>(n,1, null);
3131

@@ -39,7 +39,7 @@ public void Two_Edges_Should_Be_Diffrent_With_Null_Reference()
3939
{
4040
var g = new Graph<string, string>() + "node1";
4141
var n = g >> 1;
42-
42+
4343
var a = new Edge<string, string>(n, 1, null);
4444
var b = new Edge<string, string>(n,1, "a");
4545

@@ -55,7 +55,7 @@ public void Two_Edges_Should_Be_Diffrent_With_Diffrent_Parameter()
5555
{
5656
var g = new Graph<string, string>() + "node1";
5757
var n = g >> 1;
58-
58+
5959
var a = new Edge<string, string>(n, 1, "b");
6060
var b = new Edge<string, string>(n,1, "a");
6161

@@ -71,7 +71,7 @@ public void Two_Edges_Should_Be_Diffrent_With_Diffrent_Costs()
7171
{
7272
var g = new Graph<string, string>() + "node1";
7373
var n = g >> 1;
74-
74+
7575
var a = new Edge<string, string>(n, 3, "a");
7676
var b = new Edge<string, string>(n,1, "a");
7777

@@ -88,7 +88,7 @@ public void Two_Edges_Should_Be_Diffrent_With_Diffrent_Nodes()
8888
var g = new Graph<string, string>() + "node1" + "node2";
8989
var n1 = g >> 1;
9090
var n2 = g >> 2;
91-
91+
9292
var a = new Edge<string, string>(n1, 1, "a");
9393
var b = new Edge<string, string>(n2,1, "a");
9494

@@ -98,5 +98,25 @@ public void Two_Edges_Should_Be_Diffrent_With_Diffrent_Nodes()
9898
Assert.False(act);
9999
Assert.False(act2);
100100
}
101+
102+
[Fact]
103+
public void Edges_Get_TEdgeCustom_Should_Work()
104+
{
105+
var g = new Graph<int, string>();
106+
g.AddNode(1);
107+
g.AddNode(2);
108+
g.AddNode(3);
109+
110+
g.Connect(1, 2, 1, "First");
111+
g.Connect(1, 3, 1, "Second");
112+
113+
var node = g >> 1;
114+
var first = node.GetFirstEdgeCustom(2);
115+
var second = node.GetFirstEdgeCustom(3);
116+
117+
bool act = first == "First" && second == "Second";
118+
119+
Assert.True(act);
120+
}
101121
}
102122
}

src/Dijkstra.NET/Graph/INode.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@ public interface INode
77
{
88
uint Key { get; }
99
}
10-
10+
1111
public interface INode<T, TEdgeCustom> : INode, IEnumerable<Edge<T, TEdgeCustom>> where TEdgeCustom : IEquatable<TEdgeCustom>
1212
{
1313
T Item { get; }
1414
}
15-
}
15+
}

src/Dijkstra.NET/Graph/Node.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
using System.Collections;
33
using System.Collections.Generic;
44
using Dijkstra.NET.Graph.Exceptions;
5-
using Dijkstra.NET.PageRank;
65
using Dijkstra.NET.ShortestPath;
76

87
namespace Dijkstra.NET.Graph
@@ -130,4 +129,4 @@ IEnumerator IEnumerable.GetEnumerator()
130129
return GetEnumerator();
131130
}
132131
}
133-
}
132+
}

0 commit comments

Comments
 (0)