Exemple #1
0
        /// <summary>
        /// Solves the truth expression given the passed states.
        /// </summary>
        /// <param name="args">A bool array that represents the state of all variables. It must be the exact size of all args.</param>
        /// <returns></returns>
        private bool SolveSingleCase(IReadOnlyList <bool> args)
        {
            if (args.Count != VarNames.Length)
            {
                throw new IndexOutOfRangeException("The passed args array is not the same size as the number of args needed.");
            }

            var res = sourceExpression.InternalExpression.Parameters.Count switch
            {
                1 => TruthExpression.DynamicInvoke(args[0]),
                2 => TruthExpression.DynamicInvoke(args[0], args[1]),
                3 => TruthExpression.DynamicInvoke(args[0], args[1], args[2]),
                4 => TruthExpression.DynamicInvoke(args[0], args[1], args[2], args[3]),
                5 => TruthExpression.DynamicInvoke(args[0], args[1], args[2], args[3], args[4]),
                6 => TruthExpression.DynamicInvoke(args[0], args[1], args[2], args[3], args[4], args[5]),
                7 => TruthExpression.DynamicInvoke(args[0], args[1], args[2], args[3], args[4], args[5], args[6]),
                8 => TruthExpression.DynamicInvoke(args[0], args[1], args[2], args[3], args[4], args[5], args[6], args[7]),
                9 => TruthExpression.DynamicInvoke(args[0], args[1], args[2], args[3], args[4], args[5], args[6], args[7], args[8]),
                10 => TruthExpression.DynamicInvoke(args[0], args[1], args[2], args[3], args[4], args[5], args[6], args[7], args[8], args[9]),
                11 => TruthExpression.DynamicInvoke(args[0], args[1], args[2], args[3], args[4], args[5], args[6], args[7], args[8], args[9], args[10]),
                12 => TruthExpression.DynamicInvoke(args[0], args[1], args[2], args[3], args[4], args[5], args[6], args[7], args[8], args[9], args[10], args[11]),
                13 => TruthExpression.DynamicInvoke(args[0], args[1], args[2], args[3], args[4], args[5], args[6], args[7], args[8], args[9], args[10], args[11], args[12]),
                14 => TruthExpression.DynamicInvoke(args[0], args[1], args[2], args[3], args[4], args[5], args[6], args[7], args[8], args[9], args[10], args[11], args[12], args[13]),
                15 => TruthExpression.DynamicInvoke(args[0], args[1], args[2], args[3], args[4], args[5], args[6], args[7], args[8], args[9], args[10], args[11], args[12], args[13], args[14]),
                16 => TruthExpression.DynamicInvoke(args[0], args[1], args[2], args[3], args[4], args[5], args[6], args[7], args[8], args[9], args[10], args[11], args[12], args[13], args[14], args[15])
            };

            return((bool)res);
        }
Exemple #2
0
        /// <summary>
        /// Creates truthtable by compiling the passed truthexpression
        /// </summary>
        /// <exception cref="InvalidTruthExpressionException">thrown for errors in expression compilation</exception>
        /// <param name="truthExpression"></param>
        public TruthTableSolver(TruthExpression truthExpression)
        {
            sourceExpression = truthExpression;
            TruthExpression  = truthExpression.Compile();
            VarNames         = new char[truthExpression.InternalExpression.Parameters.Count];

            //Extract variable names
            for (var i = 0; i < VarNames.Length; i++)
            {
                VarNames[i] = truthExpression.InternalExpression.Parameters[i].Name[0];
            }
        }