예제 #1
0
        public void Simple(bool prepared)
        {
            if (!prepared)
            {
                return;
            }
            switch (_mode)
            {
            case 2:
                _r2 = new List <ValueDuo>();
                Mode2();

                _in2 = new List <ValueDuo>();
                _in2 = Output.CheckDoubleInDuo(_r2);

                Output.Duo(Output.CheckDoubleInDuo(_in2));
                break;

            case 3:
                for (var i = 0; i < 2; i++)
                {
                    _r3 = new List <ValueTrio>();
                    Mode3();

                    _in3 = new List <ValueTrio>();
                    _in3 = Output.CheckDoubleInTrio(_r3);

                    _t0.Clear(); _t1.Clear(); _t2.Clear(); _t3.Clear();
                    _used.Clear();

                    for (var j = 0; j < _in3.Count; j++)
                    {
                        var cs = ValueTrio.Cs(_in3[j]);
                        if (cs == 0)
                        {
                            _t0.Add(j);
                        }
                        if (cs == 1)
                        {
                            _t1.Add(j);
                        }
                        if (cs == 2)
                        {
                            _t2.Add(j);
                        }
                        if (cs == 3)
                        {
                            _t3.Add(j);
                        }
                    }
                }

                Output.Trio(Output.CheckDoubleInTrio(_in3));
                break;

            case 4:
                for (var i = 0; i < 3; i++)
                {
                    _r4 = new List <ValueQuartett>();
                    Mode4();

                    _in4 = new List <ValueQuartett>();
                    _in4 = Output.CheckDoubleInQuartett(_r4);

                    _t0.Clear(); _t1.Clear(); _t2.Clear(); _t3.Clear(); _t4.Clear();
                    _used.Clear();

                    for (var j = 0; j < _in4.Count; j++)
                    {
                        var cs = ValueQuartett.Cs(_in4[j]);
                        if (cs == 0)
                        {
                            _t0.Add(j);
                        }
                        if (cs == 1)
                        {
                            _t1.Add(j);
                        }
                        if (cs == 2)
                        {
                            _t2.Add(j);
                        }
                        if (cs == 3)
                        {
                            _t3.Add(j);
                        }
                        if (cs == 4)
                        {
                            _t4.Add(j);
                        }
                    }
                }

                Output.Quartett(Output.CheckDoubleInQuartett(_in4));
                break;

            case 5:
                for (var i = 0; i < 4; i++)
                {
                    Mode3();
                    _in5 = _r5;
                }
                break;

            case 6:
                for (var i = 0; i < 5; i++)
                {
                    Mode3();
                    _in6 = _r6;
                }
                break;
            }
        }
예제 #2
0
 public static bool EqualsTrio(ValueTrio a, ValueTrio b)
 {
     return(a.A == b.A && a.B == b.B && a.C == b.C);
 }
