ConnectionMatrix
The connection matrix is a (true, false, false)-adjacency matrix, implemented in Mendz.Graphs.Representation.Matrices namespace as the ConnectionMatrix.
The ConnectionMatrix is a sealed class that derives directly from the GraphMatrixBase class.
Note that the indexer has been overridden to simulate matrix-like access to the entries (ex. matrix[i, j]).
The connection matrix can be used in solutions that apply Boolean algebra with linear algebra's Matrix Theory, for example. In mathematics and mathematical logic, Boolean algebra is the branch in algebra where the variables are true or false, instead of 1 or 0 respectively. The following lists some online sources that can help you learn more about Boolean algebra:
Mendz.Graphs intentionally does not include algorithms. I encourage developers to build their own algorithm library or libraries based on Mendz.Graphs.
The ConnectionMatrix is a sealed class that derives directly from the GraphMatrixBase class.
ConnectionMatrix.cs
using Mendz.Library;
using System;
using System.Collections.Generic;
namespace Mendz.Graphs.Representations.Matrices
{
public sealed class ConnectionMatrix
: GraphMatrixBase<HashSet<(int row, int column)>>
{
public bool this[int row, int column]
{
get
{
Matrix<bool>.CheckCoordinates(Size, row, column);
return Matrix.Contains((row, column));
}
}
public ConnectionMatrix(Graph graph)
: base(graph, (graph.Order, graph.Order))
{
}
public override void Initialize()
{
Matrix = new HashSet<(int row, int column)>();
}
public override HashSet<(int row, int column)> Fill()
{
Initialize();
var indexedVertices = Graph.IndexVertices();
var indexedEdges = Graph.IndexEdges();
for (int z = 0; z < indexedEdges.Length; z++)
{
Edge edge = indexedEdges[z];
SetEntries(
Array.BinarySearch<Vertex>(indexedVertices, edge.Tail),
Array.BinarySearch<Vertex>(indexedVertices, edge.Head),
edge.Directed);
}
return Matrix;
}
private void SetEntries(int x, int y, bool directed)
{
Matrix.Add((x, y));
if (x != y)
{
if (!directed)
{
Matrix.Add((y, x));
}
}
}
}
}
The ConnectionMatrix uses a HashSet of coordinates stored as (int row, int column) tuples.Note that the indexer has been overridden to simulate matrix-like access to the entries (ex. matrix[i, j]).
The connection matrix can be used in solutions that apply Boolean algebra with linear algebra's Matrix Theory, for example. In mathematics and mathematical logic, Boolean algebra is the branch in algebra where the variables are true or false, instead of 1 or 0 respectively. The following lists some online sources that can help you learn more about Boolean algebra:
- http://mathworld.wolfram.com/BooleanAlgebra.html
- https://plato.stanford.edu/entries/boolalg-math/
- https://en.wikipedia.org/wiki/List_of_Boolean_algebra_topics
Mendz.Graphs intentionally does not include algorithms. I encourage developers to build their own algorithm library or libraries based on Mendz.Graphs.
Comments
Post a Comment