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

Classes

class  _BoundedLinearExpr
 
class  _LinearExpression
 
class  _Product
 
class  _Sum
 
class  BoundedLinearExpression
 
class  EnforcedLinearConstraint
 
class  LinearConstraint
 
class  LinearExpr
 
class  Model
 
class  Solver
 
class  VarEqVar
 
class  Variable
 

Functions

 _add_linear_constraint_to_helper (Union[bool, _BoundedLinearExpr] bounded_expr, mbh.ModelBuilderHelper helper, Optional[str] name)
 
 _add_enforced_linear_constraint_to_helper (Union[bool, _BoundedLinearExpr] bounded_expr, mbh.ModelBuilderHelper helper, Variable var, bool value, Optional[str] name)
 
_LinearExpression _sum_as_flat_linear_expression (List[Tuple[LinearExprT, float]] to_process, float offset=0.0)
 
_LinearExpression _as_flat_linear_expression (LinearExprT base_expr)
 
pd.Index _get_index (_IndexOrSeries obj)
 
pd.Series _attribute_series (*, Callable[[_VariableOrConstraint], NumberT] func, _IndexOrSeries values)
 
pd.Series _convert_to_series_and_validate_index (Union[bool, NumberT, pd.Series] value_or_series, pd.Index index)
 
pd.Series _convert_to_var_series_and_validate_index (Union["Variable", pd.Series] var_or_series, pd.Index index)
 

Variables

 NumberT = Union[int, float, numbers.Real, np.number]
 
 IntegerT = Union[int, numbers.Integral, np.integer]
 
 LinearExprT = Union["LinearExpr", NumberT]
 
 ConstraintT = Union["_BoundedLinearExpr", bool]
 
 _IndexOrSeries = Union[pd.Index, pd.Series]
 
 _VariableOrConstraint = Union["LinearConstraint", "Variable"]
 
 SolveStatus = mbh.SolveStatus
 
int _MAX_LINEAR_EXPRESSION_REPR_TERMS = 5
 
 ModelBuilder = Model
 
 ModelSolver = Solver
 

Detailed Description

Methods for building and solving model_builder models.

The following two sections describe the main
methods for building and solving those models.

