Google OR-Tools v9.11
a fast and portable software suite for combinatorial optimization
Loading...
Searching...
No Matches
ortools.math_opt.python.expressions Namespace Reference

Functions

model.LinearSum fast_sum (Iterable[model.LinearTypes] summands)
 
Union[model.LinearSum, model.QuadraticSumfast_sum (Iterable[model.QuadraticTypes] summands)
 
 fast_sum (summands)
 
float evaluate_expression (model.QuadraticTypes expression, Mapping[model.Variable, float] variable_values)
 

Detailed Description

Utilities for working with linear and quadratic expressions.

Function Documentation

◆ evaluate_expression()

float ortools.math_opt.python.expressions.evaluate_expression ( model.QuadraticTypes expression,
Mapping[model.Variable, float] variable_values )
Evaluates a linear or quadratic expression for given variable values.

E.g. if expression  = 3 * x + 4 and variable_values = {x: 2.0}, then
evaluate_expression(expression, variable_values) equals 10.0.

Args:
  expression: The expression to evaluate.
  variable_values: Must contain a value for every variable in expression.

Returns:
  The value of the expression when replacing variables by their value.

Definition at line 65 of file expressions.py.

◆ fast_sum() [1/3]

model.LinearSum ortools.math_opt.python.expressions.fast_sum ( Iterable[model.LinearTypes] summands)

Definition at line 23 of file expressions.py.

◆ fast_sum() [2/3]

Union[model.LinearSum, model.QuadraticSum] ortools.math_opt.python.expressions.fast_sum ( Iterable[model.QuadraticTypes] summands)

Definition at line 27 of file expressions.py.

◆ fast_sum() [3/3]

ortools.math_opt.python.expressions.fast_sum ( summands)
Sums the elements of summand into a linear or quadratic expression.

Similar to Python's sum function, but faster for input that not just integers
and floats.

Unlike sum(), the function returns a linear expression when all inputs are
floats and/or integers. Importantly, the code:
  model.add_linear_constraint(fast_sum(maybe_empty_list) <= 1.0)
is safe to call, while:
  model.add_linear_constraint(sum(maybe_empty_list) <= 1.0)
fails at runtime when the list is empty.

Args:
  summands: The elements to add up.

Returns:
  A linear or quadratic expression with the sum of the elements of summand.

Definition at line 39 of file expressions.py.