コード例 #1
0
        public void CreateTruthTableTest()
        {
            BooleanExpression expression1 = new BooleanExpression("a'b'cd + a'bc'd");
            TruthTable        table1      = new TruthTable(expression1);

            Console.WriteLine(table1.ToString());
            Console.WriteLine(table1.MintermString());
        }
コード例 #2
0
        private void btnGenerateTruthTable_Click(object sender, EventArgs e)
        {
            BuildTree();

            //Create the truth table from the formula
            myTruthTable = new TruthTable(myProcessing.Variables);
            myProcessing.AssignRowValues(myTruthTable.GetRows());

            //Display both truth tables and hash code
            tbTruthTable.Text           = myTruthTable.ToString();
            tbSimplifiedTruthTable.Text = myTruthTable.SimplifiedTableToString();
            tbHashCode.Text             = myTruthTable.GetHashCodeTB();
        }
コード例 #3
0
ファイル: TruthTableTests.cs プロジェクト: sjokkateer/LPP
        public void ToString_ConstantPropositionRootGivenToConstructor_ExpectedTwoRowsPrinted(string toParseExpression, int expectedNumberOfRows)
        {
            // Arrange
            parser = new Parser(toParseExpression);
            Proposition root = parser.Parse();
            TruthTable  tt   = new TruthTable(root);

            // Act
            string tableToString = tt.ToString();

            string[] rowsAsString = tableToString.Split("\n");

            // Assert
            rowsAsString.Length.Should().Be(expectedNumberOfRows);
        }
コード例 #4
0
		public static void Main (string[] args)
		{
			string line;
			noCaption = args.Contains("-n");
			while((line = Console.ReadLine ()) != null) {
				var parser = Parser.Parse (line);

				if (parser.Expression != null) {
					var table = new TruthTable (parser.Parameters.Values.ToArray (), parser.Expression);
					// 真理値表
					if (args.Contains("-T")) {
						caption ("[Truth Table]");
						echo (table.ToString());
					}
					// 主加法標準形
					if (args.Contains("-D")) {
						caption ("[Disjunctive]");
						echo (table.ToDisjunctiveCanonicalExpression ().ToSimpleString ());
					}
					// 主乗法標準形
					if (args.Contains("-C")) {
						caption ("[Conjunctive]");
						echo (table.ToConjunctiveCanonicalExpression ().ToSimpleString ());
					}

					// 省力化
					if (!args.Any (s => s.StartsWith("-q") || s.StartsWith("-c"))) {
						Console.WriteLine ();
						continue;
					}

					// QM法
					var qmc = new QuineMcCluskey (table);
					foreach (IEnumerable<TruthTableColumn> result in qmc.Compressed) {
						var newTable = new TruthTable (table.Parameters, result);
						// QM法 真理値
						if (args.Contains("-qT")) {
							caption ("[QM'ed Truth Table]");
							echo (newTable.ToString ());
						}
						// QM法 主加法標準形
						if (args.Contains("-qD")) {
							caption ("[QM'ed Disjunctive]");
							echo (newTable.ToDisjunctiveCanonicalExpression ().ToSimpleString ());
						}

						var checkTable = new TruthTable (table.Parameters, newTable.ToDisjunctiveCanonicalExpression ());
						// 確認用 真理値表
						if (args.Contains("-cT")) {
							caption ("[Check Truth Table]");
							echo (checkTable.ToString ());
						}
						// 確認用 主乗法標準形
						if (args.Contains("-cC")) {
							caption ("[Check Conjunctive]");
							echo (checkTable.ToConjunctiveCanonicalExpression ().ToSimpleString ());
						}
						// 確認用 主加法標準形
						if (args.Contains("-cD")) {
							caption ("[Check Disjunctive]");
							echo (checkTable.ToDisjunctiveCanonicalExpression ().ToSimpleString ());
						}
					}
					Console.WriteLine ();
				} else {
					Console.Error.WriteLine("Parse Error.");
				}
			}
		}