Ejemplo n.º 1
0
        /// <summary>
        /// Wrapper method that makes the initial call to CreateRowsRecursively with some basic
        /// input parameters that do not change.
        /// </summary>
        private void CreateTruthTableRows()
        {
            TruthTableRow initialRow = new TruthTableRow(propositionRoot, propositionVariablesSet, propositionVariablesSet.Count);

            if (initialRow.Cells.Length == 0)
            {
                // We had no variables and are dealing with one of the constants.
                // return an empty row with only a result value.
                initialRow.Calculate();
                Rows.Add(initialRow);
            }
            else
            {
                CreateRowsRecursively(0, new char[] { '0', '1' }, initialRow);
            }
        }
Ejemplo n.º 2
0
 /// <summary>
 /// Recursive method that evaluates a true and false value for every unique variable,
 /// exhausting all possible permutations and creating a row copy for every such row.
 /// This row copy is then added to the collection of rows of this truth table object.
 /// </summary>
 /// <param name="index">The current index, starting at 0, and evaluating until the index is equal to the number of unique variables - 1</param>
 /// <param name="truthSet">A constant set of the two boolean values false and true</param>
 /// <param name="row">A truth table row object that holds the combination of truth values for the abstract proposition variables.</param>
 private void CreateRowsRecursively(int index, char[] truthSet, TruthTableRow row)
 {
     // This is something we only have to execute if we have abstract proposition variables.
     foreach (char truthValue in truthSet)
     {
         if (index == propositionVariablesSet.Count - 1)
         {
             // add row to the table's list of rows and return back to the calling environment
             row.Cells[index] = truthValue;
             TruthTableRow copy = row.Copy();
             copy.Calculate(); // Required call to Calculate, otherwise the Result truth value can not be set :-(
                               // With the current recursive approach, only one row is constructed inside the wrapper method.
             Rows.Add(copy);
         }
         else
         {
             // Not at the final variable so we add the cell into the row and call the method again.
             row.Cells[index] = truthValue;
             CreateRowsRecursively(index + 1, truthSet, row);
         }
     }
 }