Utils
- java.lang.Object
-
- com.dashoptimization.objects.Utils
-
public abstract class Utils extends java.lang.Object
Utilities for modeling.- Since:
- 43.00
-
-
Constructor Summary
Constructor Description Utils()
-
Method Summary
Modifier and Type Method Description static InternalFunctionExpression
abs(Expression value)
Create an expression forabs(value)
.static InternalFunctionExpression
arccos(Expression value)
Create an expression forarccos(value)
.static InternalFunctionExpression
arcsin(Expression value)
Create an expression forarcsin(value)
.static InternalFunctionExpression
arctan(Expression value)
Create an expression forarctan(value)
.static InternalFunctionExpression
cos(Expression value)
Create an expression forcos(value)
.static Expression
div(double dividend, Expression divisor)
Create an expression fordividend + divisor
.static Expression
div(Expression dividend, double divisor)
Create an expression fordividend + divisor
.static Expression
div(Expression dividend, Expression divisor)
Create an expression fordividend / divisor
.static InternalFunctionExpression
exp(Expression value)
Create an expression forexp(value)
.static InternalFunctionExpression
ln(Expression value)
Create an expression forln(value)
.static InternalFunctionExpression
log10(Expression value)
Create an expression forlog10(value)
.static InternalFunctionExpression
max(Expression... value)
Create an expression formax(value, ...)
.static InternalFunctionExpression
min(Expression... value)
Create an expression formin(value, ...)
.static Expression
minus(double minuend, Expression subtrahend)
Create an expression forminuend + subtrahend
.static Expression
minus(Expression minuend, double subtrahend)
Create an expression forminuend + subtrahend
.static Expression
minus(Expression minuend, Expression subtrahend)
Create an expression forminuend - subtrahend
.static Expression
mul(double factor1, Expression factor2)
Create an expression forfactor1 + factor2
.static Expression
mul(Expression factor1, double factor2)
Create an expression forfactor1 + factor2
.static Expression
mul(Expression factor1, Expression factor2)
Create an expression forfactor1 * factor2
.static Expression
plus(double augend, Expression addend)
Create an expression foraugend + addend
.static Expression
plus(Expression augend, double addend)
Create an expression foraugend + addend
.static Expression
plus(Expression augend, Expression addend)
Create an expression foraugend + addend
.static BinaryExpression
pow(double basis, Expression exp)
Create an expression forbase ^ exp
.static BinaryExpression
pow(Expression basis, double exp)
Create an expression forbase ^ exp
.static BinaryExpression
pow(Expression basis, Expression exp)
Create an expression forbase ^ exp
.static Expression
prod(Expression... value)
Create an expression forprod(value, ...)
.static LinExpression
scalarProduct(Variable[] variables, double[] coefs)
Compute the scalar product between a vector of variables and a vector of coefficients.static QuadExpression
scalarProduct(Variable[] variables1, Variable[] variables2, double[] coefs)
Compute the elementwise product between two vectors of variables and a vector of coefficients.static QuadExpression
scalarProduct(java.lang.Iterable<Variable> variables1, java.lang.Iterable<Variable> variables2, java.lang.Iterable<java.lang.Double> coefs)
Compute the elementwise product between two vectors of variables and a vector of coefficients.static LinExpression
scalarProduct(java.lang.Iterable<Variable> variables, java.lang.Iterable<java.lang.Double> coefs)
Compute the scalar product between a vector of variables and a vector of coefficients.static <K> LinExpression
scalarProduct(java.util.Map<K,Variable> variables, java.util.Map<K,java.lang.Double> coefs)
Compute the scalar product between a map of variables and a map of coefficients.static QuadExpression
scalarProduct(java.util.stream.Stream<Variable> variables1, java.util.stream.Stream<Variable> variables2, java.util.stream.Stream<java.lang.Double> coefs)
Compute the elementwise product between two vectors of variables and a vector of coefficients.static LinExpression
scalarProduct(java.util.stream.Stream<Variable> variables, java.util.stream.Stream<java.lang.Double> coefs)
Compute the scalar product between a vector of variables and a vector of coefficients.static InternalFunctionExpression
sign(Expression value)
Create an expression forsign(value)
.static InternalFunctionExpression
sin(Expression value)
Create an expression forsin(value)
.static InternalFunctionExpression
sqrt(Expression value)
Create an expression forsqrt(value)
.static <T,A extends Expression>
SumExpressionsum(int[] data, java.util.function.IntFunction<A> makeTerm)
Create a sum of expressions.static <A extends Expression>
SumExpressionsum(int count, java.util.function.Function<java.lang.Integer,A> makeTerm)
Create a sum of expressions.static SumExpression
sum(Expression firstTerm, Expression... moreTerms)
Create an expression from an array of other expressions.static <T extends Expression>
SumExpressionsum(java.lang.Iterable<T> terms)
Create an expression from a collection of other expressions.static <T,A extends Expression>
SumExpressionsum(java.lang.Iterable<T> data, java.util.function.Function<? super T,A> makeTerm)
Create a sum of expressions.static <T,A extends Expression>
SumExpressionsum(java.util.stream.IntStream data, java.util.function.IntFunction<A> makeTerm)
Create a sum of expressions.static <T extends Expression>
SumExpressionsum(java.util.stream.Stream<T> terms)
Create an expression from a stream of other expressions.static <T,A extends Expression>
SumExpressionsum(java.util.stream.Stream<T> data, java.util.function.Function<? super T,A> makeTerm)
Create a sum of expressions.static <T extends Expression>
SumExpressionsum(T[] terms)
Create a sum of expressions.static <T,A extends Expression>
SumExpressionsum(T[] data, java.util.function.Function<? super T,A> makeTerm)
Create a sum of expressions.static InternalFunctionExpression
tan(Expression value)
Create an expression fortan(value)
.static Expression
uminus(Expression value)
Create an expression for-value
.
-
-
-
Method Detail
-
sum
public static <A extends Expression> SumExpression sum(int count, java.util.function.Function<java.lang.Integer,A> makeTerm)
Create a sum of expressions. Note that the terms are captured by reference, i.e., changing those terms later will affect the return sum.- Type Parameters:
-
A
- Type of expressions that are summed up. - Parameters:
-
count
- Number of elements in the sum. -
makeTerm
- Function to produce an expression for each data element. - Returns:
- The sum.
- Since:
- 43.00
-
sum
public static <T,A extends Expression> SumExpression sum(java.util.stream.Stream<T> data, java.util.function.Function<? super T,A> makeTerm)
Create a sum of expressions. Note that the terms are captured by reference, i.e., changing those terms later will affect the return sum.- Type Parameters:
-
T
- Type of data indata
. -
A
- Type of expressions summed up. - Parameters:
-
data
- Data to iterate. -
makeTerm
- Function to create terms. - Returns:
- The new expression.
- Since:
- 43.00
-
sum
public static <T,A extends Expression> SumExpression sum(java.lang.Iterable<T> data, java.util.function.Function<? super T,A> makeTerm)
Create a sum of expressions. Note that the terms are captured by reference, i.e., changing those terms later will affect the return sum.- Type Parameters:
-
T
- Type of data indata
. -
A
- Type of expressions to be summed up. - Parameters:
-
data
- The data from which to build the sum. -
makeTerm
- Function to produce an expression for each data element. - Returns:
- The sum.
- Since:
- 43.00
-
sum
public static <T,A extends Expression> SumExpression sum(T[] data, java.util.function.Function<? super T,A> makeTerm)
Create a sum of expressions. Note that the terms are captured by reference, i.e., changing those terms later will affect the returned sum.- Type Parameters:
-
T
- Type of data indata
. -
A
- Type of expressions to be summed up. - Parameters:
-
data
- Data to iterate. -
makeTerm
- Function to create terms. - Returns:
- The new expression.
- Since:
- 43.00
-
sum
public static <T,A extends Expression> SumExpression sum(int[] data, java.util.function.IntFunction<A> makeTerm)
Create a sum of expressions. Note that the terms are captured by reference, i.e., changing those terms later will affect the returned sum.- Type Parameters:
-
T
- Type of data indata
. -
A
- Type of expressions to be summed up. - Parameters:
-
data
- Data to iterate. -
makeTerm
- Function to create terms. - Returns:
- The new expression.
- Since:
- 43.00
-
sum
public static <T,A extends Expression> SumExpression sum(java.util.stream.IntStream data, java.util.function.IntFunction<A> makeTerm)
Create a sum of expressions. Note that the terms are captured by reference, i.e., changing those terms later will affect the returned sum.- Type Parameters:
-
T
- Type of data indata
. -
A
- Type of expressions to be summed up. - Parameters:
-
data
- Data to iterate. -
makeTerm
- Function to create terms. - Returns:
- The new expression.
- Since:
- 43.00
-
sum
public static <T extends Expression> SumExpression sum(java.util.stream.Stream<T> terms)
Create an expression from a stream of other expressions. Note that the other expressions are copied by reference, so changing them later will affect the returned expression.- Type Parameters:
-
T
- The actual term type. - Parameters:
-
terms
- The expression to sum up. - Returns:
- The new expression.
- Since:
- 43.00
-
sum
public static <T extends Expression> SumExpression sum(java.lang.Iterable<T> terms)
Create an expression from a collection of other expressions. Note that the other expressions are copied by reference, so changing them later will affect the returned expression.- Type Parameters:
-
T
- The actual term type. - Parameters:
-
terms
- The expression to sum up. - Returns:
- The new expression.
- Since:
- 43.00
-
sum
public static <T extends Expression> SumExpression sum(T[] terms)
Create a sum of expressions. Note that the terms are captured by reference, i.e., changing those terms later will affect the return sum.- Type Parameters:
-
T
- The actual term type. - Parameters:
-
terms
- Terms to sum up - Returns:
- The new expression.
- Since:
- 43.00
-
sum
public static SumExpression sum(Expression firstTerm, Expression... moreTerms)
Create an expression from an array of other expressions. Note that the other expressions are copied by reference, so changing them later will affect the returned expression.- Parameters:
-
firstTerm
- The first term to sum up. -
moreTerms
- The other terms to sum up. - Returns:
- The new expression.
- Since:
- 43.00
-
uminus
public static Expression uminus(Expression value)
Create an expression for-value
.- Parameters:
-
value
- The value to negate. - Returns:
-
An expression representing
-value
. - Since:
- 43.00
-
plus
public static Expression plus(Expression augend, Expression addend)
Create an expression foraugend + addend
. This is equivalent toaugend.plus(addend)
and is only provided for completeness.- Parameters:
-
augend
- augend. -
addend
- addend. - Returns:
- sum of augend and addend.
- Since:
- 43.00
-
plus
public static Expression plus(double augend, Expression addend)
Create an expression foraugend + addend
. This is equivalent tonew ConstantExpression(augend).plus(addend)
and is only provided for completeness.- Parameters:
-
augend
- augend. -
addend
- addend. - Returns:
- sum of augend and addend.
- Since:
- 43.00
-
plus
public static Expression plus(Expression augend, double addend)
Create an expression foraugend + addend
. This is equivalent toaugend.plus(addend)
and is only provided for completeness.- Parameters:
-
augend
- augend. -
addend
- addend. - Returns:
- sum of augend and addend.
- Since:
- 43.00
-
minus
public static Expression minus(Expression minuend, Expression subtrahend)
Create an expression forminuend - subtrahend
. This is equivalent tominuend.minus(subtrahend)
and is only provided for completeness.- Parameters:
-
minuend
- minuend. -
subtrahend
- subtrahend. - Returns:
- difference of minuend and subtrahend.
- Since:
- 43.00
-
minus
public static Expression minus(double minuend, Expression subtrahend)
Create an expression forminuend + subtrahend
. This is equivalent tonew ConstantExpression(minuend).minus(subtrahend)
and is only provided for completeness.- Parameters:
-
minuend
- minuend. -
subtrahend
- subtrahend. - Returns:
- difference of minuend and subtrahend.
- Since:
- 43.00
-
minus
public static Expression minus(Expression minuend, double subtrahend)
Create an expression forminuend + subtrahend
. This is equivalent tominuend.minus(subtrahend)
and is only provided for completeness.- Parameters:
-
minuend
- minuend. -
subtrahend
- subtrahend. - Returns:
- difference of minuend and subtrahend.
- Since:
- 43.00
-
div
public static Expression div(Expression dividend, Expression divisor)
Create an expression fordividend / divisor
. This is equivalent todividend.div(divisor)
and is only provided for completeness.- Parameters:
-
dividend
- dividend. -
divisor
- divisor. - Returns:
- quotient of dividend and divisor.
- Since:
- 43.00
-
div
public static Expression div(double dividend, Expression divisor)
Create an expression fordividend + divisor
. This is equivalent tonew ConstantExpression(dividend).div(divisor)
and is only provided for completeness.- Parameters:
-
dividend
- dividend. -
divisor
- divisor. - Returns:
- quotient of dividend and divisor.
- Since:
- 43.00
-
div
public static Expression div(Expression dividend, double divisor)
Create an expression fordividend + divisor
. This is equivalent todividend.div(divisor)
and is only provided for completeness.- Parameters:
-
dividend
- dividend. -
divisor
- divisor. - Returns:
- quotient of dividend and divisor.
- Since:
- 43.00
-
mul
public static Expression mul(Expression factor1, Expression factor2)
Create an expression forfactor1 * factor2
. This is equivalent tofactor1.mul(factor2)
and is only provided for completeness.- Parameters:
-
factor1
- factor1. -
factor2
- factor2. - Returns:
- product of factor1 and factor2.
- Since:
- 43.00
-
mul
public static Expression mul(double factor1, Expression factor2)
Create an expression forfactor1 + factor2
. This is equivalent tonew ConstantExpression(factor1).mul(factor2)
and is only provided for completeness.- Parameters:
-
factor1
- factor1. -
factor2
- factor2. - Returns:
- product of factor1 and factor2.
- Since:
- 43.00
-
mul
public static Expression mul(Expression factor1, double factor2)
Create an expression forfactor1 + factor2
. This is equivalent tofactor1.mul(factor2)
and is only provided for completeness.- Parameters:
-
factor1
- factor1. -
factor2
- factor2. - Returns:
- product of factor1 and factor2.
- Since:
- 43.00
-
pow
public static BinaryExpression pow(Expression basis, Expression exp)
Create an expression forbase ^ exp
. Note that adding the result ofpow
to your model in any way will turn the model into a non-linear model. In order to square a variable or linear expression, use one ofVariable.square()
,LinTerm.square()
, orLinExpression.square()
. They all create linear or quadratic expressions.- Parameters:
-
basis
- Base. -
exp
- Exponent. - Returns:
-
basis
raised to the power ofexp
. - Since:
- 43.00
-
pow
public static BinaryExpression pow(double basis, Expression exp)
Create an expression forbase ^ exp
. Note that adding the result ofpow
to your model in any way will turn the model into a non-linear model. In order to square a variable or linear expression, use one ofVariable.square()
,LinTerm.square()
, orLinExpression.square()
. They all create linear or quadratic expressions.- Parameters:
-
basis
- Base. -
exp
- Exponent. - Returns:
-
basis
raised to the power ofexp
. - Since:
- 43.00
-
pow
public static BinaryExpression pow(Expression basis, double exp)
Create an expression forbase ^ exp
. Note that adding the result ofpow
to your model in any way will turn the model into a non-linear model. In order to square a variable or linear expression, use one ofVariable.square()
,LinTerm.square()
, orLinExpression.square()
. They all create linear or quadratic expressions.- Parameters:
-
basis
- Base. -
exp
- Exponent. - Returns:
-
basis
raised to the power ofexp
. - Since:
- 43.00
-
log10
public static InternalFunctionExpression log10(Expression value)
Create an expression forlog10(value)
.- Parameters:
-
value
- Function argument. - Returns:
-
log10(value)
. - Since:
- 43.00
-
ln
public static InternalFunctionExpression ln(Expression value)
Create an expression forln(value)
.- Parameters:
-
value
- Function argument. - Returns:
-
ln(value)
. - Since:
- 43.00
-
exp
public static InternalFunctionExpression exp(Expression value)
Create an expression forexp(value)
.- Parameters:
-
value
- Function argument. - Returns:
-
exp(value)
. - Since:
- 43.00
-
abs
public static InternalFunctionExpression abs(Expression value)
Create an expression forabs(value)
.Used in these examples:
- AddMipSol
- FixBV
- GlobalObjectiveParametrics
- GlobalRHSParametrics
- GoalProg
- Knapsack
- LoadLP
- MipSolEnum
- MipSolPool
- MostViolated
- Repair
- SaveSol
- Tableau
- Trimloss
- Parameters:
-
value
- Function argument. - Returns:
-
abs(value)
. - Since:
- 43.00
-
sqrt
public static InternalFunctionExpression sqrt(Expression value)
Create an expression forsqrt(value)
.Used in these examples:
- TSP
- Parameters:
-
value
- Function argument. - Returns:
-
sqrt(value)
. - Since:
- 43.00
-
sin
public static InternalFunctionExpression sin(Expression value)
Create an expression forsin(value)
.Used in these examples:
- PolygonMap
- PolygonMapDelta
- PolygonMultiMap
- PolygonMultiMapDelta
- PolygonVecMap
- PolygonVecMapDelta
- Parameters:
-
value
- Function argument. - Returns:
-
sin(value)
. - Since:
- 43.00
-
cos
public static InternalFunctionExpression cos(Expression value)
Create an expression forcos(value)
.Used in these examples:
- PolygonMap
- PolygonMapDelta
- PolygonMultiMap
- PolygonMultiMapDelta
- PolygonVecMap
- PolygonVecMapDelta
- Parameters:
-
value
- Function argument. - Returns:
-
cos(value)
. - Since:
- 43.00
-
tan
public static InternalFunctionExpression tan(Expression value)
Create an expression fortan(value)
.- Parameters:
-
value
- Function argument. - Returns:
-
tan(value)
. - Since:
- 43.00
-
arcsin
public static InternalFunctionExpression arcsin(Expression value)
Create an expression forarcsin(value)
.- Parameters:
-
value
- Function argument. - Returns:
-
arcsin(value)
. - Since:
- 43.00
-
arccos
public static InternalFunctionExpression arccos(Expression value)
Create an expression forarccos(value)
.- Parameters:
-
value
- Function argument. - Returns:
-
arccos(value)
. - Since:
- 43.00
-
arctan
public static InternalFunctionExpression arctan(Expression value)
Create an expression forarctan(value)
.- Parameters:
-
value
- Function argument. - Returns:
-
arctan(value)
. - Since:
- 43.00
-
sign
public static InternalFunctionExpression sign(Expression value)
Create an expression forsign(value)
.- Parameters:
-
value
- Function argument. - Returns:
-
sign(value)
. - Since:
- 43.00
-
min
public static InternalFunctionExpression min(Expression... value)
Create an expression formin(value, ...)
. Consider also usingVariable.minOf(...)
.Used in these examples:
- MostViolated
- Parameters:
-
value
- Arguments. - Returns:
-
min(value...)
. - Since:
- 43.00
-
max
public static InternalFunctionExpression max(Expression... value)
Create an expression formax(value, ...)
. Consider also usingVariable.maxOf
.- Parameters:
-
value
- Arguments. - Returns:
-
max(value...)
. - Since:
- 43.00
-
prod
public static Expression prod(Expression... value)
Create an expression forprod(value, ...)
.- Parameters:
-
value
- Expressions to multiply. - Returns:
-
The product of the expression in
value
. - Since:
- 43.00
-
scalarProduct
public static LinExpression scalarProduct(java.util.stream.Stream<Variable> variables, java.util.stream.Stream<java.lang.Double> coefs)
Compute the scalar product between a vector of variables and a vector of coefficients. Both vectors are specified as streams of elements.- Parameters:
-
variables
- Variables in the scalar product. -
coefs
- Coefficients in the scalar product. - Returns:
- The sum of the specified terms.
- Since:
- 43.00
-
scalarProduct
public static LinExpression scalarProduct(Variable[] variables, double[] coefs)
Compute the scalar product between a vector of variables and a vector of coefficients. Both vectors are specified as arrays.- Parameters:
-
variables
- Variables in the scalar product. -
coefs
- Coefficients in the scalar product. - Returns:
- The sum of the specified terms.
- Since:
- 43.00
-
scalarProduct
public static LinExpression scalarProduct(java.lang.Iterable<Variable> variables, java.lang.Iterable<java.lang.Double> coefs)
Compute the scalar product between a vector of variables and a vector of coefficients. Both vectors are specified as iterables of elements.- Parameters:
-
variables
- Variables in the scalar product. -
coefs
- Coefficients in the scalar product. - Returns:
- The sum of the specified terms.
- Since:
- 43.00
-
scalarProduct
public static <K> LinExpression scalarProduct(java.util.Map<K,Variable> variables, java.util.Map<K,java.lang.Double> coefs)
Compute the scalar product between a map of variables and a map of coefficients. The function assumes thatvariables
andcoefs
have the same keys (missing keys incoefs
are treated as zero) and creates a new linear expression by iterating over the keys invariables
and adding up the variable/coefficient pair for each key.- Type Parameters:
-
K
- Key type. - Parameters:
-
variables
- Map of variables. -
coefs
- Map of coefficients for the variables invariables
. - Returns:
- The new linear expression.
- Since:
- 43.00
-
scalarProduct
public static QuadExpression scalarProduct(java.util.stream.Stream<Variable> variables1, java.util.stream.Stream<Variable> variables2, java.util.stream.Stream<java.lang.Double> coefs)
Compute the elementwise product between two vectors of variables and a vector of coefficients. All vectors are specified as streams of elements.- Parameters:
-
variables1
- First variables in the product. -
variables2
- Second variables in the product. -
coefs
- Coefficients in the product. - Returns:
- The sum of the specified terms.
- Since:
- 43.00
-
scalarProduct
public static QuadExpression scalarProduct(Variable[] variables1, Variable[] variables2, double[] coefs)
Compute the elementwise product between two vectors of variables and a vector of coefficients. All vectors are specified as arrays.- Parameters:
-
variables1
- First variables in the product. -
variables2
- Second variables in the product. -
coefs
- Coefficients in the product. - Returns:
- The sum of the specified terms.
- Since:
- 43.00
-
scalarProduct
public static QuadExpression scalarProduct(java.lang.Iterable<Variable> variables1, java.lang.Iterable<Variable> variables2, java.lang.Iterable<java.lang.Double> coefs)
Compute the elementwise product between two vectors of variables and a vector of coefficients. All vectors are specified as collection of elements.- Parameters:
-
variables1
- First variables in the product. -
variables2
- Second variables in the product. -
coefs
- Coefficients in the product. - Returns:
- The sum of the specified terms.
- 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.