예제 #1
0
        public void RunMain()
        {
            Proposition expr;
            string      result;

            //string s = "( p -> ( q & r ) ) <-> y";
            //string s = "(A ->( B -> C )) <-> ( C -> D ) & ( D -> E) ";
            //string s = "p<->p";
            //string s = "p <-> a & b";
            //string s = "((p | q) & (~p | r)) -> (q | r)";
            //string s = "(P|(S&T))|R";
            //string s = "(A&B)|(~A)|(~B)";
            //string s = "(~p)<->(p->F)";
            //string s = "(~((a&b)|c)&d)|(((a&b)|c)&(~d))";
            string      s           = "(a&b)|(c&d)|(e&f)";
            ParseEngine parseEngine = new ParseEngine();

            parseEngine.TryParse(out expr, out result, s);

            LogicEngine logicEng = new LogicEngine();
            Proposition nnfExpr  = logicEng.ConvertToNNF(expr);

            Proposition cnfExpr = logicEng.ConvertToCNF(nnfExpr);
            bool        b       = logicEng.IsTautology(cnfExpr);

            WriteFile(cnfExpr.ToString());
        }
예제 #2
0
        public void PropositionTestErrorWhenWrongOperator()
        {
            string      input  = "+(A,B)";
            string      output = "Ups, you did something wrong!";
            Proposition check  = new Proposition(input);

            Assert.AreEqual(output, check.ToString());
        }
예제 #3
0
        public void PropositionTestWithSpaces()
        {
            string      input  = "=( | (A ,B), &(C ,D))";
            string      output = "((A|B)=(C&D))";
            Proposition check  = new Proposition(input);

            Assert.AreEqual(output, check.ToString());
        }
예제 #4
0
        public void PropositionTestBigProposition()
        {
            string      input  = "=(&(~(B), A),|(=(C,D),>(E,F)))";
            string      output = "((~(B)&A)=((C=D)|(E>F)))";
            Proposition check  = new Proposition(input);

            Assert.AreEqual(output, check.ToString());
        }
예제 #5
0
        public void PropositionTestNormalProposition()
        {
            string      input  = "=(A,|(C,B))";
            string      output = "(A=(C|B))";
            Proposition check  = new Proposition(input);

            Assert.AreEqual(output, check.ToString());
        }
예제 #6
0
        public void PropositionTestBiimplication()
        {
            string      input  = "=(A,B)";
            string      output = "(A=B)";
            Proposition check  = new Proposition(input);

            Assert.AreEqual(output, check.ToString());
        }
예제 #7
0
        public void PropositionTestDisjunction()
        {
            string      input  = "|(A,B)";
            string      output = "(A|B)";
            Proposition check  = new Proposition(input);

            Assert.AreEqual(output, check.ToString());
        }
예제 #8
0
        public void PropositionTestNegation()
        {
            string      input  = "~(A)";
            string      output = "~(A)";
            Proposition check  = new Proposition(input);

            Assert.AreEqual(output, check.ToString());
        }
예제 #9
0
        public void ToString_ValidPropositionWithSpecificSymbol_ExpectedDataAsString(char symbol, string expectedToString)
        {
            // Arrange
            Proposition proposition = new Proposition(symbol);

            // Act
            string actualToString = proposition.ToString();

            // Assert
            actualToString.Should().Be(expectedToString, "Because for a proposition only the symbol itself is returned.");
        }
예제 #10
0
        public void ToString_CallToStringOnValidVariable_ExpectedTheVariableDataReturned()
        {
            // Arrange
            string expectedResultString = "A";

            // Act
            string actualResultString = VALID_PROPOSITION.ToString();

            // Assert
            actualResultString.Should().BeEquivalentTo(expectedResultString, "because the proposition returns its data as string");
        }
예제 #11
0
 private string[] GenerateTruthTable()
 {
     if (Rows == null)
     {
         throw new Exception("Table does not exist.");
     }
     string[] temp = new string[CombinationsCount + 1];
     temp[0] = string.Join("    ", Variables) + "    " + Proposition.ToString();
     for (int k = 0; k < Rows.Length; k++)
     {
         temp[k + 1] = SplitString(Rows[k]);
     }
     CalculateHash();
     return(temp);
 }
예제 #12
0
        //private void GenerateRows()
        //{
        //    for (int i = 1; i < RowsString.Length; i++)
        //    {
        //        Rows.Add(new Row(row)
        //    }
        //}

        private string[] GenerateNewTruthTable()
        {
            if (Rows != null)
            {
                throw new Exception("Not a new truth table.");
            }
            string[] temp  = new string[CombinationsCount + 1];
            string[] lines = GenerateTruthTableValues();
            truthValues = CalculateTruthTableChar();

            temp[0] = string.Join("    ", Variables) + "    " + Proposition.ToString();
            for (int k = 0; k < lines.Length; k++)
            {
                temp[k + 1] = lines[k] + truthValues[k];
            }
            CalculateHash();
            return(temp);
        }
예제 #13
0
 public override string ToString()
 {
     return(Proposition.ToString());
 }
예제 #14
0
파일: Goal.cs 프로젝트: foamliu/NPlanner
 public override string ToString()
 {
     return(m_prop.ToString());
 }