public Form1()
        {
            InitializeComponent();

            caracter.Controls.Clear();
            for (int i = 0; i < 12; i++)
            {
                for (int j = 0; j < 10; j++)
                {
                    int idx = 10 * i + j;  //tabindex
                    int py  = 20 * i + 20; //linha
                    int px  = 20 * j + 20; //coluna
                    caracter.Controls.Add(getLabel(px, py, idx));
                }
            }

            numeros = Casos.Carregar("numeros.xml");
            listBox2.Items.Clear();
            for (int i = 0; i < numeros.Count; i++)
            {
                listBox2.Items.Add("Numero " + numeros.lista_numero[i]);
            }

            thr = new Thread(new ThreadStart(treinar_rede));
            update_buttons(true);

            Button.CheckForIllegalCrossThreadCalls      = false;
            TextBox.CheckForIllegalCrossThreadCalls     = false;
            ProgressBar.CheckForIllegalCrossThreadCalls = false;
        }
 public static Casos Carregar(string path)
 {
     try
     {
         XmlSerializer reader = new XmlSerializer(typeof(Casos));
         StreamReader  file   = new StreamReader(path);
         Casos         nc     = (Casos)reader.Deserialize(file);
         file.Close();
         return(nc);
     }
     catch (Exception e)
     {
         Console.WriteLine(e.Message);
         return(null);
     }
 }
        private void button2_Click(object sender, EventArgs e)
        {
            //gerar casos randomicos
            casos = new Casos();

            double taxa_variacao_do_azul   = 0.10;
            double taxa_variacao_do_branco = 0.01;
            int    num_variacoes           = 20;

            listBox1.Items.Clear();

            for (int k = 0; k < numeros.Count; k++)
            {
                bool[][] caso_base = numeros.lista_caso[k];

                for (int n = 0; n < num_variacoes; n++)
                {
                    listBox1.Items.Add(string.Format("Caso {0} - {1}", k, n + 1));

                    bool[][] caso = new bool[12][];
                    for (int i = 0; i < 12; i++)
                    {
                        caso[i] = new bool[10];
                        for (int j = 0; j < 10; j++)
                        {
                            if (caso_base[i][j])
                            {
                                if (rnd.NextDouble() > taxa_variacao_do_azul)
                                {
                                    caso[i][j] = true;
                                }
                            }
                            else
                            {
                                if (rnd.NextDouble() < taxa_variacao_do_branco)
                                {
                                    caso[i][j] = true;
                                }
                            }
                        }
                    }

                    casos.AddCaso(caso, numeros.lista_numero[k]);
                }
            }
        }
        private void button4_Click(object sender, EventArgs e)
        {
            OpenFileDialog abrir = new OpenFileDialog();

            abrir.Title  = "Abrir Casos Gerados";
            abrir.Filter = "Formato XML (.xml)|*.xml|All files (*.*)|*.*";

            if (abrir.ShowDialog() != DialogResult.OK)
            {
                return;
            }

            casos = Casos.Carregar(abrir.FileName);
            listBox1.Items.Clear();
            for (int i = 0; i < casos.Count; i++)
            {
                listBox1.Items.Add(string.Format("Caso {0}", i));
            }
        }