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

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.

Classes

class  CpModel
class  CpSolver
class  CpSolverSolutionCallback
class  ObjectiveSolutionPrinter
class  VarArrayAndObjectiveSolutionPrinter
class  VarArraySolutionPrinter

Functions

Callable[[Callable], Callable] deprecated (str message)
Callable deprecated_method (func, str old_name)
str snake_case_to_camel_case (str name)
bool object_is_a_true_literal (LiteralT literal)
bool object_is_a_false_literal (LiteralT literal)
pd.Index _get_index (_IndexOrSeries obj)
pd.Series _convert_to_series_and_validate_index (Union[LinearExprT, pd.Series] value_or_series, pd.Index index)
pd.Series _convert_to_series_and_validate_index (Union[LiteralT, pd.Series] value_or_series, pd.Index index)
pd.Series _convert_to_series_and_validate_index (Union[IntegralT, pd.Series] value_or_series, pd.Index index)
 _convert_to_series_and_validate_index (value_or_series, index)

Variables

 BoundedLinearExpression = cmh.BoundedLinearExpression
 Constraint = cmh.Constraint
 CpModelProto = cmh.CpModelProto
 CpSolverResponse = cmh.CpSolverResponse
 CpSolverStatus = cmh.CpSolverStatus
 Domain = sorted_interval_list.Domain
 FlatFloatExpr = cmh.FlatFloatExpr
 FlatIntExpr = cmh.FlatIntExpr
 IntervalVar = cmh.IntervalVar
 IntVar = cmh.IntVar
 LinearExpr = cmh.LinearExpr
 NotBooleanVariable = cmh.NotBooleanVariable
 SatParameters = cmh.SatParameters
 INT_MIN = -(2**63)
int INT_MAX = 2**63 - 1
 INT32_MIN = -(2**31)
int INT32_MAX = 2**31 - 1
 UNKNOWN = cmh.CpSolverStatus.UNKNOWN
 MODEL_INVALID = cmh.CpSolverStatus.MODEL_INVALID
 FEASIBLE = cmh.CpSolverStatus.FEASIBLE
 INFEASIBLE = cmh.CpSolverStatus.INFEASIBLE
 OPTIMAL = cmh.CpSolverStatus.OPTIMAL
 CHOOSE_FIRST = cmh.DecisionStrategyProto.VariableSelectionStrategy.CHOOSE_FIRST
tuple CHOOSE_LOWEST_MIN
tuple CHOOSE_HIGHEST_MAX
tuple CHOOSE_MIN_DOMAIN_SIZE
tuple CHOOSE_MAX_DOMAIN_SIZE
 SELECT_MIN_VALUE = cmh.DecisionStrategyProto.DomainReductionStrategy.SELECT_MIN_VALUE
 SELECT_MAX_VALUE = cmh.DecisionStrategyProto.DomainReductionStrategy.SELECT_MAX_VALUE
 SELECT_LOWER_HALF = cmh.DecisionStrategyProto.DomainReductionStrategy.SELECT_LOWER_HALF
 SELECT_UPPER_HALF = cmh.DecisionStrategyProto.DomainReductionStrategy.SELECT_UPPER_HALF
tuple SELECT_MEDIAN_VALUE
tuple SELECT_RANDOM_HALF
 AUTOMATIC_SEARCH = cmh.SatParameters.SearchBranching.AUTOMATIC_SEARCH
 FIXED_SEARCH = cmh.SatParameters.SearchBranching.FIXED_SEARCH
 PORTFOLIO_SEARCH = cmh.SatParameters.SearchBranching.PORTFOLIO_SEARCH
 LP_SEARCH = cmh.SatParameters.SearchBranching.LP_SEARCH
 PSEUDO_COST_SEARCH = cmh.SatParameters.SearchBranching.PSEUDO_COST_SEARCH
tuple PORTFOLIO_WITH_QUICK_RESTART_SEARCH
 HINT_SEARCH = cmh.SatParameters.SearchBranching.HINT_SEARCH
 PARTIAL_FIXED_SEARCH = cmh.SatParameters.SearchBranching.PARTIAL_FIXED_SEARCH
 RANDOMIZED_SEARCH = cmh.SatParameters.SearchBranching.RANDOMIZED_SEARCH
 IntegralT = Union[int, np.int8, np.uint8, np.int32, np.uint32, np.int64, np.uint64]
