Exemplo n.º 1
0
    private void GenBtn()
    {
        //if (!validateInputs()) return;

        // clear the previous table:
        //TruthTableView.Columns.Clear();
        //TruthTableView.Items.Clear();

        List <char> boolVars;

        boolVars = expression1.GetBoolVars();

        bool[,] inputTable = GenInputTable(boolVars.Count);

        VARIABLE = boolVars.Count;
        //foreach (char c in boolVars)
        //{
        //    TruthTableView.Columns.Add(c.ToString());
        //}

        // solve:
        bool[] answer1 = new bool[inputTable.GetLength(0)];
        bool[] answer2 = new bool[inputTable.GetLength(0)];;
        for (int i = 0; i < inputTable.GetLength(0); i++)
        {
            for (int j = 0; j < inputTable.GetLength(1); j++)
            {
                expression1.SetValue(boolVars[j], inputTable[i, j]);
                //if (isInput2Enabled()) expression2.SetValue(boolVars[j], inputTable[i, j]);
            }
            answer1[i] = expression1.Solve();
            //if (isInput2Enabled()) answer2[i] = expression2.Solve();
        }

        bool equal = false;
        //if (isInput2Enabled()) equal = answer1.SequenceEqual(answer2);

        //TruthTableView.Columns.Add("#1");
        //if (isInput2Enabled() && !equal) TruthTableView.Columns.Add("#2");
        string temp = "";

        theTruthTable = new string[inputTable.GetLength(0)];
        for (int i = 0; i < inputTable.GetLength(0); i++)
        {
            temp = "";
            //ListViewItem L = TruthTableView.Items.Add(getBoolStr(inputTable[i, 0]));
            temp = temp + getBoolStr(inputTable[i, 0]);
            for (int j = 1; j < inputTable.GetLength(1); j++)
            {
                //L.SubItems.Add(getBoolStr(inputTable[i, j]));
                temp = temp + " : " + getBoolStr(inputTable[i, j]);
            }
            //L.SubItems.Add(getBoolStr(answer1[i]));
            temp             = temp + "  :  a=> " + getBoolStr(answer1[i]);
            theTruthTable[i] = getBoolStr(answer1[i]);
            m[i]             = Convert.ToInt32(getBoolStr(answer1[i]));
            //if (isInput2Enabled() && !equal) L.SubItems.Add(getBoolStr(answer2[i])); ;
            Debug.Log(temp);
        }
    }