ortools.sat.python.cp_model_helper
OnSolutionCallback(self: ortools.sat.python.cp_model_helper.SolutionCallback) -> None
BestObjectiveBound(self: ortools.sat.python.cp_model_helper.SolutionCallback) -> float
DeterministicTime(self: ortools.sat.python.cp_model_helper.SolutionCallback) -> float
HasResponse(self: ortools.sat.python.cp_model_helper.SolutionCallback) -> bool
NumBinaryPropagations(self: ortools.sat.python.cp_model_helper.SolutionCallback) -> int
NumBooleans(self: ortools.sat.python.cp_model_helper.SolutionCallback) -> int
NumBranches(self: ortools.sat.python.cp_model_helper.SolutionCallback) -> int
NumConflicts(self: ortools.sat.python.cp_model_helper.SolutionCallback) -> int
NumIntegerPropagations(self: ortools.sat.python.cp_model_helper.SolutionCallback) -> int
ObjectiveValue(self: ortools.sat.python.cp_model_helper.SolutionCallback) -> float
Response(self: ortools.sat.python.cp_model_helper.SolutionCallback) -> operations_research::sat::CpSolverResponse
SolutionBooleanValue(self: ortools.sat.python.cp_model_helper.SolutionCallback, index: int) -> bool
SolutionIntegerValue(self: ortools.sat.python.cp_model_helper.SolutionCallback, index: int) -> int
StopSearch(self: ortools.sat.python.cp_model_helper.SolutionCallback) -> None
Value(args, *kwargs) Overloaded function.
- Value(self: ortools.sat.python.cp_model_helper.SolutionCallback, arg0: operations_research::sat::python::LinearExpr) -> int
Returns the value of a linear expression after solve.
- Value(self: ortools.sat.python.cp_model_helper.SolutionCallback, arg0: int) -> int
Returns the value of a linear expression after solve.
BooleanValue(args, *kwargs) Overloaded function.
- BooleanValue(self: ortools.sat.python.cp_model_helper.SolutionCallback, arg0: operations_research::sat::python::Literal) -> bool
Returns the Boolean value of a literal after solve.
- BooleanValue(self: ortools.sat.python.cp_model_helper.SolutionCallback, arg0: bool) -> bool
Returns the Boolean value of a literal after solve.
best_objective_bound(self: ortools.sat.python.cp_model_helper.ResponseWrapper) -> float
boolean_value(args, *kwargs) Overloaded function.
boolean_value(self: ortools.sat.python.cp_model_helper.ResponseWrapper, lit: operations_research::sat::python::Literal) -> bool
boolean_value(self: ortools.sat.python.cp_model_helper.ResponseWrapper, lit: bool) -> bool
deterministic_time(self: ortools.sat.python.cp_model_helper.ResponseWrapper) -> float
num_binary_propagations(self: ortools.sat.python.cp_model_helper.ResponseWrapper) -> int
num_booleans(self: ortools.sat.python.cp_model_helper.ResponseWrapper) -> int
num_branches(self: ortools.sat.python.cp_model_helper.ResponseWrapper) -> int
num_conflicts(self: ortools.sat.python.cp_model_helper.ResponseWrapper) -> int
num_integer_propagations(self: ortools.sat.python.cp_model_helper.ResponseWrapper) -> int
num_restarts(self: ortools.sat.python.cp_model_helper.ResponseWrapper) -> int
objective_value(self: ortools.sat.python.cp_model_helper.ResponseWrapper) -> float
response(self: ortools.sat.python.cp_model_helper.ResponseWrapper) -> operations_research::sat::CpSolverResponse
response_stats(self: ortools.sat.python.cp_model_helper.ResponseWrapper) -> str
solution_info(self: ortools.sat.python.cp_model_helper.ResponseWrapper) -> str
status(self: ortools.sat.python.cp_model_helper.ResponseWrapper) -> operations_research::sat::CpSolverStatus
sufficient_assumptions_for_infeasibility(self: ortools.sat.python.cp_model_helper.ResponseWrapper) -> list[int]
user_time(self: ortools.sat.python.cp_model_helper.ResponseWrapper) -> float
value(args, *kwargs) Overloaded function.
value(self: ortools.sat.python.cp_model_helper.ResponseWrapper, expr: operations_research::sat::python::LinearExpr) -> int
value(self: ortools.sat.python.cp_model_helper.ResponseWrapper, value: int) -> int
wall_time(self: ortools.sat.python.cp_model_helper.ResponseWrapper) -> float
add_log_callback(self: ortools.sat.python.cp_model_helper.SolveWrapper, log_callback: Callable[[str], None]) -> None
add_solution_callback(self: ortools.sat.python.cp_model_helper.SolveWrapper, callback: ortools.sat.python.cp_model_helper.SolutionCallback) -> None
clear_solution_callback(self: ortools.sat.python.cp_model_helper.SolveWrapper, arg0: ortools.sat.python.cp_model_helper.SolutionCallback) -> None
add_best_bound_callback(self: ortools.sat.python.cp_model_helper.SolveWrapper, best_bound_callback: Callable[[float], None]) -> None
set_parameters(self: ortools.sat.python.cp_model_helper.SolveWrapper, parameters: operations_research::sat::SatParameters) -> None
solve(self: ortools.sat.python.cp_model_helper.SolveWrapper, arg0: operations_research::sat::CpModelProto) -> operations_research::sat::CpSolverResponse
solve_and_return_response_wrapper(self: ortools.sat.python.cp_model_helper.SolveWrapper, arg0: operations_research::sat::CpModelProto) -> ortools.sat.python.cp_model_helper.ResponseWrapper
stop_search(self: ortools.sat.python.cp_model_helper.SolveWrapper) -> None
solver_response_stats(response: operations_research::sat::CpSolverResponse) -> str
validate_model(model_proto: operations_research::sat::CpModelProto) -> str
variable_domain(variable_proto: operations_research::sat::IntegerVariableProto) -> ortools.util.python.sorted_interval_list.Domain
A class to hold an integer or floating point linear expression.
A linear expression is built from (integer or floating point)
constants and variables. For example, x + 2 * (y - z + 1)
.
Linear expressions are used in CP-SAT models in constraints and in the objective.
Note that constraints only accept linear expressions with integral coefficients and constants. On the other hand, The objective can be a linear expression with floating point coefficients and constants.
You can define linear constraints as in:
model.add(x + 2 * y <= 5)
model.add(sum(array_of_vars) == 5)
- In CP-SAT, the objective is a linear expression:
model.minimize(x + 2 * y + z)
- For large arrays, using the LinearExpr class is faster that using
the python
sum()
function. You can create constraints and the objective from lists of linear expressions or coefficients as follows:
model.minimize(cp_model.LinearExpr.sum(expressions))
model.add(cp_model.LinearExpr.weighted_sum(expressions, coefficients) >= 0)
sum(*args) -> ortools.sat.python.cp_model_helper.LinearExpr
Returns the sum(expressions).
weighted_sum(expressions: Sequence, coefficients: Sequence) -> ortools.sat.python.cp_model_helper.LinearExpr
Returns the sum of (expressions[i] * coefficients[i])
term(args, *kwargs) Overloaded function.
- term(expr: ortools.sat.python.cp_model_helper.LinearExpr, coeff: int) -> ortools.sat.python.cp_model_helper.LinearExpr
Returns expr * coeff.
- term(expr: ortools.sat.python.cp_model_helper.LinearExpr, coeff: float) -> ortools.sat.python.cp_model_helper.LinearExpr
Returns expr * coeff.
affine(args, *kwargs) Overloaded function.
- affine(expr: ortools.sat.python.cp_model_helper.LinearExpr, coeff: int, offset: int) -> ortools.sat.python.cp_model_helper.LinearExpr
Returns expr * coeff + offset.
- affine(expr: ortools.sat.python.cp_model_helper.LinearExpr, coeff: float, offset: float) -> ortools.sat.python.cp_model_helper.LinearExpr
Returns expr * coeff + offset.
constant(args, *kwargs) Overloaded function.
- constant(value: int) -> ortools.sat.python.cp_model_helper.LinearExpr
Returns a new LinearExpr that is the given constant.
- constant(value: float) -> ortools.sat.python.cp_model_helper.LinearExpr
Returns a new LinearExpr that is the given constant.
WeightedSum(expressions: Sequence, coefficients: Sequence) -> ortools.sat.python.cp_model_helper.LinearExpr
Term(args, *kwargs) Overloaded function.
- Term(expr: ortools.sat.python.cp_model_helper.LinearExpr, coeff: int) -> ortools.sat.python.cp_model_helper.LinearExpr
Returns expr * coeff.
- Term(expr: ortools.sat.python.cp_model_helper.LinearExpr, coeff: float) -> ortools.sat.python.cp_model_helper.LinearExpr
Returns expr * coeff.
A flattened and optimized floating point linear expression.
It can be used to cache complex expressions as parsing them is only done once.
__init__(self: ortools.sat.python.cp_model_helper.FlatFloatExpr, arg0: ortools.sat.python.cp_model_helper.LinearExpr) -> None
(arg0: ortools.sat.python.cp_model_helper.FlatFloatExpr) -> list[operations_research::sat::python::BaseIntVar]
Inherited Members
A flattened and optimized integer linear expression.
It can be used to cache complex expressions as parsing them is only done once.
__init__(self: ortools.sat.python.cp_model_helper.FlatIntExpr, arg0: ortools.sat.python.cp_model_helper.LinearExpr) -> None
(arg0: ortools.sat.python.cp_model_helper.FlatIntExpr) -> list[operations_research::sat::python::BaseIntVar]
Inherited Members
A class to hold a sum of linear expressions, and optional integer and double offsets (at most one of them can be non-zero, this is DCHECKed).
__init__(self: ortools.sat.python.cp_model_helper.SumArray, arg0: list[ortools.sat.python.cp_model_helper.LinearExpr], arg1: int, arg2: float) -> None
Inherited Members
A class to hold linear_expr * a = b (a and b are floating point numbers).
__init__(self: ortools.sat.python.cp_model_helper.FloatAffine, arg0: ortools.sat.python.cp_model_helper.LinearExpr, arg1: float, arg2: float) -> None
Inherited Members
A class to hold linear_expr * a = b (a and b are integers).
__init__(self: ortools.sat.python.cp_model_helper.IntAffine, arg0: ortools.sat.python.cp_model_helper.LinearExpr, arg1: int, arg2: int) -> None
Inherited Members
A class to hold a Boolean literal.
A literal is a Boolean variable or its negation.
Literals are used in CP-SAT models in constraints and in the objective.
- You can define literal as in:
b1 = model.new_bool_var()
b2 = model.new_bool_var()
# Simple Boolean constraint.
model.add_bool_or(b1, b2.negated())
# We can use the ~ operator to negate a literal.
model.add_bool_or(b1, ~b2)
# Enforcement literals must be literals.
x = model.new_int_var(0, 10, 'x')
model.add(x == 5).only_enforced_if(~b1)
- Literals can be used directly in linear constraints or in the objective:
model.minimize(b1 + 2 * ~b2)
negated(self: ortools.sat.python.cp_model_helper.Literal) -> ortools.sat.python.cp_model_helper.Literal
Returns the negation of a literal (a Boolean variable or its negation).
This method implements the logical negation of a Boolean variable. It is only valid if the variable has a Boolean domain (0 or 1).
Note that this method is nilpotent: x.negated().negated() == x
.
Returns: The negation of the current literal.
Inherited Members
A class to hold a variable index. It is the base class for Integer variables.
__init__(args, *kwargs) Overloaded function.
__init__(self: ortools.sat.python.cp_model_helper.BaseIntVar, arg0: int) -> None
__init__(self: ortools.sat.python.cp_model_helper.BaseIntVar, arg0: int, arg1: bool) -> None
negated(self: ortools.sat.python.cp_model_helper.BaseIntVar) -> ortools.sat.python.cp_model_helper.Literal
Returns the negation of the current variable.
Inherited Members
A class to hold a negated variable index.
negated(self: ortools.sat.python.cp_model_helper.NotBooleanVariable) -> ortools.sat.python.cp_model_helper.Literal
Returns the negation of the current literal, that is the original Boolean variable.
Not(self: ortools.sat.python.cp_model_helper.NotBooleanVariable) -> ortools.sat.python.cp_model_helper.Literal
Returns the negation of the current literal, that is the original Boolean variable.
Inherited Members
A class to hold a linear expression with bounds.
__init__(args, *kwargs) Overloaded function.
__init__(self: ortools.sat.python.cp_model_helper.BoundedLinearExpression, arg0: ortools.sat.python.cp_model_helper.LinearExpr, arg1: ortools.util.python.sorted_interval_list.Domain) -> None
__init__(self: ortools.sat.python.cp_model_helper.BoundedLinearExpression, arg0: ortools.sat.python.cp_model_helper.LinearExpr, arg1: ortools.sat.python.cp_model_helper.LinearExpr, arg2: ortools.util.python.sorted_interval_list.Domain) -> None