public void TestValidReducedExpressions()
 {
     foreach (ExpressionTestCase t in validCases)
     {
         expr = new ReducedBooleanExpression(t.inputExpression);
         Assert.AreEqual(t.expectedExpression, expr.ToString());
     }
 }
Пример #2
0
        public static void Main(string[] args)
        {
            string input;

            Console.WriteLine("Novosit Obi-Wan Challenge One\nQuine McCluskey's Algorithm\n");
            Console.WriteLine("Type input boolean expression:");
            input = Console.ReadLine();
            try
            {
                Console.WriteLine(string.Format("Reduced expression:\n\t{0}",
                                                ReducedBooleanExpression.solveQuineMcCluskey(input)));
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }
            Console.ReadKey();
        }
Пример #3
0
            // -------------
            // Constructors
            private Implicant(ReducedBooleanExpression parent, char[] binArray)
            {
                this.parent = parent;
                _BinArray   = new char[binArray.Length];
                Array.Copy(binArray, _BinArray, binArray.Length);
                foreach (char c in _BinArray)
                {
                    switch (c)
                    {
                    case '1':
                        _onesCount++;
                        break;

                    case '-':
                        _dashesCount++;
                        break;
                    }
                }
                //
                CalculateImpliedMinterms();
            }
Пример #4
0
            //
            public Implicant(ReducedBooleanExpression parent, string input)
            {
                // No input checking!
                this.parent = parent;
                int variableCount = parent._sortedVariables.Length;

                _BinArray = new char[variableCount];
                Array.Copy(DASHES, _BinArray, variableCount);
                _dashesCount = variableCount;
                string[] factors = input.Split('*');
                foreach (string f in factors)
                {
                    char literal;
                    char value;
                    //
                    if (f.Length == 0)
                    {
                        throw new Exception(string.Format("Malformed implicant ({0})", input));
                    }
                    else if (f.Length == 1)
                    {
                        literal = f[0];
                        value   = '1';
                        if (!Literal.IsValid(literal))
                        {
                            throw new Exception(string.Format("Malformed implicant ({0})", input));
                        }
                    }
                    else if (f.Length == 2)
                    {
                        literal = f[0];
                        value   = '0';
                        if (!Literal.IsValid(literal) || (f[1] != '\''))
                        {
                            throw new Exception(string.Format("Malformed implicant ({0})", input));
                        }
                    }
                    else
                    {
                        throw new Exception(string.Format("Malformed implicant ({0})", input));
                    }
                    // what is this literals sort order
                    int  position      = parent._alphabet[literal];
                    char previousValue = _BinArray[position];
                    // if we've seen this literals complement then this string does not represent
                    // a valid implicant, it is a contradiction e.g.: A*A'
                    if ((previousValue != DASH) && (previousValue != value))
                    {
                        // reset the internal representation and break
                        Array.Copy(DASHES, _BinArray, variableCount);
                        _onesCount      = 0;
                        _dashesCount    = variableCount;
                        IsContradiction = true;
                        break;
                    }
                    else
                    {
                        _BinArray[position] = value;
                        _dashesCount--;
                        if (value == '1')
                        {
                            _onesCount++;
                        }
                    }
                }
                //
                CalculateImpliedMinterms();
            }