Esempio n. 1
0
        public override Product GetProduct()
        {
            if (!IsProductOfInputs)
            {
                // bad bad
                //Debug.WriteLine("PROBLEM:\n" + GateCache.Instance.ToDebugString());

                Debug.WriteLine("not a product of inputs: {0} level {1}", this, this.GetNestingLevel());

                throw new InvalidOperationException("SMG013: expected canonical for AND.");
            }

            var dict = new Product();
            foreach (var i in Inputs.Where(i => i.Type == GateType.Input).OfType<IInput>())
            {
                dict.AddFactor(i.CreateFactor());
            }

            return dict;
        }
Esempio n. 2
0
 /// <summary>
 /// Returns a product representing the elementary factors of this input.
 /// </summary>
 /// <returns></returns>
 public override Product GetProduct()
 {
     var result = new Product();
     result.AddFactor(CreateFactor());
     return result;
 }
Esempio n. 3
0
        private IGate SimplifyProductOfInputs(Product dict)
        {
            IGate result = null;

            var factors = new List<Factor>();

            foreach (var f in dict.Factors)
            {
                if (f.IsConstant)
                {
                    if (f.Constant is FalseGate)
                    {
                        result = f.Constant;
                        break;
                    }
                }
                else
                {
                    factors.Add(f);
                }
            }

            if (null == result)
            {
                var gatelist = factors.SelectMany(e => e.ToGateList()).GetEnumerator();
                if (!gatelist.MoveNext())
                {
                    result = new TrueGate();
                }
                else
                {
                    result = Gate.Simplify(gatelist.Current);
                    if (gatelist.MoveNext())
                    {
                        var and = new ANDGate();
                        and.AddInput(result);

                        do
                        {
                            var e = Gate.Simplify(gatelist.Current);
                            and.AddInput(e);
                        }
                        while (gatelist.MoveNext());

                        result = and;
                    }
                }
            }

            return result;
        }
Esempio n. 4
0
 public void Remove(Product seq)
 {
     foreach (var i in seq.Inputs)
     {
         RemoveInput(i);
     }
 }
Esempio n. 5
0
        public int ContainsFactor(Product seq)
        {
            int result = 0;

            var itseq = seq.Inputs.GetEnumerator();
            itseq.MoveNext();

            var itgg = this.Inputs.GetEnumerator();
            if (!itgg.MoveNext())
            {
                return -1;
            }

            do
            {
                while (itgg.Current.Address < itseq.Current.Address)
                {
                    if (!itgg.MoveNext())
                    {
                        return -1;
                    }
                }

                if (itgg.Current.Address != itseq.Current.Address)
                {
                    return -1;
                }

                // look at invertflag
                var anti = itseq.Current.IsInverted != itgg.Current.IsInverted;
                var flag = anti ? 2 : 1;
                if (result == 0)
                {
                    result = flag;
                }
                else if (result != flag)
                {
                    return -1;
                }
            }
            while (itseq.MoveNext());

            return result;
        }
Esempio n. 6
0
        public Product Clone()
        {
            var p = new Product();
            foreach(var f in _map.Values)
            {
                p.AddFactor(f);
            }

            return p;
        }