Project DescriptionGrapheNET is a .net Node Graph library.
Graph (Data Structure)Below is an example represent the graph
Here
Imports GrapheNet
Imports GrapheNet.Graph_Exts
Module Module1
Sub Main()
Dim g As New Graph(Of Integer, Integer)(
BiDirectional:=True, SelfEdge:=False,
NodesValues:= {1, 2, 3, 4, 5, 6})
g(1, 2) = 7
g(1, 3) = 9
g(1, 6) = 14
g(2, 3) = 10
g(2, 4) = 15
g(3, 4) = 11
g(3, 6) = 2
g(4, 5) = 6
g(5, 6) = 9
' Find the shortest path between Nodes 1 & 5
Dim Shorest = From p In g(1).PathsTo(5)
Let d = p.Edges.Sum(Function(e) e.Value)
Order By d Ascending Take 1
Select New Tuple(Of Path(Of Integer, Integer), Integer)(p, d)
Console.WriteLine("{0} {1} ", Shorest(0).Item2, Shorest(0).Item1.ToString())
Console.ReadKey()
End Sub
End Module
C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using GrapheNet;
namespace CSharp
{
class Program
{
static void Main(string[] args)
{
var g = new Graph<Int32, Int32>(true, false, new int []{1,2,3,4,5,6});
g[1, 2] = 7;
g[1, 3] = 9;
g[1, 6] = 14;
g[2, 3] = 10;
g[2, 4] = 15;
g[3, 4] = 11;
g[3, 6] = 2;
g[4, 5] = 6;
g[5, 6] = 9;
// Find the shortest path between Nodes 1 & 5
var Shortest = (from p in g[1].PathsTo(5)
let d = p.Edges.Sum(e => e.Value)
orderby d ascending
select new Tuple<Path<Int32, Int32>, Int32>(p, d)).Take(1).ToList();
Console.WriteLine("{0} {1} ", Shortest[0].Item2, Shortest[0].Item1.ToString());
Console.ReadKey();
}
}
}