示例#1
0
        private void GenerateConnections(int num_v, int num_e)
        {
            StackPanelWithConnections.Children.Clear();

            adjacencyMatrix = new AdjacencyMatrix(num_v);
            adjacencyMatrix.Display(StackPanelForDisplayingAdjacencyMatrix, MyCanvas, StackPanelForDisplayingIncidenceMatrix, StackPanelForDisplayingAdjacencylist);


            TextBlock tmpBlock = new TextBlock();

            tmpBlock.Text = "Uzupełnij połączenia:";
            tmpBlock.VerticalAlignment = VerticalAlignment.Center;
            tmpBlock.Margin            = new Thickness(10, 20, 0, 20);
            StackPanelWithConnections.Children.Add(tmpBlock);

            int j = 0;

            ListOfLeftComboBoxes  = new List <ComboBox>();
            ListOfRightComboBoxes = new List <ComboBox>();

            for (int i = 0; i < num_e; i++)
            {
                StackPanel stackPanelForConn = new StackPanel();
                stackPanelForConn.Orientation = Orientation.Horizontal;
                stackPanelForConn.Margin      = new Thickness(20, 0, 0, 0);

                TextBlock fromInfo = new TextBlock();
                fromInfo.Text = "Połączenie od: ";

                TextBlock toInfo = new TextBlock();
                toInfo.Text = " do: ";

                ComboBox fromComboBox = new ComboBox();
                SetComboBox(num_v, fromComboBox);
                fromComboBox.Tag = j;
                ListOfRightComboBoxes.Add(fromComboBox);
                fromComboBox.SelectionChanged += FromComboBox_SelectionChanged;
                fromComboBox.DropDownOpened   += FromComboBox_DropDownOpened;

                ComboBox toComboBox = new ComboBox();
                SetComboBox(num_v, toComboBox);
                toComboBox.Tag       = j + 1;
                toComboBox.IsEnabled = false;
                ListOfLeftComboBoxes.Add(toComboBox);
                toComboBox.SelectionChanged += ToComboBox_SelectionChanged;


                stackPanelForConn.Children.Add(fromInfo);
                stackPanelForConn.Children.Add(fromComboBox);
                stackPanelForConn.Children.Add(toInfo);
                stackPanelForConn.Children.Add(toComboBox);

                StackPanelWithConnections.Children.Add(stackPanelForConn);

                j += 2;
            }
        }
示例#2
0
        // Losowanie grafu G(n,l)
        private void Button_Click_1(object sender, RoutedEventArgs e)
        {
            if (Num_Of_Vertexes_To_Draw.Text == "")
            {
                Num_Of_Vertexes_To_Draw.Background = Brushes.OrangeRed;
            }
            else if (Num_Of_Edges_To_Draw.Text == "")
            {
                Num_Of_Vertexes_To_Draw.Background = Brushes.White;
                Num_Of_Edges_To_Draw.Background    = Brushes.OrangeRed;
            }
            else if ((Int32.Parse(Num_Of_Vertexes_To_Draw.Text) * Int32.Parse(Num_Of_Vertexes_To_Draw.Text)
                      - Int32.Parse(Num_Of_Vertexes_To_Draw.Text)) / 2 >= Int32.Parse(Num_Of_Edges_To_Draw.Text))
            {
                Num_Of_Vertexes_To_Draw.Background = Brushes.White;
                Num_Of_Edges_To_Draw.Background    = Brushes.White;

                var num_of_v = Int32.Parse(Num_Of_Vertexes_To_Draw.Text);
                var num_of_e = Int32.Parse(Num_Of_Edges_To_Draw.Text);

                adjacencyMatrix = new AdjacencyMatrix(num_of_v);

                for (int i = 0; i < num_of_v; i++)
                {
                    for (int j = i + 1; j < num_of_v; j++)
                    {
                        adjacencyMatrix.AdjacencyArray[i, j] = 0;
                        adjacencyMatrix.AdjacencyArray[j, i] = 0;
                    }
                }

                int counter = 0;

                Random r = new Random();

                while (counter < num_of_e)
                {
                    int vertexToBeAdded_row = r.Next(0, num_of_v);
                    int vertexToBeAdded_col = r.Next(0, num_of_v);
                    if (adjacencyMatrix.AdjacencyArray[vertexToBeAdded_row, vertexToBeAdded_col] == 0 && vertexToBeAdded_row != vertexToBeAdded_col)
                    {
                        adjacencyMatrix.AdjacencyArray[vertexToBeAdded_row, vertexToBeAdded_col] = 1;
                        adjacencyMatrix.AdjacencyArray[vertexToBeAdded_col, vertexToBeAdded_row] = 1;
                        counter++;
                    }
                }
                adjacencyMatrix.Display(StackPanelForDisplayingAdjacencyMatrix, MyCanvas, StackPanelForDisplayingIncidenceMatrix, StackPanelForDisplayingAdjacencylist);
            }
            else
            {
                Num_Of_Vertexes_To_Draw.Background = Brushes.OrangeRed;
                Num_Of_Edges_To_Draw.Background    = Brushes.OrangeRed;
            }
        }
