Package org.sosy_lab.common.rationals
Class LinearExpression<T>
- java.lang.Object
-
- org.sosy_lab.common.rationals.LinearExpression<T>
-
@Immutable(containerOf="T") public final class LinearExpression<T> extends Object implements Iterable<Map.Entry<T,Rational>>
Simple sparse implementation for homogeneous linear expression of the form $\Sigma a_i x_i$, where $x_i$ is a set of variables and $a_i$ is a set of constants.Every constant stored has to have a non-zero value.
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description LinearExpression<T>add(LinearExpression<T> other)Addotherlinear expression.Optional<Rational>divide(LinearExpression<T> other)Returnsaiffother.multByConst(a) == this,Optional.absent()if no such constant exists.static <T> LinearExpression<T>empty()Creates an empty linear expression.booleanequals(@Nullable Object object)RationalgetCoeff(T variable)ImmutableMap<T,Rational>getMap()Returns the underlying stored map.inthashCode()booleanisEmpty()booleanisIntegral()Returns whether all coefficients are integral.Iterator<Map.Entry<T,Rational>>iterator()static <T> LinearExpression<T>monomial(T var, Rational coeff)Return a monomial with a variablevarand a coefficientcoeff.LinearExpression<T>multByConst(Rational constant)Multiply the linear expression byconstant.LinearExpression<T>negate()Negate the linear expression.static <T> LinearExpression<T>ofVariable(T var)Create a monomial consisting of variablevarwith a coefficient of one.static <T> LinearExpression<T>pair(T var, Rational coeff)Deprecated.Usemonomial(T, org.sosy_lab.common.rationals.Rational)instead.intsize()Returns number of variables with non-zero coefficients.LinearExpression<T>sub(LinearExpression<T> other)Subtractotherlinear expression.StringtoString()Returns a pretty-printed form of the linear expression.static voidwriteMonomial(String varSerialized, Rational coeff, StringBuilder b)Pretty-print monomial to the givenStringBuilder.-
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface java.lang.Iterable
forEach, spliterator
-
-
-
-
Method Detail
-
empty
public static <T> LinearExpression<T> empty()
Creates an empty linear expression.
-
pair
@Deprecated @InlineMe(replacement="LinearExpression.monomial(var, coeff)", imports="org.sosy_lab.common.rationals.LinearExpression") public static <T> LinearExpression<T> pair(T var, Rational coeff)
Deprecated.Usemonomial(T, org.sosy_lab.common.rationals.Rational)instead.Return a monomial with a variablevarand a coefficientcoeff.
-
monomial
public static <T> LinearExpression<T> monomial(T var, Rational coeff)
Return a monomial with a variablevarand a coefficientcoeff.
-
ofVariable
public static <T> LinearExpression<T> ofVariable(T var)
Create a monomial consisting of variablevarwith a coefficient of one.
-
add
public LinearExpression<T> add(LinearExpression<T> other)
Addotherlinear expression.
-
sub
public LinearExpression<T> sub(LinearExpression<T> other)
Subtractotherlinear expression.
-
multByConst
public LinearExpression<T> multByConst(Rational constant)
Multiply the linear expression byconstant.
-
negate
public LinearExpression<T> negate()
Negate the linear expression.
-
size
public int size()
Returns number of variables with non-zero coefficients.
-
isEmpty
public boolean isEmpty()
-
isIntegral
public boolean isIntegral()
Returns whether all coefficients are integral.
-
divide
public Optional<Rational> divide(LinearExpression<T> other)
Returnsaiffother.multByConst(a) == this,Optional.absent()if no such constant exists.
-
getMap
public ImmutableMap<T,Rational> getMap()
Returns the underlying stored map.
-
toString
public String toString()
Returns a pretty-printed form of the linear expression. E. g. -x + 2y + z
-
writeMonomial
public static void writeMonomial(String varSerialized, Rational coeff, StringBuilder b)
Pretty-print monomial to the givenStringBuilder.
-
-