LinTermMap
- java.lang.Object
-
- com.dashoptimization.objects.Expression
-
- com.dashoptimization.objects.AbstractExpression
-
- com.dashoptimization.objects.LinExpression
-
- com.dashoptimization.objects.LinTermMap
-
public final class LinTermMap extends LinExpression
A linear expression. This class implements a linear expression as a map from variables to values.- Since:
- 43.00
-
-
Constructor Summary
Constructor Description LinTermMap()
Create a new empty expression.LinTermMap(double constant)
Create an expression with a constant term.
-
Method Summary
Modifier and Type Method Description LinExpression
addConstant(double constant)
Add a value to the constant term of this expression.LinExpression
addTerm(double coefficient, Variable variable)
Add a term to this expression.LinExpression
addTerm(Variable x)
Add term1*x
this expression.LinExpression
addTerm(Variable variable, double coefficient)
Add a term to this expression.LinExpression
addTerms(LinExpression expr)
Add another linear expression to this expression.LinExpression
addTerms(LinExpression expr, double factor)
Add another linear expression to this expression.LinExpression
addTerms(Variable[] variables, double[] coefficients)
Add multiple terms to this expression.LinExpression
addTerms(java.util.Collection<Variable> variables, java.util.Collection<java.lang.Double> coefficients)
Add multiple terms to this expression.LinExpression
deepCopy()
Get a deep copy of this expression.LinExpression
deepCopy(double factor)
Get a deep copy of this expression multiplied by a constantdouble
evaluate(double[] solution)
Compute the value of this expression with respect to the given solution vector (which is not required to be feasible).void
extract(double factor, PostfixExtractor extractor)
Extract this expression into postfix notation.boolean
extract(double factor, XPRSprob.RowCreator creator)
Extract this expression into a row.double
getCoefficient(Variable variable)
Get the coefficient for a variable.double
getConstant()
Get the constant value in this expression.LinExpression
reset()
Clear this expression.LinTermMap
setCoefficient(Variable variable, double coefficient)
Set the coefficient for a variable in this expression.LinExpression
setConstant(double constant)
Set the constant term in this expression.-
Methods inherited from class com.dashoptimization.objects.LinExpression
addTerm, create, create, square, toString
-
Methods inherited from class com.dashoptimization.objects.AbstractExpression
eq, eq, geq, geq, in, leq, leq
-
-
-
-
Method Detail
-
deepCopy
public LinExpression deepCopy()
Get a deep copy of this expression.- Specified by:
-
deepCopy
in 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:
-
deepCopy
in classLinExpression
- Parameters:
-
factor
- Factor to scalethis
with. - Returns:
-
A deep copy of this expression multiplied by
factor
. - Since:
- 43.00
-
reset
public LinExpression reset()
Clear this expression. Removes all terms and sets the constant to 0.- Specified by:
-
reset
in classLinExpression
- Returns:
-
Always returns
this
. - Since:
- 43.00
-
addTerms
public LinExpression addTerms(java.util.Collection<Variable> variables, java.util.Collection<java.lang.Double> coefficients)
Add multiple terms to this expression. Adds the scalar product defined by the two parallel collections to this expression.- Specified by:
-
addTerms
in classLinExpression
- Parameters:
-
variables
- Variables. -
coefficients
- Coefficients. - Returns:
-
Always returns
this
. - Since:
- 43.00
-
addTerms
public LinExpression addTerms(Variable[] variables, double[] coefficients)
Add multiple terms to this expression. Adds the scalar product defined by the two parallel arrays to this expression. This function is equivalent tofor (int i = 0; i < variables.length; ++i) addTerm(variables[i], coefficients[i]);
- Specified by:
-
addTerms
in classLinExpression
- Parameters:
-
variables
- Variables -
coefficients
- Coefficients - Returns:
-
Always returns
this
. - Since:
- 43.00
-
addTerm
public LinExpression addTerm(Variable variable, double coefficient)
Add a term to this expression. If the expression already has a coefficient forvariable
then the old and the new coefficients will be added.- Specified by:
-
addTerm
in classLinExpression
- Parameters:
-
variable
- Variable. -
coefficient
- Coefficient to add forvariable
. - Returns:
-
Always returns
this
. - Since:
- 43.00
-
addTerm
public LinExpression addTerm(double coefficient, Variable variable)
Add a term to this expression. If the expression already has a coefficient forvariable
then the old and the new coefficients will be added.- Specified by:
-
addTerm
in classLinExpression
- Parameters:
-
coefficient
- Coefficient to add forvariable
. -
variable
- Variable. - Returns:
-
Always returns
this
. - Since:
- 43.00
-
addTerm
public LinExpression addTerm(Variable x)
Add term1*x
this expression. If the expression already has a coefficient forx
then the old and the new coefficients will be added.- Specified by:
-
addTerm
in classLinExpression
- Parameters:
-
x
- Variable. - Returns:
-
Always returns
this
. - Since:
- 43.00
-
addTerms
public LinExpression addTerms(LinExpression expr)
Add another linear expression to this expression.- Specified by:
-
addTerms
in classLinExpression
- Parameters:
-
expr
- The expression to add - Returns:
-
Always returns
this
. - Since:
- 43.00
-
addTerms
public LinExpression addTerms(LinExpression expr, double factor)
Add another linear expression to this expression.- Specified by:
-
addTerms
in classLinExpression
- Parameters:
-
expr
- The expression to add. -
factor
- Factor by which to multiply elements inexpr
before adding. - Returns:
-
Always returns
this
. - Since:
- 43.00
-
setCoefficient
public LinTermMap setCoefficient(Variable variable, double coefficient)
Set the coefficient for a variable in this expression. Any existing coefficient will be overwritten.- Parameters:
-
variable
- Variable index. -
coefficient
- New coefficient forvariable
. - Returns:
-
Always returns
this
. - Since:
- 43.00
-
getCoefficient
public double getCoefficient(Variable variable)
Get the coefficient for a variable.- Parameters:
-
variable
- Variable to query. - Returns:
-
The coefficient for
variable
in this expression. - Since:
- 43.00
-
addConstant
public LinExpression addConstant(double constant)
Add a value to the constant term of this expression.- Specified by:
-
addConstant
in classLinExpression
- Parameters:
-
constant
- The constant to add. - Returns:
-
Always returns
this
. - Since:
- 43.00
-
setConstant
public LinExpression setConstant(double constant)
Set the constant term in this expression. Any existing constant term will be overwritten.- Specified by:
-
setConstant
in classLinExpression
- Parameters:
-
constant
- 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:
-
getConstant
in classLinExpression
- Returns:
- The constant value in this expression.
- Since:
- 43.00
-
extract
public boolean extract(double factor, XPRSprob.RowCreator creator)
Extract this expression into a row. This is for internal use only, you should never have to call this function explicitly.- Specified by:
-
extract
in classExpression
- Parameters:
-
factor
- Factor by which to multiply the expression during extraction. -
creator
- The creator to which this expression should be extracted. - Returns:
-
true
if the low-level representation does requires normalization (sorting, removal of dups, ...). In some special cases we know that this is not required and can returnfalse
to save the overhead. - Since:
- 43.00
-
extract
public void extract(double factor, PostfixExtractor extractor)
Extract this expression into postfix notation.- Specified by:
-
extract
in classExpression
- Parameters:
-
factor
- Factor by which to multiply the expression during extraction. -
extractor
- The extractor to which the expression is extract. - 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).- Specified by:
-
evaluate
in classExpression
- Parameters:
-
solution
- Solution values for which the expression is evaluated. - Since:
- 43.00
-
-
© 2001-2024 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.