* [`Model`](#model_builder.Model): Methods for creating
models, including variables and constraints.
* [`Solver`](#model_builder.Solver): Methods for solving
a model and evaluating solutions.

Additional methods for solving Model models:

* [`Constraint`](#model_builder.Constraint): A few utility methods for modifying
  constraints created by `Model`.
* [`LinearExpr`](#model_builder.LinearExpr): Methods for creating constraints
  and the objective from large arrays of coefficients.

Other methods and functions listed are primarily used for developing OR-Tools,
rather than for solving specific optimization problems.

Function Documentation

◆ _add_enforced_linear_constraint_to_helper()

ortools.linear_solver.python.model_builder._add_enforced_linear_constraint_to_helper ( Union[bool, _BoundedLinearExpr] bounded_expr,
mbh.ModelBuilderHelper helper,
Variable var,
bool value,
Optional[str] name )
protected
Creates a new enforced linear constraint in the helper.

It handles boolean values (which might arise in the construction of
BoundedLinearExpressions).

If bounded_expr is a Boolean value, the linear part of the constraint is
different.
In that case, the constraint will be immutable and marked as under-specified.
Its linear part will be always feasible or infeasible whether the value is
True or False.

Args:
  bounded_expr: The bounded expression used to create the constraint.
  helper: The helper to create the constraint.
  var: the variable used in the indicator
  value: the value used in the indicator
  name: The name of the constraint to be created.

Returns:
  EnforcedLinearConstraint: a constraint in the helper corresponding to the
  input.

Raises:
  TypeError: If constraint is an invalid type.

Definition at line 457 of file model_builder.py.

◆ _add_linear_constraint_to_helper()

ortools.linear_solver.python.model_builder._add_linear_constraint_to_helper ( Union[bool, _BoundedLinearExpr] bounded_expr,
mbh.ModelBuilderHelper helper,
Optional[str] name )
protected
Creates a new linear constraint in the helper.

It handles boolean values (which might arise in the construction of
BoundedLinearExpressions).

If bounded_expr is a Boolean value, the created constraint is different.
In that case, the constraint will be immutable and marked as under-specified.
It will be always feasible or infeasible whether the value is True or False.

Args:
  bounded_expr: The bounded expression used to create the constraint.
  helper: The helper to create the constraint.
  name: The name of the constraint to be created.

Returns:
  LinearConstraint: a constraint in the helper corresponding to the input.

Raises:
  TypeError: If constraint is an invalid type.

Definition at line 413 of file model_builder.py.

◆ _as_flat_linear_expression()

_LinearExpression ortools.linear_solver.python.model_builder._as_flat_linear_expression ( LinearExprT base_expr)
protected
Converts floats, ints and Linear objects to a LinearExpression.

Definition at line 1941 of file model_builder.py.

◆ _attribute_series()

pd.Series ortools.linear_solver.python.model_builder._attribute_series ( * ,
Callable[[_VariableOrConstraint], NumberT] func,
_IndexOrSeries values )
protected
Returns the attributes of `values`.

Args:
  func: The function to call for getting the attribute data.
  values: The values that the function will be applied (element-wise) to.

Returns:
  pd.Series: The attribute values.

Definition at line 1987 of file model_builder.py.

◆ _convert_to_series_and_validate_index()

pd.Series ortools.linear_solver.python.model_builder._convert_to_series_and_validate_index ( Union[bool, NumberT, pd.Series] value_or_series,
pd.Index index )
protected
Returns a pd.Series of the given index with the corresponding values.

Args:
  value_or_series: the values to be converted (if applicable).
  index: the index of the resulting pd.Series.

Returns:
  pd.Series: The set of values with the given index.

Raises:
  TypeError: If the type of `value_or_series` is not recognized.
  ValueError: If the index does not match.

Definition at line 2007 of file model_builder.py.

◆ _convert_to_var_series_and_validate_index()

pd.Series ortools.linear_solver.python.model_builder._convert_to_var_series_and_validate_index ( Union["Variable", pd.Series] var_or_series,
pd.Index index )
protected
Returns a pd.Series of the given index with the corresponding values.

Args:
  var_or_series: the variables to be converted (if applicable).
  index: the index of the resulting pd.Series.

Returns:
  pd.Series: The set of values with the given index.

Raises:
  TypeError: If the type of `value_or_series` is not recognized.
  ValueError: If the index does not match.

Definition at line 2035 of file model_builder.py.

◆ _get_index()

pd.Index ortools.linear_solver.python.model_builder._get_index ( _IndexOrSeries obj)
protected
Returns the indices of `obj` as a `pd.Index`.

Definition at line 1980 of file model_builder.py.

◆ _sum_as_flat_linear_expression()

_LinearExpression ortools.linear_solver.python.model_builder._sum_as_flat_linear_expression ( List[Tuple[LinearExprT, float]] to_process,
float offset = 0.0 )
protected
Creates a _LinearExpression as the sum of terms.

Definition at line 1890 of file model_builder.py.

Variable Documentation

◆ _IndexOrSeries

ortools.linear_solver.python.model_builder._IndexOrSeries = Union[pd.Index, pd.Series]
protected

Definition at line 56 of file model_builder.py.

◆ _MAX_LINEAR_EXPRESSION_REPR_TERMS

int ortools.linear_solver.python.model_builder._MAX_LINEAR_EXPRESSION_REPR_TERMS = 5
protected

Definition at line 1823 of file model_builder.py.

◆ _VariableOrConstraint

ortools.linear_solver.python.model_builder._VariableOrConstraint = Union["LinearConstraint", "Variable"]
protected

Definition at line 57 of file model_builder.py.

◆ ConstraintT

ortools.linear_solver.python.model_builder.ConstraintT = Union["_BoundedLinearExpr", bool]

Definition at line 55 of file model_builder.py.

◆ IntegerT

ortools.linear_solver.python.model_builder.IntegerT = Union[int, numbers.Integral, np.integer]

Definition at line 53 of file model_builder.py.

◆ LinearExprT

ortools.linear_solver.python.model_builder.LinearExprT = Union["LinearExpr", NumberT]

Definition at line 54 of file model_builder.py.

◆ ModelBuilder

ortools.linear_solver.python.model_builder.ModelBuilder = Model

Definition at line 2064 of file model_builder.py.

◆ ModelSolver

ortools.linear_solver.python.model_builder.ModelSolver = Solver

Definition at line 2065 of file model_builder.py.

◆ NumberT

ortools.linear_solver.python.model_builder.NumberT = Union[int, float, numbers.Real, np.number]

Definition at line 52 of file model_builder.py.

◆ SolveStatus

ortools.linear_solver.python.model_builder.SolveStatus = mbh.SolveStatus

Definition at line 60 of file model_builder.py.