Expression
- java.lang.Object
-
- com.dashoptimization.objects.Expression
-
- Direct Known Subclasses:
-
AbstractExpression,Variable
public abstract class Expression extends java.lang.ObjectBase class for all expressions. Expressions are the building blocks for all constraints represented byInequalityand also for indicator constraints. Expressions are created by combining variables and constant using operators and functions. The operators available for combining constants, variables and expressions areplus,minus,mul(multiply) anddiv(divide) and are defined as member functions of theExpressionclass (or its subclasses). To add two variablesxandyone would do ce.x.plus(y). To create the expression2x + 3yone could writex.mul(2).plus(y.mul(3)). The functions that can be used to combine expressions can be found in theUtilsclass. Examples aresum,sin, etc. Expressions are unmodifiable and are represented as expression trees. This means that all operators are implemented to take only constant time to produce the result. An exception to the above are linear and quadratic expressions (classLinExpressionandQuadExpression). Linear and quadratic expressions are very common to math programming and thus they can be built in even more efficient ways: TheLinExpressionandQuadExpressionare the only mutable expressions. They can be modified using theaddTerm()family of functions. When creating a linear expression like2x+3y+4zthen it is more efficient to do this asLinExpression.create().addTerm(x,2).addTerm(y,3).addTerm(z,4)than to create the expression using operatorsplusandmul. For short expressions the performance difference will not be measurable but for longer expressions it will start to matter. Since operators copy their argument expressions by reference, care must be taken when applying operators toLinExpressionorQuadExpression: when changing an instance ofLinExpressionorQuadExpression, this will implicitly change any other expression that references this expression through operators or functions.- Since:
- 43.00
-
-
Constructor Summary
Constructor Description Expression()
-
Method Summary
Modifier and Type Method Description Expressiondiv(double arg)Create a new expression that represents the quotient ofthisandarg.Expressiondiv(Expression arg)Create a new expression that represents the quotient ofthisandarg.abstract Inequality.Definitioneq(double rhs)Create an "equals" constraint with this expression as left-hand side.abstract Inequality.Definitioneq(Expression rhs)Create an "equals" constraint with this expression as left-hand side.abstract doubleevaluate(double[] solution)Compute the value of this expression with respect to the given solution vector (which is not required to be feasible).abstract Inequality.Definitiongeq(double rhs)Create a "greater than or equal" constraint with this expression as left-hand side.abstract Inequality.Definitiongeq(Expression rhs)Create a "greater than or equal" constraint with this expression as left-hand side.abstract doublegetConstantView()Get the constant value to which this expression evaluates.abstract LinearViewgetLinearView()Get a linear read-only view on this expression.abstract intgetMaxDegree()Get the maximum degree of any of the terms/monomials that appear in the symbolic representation of all parenthesized sub-expressions are fully expanded.abstract QuadViewgetQuadView()Get a quadratic read-only view on this expression.abstract Inequality.Definitionin(double lb, double ub)Create a range constraint that bounds this expression from below and above.abstract Inequality.Definitionleq(double rhs)Create a "less than or equal" constraint with this expression as left-hand side.abstract Inequality.Definitionleq(Expression rhs)Create a "less than or equal" constraint with this expression as left-hand side.Expressionminus(double arg)Create a new expression that represents the difference ofthisandarg.Expressionminus(Expression arg)Create a new expression that represents the difference ofthisandarg.Expressionmul(double arg)Create a new expression that represents the product ofthisandarg.Expressionmul(Expression arg)Create a new expression that represents the product ofthisandarg.Expressionplus(double arg)Create a new expression that represents the sum ofthisandarg.Expressionplus(Expression arg)Create a new expression that represents the sum ofthisandarg.Expressionuminus()Create a new expression that represents the unary minus of this one.
-
-
-
Method Detail
-
leq
public abstract Inequality.Definition leq(double rhs)
Create a "less than or equal" constraint with this expression as left-hand side.Examples using
leq:- BinBurglar.java
- Boxes02.java
- Capbgt2l.java
- CapitalBudgeting.java
- Catenary.java
- CuttingStock.java
- ELSManagedCuts.java
- FacilityLocationArray.java
- FacilityLocationCollection.java
- Folio.java
- FolioCB.java
- GeneralConstraints.java
- MultipleKnapsack_Arrays.java
- MultipleKnapsack_Collections.java
- MultipleProblems.java
- PolygonObjects.java
- Pplan.java
- Pplan2.java
- ProductionPlanning_Index.java
- Sangraalind.java
- TravelingSalesPerson.java
- Parameters:
-
rhs- Right-hand side of new constraint. - Returns:
- The new constraint.
- Since:
- 43.00
-
leq
public abstract Inequality.Definition leq(Expression rhs)
Create a "less than or equal" constraint with this expression as left-hand side.Examples using
leq:- BinBurglar.java
- Boxes02.java
- Capbgt2l.java
- CapitalBudgeting.java
- Catenary.java
- CuttingStock.java
- ELSManagedCuts.java
- FacilityLocationArray.java
- FacilityLocationCollection.java
- Folio.java
- FolioCB.java
- GeneralConstraints.java
- MultipleKnapsack_Arrays.java
- MultipleKnapsack_Collections.java
- MultipleProblems.java
- PolygonObjects.java
- Pplan.java
- Pplan2.java
- ProductionPlanning_Index.java
- Sangraalind.java
- TravelingSalesPerson.java
- Parameters:
-
rhs- Right-hand side of new constraint. - Returns:
- The new constraint.
- Since:
- 43.00
-
geq
public abstract Inequality.Definition geq(double rhs)
Create a "greater than or equal" constraint with this expression as left-hand side.Examples using
geq:- Parameters:
-
rhs- Right-hand side of new constraint. - Returns:
- The new constraint.
- Since:
- 43.00
-
geq
public abstract Inequality.Definition geq(Expression rhs)
Create a "greater than or equal" constraint with this expression as left-hand side.Examples using
geq:- Parameters:
-
rhs- Right-hand side of new constraint. - Returns:
- The new constraint.
- Since:
- 43.00
-
eq
public abstract Inequality.Definition eq(double rhs)
Create an "equals" constraint with this expression as left-hand side.Examples using
eq:- BinBurglar.java
- BoolVars.java
- Boxes02.java
- Capbgt2l.java
- FacilityLocationArray.java
- FacilityLocationCollection.java
- Folio.java
- GeneralConstraints.java
- Glidert.java
- MultipleKnapsack_Arrays.java
- MultipleKnapsack_Collections.java
- PolygonObjects.java
- Pplan.java
- Pplan2.java
- ProductionPlanning_Index.java
- PurchaseSOS2.java
- RecursiveFinancialPlanning.java
- Sangraalind.java
- SpecialOrderedSets.java
- SpecialOrderedSetsQuadratic.java
- TravelingSalesPerson.java
- Wagon.java
- Parameters:
-
rhs- Right-hand side of new constraint. - Returns:
- The new constraint.
- Since:
- 43.00
-
eq
public abstract Inequality.Definition eq(Expression rhs)
Create an "equals" constraint with this expression as left-hand side.Examples using
eq:- BinBurglar.java
- BoolVars.java
- Boxes02.java
- Capbgt2l.java
- FacilityLocationArray.java
- FacilityLocationCollection.java
- Folio.java
- GeneralConstraints.java
- Glidert.java
- MultipleKnapsack_Arrays.java
- MultipleKnapsack_Collections.java
- PolygonObjects.java
- Pplan.java
- Pplan2.java
- ProductionPlanning_Index.java
- PurchaseSOS2.java
- RecursiveFinancialPlanning.java
- Sangraalind.java
- SpecialOrderedSets.java
- SpecialOrderedSetsQuadratic.java
- TravelingSalesPerson.java
- Wagon.java
- Parameters:
-
rhs- Right-hand side of new constraint. - Returns:
- The new constraint.
- Since:
- 43.00
-
in
public abstract Inequality.Definition in(double lb, double ub)
Create a range constraint that bounds this expression from below and above.Examples using
in:- Parameters:
-
lb- Lower bound for this expression. -
ub- Upper bound for this expression. - Returns:
- The new constraint.
- Since:
- 43.00
-
evaluate
public abstract 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:- Parameters:
-
solution- Solution values for which the expression is evaluated. - Returns:
-
The value of this expression evaluated at
solution. - Since:
- 43.00
-
getMaxDegree
public abstract int getMaxDegree()
Get the maximum degree of any of the terms/monomials that appear in the symbolic representation of all parenthesized sub-expressions are fully expanded. The maximum degree is- 0 for constant expressions.
- 1 for linear expressions.
- 2 for quadratic expressions.
Integer.MAX_VALUEfor function calls or formulas.
- Returns:
- The maximum degree in this function.
- Since:
- 43.00
-
getConstantView
public abstract double getConstantView()
Get the constant value to which this expression evaluates. If this expression can be treated as a constant value then the function returns the constant value. If the expression cannot be treated as a constant then an exception is raised. In order to test whether the expression can be treated as constant, use functiongetMaxDegree()and check whether it returns 0.- Returns:
- The constant represented by this expression.
- Since:
- 43.00
-
getLinearView
public abstract LinearView getLinearView()
Get a linear read-only view on this expression. If this expression can be treated as a linear expression then the function returns a readonly view on the linear terms (including the constant term if there is any). If the expression cannot be treated as a linear expression then an exception is raised. In order to test this expression can be treated as linear, use functiongetMaxDegree()and check whether it returns 0 or 1. In the returnedjava.util.Map.Entryinstances the constant term is indicated with a key ofXpressProblem.NULL_VARIABLE. Note that depending on the actual expression class and its implementation, the terms may not be presented in the same order in which you added them. There may also be multiple elements with the same key (again depending on the implementation of the actual object).- Returns:
- View on this linear expression.
- Since:
- 43.00
-
getQuadView
public abstract QuadView getQuadView()
Get a quadratic read-only view on this expression. If this expression can be treated as a quadratic expression then the function returns a readonly view on the quadratic terms (including the constant term and linear terms if there are any). If the expression cannot be treated as a linear expression then an exception is raised. In order to test this expression can be treated as quadratic, use functiongetMaxDegree()and check whether it returns 0, 1, or 2. In the returnedjava.util.Map.Entryinstances the constant term is indicated with a key with twoXpressProblem.NULL_VARIABLEs. Linear terms are represented by aQPairwithXpressProblem.NULL_VARIABLEas second variable. Note that depending on the actual expression class and its implementation, the terms may not be presented in the same order in which you added them. There may also be multiple elements with the same key (again depending on the implementation of the actual object).- Returns:
- View on this linear expression.
- Since:
- 43.00
-
uminus
public Expression uminus()
Create a new expression that represents the unary minus of this one.- Returns:
-
Expression representing
-this. - Since:
- 43.00
-
plus
public Expression plus(Expression arg)
Create a new expression that represents the sum ofthisandarg.Examples using
plus:- Parameters:
-
arg- Addend. - Returns:
-
Sum of
thisandarg. - Since:
- 43.00
-
plus
public Expression plus(double arg)
Create a new expression that represents the sum ofthisandarg.Examples using
plus:- Parameters:
-
arg- Addend. - Returns:
-
Sum of
thisandarg. - Since:
- 43.00
-
minus
public Expression minus(Expression arg)
Create a new expression that represents the difference ofthisandarg.Examples using
minus:- Parameters:
-
arg- Minuend. - Returns:
-
Difference of
thisandarg. - Since:
- 43.00
-
minus
public Expression minus(double arg)
Create a new expression that represents the difference ofthisandarg.Examples using
minus:- Parameters:
-
arg- Minuend. - Returns:
-
Difference of
thisandarg. - Since:
- 43.00
-
mul
public Expression mul(Expression arg)
Create a new expression that represents the product ofthisandarg.Examples using
mul:- Boxes02.java
- Capbgt2l.java
- ContractAllocation.java
- CuttingStock.java
- ELS.java
- ELSCut.java
- ELSManagedCuts.java
- FacilityLocationArray.java
- FacilityLocationCollection.java
- Folio.java
- FolioCB.java
- FolioIIS.java
- FolioMipIIS.java
- GeneralConstraints.java
- Glidert.java
- MultipleKnapsack_Arrays.java
- MultipleKnapsack_Collections.java
- MultipleProblems.java
- PolygonObjects.java
- Pplan.java
- Pplan2.java
- ProductionPlanning_Index.java
- PurchaseSOS2.java
- QuadraticProgramming.java
- RecursiveFinancialPlanning.java
- Sangraalind.java
- SpecialOrderedSetsQuadratic.java
- TravelingSalesPerson.java
- Wagon.java
- Parameters:
-
arg- Factor. - Returns:
-
Product of
thisandarg. - Since:
- 43.00
-
mul
public Expression mul(double arg)
Create a new expression that represents the product ofthisandarg.Examples using
mul:- Boxes02.java
- Capbgt2l.java
- ContractAllocation.java
- CuttingStock.java
- ELS.java
- ELSCut.java
- ELSManagedCuts.java
- FacilityLocationArray.java
- FacilityLocationCollection.java
- Folio.java
- FolioCB.java
- FolioIIS.java
- FolioMipIIS.java
- GeneralConstraints.java
- Glidert.java
- MultipleKnapsack_Arrays.java
- MultipleKnapsack_Collections.java
- MultipleProblems.java
- PolygonObjects.java
- Pplan.java
- Pplan2.java
- ProductionPlanning_Index.java
- PurchaseSOS2.java
- QuadraticProgramming.java
- RecursiveFinancialPlanning.java
- Sangraalind.java
- SpecialOrderedSetsQuadratic.java
- TravelingSalesPerson.java
- Wagon.java
- Parameters:
-
arg- Factor. - Returns:
-
Product of
thisandarg. - Since:
- 43.00
-
div
public Expression div(Expression arg)
Create a new expression that represents the quotient ofthisandarg.Examples using
div:- Parameters:
-
arg- Divisor. - Returns:
-
Quotient of
thisandarg. - Since:
- 43.00
-
div
public Expression div(double arg)
Create a new expression that represents the quotient ofthisandarg.Examples using
div:- Parameters:
-
arg- Divisor. - Returns:
-
Quotient of
thisandarg. - 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.
