コード例 #1
0
 /// <summary>
 /// Instancia um novo objecto do tipo <see cref="BooleanCombination"/>.
 /// </summary>
 /// <param name="logicInput">A combinação lógica de entrada.</param>
 /// <param name="logicOutput">The logic output.</param>
 /// <exception cref="ArgumentNullException">logicInput</exception>
 internal BooleanCombination(LogicCombinationBitArray logicInput, EBooleanMinimalFormOutStatus logicOutput)
 {
     if (logicInput == null)
     {
         throw new ArgumentNullException("logicInput");
     }
     else
     {
         this.logicInput  = logicInput;
         this.logicOutput = logicOutput;
     }
 }
コード例 #2
0
        /// <summary>
        /// Adiciona uma combinação à lista de entrada/saída.
        /// </summary>
        /// <param name="array">O vector de bits que representa uma entrada.</param>
        /// <param name="outputStatus">O estado de saída associado à entrada.</param>
        /// <returns>A representação interna.</returns>
        /// <exception cref="ArgumentNullException">Se o vector de bits for nulo.</exception>
        public BooleanCombination Add(
            LogicCombinationBitArray array,
            EBooleanMinimalFormOutStatus outputStatus)
        {
            if (array == null)
            {
                throw new ArgumentNullException("array");
            }
            else
            {
                var result = new BooleanCombination(
                    array,
                    outputStatus);
                this.combinationElements.Add(result);
                this.maxCombinationsLength = Math.Max(
                    this.maxCombinationsLength,
                    array.Length);

                return(result);
            }
        }
コード例 #3
0
        /// <summary>
        /// Tenta obter uma redução lógica como resultado da combinação com outra expressão.
        /// </summary>
        /// <param name="combination">A combinação lógica a cobrir.</param>
        /// <param name="cover">A função lógica simplificada.</param>
        /// <returns>Verdadeiro caso a simplificação seja possível e falso caso contrário.</returns>
        public bool TryToGetReduced(LogicCombinationBitArray combination, out LogicCombinationBitArray cover)
        {
            cover = default(LogicCombinationBitArray);
            if (combination == null)
            {
                return(false);
            }
            if (this.length != combination.length)
            {
                return(false);
            }
            else
            {
                var xoredValues = this.XorValues(this.values, combination.values);

                // Se não existirem valores de indiferentes que se sobreponham a valores ligado / desligado...
                if (this.HasNoBitValues(xoredValues))
                {
                    bool foundIndex            = false;
                    var  currentGeneralPointer = 0;
                    var  currentValuesPointer  = 0;
                    while (currentGeneralPointer < this.length)
                    {
                        var currentInnerIndex = 0;
                        while (currentInnerIndex < semiIntegerSize &&
                               currentGeneralPointer < this.length)
                        {
                            var valuesElement = this.values[currentValuesPointer];
                            var xoredElement  = xoredValues[currentValuesPointer];
                            var mask          = masks[currentInnerIndex];

                            var statusValue = (valuesElement & mask) >> (currentInnerIndex << 1);
                            if (statusValue == 3U)
                            {
                                xoredElement = (~mask & xoredElement) |
                                               (3U << (currentInnerIndex << 1));
                                xoredValues[currentValuesPointer] = xoredElement;
                            }
                            else
                            {
                                statusValue = (xoredElement & mask) >> (currentInnerIndex << 1);
                                if (statusValue == 3)
                                {
                                    if (foundIndex)
                                    {
                                        return(false);
                                    }
                                    else
                                    {
                                        xoredElement = (~mask & xoredElement) |
                                                       (3U << (currentInnerIndex << 1));
                                        xoredValues[currentValuesPointer] = xoredElement;
                                        foundIndex = true;
                                    }
                                }
                            }

                            ++currentInnerIndex;
                            ++currentGeneralPointer;
                        }

                        ++currentValuesPointer;
                    }

                    xoredValues  = this.OrValues(this.values, xoredValues);
                    cover        = new LogicCombinationBitArray();
                    cover.length = this.length;
                    cover.values = xoredValues;
                    return(true);
                }
                else
                {
                    return(false);
                }
            }
        }