tuple IntegralTypes
 NumberT
tuple NumberTypes
 LiteralT = Union[cmh.Literal, IntegralT, bool]
 BoolVarT = cmh.Literal
 VariableT = Union["IntVar", IntegralT]
 LinearExprT = Union[LinearExpr, "IntVar", IntegralT]
 ObjLinearExprT = Union[LinearExpr, NumberT]
 ArcT = tuple[IntegralT, IntegralT, LiteralT]
 _IndexOrSeries = Union[pd.Index, pd.Series]
bool enable_warnings = False

Function Documentation

◆ _convert_to_series_and_validate_index() [1/4]

pd.Series ortools.sat.python.cp_model._convert_to_series_and_validate_index ( Union[IntegralT, pd.Series] value_or_series,
pd.Index index )
protected

Definition at line 291 of file cp_model.py.

◆ _convert_to_series_and_validate_index() [2/4]

pd.Series ortools.sat.python.cp_model._convert_to_series_and_validate_index ( Union[LinearExprT, pd.Series] value_or_series,
pd.Index index )
protected

Definition at line 279 of file cp_model.py.

◆ _convert_to_series_and_validate_index() [3/4]

pd.Series ortools.sat.python.cp_model._convert_to_series_and_validate_index ( Union[LiteralT, pd.Series] value_or_series,
pd.Index index )
protected

Definition at line 285 of file cp_model.py.

◆ _convert_to_series_and_validate_index() [4/4]

ortools.sat.python.cp_model._convert_to_series_and_validate_index ( value_or_series,
index )
protected
Returns a pd.Series of the given index with the corresponding values.

Definition at line 296 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 271 of file cp_model.py.

◆ deprecated()

Callable[[Callable], Callable] ortools.sat.python.cp_model.deprecated ( str message)
Decorator that warns about a deprecated function.

Definition at line 191 of file cp_model.py.

◆ deprecated_method()

Callable ortools.sat.python.cp_model.deprecated_method ( func,
str old_name )
Wrapper that warns about a deprecated method.

Definition at line 210 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 255 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 239 of file cp_model.py.

◆ snake_case_to_camel_case()

str ortools.sat.python.cp_model.snake_case_to_camel_case ( str name)
Converts a snake_case name to CamelCase.

Definition at line 229 of file cp_model.py.

Variable Documentation

◆ _IndexOrSeries

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

Definition at line 183 of file cp_model.py.

◆ ArcT

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

Definition at line 182 of file cp_model.py.

◆ AUTOMATIC_SEARCH

ortools.sat.python.cp_model.AUTOMATIC_SEARCH = cmh.SatParameters.SearchBranching.AUTOMATIC_SEARCH

Definition at line 128 of file cp_model.py.

◆ BoolVarT

ortools.sat.python.cp_model.BoolVarT = cmh.Literal

Definition at line 175 of file cp_model.py.

◆ BoundedLinearExpression

ortools.sat.python.cp_model.BoundedLinearExpression = cmh.BoundedLinearExpression

Definition at line 68 of file cp_model.py.

◆ CHOOSE_FIRST

ortools.sat.python.cp_model.CHOOSE_FIRST = cmh.DecisionStrategyProto.VariableSelectionStrategy.CHOOSE_FIRST

Definition at line 101 of file cp_model.py.

◆ CHOOSE_HIGHEST_MAX

tuple ortools.sat.python.cp_model.CHOOSE_HIGHEST_MAX
Initial value:
1= (
2 cmh.DecisionStrategyProto.VariableSelectionStrategy.CHOOSE_HIGHEST_MAX
3)

Definition at line 105 of file cp_model.py.

◆ CHOOSE_LOWEST_MIN

tuple ortools.sat.python.cp_model.CHOOSE_LOWEST_MIN
Initial value:
1= (
2 cmh.DecisionStrategyProto.VariableSelectionStrategy.CHOOSE_LOWEST_MIN
3)

Definition at line 102 of file cp_model.py.

◆ CHOOSE_MAX_DOMAIN_SIZE

tuple ortools.sat.python.cp_model.CHOOSE_MAX_DOMAIN_SIZE
Initial value:
1= (
2 cmh.DecisionStrategyProto.VariableSelectionStrategy.CHOOSE_MAX_DOMAIN_SIZE
3)

