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
Modifier and TypeMethodDescriptionadd(LinearExpression<T> other) Addotherlinear expression.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.booleangetMap()Returns the underlying stored map.inthashCode()booleanisEmpty()booleanReturns whether all coefficients are integral.iterator()static <T> LinearExpression<T>Return a monomial with a variablevarand a coefficientcoeff.multByConst(Rational constant) Multiply the linear expression byconstant.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>Deprecated.intsize()Returns number of variables with non-zero coefficients.sub(LinearExpression<T> other) Subtractotherlinear expression.toString()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, waitMethods inherited from interface java.lang.Iterable
forEach, spliterator
-
Method Details
-
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
Return a monomial with a variablevarand a coefficientcoeff. -
ofVariable
Create a monomial consisting of variablevarwith a coefficient of one. -
add
Addotherlinear expression. -
sub
Subtractotherlinear expression. -
multByConst
Multiply the linear expression byconstant. -
negate
Negate the linear expression. -
getCoeff
-
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
Returnsaiffother.multByConst(a) == this,Optional.absent()if no such constant exists. -
iterator
-
getMap
Returns the underlying stored map. -
toString
Returns a pretty-printed form of the linear expression. E. g. -x + 2y + z -
writeMonomial
Pretty-print monomial to the givenStringBuilder. -
equals
-
hashCode
public int hashCode()
-
monomial(T, org.sosy_lab.common.rationals.Rational)instead.