Dense - Generic Adjacency Matrix
Mendz.Graphs..Dense.AdjacencyMatrixBase makes it very easy to define (a, b, c)-adjacency matrices. So much so that I just had to create a 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.Dense
{
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..Dense 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