Definition at line 111 of file cp_model.py.

◆ CHOOSE_MIN_DOMAIN_SIZE

tuple ortools.sat.python.cp_model.CHOOSE_MIN_DOMAIN_SIZE
Initial value:
1= (
2 cmh.DecisionStrategyProto.VariableSelectionStrategy.CHOOSE_MIN_DOMAIN_SIZE
3)

Definition at line 108 of file cp_model.py.

◆ Constraint

ortools.sat.python.cp_model.Constraint = cmh.Constraint

Definition at line 69 of file cp_model.py.

◆ CpModelProto

ortools.sat.python.cp_model.CpModelProto = cmh.CpModelProto

Definition at line 70 of file cp_model.py.

◆ CpSolverResponse

ortools.sat.python.cp_model.CpSolverResponse = cmh.CpSolverResponse

Definition at line 71 of file cp_model.py.

◆ CpSolverStatus

ortools.sat.python.cp_model.CpSolverStatus = cmh.CpSolverStatus

Definition at line 72 of file cp_model.py.

◆ Domain

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

Definition at line 73 of file cp_model.py.

◆ enable_warnings

bool ortools.sat.python.cp_model.enable_warnings = False

Definition at line 187 of file cp_model.py.

◆ FEASIBLE

ortools.sat.python.cp_model.FEASIBLE = cmh.CpSolverStatus.FEASIBLE

Definition at line 96 of file cp_model.py.

◆ FIXED_SEARCH

ortools.sat.python.cp_model.FIXED_SEARCH = cmh.SatParameters.SearchBranching.FIXED_SEARCH

Definition at line 129 of file cp_model.py.

◆ FlatFloatExpr

ortools.sat.python.cp_model.FlatFloatExpr = cmh.FlatFloatExpr

Definition at line 74 of file cp_model.py.

◆ FlatIntExpr

ortools.sat.python.cp_model.FlatIntExpr = cmh.FlatIntExpr

Definition at line 75 of file cp_model.py.

◆ HINT_SEARCH

ortools.sat.python.cp_model.HINT_SEARCH = cmh.SatParameters.SearchBranching.HINT_SEARCH

Definition at line 136 of file cp_model.py.

◆ INFEASIBLE

ortools.sat.python.cp_model.INFEASIBLE = cmh.CpSolverStatus.INFEASIBLE

Definition at line 97 of file cp_model.py.

◆ INT32_MAX

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

Definition at line 90 of file cp_model.py.

◆ INT32_MIN

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

Definition at line 89 of file cp_model.py.

◆ INT_MAX

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

Definition at line 88 of file cp_model.py.

◆ INT_MIN

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

Definition at line 87 of file cp_model.py.

◆ IntegralT

ortools.sat.python.cp_model.IntegralT = Union[int, np.int8, np.uint8, np.int32, np.uint32, np.int64, np.uint64]

Definition at line 141 of file cp_model.py.

◆ IntegralTypes

tuple ortools.sat.python.cp_model.IntegralTypes
Initial value:
1= (
2 int,
3 np.int8,
4 np.uint8,
5 np.int32,
6 np.uint32,
7 np.int64,
8 np.uint64,
9)

Definition at line 142 of file cp_model.py.

◆ IntervalVar

ortools.sat.python.cp_model.IntervalVar = cmh.IntervalVar

Definition at line 76 of file cp_model.py.

◆ IntVar

ortools.sat.python.cp_model.IntVar = cmh.IntVar

Definition at line 77 of file cp_model.py.

◆ LinearExpr

ortools.sat.python.cp_model.LinearExpr = cmh.LinearExpr

Definition at line 78 of file cp_model.py.

◆ LinearExprT

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

Definition at line 179 of file cp_model.py.

◆ LiteralT

ortools.sat.python.cp_model.LiteralT = Union[cmh.Literal, IntegralT, bool]

Definition at line 174 of file cp_model.py.

◆ LP_SEARCH

ortools.sat.python.cp_model.LP_SEARCH = cmh.SatParameters.SearchBranching.LP_SEARCH

Definition at line 131 of file cp_model.py.

◆ MODEL_INVALID

ortools.sat.python.cp_model.MODEL_INVALID = cmh.CpSolverStatus.MODEL_INVALID

Definition at line 95 of file cp_model.py.

