Google OR-Tools v9.9
a fast and portable software suite for combinatorial optimization
Loading...
Searching...
No Matches
ortools.sat.python.cp_model Namespace Reference

Classes

class  _NotBooleanVariable
 
class  _ProductCst
 
class  _Sum
 
class  _SumArray
 
class  _WeightedSum
 
class  BoundedLinearExpression
 
class  Constraint
 
class  CpModel
 
class  CpSolver
 
class  CpSolverSolutionCallback
 
class  IntervalVar
 
class  IntVar
 
class  LinearExpr
 
class  ObjectiveSolutionPrinter
 
class  VarArrayAndObjectiveSolutionPrinter
 
class  VarArraySolutionPrinter
 

Functions

str display_bounds (Sequence[int] bounds)
 
str short_name (cp_model_pb2.CpModelProto model, int i)
 
str short_expr_name (cp_model_pb2.CpModelProto model, cp_model_pb2.LinearExpressionProto e)
 
bool object_is_a_true_literal (LiteralT literal)
 
bool object_is_a_false_literal (LiteralT literal)
 
Union[Iterable[LiteralT], LiteralTexpand_generator_or_tuple (Union[Tuple[LiteralT,...], Iterable[LiteralT]] args)
 
Union[Iterable[LinearExprT], LinearExprTexpand_generator_or_tuple (Union[Tuple[LinearExprT,...], Iterable[LinearExprT]] args)
 
 expand_generator_or_tuple (args)
 
int evaluate_linear_expr (LinearExprT expression, cp_model_pb2.CpSolverResponse solution)
 
bool evaluate_boolean_expression (LiteralT literal, cp_model_pb2.CpSolverResponse solution)
 
pd.Index _get_index (_IndexOrSeries obj)
 
pd.Series _attribute_series (*Callable[[IntVar], IntegralT] func, _IndexOrSeries values)
 
pd.Series _convert_to_integral_series_and_validate_index (Union[IntegralT, pd.Series] value_or_series, pd.Index index)
 
pd.Series _convert_to_linear_expr_series_and_validate_index (Union[LinearExprT, pd.Series] value_or_series, pd.Index index)
 
pd.Series _convert_to_literal_series_and_validate_index (Union[LiteralT, pd.Series] value_or_series, pd.Index index)
 

Variables

 Domain = sorted_interval_list.Domain
 
 INT_MIN = -(2**63)
 
int INT_MAX = 2**63 - 1
 
 INT32_MIN = -(2**31)
 
int INT32_MAX = 2**31 - 1
 
 UNKNOWN = cp_model_pb2.UNKNOWN
 
 MODEL_INVALID = cp_model_pb2.MODEL_INVALID
 
 FEASIBLE = cp_model_pb2.FEASIBLE
 
 INFEASIBLE = cp_model_pb2.INFEASIBLE
 
 OPTIMAL = cp_model_pb2.OPTIMAL
 
 CHOOSE_FIRST = cp_model_pb2.DecisionStrategyProto.CHOOSE_FIRST
 
 CHOOSE_LOWEST_MIN = cp_model_pb2.DecisionStrategyProto.CHOOSE_LOWEST_MIN
 
 CHOOSE_HIGHEST_MAX = cp_model_pb2.DecisionStrategyProto.CHOOSE_HIGHEST_MAX
 
 CHOOSE_MIN_DOMAIN_SIZE = cp_model_pb2.DecisionStrategyProto.CHOOSE_MIN_DOMAIN_SIZE
 
 CHOOSE_MAX_DOMAIN_SIZE = cp_model_pb2.DecisionStrategyProto.CHOOSE_MAX_DOMAIN_SIZE
 
 SELECT_MIN_VALUE = cp_model_pb2.DecisionStrategyProto.SELECT_MIN_VALUE
 
 SELECT_MAX_VALUE = cp_model_pb2.DecisionStrategyProto.SELECT_MAX_VALUE
 
 SELECT_LOWER_HALF = cp_model_pb2.DecisionStrategyProto.SELECT_LOWER_HALF
 
 SELECT_UPPER_HALF = cp_model_pb2.DecisionStrategyProto.SELECT_UPPER_HALF
 
 AUTOMATIC_SEARCH = sat_parameters_pb2.SatParameters.AUTOMATIC_SEARCH
 
 FIXED_SEARCH = sat_parameters_pb2.SatParameters.FIXED_SEARCH
 
 PORTFOLIO_SEARCH = sat_parameters_pb2.SatParameters.PORTFOLIO_SEARCH
 
 LP_SEARCH = sat_parameters_pb2.SatParameters.LP_SEARCH
 
 PSEUDO_COST_SEARCH = sat_parameters_pb2.SatParameters.PSEUDO_COST_SEARCH
 
tuple PORTFOLIO_WITH_QUICK_RESTART_SEARCH
 
 HINT_SEARCH = sat_parameters_pb2.SatParameters.HINT_SEARCH
 
 PARTIAL_FIXED_SEARCH = sat_parameters_pb2.SatParameters.PARTIAL_FIXED_SEARCH
 
 RANDOMIZED_SEARCH = sat_parameters_pb2.SatParameters.RANDOMIZED_SEARCH
 
 IntegralT = Union[numbers.Integral, int]
 
 NumberT = Union[numbers.Integral, int, numbers.Number, float]
 
 LiteralT = Union["IntVar", "_NotBooleanVariable", IntegralT, bool]
 
 BoolVarT = Union["IntVar", "_NotBooleanVariable"]
 
 VariableT = Union["IntVar", IntegralT]
 
 LinearExprT = Union["LinearExpr", "IntVar", IntegralT]
 
 ObjLinearExprT = Union["LinearExpr", "IntVar", NumberT]
 
 BoundedLinearExprT = Union["BoundedLinearExpression", bool]
 
 ArcT = Tuple[IntegralT, IntegralT, LiteralT]
 
 _IndexOrSeries = Union[pd.Index, pd.Series]
 

Detailed Description

Methods for building and solving CP-SAT models.

The following two sections describe the main
methods for building and solving CP-SAT models.

* [`CpModel`](#cp_model.CpModel): Methods for creating
models, including variables and constraints.
* [`CPSolver`](#cp_model.CpSolver): Methods for solving
a model and evaluating solutions.

The following methods implement callbacks that the
solver calls each time it finds a new solution.

* [`CpSolverSolutionCallback`](#cp_model.CpSolverSolutionCallback):
  A general method for implementing callbacks.
* [`ObjectiveSolutionPrinter`](#cp_model.ObjectiveSolutionPrinter):
  Print objective values and elapsed time for intermediate solutions.
* [`VarArraySolutionPrinter`](#cp_model.VarArraySolutionPrinter):
  Print intermediate solutions (variable values, time).
* [`VarArrayAndObjectiveSolutionPrinter`]
      (#cp_model.VarArrayAndObjectiveSolutionPrinter):
  Print both intermediate solutions and objective values.

Additional methods for solving CP-SAT models:

* [`Constraint`](#cp_model.Constraint): A few utility methods for modifying
  constraints created by `CpModel`.
* [`LinearExpr`](#lineacp_model.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

◆ _attribute_series()

pd.Series ortools.sat.python.cp_model._attribute_series ( *Callable[[IntVar], IntegralT] 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 3648 of file cp_model.py.

◆ _convert_to_integral_series_and_validate_index()

pd.Series ortools.sat.python.cp_model._convert_to_integral_series_and_validate_index ( Union[IntegralT, 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 3668 of file cp_model.py.

◆ _convert_to_linear_expr_series_and_validate_index()

pd.Series ortools.sat.python.cp_model._convert_to_linear_expr_series_and_validate_index ( Union[LinearExprT, 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 3696 of file cp_model.py.

◆ _convert_to_literal_series_and_validate_index()

pd.Series ortools.sat.python.cp_model._convert_to_literal_series_and_validate_index ( Union[LiteralT, 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 3724 of file cp_model.py.

◆ _get_index()

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

Definition at line 3641 of file cp_model.py.

◆ display_bounds()

str ortools.sat.python.cp_model.display_bounds ( Sequence[int] bounds)
Displays a flattened list of intervals.

Definition at line 136 of file cp_model.py.

◆ evaluate_boolean_expression()

bool ortools.sat.python.cp_model.evaluate_boolean_expression ( LiteralT literal,
cp_model_pb2.CpSolverResponse solution )
Evaluate a boolean expression against a solution.

Definition at line 3071 of file cp_model.py.

◆ evaluate_linear_expr()

int ortools.sat.python.cp_model.evaluate_linear_expr ( LinearExprT expression,
cp_model_pb2.CpSolverResponse solution )
Evaluate a linear expression against a solution.

Definition at line 3033 of file cp_model.py.

◆ expand_generator_or_tuple() [1/3]

ortools.sat.python.cp_model.expand_generator_or_tuple ( args)

Definition at line 3023 of file cp_model.py.

◆ expand_generator_or_tuple() [2/3]

Union[Iterable[LinearExprT], LinearExprT] ortools.sat.python.cp_model.expand_generator_or_tuple ( Union[Tuple[LinearExprT, ...], Iterable[LinearExprT]] args)

Definition at line 3017 of file cp_model.py.

◆ expand_generator_or_tuple() [3/3]

Union[Iterable[LiteralT], LiteralT] ortools.sat.python.cp_model.expand_generator_or_tuple ( Union[Tuple[LiteralT, ...], Iterable[LiteralT]] args)

Definition at line 3010 of file cp_model.py.

◆ object_is_a_false_literal()

bool ortools.sat.python.cp_model.object_is_a_false_literal ( LiteralT literal)
Checks if literal is either False, or a Boolean literals fixed to False.

Definition at line 1283 of file cp_model.py.

◆ object_is_a_true_literal()

bool ortools.sat.python.cp_model.object_is_a_true_literal ( LiteralT literal)
Checks if literal is either True, or a Boolean literals fixed to True.

Definition at line 1270 of file cp_model.py.

◆ short_expr_name()

str ortools.sat.python.cp_model.short_expr_name ( cp_model_pb2.CpModelProto model,
cp_model_pb2.LinearExpressionProto e )
Pretty-print LinearExpressionProto instances.

Definition at line 162 of file cp_model.py.

◆ short_name()

str ortools.sat.python.cp_model.short_name ( cp_model_pb2.CpModelProto model,
int i )
Returns a short name of an integer variable, or its negation.

Definition at line 149 of file cp_model.py.

Variable Documentation

◆ _IndexOrSeries

ortools.sat.python.cp_model._IndexOrSeries = Union[pd.Index, pd.Series]
protected

Definition at line 133 of file cp_model.py.

◆ ArcT

ortools.sat.python.cp_model.ArcT = Tuple[IntegralT, IntegralT, LiteralT]

Definition at line 132 of file cp_model.py.

◆ AUTOMATIC_SEARCH

ortools.sat.python.cp_model.AUTOMATIC_SEARCH = sat_parameters_pb2.SatParameters.AUTOMATIC_SEARCH

Definition at line 109 of file cp_model.py.

◆ BoolVarT

ortools.sat.python.cp_model.BoolVarT = Union["IntVar", "_NotBooleanVariable"]

Definition at line 127 of file cp_model.py.

◆ BoundedLinearExprT

ortools.sat.python.cp_model.BoundedLinearExprT = Union["BoundedLinearExpression", bool]

Definition at line 131 of file cp_model.py.

◆ CHOOSE_FIRST

ortools.sat.python.cp_model.CHOOSE_FIRST = cp_model_pb2.DecisionStrategyProto.CHOOSE_FIRST

Definition at line 96 of file cp_model.py.

◆ CHOOSE_HIGHEST_MAX

ortools.sat.python.cp_model.CHOOSE_HIGHEST_MAX = cp_model_pb2.DecisionStrategyProto.CHOOSE_HIGHEST_MAX

Definition at line 98 of file cp_model.py.

◆ CHOOSE_LOWEST_MIN

ortools.sat.python.cp_model.CHOOSE_LOWEST_MIN = cp_model_pb2.DecisionStrategyProto.CHOOSE_LOWEST_MIN

Definition at line 97 of file cp_model.py.

◆ CHOOSE_MAX_DOMAIN_SIZE

ortools.sat.python.cp_model.CHOOSE_MAX_DOMAIN_SIZE = cp_model_pb2.DecisionStrategyProto.CHOOSE_MAX_DOMAIN_SIZE

Definition at line 100 of file cp_model.py.

◆ CHOOSE_MIN_DOMAIN_SIZE

ortools.sat.python.cp_model.CHOOSE_MIN_DOMAIN_SIZE = cp_model_pb2.DecisionStrategyProto.CHOOSE_MIN_DOMAIN_SIZE

Definition at line 99 of file cp_model.py.

◆ Domain

ortools.sat.python.cp_model.Domain = sorted_interval_list.Domain

Definition at line 77 of file cp_model.py.

◆ FEASIBLE

ortools.sat.python.cp_model.FEASIBLE = cp_model_pb2.FEASIBLE

Definition at line 91 of file cp_model.py.

◆ FIXED_SEARCH

ortools.sat.python.cp_model.FIXED_SEARCH = sat_parameters_pb2.SatParameters.FIXED_SEARCH

Definition at line 110 of file cp_model.py.

◆ HINT_SEARCH

ortools.sat.python.cp_model.HINT_SEARCH = sat_parameters_pb2.SatParameters.HINT_SEARCH

Definition at line 117 of file cp_model.py.

◆ INFEASIBLE

ortools.sat.python.cp_model.INFEASIBLE = cp_model_pb2.INFEASIBLE

Definition at line 92 of file cp_model.py.

◆ INT32_MAX

int ortools.sat.python.cp_model.INT32_MAX = 2**31 - 1

Definition at line 86 of file cp_model.py.

◆ INT32_MIN

ortools.sat.python.cp_model.INT32_MIN = -(2**31)

Definition at line 85 of file cp_model.py.

◆ INT_MAX

int ortools.sat.python.cp_model.INT_MAX = 2**63 - 1

Definition at line 84 of file cp_model.py.

◆ INT_MIN

ortools.sat.python.cp_model.INT_MIN = -(2**63)

Definition at line 83 of file cp_model.py.

◆ IntegralT

ortools.sat.python.cp_model.IntegralT = Union[numbers.Integral, int]

Definition at line 123 of file cp_model.py.

◆ LinearExprT

ortools.sat.python.cp_model.LinearExprT = Union["LinearExpr", "IntVar", IntegralT]

Definition at line 129 of file cp_model.py.

◆ LiteralT

ortools.sat.python.cp_model.LiteralT = Union["IntVar", "_NotBooleanVariable", IntegralT, bool]

Definition at line 126 of file cp_model.py.

◆ LP_SEARCH

ortools.sat.python.cp_model.LP_SEARCH = sat_parameters_pb2.SatParameters.LP_SEARCH

Definition at line 112 of file cp_model.py.

◆ MODEL_INVALID

ortools.sat.python.cp_model.MODEL_INVALID = cp_model_pb2.MODEL_INVALID

Definition at line 90 of file cp_model.py.

◆ NumberT

ortools.sat.python.cp_model.NumberT = Union[numbers.Integral, int, numbers.Number, float]

Definition at line 125 of file cp_model.py.

◆ ObjLinearExprT

ortools.sat.python.cp_model.ObjLinearExprT = Union["LinearExpr", "IntVar", NumberT]

Definition at line 130 of file cp_model.py.

◆ OPTIMAL

ortools.sat.python.cp_model.OPTIMAL = cp_model_pb2.OPTIMAL

Definition at line 93 of file cp_model.py.

◆ PARTIAL_FIXED_SEARCH

ortools.sat.python.cp_model.PARTIAL_FIXED_SEARCH = sat_parameters_pb2.SatParameters.PARTIAL_FIXED_SEARCH

Definition at line 118 of file cp_model.py.

◆ PORTFOLIO_SEARCH

ortools.sat.python.cp_model.PORTFOLIO_SEARCH = sat_parameters_pb2.SatParameters.PORTFOLIO_SEARCH

Definition at line 111 of file cp_model.py.

◆ PORTFOLIO_WITH_QUICK_RESTART_SEARCH

tuple ortools.sat.python.cp_model.PORTFOLIO_WITH_QUICK_RESTART_SEARCH
Initial value:
1= (
2 sat_parameters_pb2.SatParameters.PORTFOLIO_WITH_QUICK_RESTART_SEARCH
3)

Definition at line 114 of file cp_model.py.

◆ PSEUDO_COST_SEARCH

ortools.sat.python.cp_model.PSEUDO_COST_SEARCH = sat_parameters_pb2.SatParameters.PSEUDO_COST_SEARCH

Definition at line 113 of file cp_model.py.

◆ RANDOMIZED_SEARCH

ortools.sat.python.cp_model.RANDOMIZED_SEARCH = sat_parameters_pb2.SatParameters.RANDOMIZED_SEARCH

Definition at line 119 of file cp_model.py.

◆ SELECT_LOWER_HALF

ortools.sat.python.cp_model.SELECT_LOWER_HALF = cp_model_pb2.DecisionStrategyProto.SELECT_LOWER_HALF

Definition at line 105 of file cp_model.py.

◆ SELECT_MAX_VALUE

ortools.sat.python.cp_model.SELECT_MAX_VALUE = cp_model_pb2.DecisionStrategyProto.SELECT_MAX_VALUE

Definition at line 104 of file cp_model.py.

◆ SELECT_MIN_VALUE

ortools.sat.python.cp_model.SELECT_MIN_VALUE = cp_model_pb2.DecisionStrategyProto.SELECT_MIN_VALUE

Definition at line 103 of file cp_model.py.

◆ SELECT_UPPER_HALF

ortools.sat.python.cp_model.SELECT_UPPER_HALF = cp_model_pb2.DecisionStrategyProto.SELECT_UPPER_HALF

Definition at line 106 of file cp_model.py.

◆ UNKNOWN

ortools.sat.python.cp_model.UNKNOWN = cp_model_pb2.UNKNOWN

Definition at line 89 of file cp_model.py.

◆ VariableT

ortools.sat.python.cp_model.VariableT = Union["IntVar", IntegralT]

Definition at line 128 of file cp_model.py.