Exemple #1
0
        public void PrintAllPaths()
        {
            if (graph == null)
            {
                return;
            }
            string begin = pathBegin.Text.ToUpper(), end = pathEnd.Text.ToUpper();

            if (begin == null || end == null || !graph.Vertices.ContainsKey(begin) || !graph.Vertices.ContainsKey(end))
            {
                return;
            }
            var result = GraphUtils.FindAllPathsWithLength(graph.AdjacenceyList, graph.Vertices, begin, end, (int)pathLength.Value);

            terminalForm.PrintLn();
            terminalForm.PrintLn("All Paths from " + begin + " to " + end + " :");
            terminalForm.PrintLn();


            foreach (var path in result)
            {
                foreach (var v in path)
                {
                    terminalForm.Print(v + " ");
                }
                terminalForm.PrintLn();
            }
        }
Exemple #2
0
        private void PrintDegressSequence()
        {
            var result = GraphUtils.GetDegreeSequence(graph.AdjacenceyList);

            degreesSeqLabel.Text = "";
            for (int i = 0; i < graph.VerticesCount; i++)
            {
                degreesSeqLabel.Text += result[i] + " ";
            }
        }
Exemple #3
0
        private void DrawGraph()
        {
            if (graph == null || !graph.IsValid())
            {
                return;
            }
            //Clear The Previous drawing

            graph.verticesLabels = GraphUtils.DrawGraph(graph.AdjacencyMatrix, graph.Vertices, graph.verticesLabels, graphics, paintBox, paintBox.Size.Width, paintBox.Size.Height);
        }
Exemple #4
0
 private void PrintContainsOdd()
 {
     if (GraphUtils.ContiansOddCycle(graph.AdjacenceyList, graph.Vertices))
     {
         oddCycleLabel.ForeColor = Color.Green;
         oddCycleLabel.Text      = "Yes";
     }
     else
     {
         oddCycleLabel.ForeColor = Color.Red;
         oddCycleLabel.Text      = "No";
     }
 }
Exemple #5
0
        private void button1_Click(object sender, EventArgs e)
        {
            var adjacencyMatrix1 = CreateAdjacencyMatrixFromText(isomorphicGraphInput1.Text);
            var adjacencyMatrix2 = CreateAdjacencyMatrixFromText(isomorphicGraphInput2.Text);

            if (adjacencyMatrix1 == null || adjacencyMatrix2 == null)
            {
                MessageBox.Show("Make Sure The Adjacency matrices are Valid and doesn't contains extra spaces", "Not Valid Input", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }
            Graph graph1 = new Graph(adjacencyMatrix1);
            Graph graph2 = new Graph(adjacencyMatrix2);

            //Is The Same Number Of Vertices
            if (graph1.VerticesCount == graph2.VerticesCount)
            {
                sameNOfVerticesLabel.ForeColor = Color.Green;
                sameNOfVerticesLabel.Text      = "Yes";
            }
            else
            {
                sameNOfVerticesLabel.ForeColor = Color.Red;
                sameNOfVerticesLabel.Text      = "No";
            }

            //Is The Same Number Of Edges
            if (graph1.EdgesCount == graph2.EdgesCount)
            {
                sameNOfEdges.ForeColor = Color.Green;
                sameNOfEdges.Text      = "Yes";
            }
            else
            {
                sameNOfEdges.ForeColor = Color.Red;
                sameNOfEdges.Text      = "No";
            }
            //Is The Same Number Of Components
            if (GraphUtils.GetNumberOfComponents(graph1.AdjacenceyList, graph1.Vertices) == GraphUtils.GetNumberOfComponents(graph2.AdjacenceyList, graph2.Vertices))
            {
                sameNOfComponents.ForeColor = Color.Green;
                sameNOfComponents.Text      = "Yes";
            }
            else
            {
                sameNOfComponents.ForeColor = Color.Red;
                sameNOfComponents.Text      = "No";
            }
            //Is The Same Degrees Sequence
            var degreeSequence1 = GraphUtils.GetDegreeSequence(graph1.AdjacenceyList).OrderBy(n => n).ToList();
            var degreeSequence2 = GraphUtils.GetDegreeSequence(graph2.AdjacenceyList).OrderBy(n => n).ToList();

            if (degreeSequence2.Count == degreeSequence1.Count)
            {
                bool success = true;
                for (int i = 0; i < degreeSequence1.Count; i++)
                {
                    if (degreeSequence1[i] != degreeSequence2[i])
                    {
                        sameDegressSequence.ForeColor = Color.Red;
                        sameDegressSequence.Text      = "No";
                        success = false;
                        break;
                    }
                }
                if (success)
                {
                    sameDegressSequence.ForeColor = Color.Green;
                    sameDegressSequence.Text      = "Yes";
                }
            }
            else
            {
                sameDegressSequence.ForeColor = Color.Red;
                sameDegressSequence.Text      = "No";
            }


            //Is The Same Number of K Cycles
            var graphCycles1 = GraphUtils.GetAllCycles(graph1.AdjacenceyList, graph1.Vertices);
            var graphCycles2 = GraphUtils.GetAllCycles(graph2.AdjacenceyList, graph2.Vertices);

            if (graphCycles1.Count == graphCycles2.Count)
            {
                bool success = true;
                for (int i = 0; i < graphCycles1.Count; i++)
                {
                    if (graphCycles1[i] != graphCycles2[i])
                    {
                        sameNumberOfKCycles.ForeColor = Color.Red;
                        sameNumberOfKCycles.Text      = "No";
                        success = false;
                        break;
                    }
                }
                if (success)
                {
                    sameNumberOfKCycles.ForeColor = Color.Green;
                    sameNumberOfKCycles.Text      = "Yes";
                }
            }
            else
            {
                sameNumberOfKCycles.ForeColor = Color.Red;
                sameNumberOfKCycles.Text      = "No";
            }
        }
Exemple #6
0
        private void PrintNumOfComponents()
        {
            var numOfComponents = GraphUtils.GetNumberOfComponents(graph.AdjacenceyList, graph.Vertices);

            numOfComponentsLabel.Text = numOfComponents.ToString();
        }