◆ NotBooleanVariable

ortools.sat.python.cp_model.NotBooleanVariable = cmh.NotBooleanVariable

Definition at line 79 of file cp_model.py.

◆ NumberT

ortools.sat.python.cp_model.NumberT
Initial value:
1= Union[
2 int,
3 float,
4 np.int8,
5 np.uint8,
6 np.int32,
7 np.uint32,
8 np.int64,
9 np.uint64,
10 np.double,
11]

Definition at line 151 of file cp_model.py.

◆ NumberTypes

tuple ortools.sat.python.cp_model.NumberTypes
Initial value:
1= (
2 int,
3 float,
4 np.int8,
5 np.uint8,
6 np.int32,
7 np.uint32,
8 np.int64,
9 np.uint64,
10 np.double,
11)

Definition at line 162 of file cp_model.py.

◆ ObjLinearExprT

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

Definition at line 180 of file cp_model.py.

◆ OPTIMAL

ortools.sat.python.cp_model.OPTIMAL = cmh.CpSolverStatus.OPTIMAL

Definition at line 98 of file cp_model.py.

◆ PARTIAL_FIXED_SEARCH

ortools.sat.python.cp_model.PARTIAL_FIXED_SEARCH = cmh.SatParameters.SearchBranching.PARTIAL_FIXED_SEARCH

Definition at line 137 of file cp_model.py.

◆ PORTFOLIO_SEARCH

ortools.sat.python.cp_model.PORTFOLIO_SEARCH = cmh.SatParameters.SearchBranching.PORTFOLIO_SEARCH

Definition at line 130 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 cmh.SatParameters.SearchBranching.PORTFOLIO_WITH_QUICK_RESTART_SEARCH
3)

Definition at line 133 of file cp_model.py.

◆ PSEUDO_COST_SEARCH

ortools.sat.python.cp_model.PSEUDO_COST_SEARCH = cmh.SatParameters.SearchBranching.PSEUDO_COST_SEARCH

Definition at line 132 of file cp_model.py.

◆ RANDOMIZED_SEARCH

ortools.sat.python.cp_model.RANDOMIZED_SEARCH = cmh.SatParameters.SearchBranching.RANDOMIZED_SEARCH

Definition at line 138 of file cp_model.py.

◆ SatParameters

ortools.sat.python.cp_model.SatParameters = cmh.SatParameters

Definition at line 80 of file cp_model.py.

◆ SELECT_LOWER_HALF

ortools.sat.python.cp_model.SELECT_LOWER_HALF = cmh.DecisionStrategyProto.DomainReductionStrategy.SELECT_LOWER_HALF

Definition at line 118 of file cp_model.py.

◆ SELECT_MAX_VALUE

ortools.sat.python.cp_model.SELECT_MAX_VALUE = cmh.DecisionStrategyProto.DomainReductionStrategy.SELECT_MAX_VALUE

Definition at line 117 of file cp_model.py.

◆ SELECT_MEDIAN_VALUE

tuple ortools.sat.python.cp_model.SELECT_MEDIAN_VALUE
Initial value:
1= (
2 cmh.DecisionStrategyProto.DomainReductionStrategy.SELECT_MEDIAN_VALUE
3)

Definition at line 120 of file cp_model.py.

◆ SELECT_MIN_VALUE

ortools.sat.python.cp_model.SELECT_MIN_VALUE = cmh.DecisionStrategyProto.DomainReductionStrategy.SELECT_MIN_VALUE

Definition at line 116 of file cp_model.py.

◆ SELECT_RANDOM_HALF

tuple ortools.sat.python.cp_model.SELECT_RANDOM_HALF
Initial value:
1= (
2 cmh.DecisionStrategyProto.DomainReductionStrategy.SELECT_RANDOM_HALF
3)

Definition at line 123 of file cp_model.py.

◆ SELECT_UPPER_HALF

ortools.sat.python.cp_model.SELECT_UPPER_HALF = cmh.DecisionStrategyProto.DomainReductionStrategy.SELECT_UPPER_HALF

Definition at line 119 of file cp_model.py.

◆ UNKNOWN

ortools.sat.python.cp_model.UNKNOWN = cmh.CpSolverStatus.UNKNOWN

Definition at line 93 of file cp_model.py.

◆ VariableT

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

Definition at line 176 of file cp_model.py.