Esempio n. 1
0
File: Form1.cs Progetto: dovh/openu
        private void RandomizeButton_Click(object sender, EventArgs e)
        {
            Source.Preferences Data = Source.Preferences.GetInstance();
            Data.Randomize();
            m_Network.Randomize();

            dump();
        }
Esempio n. 2
0
File: Form1.cs Progetto: dovh/openu
        void dump(bool Mark = false)
        {
            Source.Preferences data = Source.Preferences.GetInstance();
            for (int y = 0; y < 10; y++)
            {
                int Marked = -1;
                for (int x = 0; x < 10; x++)
                {
                    Source.Neuron N = m_Network.Neuron(x, y);
                    NetworkGridView.Rows[y].Cells[x].Value = N.ToString();

                    if (Mark && N.Value > 0)
                    {
                        NetworkGridView.Rows[y].Cells[x].Style.ApplyStyle(m_RedStyle);
                        Marked = x + 1;
                    }
                    else
                    {
                        NetworkGridView.Rows[y].Cells[x].Style.ApplyStyle(m_DefaultStyle);
                    }
                }

                for (int x = 0; x < 10; x++)
                {
                    int Preference = data.GetPreferenceByIndex(y, x);
                    PreferencesGridView.Rows[y].Cells[x + 1].Value = Preference.ToString();

                    if (Mark && Marked == Preference)
                    {
                        PreferencesGridView.Rows[y].Cells[x + 1].Style.ApplyStyle(m_RedStyle);
                    }
                    else
                    {
                        PreferencesGridView.Rows[y].Cells[x + 1].Style.ApplyStyle(m_DefaultStyle);
                    }
                }
            }

            if (Mark)
            {
                TotalHappinessTextBox.Text = String.Format("{0:00.00}%", m_Network.GetTotalHappines());
                if (m_Network.IsLegaySolution())
                {
                    LegalSolutionTextBox.Text      = "Yes";
                    LegalSolutionTextBox.BackColor = Color.Green;
                }
                else
                {
                    LegalSolutionTextBox.Text      = "NO";
                    LegalSolutionTextBox.BackColor = Color.Red;
                }
            }
        }
Esempio n. 3
0
File: Form1.cs Progetto: dovh/openu
        private void runThread()
        {
            m_running_start_time = DateTime.Now;
            DateTime time_sample = m_running_start_time;

            for (int batch_index = 0; batch_index < 100; batch_index++)
            {
                bool Stable = false;
                while (m_running && !Stable)
                {
                    Stable = m_Network.Step(false);
                    dumpCallback d = new dumpCallback(dump);
                    if (d != null)
                    {
                        Invoke(d, new object[] { false });
                    }
                }

                dumpCallback d2 = new dumpCallback(dump);
                if (d2 != null)
                {
                    Invoke(d2, new object[] { true });
                }

                if (m_batch && m_running)
                {
                    Console.WriteLine("{0}: {1}, {2}", batch_index, TotalHappinessTextBox.Text, m_Network.IsLegaySolution());

                    if (!m_Network.IsLegaySolution())
                    {
                        Console.Write("");
                    }

                    Source.Preferences Data = Source.Preferences.GetInstance();
                    Data.Randomize();
                    m_Network.Randomize();
                }
                else
                {
                    break;
                }
            }

            m_running = false;
            m_batch   = false;
        }