|
@@ -79,6 +79,15 @@ namespace DrawGraph
|
|
|
return matrix;
|
|
|
}
|
|
|
/// <summary>
|
|
|
+ /// Creates an adjacency matrix from given graph
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="graph">Your graph</param>
|
|
|
+ /// <returns>Adjacency matrix in 2D int array</returns>
|
|
|
+ public static int[,] AdjacencyCreate(Graph graph)
|
|
|
+ {
|
|
|
+ return AdjacencyCreate(graph.Nodes, graph.Edges);
|
|
|
+ }
|
|
|
+ /// <summary>
|
|
|
/// Creates an adjacency matrix from given nodes and edges
|
|
|
/// </summary>
|
|
|
/// <param name="nodes">List of nodes</param>
|
|
@@ -135,6 +144,15 @@ namespace DrawGraph
|
|
|
return matrix;
|
|
|
}
|
|
|
/// <summary>
|
|
|
+ /// Creates an incidence matrix from given graph
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="graph">Your graph</param>
|
|
|
+ /// <returns>Incidence matrix in 2D int array</returns>
|
|
|
+ public static int[,] IncidenceCreate(Graph graph)
|
|
|
+ {
|
|
|
+ return IncidenceCreate(graph.Nodes, graph.Edges);
|
|
|
+ }
|
|
|
+ /// <summary>
|
|
|
/// Creates an incidence matrix from given nodes and edges
|
|
|
/// </summary>
|
|
|
/// <param name="nodes">List of nodes</param>
|
|
@@ -152,7 +170,7 @@ namespace DrawGraph
|
|
|
/// </summary>
|
|
|
/// <param name="matrix">Adjacency matrix</param>
|
|
|
/// <returns>Tuple of node and edge array</returns>
|
|
|
- public static Tuple<Node[], Edge[]> FromAdjacency(int[,] matrix)
|
|
|
+ public static Graph FromAdjacency(int[,] matrix)
|
|
|
{
|
|
|
Random random = new Random();
|
|
|
Node[] nodes = new Node[matrix.GetLength(0)];
|
|
@@ -200,7 +218,8 @@ namespace DrawGraph
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
- return Tuple.Create(nodes, edges);
|
|
|
+ Graph graph = new Graph(nodes, edges);
|
|
|
+ return graph;
|
|
|
}
|
|
|
/// <summary>
|
|
|
/// Creates nodes and edges from adjacency matrix and add all elements to your canvas
|
|
@@ -208,21 +227,21 @@ namespace DrawGraph
|
|
|
/// <param name="matrix">Adjacency matrix</param>
|
|
|
/// <param name="canvas">Canvas to draw</param>
|
|
|
/// <returns>Tuple of nodes and edges</returns>
|
|
|
- public static Tuple<Node[], Edge[]> FromAdjacencyToCanvas(int[,] matrix, Canvas canvas)
|
|
|
+ public static Graph FromAdjacencyToCanvas(int[,] matrix, Canvas canvas)
|
|
|
{
|
|
|
var items = FromAdjacency(matrix);
|
|
|
- Node[] nodes = items.Item1;
|
|
|
- Edge[] edges = items.Item2;
|
|
|
+ Node[] nodes = items.Nodes;
|
|
|
+ Edge[] edges = items.Edges;
|
|
|
|
|
|
GraphAction.AddRangeToCanvas(nodes, edges, canvas);
|
|
|
- return Tuple.Create(nodes, edges);
|
|
|
+ return items;
|
|
|
}
|
|
|
/// <summary>
|
|
|
/// Creates nodes and edges from incidence matrix
|
|
|
/// </summary>
|
|
|
/// <param name="matrix">Incidence matrix</param>
|
|
|
/// <returns>Tuple of nodes and edges array</returns>
|
|
|
- public static Tuple<Node[], Edge[]> FromIncidence(int[,] matrix)
|
|
|
+ public static Graph FromIncidence(int[,] matrix)
|
|
|
{
|
|
|
Random random = new Random();
|
|
|
int rows = matrix.GetLength(0);
|
|
@@ -258,7 +277,8 @@ namespace DrawGraph
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
- return Tuple.Create(nodes, edges);
|
|
|
+ Graph graph = new Graph(nodes, edges);
|
|
|
+ return graph;
|
|
|
}
|
|
|
/// <summary>
|
|
|
/// Creates nodes and edges from incidence matrix and add all elements to your canvas
|
|
@@ -266,13 +286,33 @@ namespace DrawGraph
|
|
|
/// <param name="matrix">Incidence matrix</param>
|
|
|
/// <param name="canvas">Canvas to draw</param>
|
|
|
/// <returns>Tuple of nodes and edges</returns>
|
|
|
- public static Tuple<Node[], Edge[]> FromIncidenceToCanvas(int[,] matrix, Canvas canvas)
|
|
|
+ public static Graph FromIncidenceToCanvas(int[,] matrix, Canvas canvas)
|
|
|
{
|
|
|
var tuple = FromIncidence(matrix);
|
|
|
- Node[] nodes = tuple.Item1;
|
|
|
- Edge[] edges = tuple.Item2;
|
|
|
+ Node[] nodes = tuple.Nodes;
|
|
|
+ Edge[] edges = tuple.Edges;
|
|
|
GraphAction.AddRangeToCanvas(nodes, edges, canvas);
|
|
|
- return Tuple.Create(nodes, edges);
|
|
|
+ return tuple;
|
|
|
+ }
|
|
|
+
|
|
|
+ //TODO
|
|
|
+ public static int[,] DistanceCreate(Node[] nodes, Edge[] edges)
|
|
|
+ {
|
|
|
+ if (edges is null)
|
|
|
+ {
|
|
|
+ throw new ArgumentNullException(nameof(edges));
|
|
|
+ }
|
|
|
+
|
|
|
+ var length = nodes.Length;
|
|
|
+ int[,] matrix = new int[length, length];
|
|
|
+
|
|
|
+
|
|
|
+ return matrix;
|
|
|
+ }
|
|
|
+
|
|
|
+ public static int[,] DistanceCreate(Graph graph)
|
|
|
+ {
|
|
|
+ return DistanceCreate(graph.Nodes, graph.Edges);
|
|
|
}
|
|
|
}
|
|
|
}
|