public override Element /*!*/ Constrain(Element /*!*/ e, IExpr /*!*/ expr)
        {
            //Contract.Requires(expr != null);
            //Contract.Requires(e != null);
            Contract.Ensures(Contract.Result <Element>() != null);
            log.DbgMsg(string.Format("Constraining with {0} into {1} ...", expr, this.ToString(e)));

            PolyhedraLatticeElement ple = (PolyhedraLatticeElement)e;

            if (ple.lcs.IsBottom())
            {
                return(ple);
            }
            LinearCondition le = LinearExpressionBuilder.AsCondition(expr);

            if (le != null)
            {
                // update the polyhedron according to the linear expression
                Contract.Assume(ple.lcs.Constraints != null);
                ArrayList /*LinearConstraint*/ clist = (ArrayList /*!*/ /*LinearConstraint*/)cce.NonNull(ple.lcs.Constraints.Clone());
                le.AddToConstraintSystem(clist);
                LinearConstraintSystem newLcs = new LinearConstraintSystem(clist);

                return(new PolyhedraLatticeElement(newLcs));
            }
            return(ple);
        }
        public override Answer CheckVariableDisequality(Element /*!*/ e, IVariable /*!*/ var1, IVariable /*!*/ var2)
        {
            //Contract.Requires(var2 != null);
            //Contract.Requires(var1 != null);
            //Contract.Requires(e != null);
            PolyhedraLatticeElement /*!*/ ple = (PolyhedraLatticeElement)cce.NonNull(e);

            Contract.Assume(ple.lcs.Constraints != null);
            ArrayList /*LinearConstraint!*//*!*/ clist = (ArrayList /*LinearConstraint!*/)cce.NonNull(ple.lcs.Constraints.Clone());
            LinearConstraint /*!*/ lc = new LinearConstraint(LinearConstraint.ConstraintRelation.EQ);

            Contract.Assert(lc != null);
            lc.SetCoefficient(var1, Rational.ONE);
            lc.SetCoefficient(var2, Rational.MINUS_ONE);
            clist.Add(lc);
            LinearConstraintSystem newLcs = new LinearConstraintSystem(clist);

            if (newLcs.IsBottom())
            {
                return(Answer.Yes);
            }
            else
            {
                return(Answer.Maybe);
            }
        }
 /// <summary>
 /// Creates a top or bottom elements, according to parameter "top".
 /// </summary>
 public PolyhedraLatticeElement(bool top)
 {
     if (top)
     {
         lcs = new LinearConstraintSystem(new ArrayList/*LinearConstraint*/ ());
     }
     else
     {
         lcs = new LinearConstraintSystem();
     }
 }
        public override Lattice.Element /*!*/ Widen(Element /*!*/ first, Element /*!*/ second)
        {
            //Contract.Requires(second != null);
            //Contract.Requires(first != null);
            Contract.Ensures(Contract.Result <Lattice.Element>() != null);
            log.DbgMsg("Widening ...");
            log.DbgMsgIndent();
            PolyhedraLatticeElement aa = (PolyhedraLatticeElement)first;
            PolyhedraLatticeElement bb = (PolyhedraLatticeElement)second;

            LinearConstraintSystem  lcs    = aa.lcs.Widen(bb.lcs);
            PolyhedraLatticeElement result = new PolyhedraLatticeElement(lcs);

            log.DbgMsg(string.Format("{0} |_| {1} --> {2}", this.ToString(first), this.ToString(second), this.ToString(result)));
            log.DbgMsgUnindent();
            return(result);
        }
 public PolyhedraLatticeElement(LinearConstraintSystem /*!*/ lcs)
 {
     Contract.Requires(lcs != null);
     this.lcs = lcs;
 }