Ejemplo n.º 1
0
        private string print_graph_coloring_result(graph_coloring gc, int[] result)
        {
            string pr = "Graph coloring problem:\r\nAdjacency matrix:\r\n  ";
            int    c  = gc.number_of_colors();
            int    n  = result.Length;

            bool[,] matrix = gc.get_matrix();
            for (int i = 0; i < n; i++)
            {
                pr += "  " + i + " ";
            }
            pr += "\r\n";
            for (int i = 0; i < n; i++)
            {
                pr += i + " ";
                for (int j = 0; j < n; j++)
                {
                    pr += "  " + bool_to_check(matrix[i, j]) + " ";
                }
                pr += "\r\n";
            }
            pr += "number of available colors: " + c + "\r\nresult:\r\n";

            for (int i = 0; i < n; i++)
            {
                pr += "[" + i + "]: " + int_to_color(result[i]) + "\t";
            }

            if (!gc.total_satisfaction(result))
            {
                pr += ("\r\nAlgorithm trapped in local optimum!!");
            }
            return(pr);
        }
Ejemplo n.º 2
0
        private void button4_Click(object sender, EventArgs e)
        {
            textBox5.Text = "searching...";
            textBox5.Refresh();
            int color_constraint = number_of_colors();

            int[] a = helper.generate_random_array(number_of_nodes(), color_constraint);
            bool[,] adj_matrix = get_adjacency_matrix();
            ILocal_Search <int[]> h  = new first_choise <int[]>();
            graph_coloring        gc = new graph_coloring(adj_matrix, color_constraint);

            int[] result = h.solve(gc, a);
            textBox5.Text = print_graph_coloring_result(gc, result);
        }
Ejemplo n.º 3
0
        private void button10_Click(object sender, EventArgs e)
        {
            textBox10.Text = "searching...";
            textBox10.Refresh();
            int color_constraint = number_of_colors();

            int[] a = helper.generate_random_array(number_of_nodes(), color_constraint);
            bool[,] adj_matrix = get_adjacency_matrix();
            double initial_temp            = (double)numericUpDown8.Value;
            double cooling_factor          = double.Parse(textBox6.Text);
            simulated_annealing <int[]> sa = new simulated_annealing <int[]>(initial_temp, cooling_factor);
            graph_coloring gc = new graph_coloring(adj_matrix, color_constraint);

            int[] result = sa.solve(gc, a);
            textBox10.Text = print_graph_coloring_result(gc, result);
        }
Ejemplo n.º 4
0
        private void button11_Click(object sender, EventArgs e)
        {
            textBox9.Text = "searching...";
            textBox9.Refresh();
            int color_constraint = number_of_colors();
            int n_beams          = number_of_beams();

            bool[,] adj_matrix = get_adjacency_matrix();
            int[][] initialize_beams = new int[n_beams][];
            int     n_of_nodes       = number_of_nodes();

            for (int i = 0; i < n_beams; i++)
            {
                initialize_beams[i] = helper.generate_random_array(n_of_nodes, color_constraint);
            }
            local_beam_search <int[]> lbs = new local_beam_search <int[]>();
            graph_coloring            gc  = new graph_coloring(adj_matrix, color_constraint);

            int[] result = lbs.solve(gc, initialize_beams, n_beams);
            textBox9.Text = print_graph_coloring_result(gc, result);
        }
Ejemplo n.º 5
0
        private void button7_Click(object sender, EventArgs e)
        {
            textBox5.Text = "searching...";
            textBox5.Refresh();
            int color_constraint = number_of_colors();

            bool[,] adj_matrix = get_adjacency_matrix();
            ILocal_Search <int[]> h  = new best_choise <int[]>();
            graph_coloring        gc = new graph_coloring(adj_matrix, color_constraint);

            int[] a;
            int[] result;
            int   i = 0;

            do
            {
                i++;
                a      = helper.generate_random_array(number_of_nodes(), color_constraint);
                result = h.solve(gc, a);
            } while (!gc.total_satisfaction(result) && i < 1000);

            textBox5.Text = print_graph_coloring_result(gc, result);
        }