public PolyhedraLattice(ILinearExprFactory/*!*/ linearFactory, IPropExprFactory/*!*/ propFactory) : base(linearFactory) { Contract.Requires(propFactory != null); Contract.Requires(linearFactory != null); log.Enabled = Lattice.LogSwitch; this.factory = linearFactory; this.propFactory = propFactory; // base(linearFactory); }
public PolyhedraLattice(ILinearExprFactory /*!*/ linearFactory, IPropExprFactory /*!*/ propFactory) : base(linearFactory) { Contract.Requires(propFactory != null); Contract.Requires(linearFactory != null); log.Enabled = Lattice.LogSwitch; this.factory = linearFactory; this.propFactory = propFactory; // base(linearFactory); }
/// <summary> /// Note: This method requires that all dimensions are of type Variable, something that's /// not required elsewhere in this class. /// </summary> /// <returns></returns> public IExpr /*!*/ ConvertToExpression(ILinearExprFactory /*!*/ factory) { Contract.Requires(factory != null); Contract.Ensures(Contract.Result <IExpr>() != null); IExpr leftSum = null; IExpr rightSum = null; foreach (DictionaryEntry /*object->Rational*/ entry in coefficients) { IVariable var = (IVariable)entry.Key; Rational coeff = (Rational)(cce.NonNull(entry.Value)); if (coeff.IsPositive) { leftSum = AddTerm(factory, leftSum, coeff, var); } else if (coeff.IsNegative) { rightSum = AddTerm(factory, rightSum, -coeff, var); } else { // ignore the term is coeff==0 } } if (leftSum == null && rightSum == null) { // there are no variables in this constraint if (Relation == ConstraintRelation.EQ ? rhs.IsZero : rhs.IsNonNegative) { return(factory.True); } else { return(factory.False); } } if (leftSum == null || (rightSum != null && rhs.IsNegative)) { // show the constant on the left side leftSum = AddTerm(factory, leftSum, -rhs, null); } else if (rightSum == null || rhs.IsPositive) { // show the constant on the right side rightSum = AddTerm(factory, rightSum, rhs, null); } Contract.Assert(leftSum != null); Contract.Assert(rightSum != null); return(Relation == ConstraintRelation.EQ ? factory.Eq(leftSum, rightSum) : factory.AtMost(leftSum, rightSum)); }
/// <summary> /// Returns an expression that denotes sum + r*x. /// If sum==null, drops the "sum +". /// If x==null, drops the "*x". /// if x!=null and r==1, drops the "r*". /// </summary> /// <param name="factory"></param> /// <param name="sum"></param> /// <param name="r"></param> /// <param name="x"></param> static IExpr /*!*/ AddTerm(ILinearExprFactory /*!*/ factory, /*MayBeNull*/ IExpr sum, Rational r, /*MayBeNull*/ IVariable x) { Contract.Requires(factory != null); Contract.Ensures(Contract.Result <IExpr>() != null); IExpr /*!*/ product = factory.Term(r, x); Contract.Assert(product != null); if (sum == null) { return(product); } else { return(factory.Add(sum, product)); } }
/// <summary> /// Note: This method requires that all dimensions are of type Variable, something that's /// not required elsewhere in this class. /// </summary> /// <returns></returns> public IExpr/*!*/ ConvertToExpression(ILinearExprFactory/*!*/ factory) { Contract.Requires(factory != null); Contract.Ensures(Contract.Result<IExpr>() != null); IExpr leftSum = null; IExpr rightSum = null; foreach (DictionaryEntry /*object->Rational*/ entry in coefficients) { IVariable var = (IVariable)entry.Key; Rational coeff = (Rational)(cce.NonNull(entry.Value)); if (coeff.IsPositive) { leftSum = AddTerm(factory, leftSum, coeff, var); } else if (coeff.IsNegative) { rightSum = AddTerm(factory, rightSum, -coeff, var); } else { // ignore the term is coeff==0 } } if (leftSum == null && rightSum == null) { // there are no variables in this constraint if (Relation == ConstraintRelation.EQ ? rhs.IsZero : rhs.IsNonNegative) { return factory.True; } else { return factory.False; } } if (leftSum == null || (rightSum != null && rhs.IsNegative)) { // show the constant on the left side leftSum = AddTerm(factory, leftSum, -rhs, null); } else if (rightSum == null || rhs.IsPositive) { // show the constant on the right side rightSum = AddTerm(factory, rightSum, rhs, null); } Contract.Assert(leftSum != null); Contract.Assert(rightSum != null); return Relation == ConstraintRelation.EQ ? factory.Eq(leftSum, rightSum) : factory.AtMost(leftSum, rightSum); }
public IntervalLattice(ILinearExprFactory/*!*/ factory) { Contract.Requires(factory != null); this.factory = factory; // base(); }
public IntervalLattice(ILinearExprFactory /*!*/ factory) { Contract.Requires(factory != null); this.factory = factory; // base(); }
/// <summary> /// Returns an expression that denotes sum + r*x. /// If sum==null, drops the "sum +". /// If x==null, drops the "*x". /// if x!=null and r==1, drops the "r*". /// </summary> /// <param name="factory"></param> /// <param name="sum"></param> /// <param name="r"></param> /// <param name="x"></param> static IExpr/*!*/ AddTerm(ILinearExprFactory/*!*/ factory, /*MayBeNull*/ IExpr sum, Rational r, /*MayBeNull*/ IVariable x) { Contract.Requires(factory != null); Contract.Ensures(Contract.Result<IExpr>() != null); IExpr/*!*/ product = factory.Term(r, x); Contract.Assert(product != null); if (sum == null) { return product; } else { return factory.Add(sum, product); } }
/// <summary> /// Note: This method requires that all dimensions are of type Variable, something that's /// not required elsewhere in this class. /// </summary> /// <returns></returns> public IExpr/*!*/ ConvertToExpression(ILinearExprFactory/*!*/ factory) { Contract.Requires(factory != null); Contract.Ensures(Contract.Result<IExpr>() != null); if (this.Constraints == null) { return factory.False; } if (this.Constraints.Count == 0) { return factory.True; } IExpr result = null; foreach (LinearConstraint/*!*/ lc in Constraints) { Contract.Assert(lc != null); IExpr conjunct = lc.ConvertToExpression(factory); result = (result == null) ? conjunct : (IExpr)factory.And(conjunct, result); } Contract.Assert(result != null); return result; }