Sparse - Generic Adjacency Matrix
If there is a Mendz.Graphs..Dense.GenericAdjacencyMatrix, there should definitely be a Mendz.Graphs..Sparse.GenericAdjacencyMatrix!
The GenericAdjacencyMatrix is my solution to NOT creating so many adjacency matrix classes. For as long as the (a, b, c)-adjacency matrix implementation would not require the SetEntries() method to be overridden, the GenericAdjacencyMatrix should be good enough to create an adjacency matrix instance.
The GenericAdjacencyMatrix is my solution to NOT creating so many adjacency matrix classes. For as long as the (a, b, c)-adjacency matrix implementation would not require the SetEntries() method to be overridden, the GenericAdjacencyMatrix should be good enough to create an adjacency matrix instance.
GenericAdjacencyMatrix.cs
using System;
namespace Mendz.Graphs.Representations.Matrices.Sparse
{
public class GenericAdjacencyMatrix<T> : AdjacencyMatrixBase<T>
{
public GenericAdjacencyMatrix(Graph graph,
Func<int, Edge, T> adjacent,
T nonadjacent = default(T),
T diagonal = default(T))
: base(graph, adjacent, nonadjacent, diagonal)
{
}
}
}
Sample use:
var adjacencyMatrixOfIndexedEdges = new GenericAdjacencyMatrix<int>(graph, (z, edge) => z);
var adjacencyMatrixOfEdges = new GenericAdjacencyMatrix<Edge>(graph, (z, edge) => edge);
var connectionMatrix = new GenericAdjacencyMatrix<bool>(graph, (z, edge) => true);
Even the adjacency matrices already in Mendz.Graphs..Sparse can be created just by using the GenericAdjacencyMatrix.
var adjacencyMatrix = new GenericAdjacencyMatrix<int>(graph, (z, edge) => 1);
var weightedAdjacencyMatrix =
new GenericAdjacencyMatrix<double>(graph, (z, edge) => edge.Weight);
Cool, right?!
Comments
Post a Comment