|
@@ -26,26 +26,25 @@ namespace GraphDrawer
|
|
|
|
|
|
VertexArray.vertexCount = 0;
|
|
|
}
|
|
|
+
|
|
|
public GraphByClick(int[,] matrix, bool state)
|
|
|
{
|
|
|
InitializeComponent();
|
|
|
VertexArray.vertexCount = 0;
|
|
|
+
|
|
|
+
|
|
|
if (state)
|
|
|
{
|
|
|
int length = (int)Math.Sqrt(matrix.Length);
|
|
|
for(int i = 0; i < length; i++)
|
|
|
- {
|
|
|
- VertexArray.AddVertex(canvas, rand.Next(0, (int)canvas.ActualWidth/2), rand.Next(0, (int)canvas.ActualHeight/2));
|
|
|
- }
|
|
|
+ VertexArray.AddVertex(canvas, rand.Next(1, 600), rand.Next(1, 300));
|
|
|
|
|
|
for(int i = 0; i < length; i++)
|
|
|
{
|
|
|
for(int j = 0; j < length; j++)
|
|
|
{
|
|
|
if (matrix[i, j] == 1)
|
|
|
- {
|
|
|
EdgeArray.AddEdge(canvas, VertexArray.vertex[i], VertexArray.vertex[j]);
|
|
|
- }
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@@ -53,7 +52,7 @@ namespace GraphDrawer
|
|
|
|
|
|
private void backBtn_Click(object sender, RoutedEventArgs e) // Выбор режима рисования
|
|
|
{
|
|
|
- ChoiseRegime regime = new ChoiseRegime();
|
|
|
+ ChoiceMode regime = new ChoiceMode();
|
|
|
regime.Show();
|
|
|
Close();
|
|
|
}
|
|
@@ -238,106 +237,70 @@ namespace GraphDrawer
|
|
|
GraphState.named = false;
|
|
|
}
|
|
|
|
|
|
- private void AdjacencyBtn_Click(object sender, RoutedEventArgs e)
|
|
|
+ private void AdjacencyMatrix_Click(object sender, RoutedEventArgs e)
|
|
|
{
|
|
|
- if (!GraphState.focused)
|
|
|
+ int length = VertexArray.vertex.Length;
|
|
|
+ int[,] matrix = new int[length, length];
|
|
|
+ for(int i = 0; i < VertexArray.vertex.Length; i++)
|
|
|
{
|
|
|
- int length = VertexArray.vertex.Length;
|
|
|
- int[,] matrix = new int[length, length];
|
|
|
- for (int i = 0; i < length; i++)
|
|
|
+ var vertex1 = VertexArray.vertex[i];
|
|
|
+ for(int j = 0; j < VertexArray.vertex.Length; j++)
|
|
|
{
|
|
|
- var vertex1 = VertexArray.vertex[i];
|
|
|
- for (int j = 0; j < length; j++)
|
|
|
+ if (i != j)
|
|
|
{
|
|
|
var vertex2 = VertexArray.vertex[j];
|
|
|
for (int k = 0; k < EdgeArray.edge.Length; k++)
|
|
|
{
|
|
|
var edge = EdgeArray.edge[k];
|
|
|
- if (i == j)
|
|
|
- {
|
|
|
- matrix[i, j] = 0;
|
|
|
- }
|
|
|
- else if ((Vertex.Compare(vertex1, edge.startVertex) && Vertex.Compare(vertex2, edge.finishVertex)) || (Vertex.Compare(vertex1, edge.finishVertex) && Vertex.Compare(vertex2, edge.startVertex)))
|
|
|
- {
|
|
|
+ if (Vertex.Compare(edge.finishVertex, vertex1) && Vertex.Compare(edge.startVertex, vertex2))
|
|
|
+ matrix[i, j] = 1;
|
|
|
+ else if (Vertex.Compare(edge.startVertex, vertex1) && Vertex.Compare(edge.finishVertex, vertex2))
|
|
|
matrix[i, j] = 1;
|
|
|
- matrix[j, i] = matrix[i, j];
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- matrix[i, j] = 0;
|
|
|
- }
|
|
|
}
|
|
|
}
|
|
|
- }
|
|
|
- for (int i = 0; i < length; i++)
|
|
|
- for (int j = 0; j < length; j++)
|
|
|
- if (i > j)
|
|
|
- matrix[i, j] = matrix[j, i];
|
|
|
- AdjacencyMatrix adjacencyMatrix = new AdjacencyMatrix(matrix, false);
|
|
|
- adjacencyMatrix.Show();
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- int length = VertexArray.vertex.Length;
|
|
|
- int[,] matrix = new int[length, length];
|
|
|
- for (int i = 0; i < length; i++)
|
|
|
- {
|
|
|
- var vertex1 = VertexArray.vertex[i];
|
|
|
- for (int j = 0; j < length; j++)
|
|
|
+ else
|
|
|
{
|
|
|
- var vertex2 = VertexArray.vertex[j];
|
|
|
- for (int k = 0; k < ArrowedEdgeArray.edge.Length; k++)
|
|
|
- {
|
|
|
- var edge = ArrowedEdgeArray.edge[k];
|
|
|
- if (i == j)
|
|
|
- {
|
|
|
- matrix[i, j] = 0;
|
|
|
- }
|
|
|
- else if ((Vertex.Compare(vertex1, edge.startVertex) && Vertex.Compare(vertex2, edge.finishVertex)))
|
|
|
- {
|
|
|
- matrix[i, j] = 1;
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- matrix[i, j] = 0;
|
|
|
- }
|
|
|
- }
|
|
|
+ matrix[i, j] = 0;
|
|
|
}
|
|
|
}
|
|
|
- AdjacencyMatrix adjacencyMatrix = new AdjacencyMatrix(matrix, false);
|
|
|
- adjacencyMatrix.Show();
|
|
|
}
|
|
|
+
|
|
|
+ for (int i = 0; i < length; i++)
|
|
|
+ for (int j = 0; j < length; j++)
|
|
|
+ matrix[i, j] = matrix[j, i];
|
|
|
+
|
|
|
+ MatrixOutput output = new MatrixOutput(matrix);
|
|
|
+ output.Show();
|
|
|
}
|
|
|
|
|
|
- private void IncidenceBtn_Click(object sender, RoutedEventArgs e)
|
|
|
+ private void IncidenceMatrix_Click(object sender, RoutedEventArgs e)
|
|
|
{
|
|
|
- int vertexLength = VertexArray.vertex.Length;
|
|
|
- int edgeLength = EdgeArray.edge.Length;
|
|
|
- int[,] matrix = new int[vertexLength, edgeLength];
|
|
|
- for(int i = 0; i < vertexLength; i++)
|
|
|
+ int rows = VertexArray.vertex.Length;
|
|
|
+ int cols = EdgeArray.edge.Length;
|
|
|
+ int[,] matrix = new int[rows, cols];
|
|
|
+ for(int i = 0; i < rows; i++)
|
|
|
{
|
|
|
var vertex = VertexArray.vertex[i];
|
|
|
- for(int j = 0; j < edgeLength; j++)
|
|
|
+
|
|
|
+ for (int j = 0; j < cols; j++)
|
|
|
{
|
|
|
var edge = EdgeArray.edge[j];
|
|
|
- if(Vertex.Compare(vertex, edge.startVertex) || Vertex.Compare(vertex, edge.finishVertex))
|
|
|
- {
|
|
|
+ if (Vertex.Compare(vertex, edge.finishVertex) || Vertex.Compare(vertex, edge.startVertex))
|
|
|
matrix[i, j] = 1;
|
|
|
- }
|
|
|
else
|
|
|
- {
|
|
|
matrix[i, j] = 0;
|
|
|
- }
|
|
|
}
|
|
|
}
|
|
|
- AdjacencyMatrix incidence = new AdjacencyMatrix(matrix, true);
|
|
|
- incidence.Show();
|
|
|
+ MatrixOutput output = new MatrixOutput(matrix);
|
|
|
+ output.Show();
|
|
|
+
|
|
|
}
|
|
|
|
|
|
- private void GraphByMatrix_Click(object sender, RoutedEventArgs e)
|
|
|
+ private void CreateGraphByMatrixBtn_Click(object sender, RoutedEventArgs e)
|
|
|
{
|
|
|
- GraphByMatrix graph = new GraphByMatrix();
|
|
|
- graph.Show();
|
|
|
+ GraphByMatrix matrix = new GraphByMatrix();
|
|
|
+ matrix.Show();
|
|
|
+ Close();
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -352,6 +315,7 @@ namespace GraphDrawer
|
|
|
|
|
|
public static int AddVertex(Canvas canvas, int x, int y)
|
|
|
{
|
|
|
+
|
|
|
vertexCount++;
|
|
|
Array.Resize(ref vertex, vertexCount);
|
|
|
Array.Resize(ref ellipse, vertexCount);
|