SharpGraph 1.3.2

There is a newer version of this package available.
See the version list below for details.
dotnet add package SharpGraph --version 1.3.2
                    
NuGet\Install-Package SharpGraph -Version 1.3.2
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="SharpGraph" Version="1.3.2" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="SharpGraph" Version="1.3.2" />
                    
Directory.Packages.props
<PackageReference Include="SharpGraph" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add SharpGraph --version 1.3.2
                    
#r "nuget: SharpGraph, 1.3.2"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#addin nuget:?package=SharpGraph&version=1.3.2
                    
Install as a Cake Addin
#tool nuget:?package=SharpGraph&version=1.3.2
                    
Install as a Cake Tool

SharpGraph .NET Publish

A C# graph library with support for both directed- and undirected graphs (simpel- and multigraphs).

Features

  1. Serializable to json and deserializable from json.
  2. Graph properties:
    • Vertices
    • Edges (arrows and lines)
    • Sources
    • Sinks
    • IsAcyclic
    • HasCycles
    • Density
    • IsSparse
    • IsDense
    • IsDirected
    • IsDirectedAcyclic
  3. Graph methods:
    • AddVertex (given a vertex)
    • AddEdge (given a edge)
    • AdjacentVertices (given a vertex)
    • AdjacentEdges (given a vertex)
    • AllPaths (between two given vertices)
  4. Multiple graph representations available.
    • AdjacencyList
    • AdjacencyMatrix

Nuget

Install-Package SharpGraph

How to use

Step 1

Create a vertex class by extending the Vertex base class.

public class TestVertex : Vertex
{
    public TestVertex(string identifier)
        : base(identifier)
    {
    }
}

Step 2

Create a edge class by extending either the Line class (undirected edge) or the Arrow class (directed edge).

public class TestArrow : Arrow<TestVertex>
{
    public TestArrow(TestVertex source, TestVertex target)
        : base(source, target)
    {
    }
}

Step 3

Create a new instance of the Graph class with your own vertex and edge classes as generic types. You can use a fluent syntax for adding vertices and edges.

var vertex1 = new TestVertex("A");
var vertex2 = new TestVertex("B");
var vertex3 = new TestVertex("C");
var vertex4 = new TestVertex("D");
var graph = new Graph<TestVertex, TestArrow>()
    .AddVertex(vertex1)
    .AddVertex(vertex2)
    .AddVertex(vertex3)
    .AddVertex(vertex4)
    .AddEdge(new TestArrow(vertex1, vertex2))
    .AddEdge(new TestArrow(vertex1, vertex3))
    .AddEdge(new TestArrow(vertex2, vertex4))
    .AddEdge(new TestArrow(vertex3, vertex4));
var pathsVertex1ToVertex4 = graph.AllPaths(vertex1, vertex4);

foreach (var path in pathsVertex1ToVertex4)
{
    Console.WriteLine(string.Join(", ", path.Select(i => $"{i.Source}->{i.Target}")));
}

This gives the following result on the console.

A->B, B->D
A->C, C->D
Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (1)

Showing the top 1 NuGet packages that depend on SharpGraph:

Package Downloads
SharpMachineLearning

Package Description

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.4.7 907 4/11/2025
1.4.6 219 4/8/2025
1.4.4 1,783 11/17/2024
1.4.3 136 11/17/2024
1.4.2 124 11/17/2024
1.4.1 127 11/17/2024
1.4.0 120 11/17/2024
1.3.13 126 11/16/2024
1.3.12 134 11/16/2024
1.3.11 174 9/19/2024
1.3.10 136 9/19/2024
1.3.9 127 9/19/2024
1.3.8 2,755 9/5/2024
1.3.7 162 9/5/2024
1.3.6 154 9/5/2024
1.3.5 154 9/5/2024
1.3.4 144 9/4/2024
1.3.3 145 9/1/2024
1.3.2 136 9/1/2024
1.3.1 140 9/1/2024
1.3.0 222 2/19/2024
1.2.9 185 2/13/2024
1.2.8 144 2/13/2024
1.2.7 219 12/20/2023
1.2.6 154 12/20/2023
1.2.5 318 3/27/2023
1.2.3 336 12/22/2022
1.2.2 474 6/1/2022
1.2.1 473 5/25/2022
1.2.0 479 5/1/2022
1.1.7 500 2/16/2022
1.1.6 490 2/16/2022
1.1.5 491 2/15/2022
1.1.4 492 2/15/2022
1.1.3 476 2/15/2022
1.1.2 471 2/15/2022
1.1.1 492 2/14/2022
1.1.0 486 2/13/2022
1.0.9 493 2/13/2022
1.0.8 504 1/15/2022
1.0.7 337 12/19/2021
1.0.6 363 11/19/2021
1.0.5 443 10/10/2021
1.0.4 409 10/10/2021