My C# graph library
My C# graph library
Create a new Graph objectum:
Graph graph = new Graph();
Create a random graph with 5-15 vertices and 5-15 edges with the following function:
graph.createRandomGraph();
Or specify the number of vertices and edges:
graph.createRandomGraph([int] vertices, [int] edges);
Every vertice has a unique ID, and every edge contains 2 vertice IDs To create a new vertice with a random ID:
graph.createNewPoint();
Or create a new vertice with a specific ID:
graph.createNewPoint([string] ID);
To create an edge you need 2 vertice IDs or vertice objects (GraphPoint):
graph.createNewConnection([string] ID1, [string] ID2);
graph.createNewConnection([GraphPoint] vertice1, [GraphPoint] vertice2);
List<GraphPoint> vertices = graph.getPoints();
List<GraphConnection> vertices = graph.getConnections();
To calculate the degree of a vertice you need to call the following function:
int degree = graph.getPointDegree([GraphPoint] vertice);
Or you can get an array of every degree in ascending order:
int[] degrees = graph.getDegree();
You can simply count the number of components by the following function:
int components = graph.countComponents();
You can convert you graph into a edge matrix by the following function:
bool[,] arr = graph.convertToBoolArray();
Or you can convert your graph into a matrix string:
string matrix = graph.boolString();
The result will look like this:
7
0 0 0 0 1 1 1
0 0 0 0 1 1 1
0 0 0 0 1 1 1
0 0 0 0 1 1 1
1 1 1 1 0 0 0
1 1 1 1 0 0 0
1 1 1 1 0 0 0
To get a graph from a matrix string:
graph.importFromStringData([string] data);
Not fully functional You can generate a graph from a list of degrees:
graph.generateGraphFromDegree([int[]] degreeArray);
To detect if a graph matches with another graph use the following operators:
if (graph1 == graph2) {
}
Note, that this perator does not check for isomorphism
To get a graphs complementer use the following operator:
Graph comp = ~ graph;
To check is two graphs are isomorph, use the following operator:
if (graph1 ^ graph2) {
}
You can simply generate an image of the graph with this function:
Image img = graph.generateImage();