LinTermList
- java.lang.Object
-
- com.dashoptimization.objects.Expression
-
- com.dashoptimization.objects.AbstractExpression
-
- com.dashoptimization.objects.LinExpression
-
- com.dashoptimization.objects.LinTermList
-
public final class LinTermList extends LinExpression
A linear expression that is represented as a list of terms. Instances of this class represent a linear expression as a list of terms. This is the most efficient way to represent a list. By default, the implementation assumes that there are no two terms in the list that refer to the same variable. If there are you must either explicitly callcompress()or set theautoCompressproperty totrue.- Since:
- 43.00
-
-
Constructor Summary
Constructor Description LinTermList()Create a new empty expression.LinTermList(double c)Create a new expression that represents a constant term.LinTermList(double c, int capacity)Create a new expression with a constant term and an initial capacity.
-
Method Summary
Modifier and Type Method Description LinTermListaddConstant(double c)Add a value to the constant term of this expression.LinTermListaddTerm(double coefficient, Variable variable)Add a term to this expression.LinTermListaddTerm(Variable x)Add term1*xto this expression.LinTermListaddTerm(Variable variable, double coefficient)Add a term to this expression.LinTermListaddTerms(LinExpression expr)Add another linear expression to this expression.LinTermListaddTerms(LinExpression expr, double factor)Add another linear expression to this expression.LinTermListaddTerms(Variable[] variables, double[] coefficients)Add multiple terms to this expression.LinTermListaddTerms(java.lang.Iterable<Variable> variables, java.lang.Iterable<java.lang.Double> coefficients)Add multiple terms to this expression.LinTermListaddTerms(java.util.stream.Stream<Variable> variables, java.util.stream.Stream<java.lang.Double> coefficients)Add multiple terms to this expression.voidcompress()Compress duplicate terms.LinExpressiondeepCopy()Get a deep copy of this expression.LinExpressiondeepCopy(double factor)Get a deep copy of this expression multiplied by a constantdoubleevaluate(double[] solution)Compute the value of this expression with respect to the given solution vector (which is not required to be feasible).doublegetConstant()Get the constant value in this expression.static booleanisAutoCompress()Test whether auto-compression is enabled for this class.LinTermListreserve(int l)Reserve a maximum number of elements in this expression.LinTermListreset()Clear this expression.static voidsetAutoCompress(boolean compress)Enable/disable auto-compression for instances of this class.LinTermListsetConstant(double c)Set the constant term in this expression.java.lang.StringtoString()-
Methods inherited from class com.dashoptimization.objects.LinExpression
addTerm, create, create, square
-
Methods inherited from class com.dashoptimization.objects.AbstractExpression
eq, eq, geq, geq, in, leq, leq
-
-
-
-
Constructor Detail
-
LinTermList
public LinTermList()
Create a new empty expression.Examples using
LinTermList:- Since:
- 43.00
-
LinTermList
public LinTermList(double c)
Create a new expression that represents a constant term.Examples using
LinTermList:- Parameters:
-
c- The constant term. - Since:
- 43.00
-
LinTermList
public LinTermList(double c, int capacity)Create a new expression with a constant term and an initial capacity.Examples using
LinTermList:- Parameters:
-
c- The constant term. -
capacity- The initial capacity. - Since:
- 43.00
-
-
Method Detail
-
setAutoCompress
public static void setAutoCompress(boolean compress)
Enable/disable auto-compression for instances of this class. With auto-compression disabled, any instance of this class assumes that expressions do not contain two terms with the same variable.- Parameters:
-
compress-trueto enable,falseotherwise. - Since:
- 43.00
-
isAutoCompress
public static boolean isAutoCompress()
Test whether auto-compression is enabled for this class.- Returns:
-
trueif auto compression is enabled for all instances of this class. - Since:
- 43.00
-
deepCopy
public LinExpression deepCopy()
Get a deep copy of this expression.- Specified by:
-
deepCopyin classLinExpression - Returns:
- A deep copy of this expression.
- Since:
- 43.00
-
deepCopy
public LinExpression deepCopy(double factor)
Get a deep copy of this expression multiplied by a constant- Specified by:
-
deepCopyin classLinExpression - Parameters:
-
factor- Factor to scalethiswith. - Returns:
-
A deep copy of this expression multiplied by
factor. - Since:
- 43.00
-
reserve
public LinTermList reserve(int l)
Reserve a maximum number of elements in this expression.- Parameters:
-
l- The number of additional elements to reserve. - Returns:
- Always returns this instance.
- Since:
- 43.00
-
reset
public LinTermList reset()
Clear this expression. Removes all terms and sets the constant to 0.- Specified by:
-
resetin classLinExpression - Returns:
-
Always returns
this. - Since:
- 43.00
-
addTerms
public LinTermList addTerms(java.util.stream.Stream<Variable> variables, java.util.stream.Stream<java.lang.Double> coefficients)
Add multiple terms to this expression. Adds the scalar product defined by the element-wise multiplication ofvariablesandcoefficients.- Overrides:
-
addTermsin classLinExpression - Parameters:
-
variables- Variables. -
coefficients- Coefficients. - Returns:
-
Always returns
this. - Since:
- 43.00
-
addTerms
public LinTermList addTerms(java.lang.Iterable<Variable> variables, java.lang.Iterable<java.lang.Double> coefficients)
Add multiple terms to this expression. Adds the scalar product defined by the element-wise multiplication ofvariablesandcoefficients.- Overrides:
-
addTermsin classLinExpression - Parameters:
-
variables- Variables. -
coefficients- Coefficients. - Returns:
-
Always returns
this. - Since:
- 43.00
-
addTerms
public LinTermList addTerms(Variable[] variables, double[] coefficients)
Add multiple terms to this expression. Adds the scalar product defined by the element-wise multiplication ofvariablesandcoefficients.- Overrides:
-
addTermsin classLinExpression - Parameters:
-
variables- Variables -
coefficients- Coefficients - Returns:
-
Always returns
this. - Since:
- 43.00
-
addTerm
public LinTermList addTerm(Variable variable, double coefficient)
Add a term to this expression. If the expression already has a coefficient forvariablethen the old and the new coefficients will be added.Examples using
addTerm:- Specified by:
-
addTermin classLinExpression - Parameters:
-
variable- Variable. -
coefficient- Coefficient to add forvariable. - Returns:
-
Always returns
this. - Since:
- 43.00
-
addTerm
public LinTermList addTerm(double coefficient, Variable variable)
Add a term to this expression. If the expression already has a coefficient forvariablethen the old and the new coefficients will be added.Examples using
addTerm:- Specified by:
-
addTermin classLinExpression - Parameters:
-
coefficient- Coefficient to add forvariable. -
variable- Variable. - Returns:
-
Always returns
this. - Since:
- 43.00
-
addTerm
public LinTermList addTerm(Variable x)
Add term1*xto this expression. If the expression already has a coefficient forxthen the old and the new coefficients will be added.Examples using
addTerm:- Specified by:
-
addTermin classLinExpression - Parameters:
-
x- Variable. - Returns:
-
Always returns
this. - Since:
- 43.00
-
addTerms
public LinTermList addTerms(LinExpression expr)
Add another linear expression to this expression.- Specified by:
-
addTermsin classLinExpression - Parameters:
-
expr- The expression to add - Returns:
-
Always returns
this. - Since:
- 43.00
-
addTerms
public LinTermList addTerms(LinExpression expr, double factor)
Add another linear expression to this expression.- Specified by:
-
addTermsin classLinExpression - Parameters:
-
expr- The expression to add. -
factor- Factor by which to multiply elements inexprbefore adding. - Returns:
-
Always returns
this. - Since:
- 43.00
-
addConstant
public LinTermList addConstant(double c)
Add a value to the constant term of this expression.- Specified by:
-
addConstantin classLinExpression - Parameters:
-
c- The constant to add. - Returns:
-
Always returns
this. - Since:
- 43.00
-
setConstant
public LinTermList setConstant(double c)
Set the constant term in this expression. Any existing constant term will be overwritten.- Specified by:
-
setConstantin classLinExpression - Parameters:
-
c- New constant term for this expression - Returns:
-
Always returns
this. - Since:
- 43.00
-
getConstant
public double getConstant()
Get the constant value in this expression.- Specified by:
-
getConstantin classLinExpression - Returns:
- The constant value in this expression.
- Since:
- 43.00
-
compress
public void compress()
Compress duplicate terms. Sorts the terms and merges any terms for the same variable into a single term.- Since:
- 43.00
-
evaluate
public double evaluate(double[] solution)
Compute the value of this expression with respect to the given solution vector (which is not required to be feasible).Examples using
evaluate:- Specified by:
-
evaluatein classExpression - Parameters:
-
solution- Solution values for which the expression is evaluated. - Returns:
-
The value of this expression evaluated at
solution. - Since:
- 43.00
-
toString
public java.lang.String toString()
- Overrides:
-
toStringin classjava.lang.Object - Returns:
- Since:
- 43.00
-
-
© 2001-2025 Fair Isaac Corporation. All rights reserved. This documentation is the property of Fair Isaac Corporation (“FICO”). Receipt or possession of this documentation does not convey rights to disclose, reproduce, make derivative works, use, or allow others to use it except solely for internal evaluation purposes to determine whether to purchase a license to the software described in this documentation, or as otherwise set forth in a written software license agreement between you and FICO (or a FICO affiliate). Use of this documentation and the software described in it must conform strictly to the foregoing permitted uses, and no other use is permitted.