示例#3
0
        private void AdjacencyList_to_AdjacencyMatrix_Click(object sender, RoutedEventArgs e)
        {
            if (adjacencyMatrix != null)
            {
                IncidenceMatrix tmpIncendenceMatrix      = new IncidenceMatrix(adjacencyMatrix);
                AdjacencyList   tmpAdjacencyList         = new AdjacencyList(tmpIncendenceMatrix);
                AdjacencyMatrix convertedAdjacencyMatrix = new AdjacencyMatrix(tmpAdjacencyList);

                convertedAdjacencyMatrix.Display(StackPanelForDisplayingAdjacencyMatrix, MyCanvas, StackPanelForDisplayingIncidenceMatrix, StackPanelForDisplayingAdjacencylist);
            }
        }
示例#4
0
        public IncidenceMatrix(AdjacencyMatrix sourceMatrix)
        {
            int num_v = sourceMatrix.AdjacencyArray.GetLength(1);
            int num_e = 0;

            // Zliczanie liczby wierzcholkow w macierzy sasiedztwa
            for (int i = 0; i < num_v; i++)
            {
                for (int j = i + 1; j < num_v; j++)
                {
                    if (sourceMatrix.AdjacencyArray[i, j] == 1)
                    {
                        num_e++;
                    }
                }
            }

            IncidenceArray = new int[num_v, num_e];

            // Zerowanie macierzy incydencji
            for (int i = 0; i < num_v; i++)
            {
                for (int j = 0; j < num_e; j++)
                {
                    IncidenceArray[i, j] = 0;
                }
            }


            int k = 0;

            // Konwersja Macierzy sąsiedztwa -> incydencji
            for (int i = 0; i < num_v; i++)
            {
                for (int j = i + 1; j < num_v; j++)
                {
                    if (sourceMatrix.AdjacencyArray[i, j] == 1)
                    {
                        IncidenceArray[i, k] = -1;
                        IncidenceArray[j, k] = 1;
                        k++;
                    }
                }
            }
        }
示例#5
0
        // Losowanie grafu G(n,p)
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            if (Probability_Of_Edge_Occurence.Text != "")
            {
                Probability_Of_Edge_Occurence.Background = Brushes.White;

                StackPanelWithConnections.Children.Clear();

                Random r = new Random();
                int    v = Int32.Parse(Number_Of_Vertex.Text);

                adjacencyMatrix = new AdjacencyMatrix(v);

                for (int i = 0; i < v; i++)
                {
                    for (int j = i + 1; j < v; j++)
                    {
                        int probability = r.Next(0, 100);

                        if (probability > Int32.Parse(Probability_Of_Edge_Occurence.Text))
                        {
                            adjacencyMatrix.AdjacencyArray[i, j] = 0;
                            adjacencyMatrix.AdjacencyArray[j, i] = 0;
                        }
                        else
                        {
                            adjacencyMatrix.AdjacencyArray[i, j] = 1;
                            adjacencyMatrix.AdjacencyArray[j, i] = 1;
                        }
                        adjacencyMatrix.AdjacencyArray[i, i] = 0;
                    }
                }

                adjacencyMatrix.Display(StackPanelForDisplayingAdjacencyMatrix, MyCanvas, StackPanelForDisplayingIncidenceMatrix, StackPanelForDisplayingAdjacencylist);
            }
            else
            {
                Probability_Of_Edge_Occurence.Background = Brushes.OrangeRed;
            }
        }