Table of Contents

Class GridGraph

Namespace
AlgorithmsSW.Graph
Assembly
AlgorithmsSW.dll
public class GridGraph : IGraph, IReadOnlyGraph, IEnumerable<(int vertex0, int vertex1)>, IEnumerable
Inheritance
GridGraph
Implements
Inherited Members
Extension Methods

Constructors

GridGraph(int, int)

public GridGraph(int width, int height)

Parameters

width int
height int

Properties

Cells

public IEnumerable<(int x, int y)> Cells { get; }

Property Value

IEnumerable<(int source, int target)>

EdgeCount

Gets the number of edges in the graph.

public int EdgeCount { get; }

Property Value

int

SupportsParallelEdges

Gets a value indicating whether the graph supports parallel edges.

public bool SupportsParallelEdges { get; }

Property Value

bool

Remarks

This can be used to ensure algorithms are implemented correctly.

SupportsSelfLoops

Gets a value indicating whether the graph supports self-loops.

public bool SupportsSelfLoops { get; }

Property Value

bool

Remarks

This can be used to ensure algorithms are implemented correctly.

VertexCount

Gets the number of vertices in the graph.

public int VertexCount { get; }

Property Value

int

Methods

AddEdge(int, int)

Adds an edge between two vertices in the graph.

public void AddEdge(int vertex0, int vertex1)

Parameters

vertex0 int

The first vertex of the edge to add.

vertex1 int

The second vertex of the edge to add.

AddEdge((int x, int y), (int x, int y))

public void AddEdge((int x, int y) cell0, (int x, int y) cell1)

Parameters

cell0 (int vertex0, int vertex1)
cell1 (int vertex0, int vertex1)

ContainsEdge(int, int)

Gets whether the graph contains an edge between two vertices.

public bool ContainsEdge(int vertex0, int vertex1)

Parameters

vertex0 int
vertex1 int

Returns

bool

ContainsEdge((int x, int y), (int x, int y))

public bool ContainsEdge((int x, int y) cell0, (int x, int y) cell1)

Parameters

cell0 (int vertex0, int vertex1)
cell1 (int vertex0, int vertex1)

Returns

bool

GetAdjacents(int)

Gets the adjacent vertices of a given vertex.

public IEnumerable<int> GetAdjacents(int vertex)

Parameters

vertex int

The vertex to find adjacents for.

Returns

IEnumerable<int>

An enumerable of adjacent vertices.

GetAdjacents((int x, int y))

public IEnumerable<(int x, int y)> GetAdjacents((int x, int y) cell)

Parameters

cell (int vertex0, int vertex1)

Returns

IEnumerable<(int source, int target)>

GetEnumerator()

Returns an enumerator that iterates through the collection.

public IEnumerator<(int vertex0, int vertex1)> GetEnumerator()

Returns

IEnumerator<(int vertex0, int vertex1)>

An enumerator that can be used to iterate through the collection.

RemoveEdge(int, int)

Removes an edge between two vertices in the graph.

public bool RemoveEdge(int vertex0, int vertex1)

Parameters

vertex0 int

The first vertex of the edge to remove.

vertex1 int

The second vertex of the edge to remove.

Returns

bool

true if the edge was removed, false otherwise.

RemoveEdge((int x, int y), (int x, int y))

public bool RemoveEdge((int x, int y) cell0, (int x, int y) cell1)

Parameters

cell0 (int vertex0, int vertex1)
cell1 (int vertex0, int vertex1)

Returns

bool