예제 #3
0
        private void buttonStart_Click(object sender, EventArgs e)
        {
            if (_checked)
            {
                // Debugging
                Console.WriteLine(@"Start simplifying");
                MainForm.DebugForm.AddLine("Start simplifying");

                // Get all rows
                var dgvr = dataGrid.Rows;

                // Debugging
                Console.WriteLine(@"Mode " + dataGrid.ColumnCount);
                MainForm.DebugForm.AddLine("Mode " + dataGrid.ColumnCount);

                // Create instance of Simplify.cs
                var simple = new Simplify();

                // 2 columns, use ValueDuo
                if (dataGrid.ColumnCount == 2)
                {
                    // as a result
                    var list = new List <ValueDuo>();

                    // Get row i
                    for (var i = 0; i < dgvr.Count - 1; i++)
                    {
                        int[] ba = { 0, 0 };
                        // Get cell j in row i
                        for (var j = 0; j < dgvr[i].Cells.Count; j++)
                        {
                            // check for 1 and 0 and put it into an bool-array
                            if (dgvr[i].Cells[j].Value.ToString() == "1")
                            {
                                ba[j] = 1;
                            }
                        }
                        // convert bool array to a ValueDuo and add it to Dictionary
                        var v = new ValueDuo(ba);
                        list.Add(v);
                    }
                    // put dictionary to instance simple of Simplify.cs
                    simple.Add(list); simple.SetMode(2);
                }

                // 3 columns, use ValueTrio
                if (dataGrid.ColumnCount == 3)
                {
                    // as a result
                    var list = new List <ValueTrio>();

                    // Get row i
                    for (var i = 0; i < dgvr.Count - 1; i++)
                    {
                        int[] ba = { 0, 0, 0 };
                        // Get cell j in row i
                        for (var j = 0; j < dgvr[i].Cells.Count; j++)
                        {
                            // check for 1 and 0 and put it into an bool-array
                            if (dgvr[i].Cells[j].Value.ToString() == "1")
                            {
                                ba[j] = 1;
                            }
                        }
                        // convert bool array to a ValueDuo and add it to Dictionary
                        var v = new ValueTrio(ba);
                        list.Add(v);
                    }
                    // put dictionary to instance simple of Simplify.cs
                    simple.Add(list); simple.SetMode(3);
                }

                // 4 columns, use ValueQuartett
                if (dataGrid.ColumnCount == 4)
                {
                    // as a result
                    var list = new List <ValueQuartett>();

                    // Get row i
                    for (var i = 0; i < dgvr.Count - 1; i++)
                    {
                        int[] ba = { 0, 0, 0, 0 };
                        // Get cell j in row i
                        for (var j = 0; j < dgvr[i].Cells.Count; j++)
                        {
                            // check for 1 and 0 and put it into an bool-array
                            if (dgvr[i].Cells[j].Value.ToString() == "1")
                            {
                                ba[j] = 1;
                            }
                        }
                        // convert bool array to a ValueDuo and add it to Dictionary
                        var v = new ValueQuartett(ba);
                        list.Add(v);
                    }
                    // put dictionary to instance simple of Simplify.cs
                    simple.Add(list); simple.SetMode(4);
                }

                // 5 columns, use ValueQuintett
                if (dataGrid.ColumnCount == 5)
                {
                    // as a result
                    var list = new List <ValueQuintett>();

                    // Get row i
                    for (var i = 0; i < dgvr.Count - 1; i++)
                    {
                        int[] ba = { 0, 0, 0, 0, 0 };
                        // Get cell j in row i
                        for (var j = 0; j < dgvr[i].Cells.Count; j++)
                        {
                            // check for 1 and 0 and put it into an bool-array
                            if (dgvr[i].Cells[j].Value.ToString() == "1")
                            {
                                ba[j] = 1;
                            }
                        }
                        // convert bool array to a ValueDuo and add it to Dictionary
                        var v = new ValueQuintett(ba);
                        list.Add(v);
                    }
                    // put dictionary to instance simple of Simplify.cs
                    simple.Add(list); simple.SetMode(5);
                }

                // 6 columns, use ValueSextett
                if (dataGrid.ColumnCount == 6)
                {
                    // as a result
                    var list = new List <ValueSextett>();

                    // Get row i
                    for (var i = 0; i < dgvr.Count - 1; i++)
                    {
                        int[] ba = { 0, 0, 0, 0, 0, 0 };
                        // Get cell j in row i
                        for (var j = 0; j < dgvr[i].Cells.Count; j++)
                        {
                            // check for 1 and 0 and put it into an bool-array
                            if (dgvr[i].Cells[j].Value.ToString() == "1")
                            {
                                ba[j] = 1;
                            }
                        }
                        // convert bool array to a ValueDuo and add it to Dictionary
                        var v = new ValueSextett(ba);
                        list.Add(v);
                    }
                    // put dictionary to instance simple of Simplify.cs
                    simple.Add(list); simple.SetMode(6);
                }

                // Prepare the algorythm and run it!
                simple.Simple(simple.Prepare());

                if (MainForm.OutputWindow.Visible)
                {
                    MainForm.OutputWindow.Hide();
                }
                else
                {
                    MainForm.OutputWindow = new OutputDnf();
                    MainForm.OutputWindow.Activate();

                    if (dataGrid.ColumnCount == 2)
                    {
                        MainForm.OutputWindow.SetString(GetDuoString(simple.GetDuo()));
                    }
                    if (dataGrid.ColumnCount == 3)
                    {
                        MainForm.OutputWindow.SetString(GetTrioString(simple.GetTrio()));
                    }
                    if (dataGrid.ColumnCount == 4)
                    {
                        MainForm.OutputWindow.SetString(GetQuartettString(simple.GetQuartett()));
                    }

                    MainForm.OutputWindow.Show();
                }
            }
            else
            {
                // If no error
                labelProblem.Text      = @"Check first.";
                labelProblem.ForeColor = Color.Red;
            }
        }