![]() |
Google OR-Tools v9.14
a fast and portable software suite for combinatorial optimization
|
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 | Constraint |
| class | CpModel |
| class | CpSolver |
| class | CpSolverSolutionCallback |
| class | IntervalVar |
| class | IntVar |
| class | ObjectiveSolutionPrinter |
| class | VarArrayAndObjectiveSolutionPrinter |
| class | VarArraySolutionPrinter |
| class | VariableList |
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], LiteralT] | expand_generator_or_tuple (Union[Tuple[LiteralT,...], Iterable[LiteralT]] args) |
| Union[Iterable[LinearExprT], LinearExprT] | expand_generator_or_tuple (Union[Tuple[LinearExprT,...], Iterable[LinearExprT]] args) |
| expand_generator_or_tuple (args) | |
| pd.Index | _get_index (_IndexOrSeries obj) |
| 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 | |
| BoundedLinearExpression = cmh.BoundedLinearExpression | |
| FlatFloatExpr = cmh.FlatFloatExpr | |
| FlatIntExpr = cmh.FlatIntExpr | |
| LinearExpr = cmh.LinearExpr | |
| NotBooleanVariable = cmh.NotBooleanVariable | |
| 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 | |
| SELECT_MEDIAN_VALUE = cp_model_pb2.DecisionStrategyProto.SELECT_MEDIAN_VALUE | |
| SELECT_RANDOM_HALF = cp_model_pb2.DecisionStrategyProto.SELECT_RANDOM_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[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] | |
|
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 3040 of file cp_model.py.
|
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 3067 of file cp_model.py.
|
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 3094 of file cp_model.py.
|
protected |
Returns the indices of `obj` as a `pd.Index`.
Definition at line 3033 of file cp_model.py.
| str ortools.sat.python.cp_model.display_bounds | ( | Sequence[int] | bounds | ) |
Displays a flattened list of intervals.
Definition at line 173 of file cp_model.py.
| ortools.sat.python.cp_model.expand_generator_or_tuple | ( | args | ) |
Definition at line 2449 of file cp_model.py.
| Union[Iterable[LinearExprT], LinearExprT] ortools.sat.python.cp_model.expand_generator_or_tuple | ( | Union[Tuple[LinearExprT, ...], Iterable[LinearExprT]] | args | ) |
Definition at line 2444 of file cp_model.py.
| Union[Iterable[LiteralT], LiteralT] ortools.sat.python.cp_model.expand_generator_or_tuple | ( | Union[Tuple[LiteralT, ...], Iterable[LiteralT]] | args | ) |
Definition at line 2438 of file cp_model.py.
| 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 627 of file cp_model.py.
| 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 614 of file cp_model.py.
| 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 199 of file cp_model.py.
| 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 186 of file cp_model.py.
|
protected |
Definition at line 170 of file cp_model.py.
Definition at line 169 of file cp_model.py.
| ortools.sat.python.cp_model.AUTOMATIC_SEARCH = sat_parameters_pb2.SatParameters.AUTOMATIC_SEARCH |
Definition at line 115 of file cp_model.py.
| ortools.sat.python.cp_model.BoolVarT = cmh.Literal |
Definition at line 162 of file cp_model.py.
| ortools.sat.python.cp_model.BoundedLinearExpression = cmh.BoundedLinearExpression |
Definition at line 76 of file cp_model.py.
| ortools.sat.python.cp_model.CHOOSE_FIRST = cp_model_pb2.DecisionStrategyProto.CHOOSE_FIRST |
Definition at line 100 of file cp_model.py.
| ortools.sat.python.cp_model.CHOOSE_HIGHEST_MAX = cp_model_pb2.DecisionStrategyProto.CHOOSE_HIGHEST_MAX |
Definition at line 102 of file cp_model.py.
| ortools.sat.python.cp_model.CHOOSE_LOWEST_MIN = cp_model_pb2.DecisionStrategyProto.CHOOSE_LOWEST_MIN |
Definition at line 101 of file cp_model.py.
| ortools.sat.python.cp_model.CHOOSE_MAX_DOMAIN_SIZE = cp_model_pb2.DecisionStrategyProto.CHOOSE_MAX_DOMAIN_SIZE |
Definition at line 104 of file cp_model.py.
| ortools.sat.python.cp_model.CHOOSE_MIN_DOMAIN_SIZE = cp_model_pb2.DecisionStrategyProto.CHOOSE_MIN_DOMAIN_SIZE |
Definition at line 103 of file cp_model.py.
| ortools.sat.python.cp_model.Domain = sorted_interval_list.Domain |
Definition at line 75 of file cp_model.py.
| ortools.sat.python.cp_model.FEASIBLE = cp_model_pb2.FEASIBLE |
Definition at line 95 of file cp_model.py.
| ortools.sat.python.cp_model.FIXED_SEARCH = sat_parameters_pb2.SatParameters.FIXED_SEARCH |
Definition at line 116 of file cp_model.py.
| ortools.sat.python.cp_model.FlatFloatExpr = cmh.FlatFloatExpr |
Definition at line 77 of file cp_model.py.
| ortools.sat.python.cp_model.FlatIntExpr = cmh.FlatIntExpr |
Definition at line 78 of file cp_model.py.
| ortools.sat.python.cp_model.HINT_SEARCH = sat_parameters_pb2.SatParameters.HINT_SEARCH |
Definition at line 123 of file cp_model.py.
| ortools.sat.python.cp_model.INFEASIBLE = cp_model_pb2.INFEASIBLE |
Definition at line 96 of file cp_model.py.
| int ortools.sat.python.cp_model.INT32_MAX = 2**31 - 1 |
Definition at line 90 of file cp_model.py.
| ortools.sat.python.cp_model.INT32_MIN = -(2**31) |
Definition at line 89 of file cp_model.py.
| int ortools.sat.python.cp_model.INT_MAX = 2**63 - 1 |
Definition at line 88 of file cp_model.py.
| ortools.sat.python.cp_model.INT_MIN = -(2**63) |
Definition at line 87 of file cp_model.py.
| ortools.sat.python.cp_model.IntegralT = Union[int, np.int8, np.uint8, np.int32, np.uint32, np.int64, np.uint64] |
Definition at line 128 of file cp_model.py.
| tuple ortools.sat.python.cp_model.IntegralTypes |
Definition at line 129 of file cp_model.py.
| ortools.sat.python.cp_model.LinearExpr = cmh.LinearExpr |
Definition at line 79 of file cp_model.py.
| ortools.sat.python.cp_model.LinearExprT = Union[LinearExpr, "IntVar", IntegralT] |
Definition at line 166 of file cp_model.py.
| ortools.sat.python.cp_model.LiteralT = Union[cmh.Literal, IntegralT, bool] |
Definition at line 161 of file cp_model.py.
| ortools.sat.python.cp_model.LP_SEARCH = sat_parameters_pb2.SatParameters.LP_SEARCH |
Definition at line 118 of file cp_model.py.
| ortools.sat.python.cp_model.MODEL_INVALID = cp_model_pb2.MODEL_INVALID |
Definition at line 94 of file cp_model.py.
| ortools.sat.python.cp_model.NotBooleanVariable = cmh.NotBooleanVariable |
Definition at line 80 of file cp_model.py.
| ortools.sat.python.cp_model.NumberT |
Definition at line 138 of file cp_model.py.
| tuple ortools.sat.python.cp_model.NumberTypes |
Definition at line 149 of file cp_model.py.
| ortools.sat.python.cp_model.ObjLinearExprT = Union[LinearExpr, NumberT] |
Definition at line 167 of file cp_model.py.
| ortools.sat.python.cp_model.OPTIMAL = cp_model_pb2.OPTIMAL |
Definition at line 97 of file cp_model.py.
| ortools.sat.python.cp_model.PARTIAL_FIXED_SEARCH = sat_parameters_pb2.SatParameters.PARTIAL_FIXED_SEARCH |
Definition at line 124 of file cp_model.py.
| ortools.sat.python.cp_model.PORTFOLIO_SEARCH = sat_parameters_pb2.SatParameters.PORTFOLIO_SEARCH |
Definition at line 117 of file cp_model.py.
| tuple ortools.sat.python.cp_model.PORTFOLIO_WITH_QUICK_RESTART_SEARCH |
Definition at line 120 of file cp_model.py.
| ortools.sat.python.cp_model.PSEUDO_COST_SEARCH = sat_parameters_pb2.SatParameters.PSEUDO_COST_SEARCH |
Definition at line 119 of file cp_model.py.
| ortools.sat.python.cp_model.RANDOMIZED_SEARCH = sat_parameters_pb2.SatParameters.RANDOMIZED_SEARCH |
Definition at line 125 of file cp_model.py.
| ortools.sat.python.cp_model.SELECT_LOWER_HALF = cp_model_pb2.DecisionStrategyProto.SELECT_LOWER_HALF |
Definition at line 109 of file cp_model.py.
| ortools.sat.python.cp_model.SELECT_MAX_VALUE = cp_model_pb2.DecisionStrategyProto.SELECT_MAX_VALUE |
Definition at line 108 of file cp_model.py.
| ortools.sat.python.cp_model.SELECT_MEDIAN_VALUE = cp_model_pb2.DecisionStrategyProto.SELECT_MEDIAN_VALUE |
Definition at line 111 of file cp_model.py.
| ortools.sat.python.cp_model.SELECT_MIN_VALUE = cp_model_pb2.DecisionStrategyProto.SELECT_MIN_VALUE |
Definition at line 107 of file cp_model.py.
| ortools.sat.python.cp_model.SELECT_RANDOM_HALF = cp_model_pb2.DecisionStrategyProto.SELECT_RANDOM_HALF |
Definition at line 112 of file cp_model.py.
| ortools.sat.python.cp_model.SELECT_UPPER_HALF = cp_model_pb2.DecisionStrategyProto.SELECT_UPPER_HALF |
Definition at line 110 of file cp_model.py.
| ortools.sat.python.cp_model.UNKNOWN = cp_model_pb2.UNKNOWN |
Definition at line 93 of file cp_model.py.
| ortools.sat.python.cp_model.VariableT = Union["IntVar", IntegralT] |
Definition at line 163 of file cp_model.py.