ortools.sat.python.cp_model_helper

class SolutionCallback(pybind11_builtins.pybind11_object):
SolutionCallback()
def OnSolutionCallback(unknown):

OnSolutionCallback(self: ortools.sat.python.cp_model_helper.SolutionCallback) -> None

def BestObjectiveBound(unknown):

BestObjectiveBound(self: ortools.sat.python.cp_model_helper.SolutionCallback) -> float

def DeterministicTime(unknown):

DeterministicTime(self: ortools.sat.python.cp_model_helper.SolutionCallback) -> float

def HasResponse(unknown):
def NumBinaryPropagations(unknown):

NumBinaryPropagations(self: ortools.sat.python.cp_model_helper.SolutionCallback) -> int

def NumBooleans(unknown):
def NumBranches(unknown):
def NumConflicts(unknown):
def NumIntegerPropagations(unknown):

NumIntegerPropagations(self: ortools.sat.python.cp_model_helper.SolutionCallback) -> int

def ObjectiveValue(unknown):
def Response(unknown):

Response(self: ortools.sat.python.cp_model_helper.SolutionCallback) -> operations_research::sat::CpSolverResponse

def SolutionBooleanValue(unknown):

SolutionBooleanValue(self: ortools.sat.python.cp_model_helper.SolutionCallback, index: int) -> bool

def SolutionIntegerValue(unknown):

SolutionIntegerValue(self: ortools.sat.python.cp_model_helper.SolutionCallback, index: int) -> int

def StopSearch(unknown):
def UserTime(unknown):
def WallTime(unknown):
def Value(unknown):

Value(args, *kwargs) Overloaded function.

  1. 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.

  1. Value(self: ortools.sat.python.cp_model_helper.SolutionCallback, arg0: int) -> int

Returns the value of a linear expression after solve.

def BooleanValue(unknown):

BooleanValue(args, *kwargs) Overloaded function.

  1. 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.

  1. BooleanValue(self: ortools.sat.python.cp_model_helper.SolutionCallback, arg0: bool) -> bool

Returns the Boolean value of a literal after solve.

class ResponseWrapper(pybind11_builtins.pybind11_object):
ResponseWrapper(*args, **kwargs)
def best_objective_bound(unknown):

best_objective_bound(self: ortools.sat.python.cp_model_helper.ResponseWrapper) -> float

def boolean_value(unknown):

boolean_value(args, *kwargs) Overloaded function.

  1. boolean_value(self: ortools.sat.python.cp_model_helper.ResponseWrapper, lit: operations_research::sat::python::Literal) -> bool

  2. boolean_value(self: ortools.sat.python.cp_model_helper.ResponseWrapper, lit: bool) -> bool

def deterministic_time(unknown):

deterministic_time(self: ortools.sat.python.cp_model_helper.ResponseWrapper) -> float

def num_binary_propagations(unknown):

num_binary_propagations(self: ortools.sat.python.cp_model_helper.ResponseWrapper) -> int

def num_booleans(unknown):
def num_branches(unknown):
def num_conflicts(unknown):
def num_integer_propagations(unknown):

num_integer_propagations(self: ortools.sat.python.cp_model_helper.ResponseWrapper) -> int

def num_restarts(unknown):
def objective_value(unknown):
def response(unknown):

response(self: ortools.sat.python.cp_model_helper.ResponseWrapper) -> operations_research::sat::CpSolverResponse

def response_stats(unknown):
def solution_info(unknown):
def status(unknown):

status(self: ortools.sat.python.cp_model_helper.ResponseWrapper) -> operations_research::sat::CpSolverStatus

def sufficient_assumptions_for_infeasibility(unknown):

sufficient_assumptions_for_infeasibility(self: ortools.sat.python.cp_model_helper.ResponseWrapper) -> list[int]

def user_time(unknown):
def value(unknown):

value(args, *kwargs) Overloaded function.

  1. value(self: ortools.sat.python.cp_model_helper.ResponseWrapper, expr: operations_research::sat::python::LinearExpr) -> int

  2. value(self: ortools.sat.python.cp_model_helper.ResponseWrapper, value: int) -> int

def wall_time(unknown):
class SolveWrapper(pybind11_builtins.pybind11_object):
SolveWrapper()
def add_log_callback(unknown):

add_log_callback(self: ortools.sat.python.cp_model_helper.SolveWrapper, log_callback: Callable[[str], None]) -> None

def add_solution_callback(unknown):
def clear_solution_callback(unknown):
def add_best_bound_callback(unknown):

add_best_bound_callback(self: ortools.sat.python.cp_model_helper.SolveWrapper, best_bound_callback: Callable[[float], None]) -> None

def set_parameters(unknown):

set_parameters(self: ortools.sat.python.cp_model_helper.SolveWrapper, parameters: operations_research::sat::SatParameters) -> None

def solve(unknown):

solve(self: ortools.sat.python.cp_model_helper.SolveWrapper, arg0: operations_research::sat::CpModelProto) -> operations_research::sat::CpSolverResponse

def solve_and_return_response_wrapper(unknown):

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

class CpSatHelper(pybind11_builtins.pybind11_object):
CpSatHelper(*args, **kwargs)
def model_stats(unknown):

model_stats(model_proto: operations_research::sat::CpModelProto) -> str

def solver_response_stats(unknown):

solver_response_stats(response: operations_research::sat::CpSolverResponse) -> str

def validate_model(unknown):

validate_model(model_proto: operations_research::sat::CpModelProto) -> str

def variable_domain(unknown):

variable_domain(variable_proto: operations_research::sat::IntegerVariableProto) -> ortools.util.python.sorted_interval_list.Domain

def write_model_to_file(unknown):

write_model_to_file(model_proto: operations_research::sat::CpModelProto, filename: str) -> bool

class LinearExpr(pybind11_builtins.pybind11_object):

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)
LinearExpr(*args, **kwargs)
def sum(unknown):

sum(*args) -> ortools.sat.python.cp_model_helper.LinearExpr

Returns the sum(expressions).

def weighted_sum(unknown):

weighted_sum(expressions: Sequence, coefficients: Sequence) -> ortools.sat.python.cp_model_helper.LinearExpr

Returns the sum of (expressions[i] * coefficients[i])

def term(unknown):

term(args, *kwargs) Overloaded function.

  1. term(expr: ortools.sat.python.cp_model_helper.LinearExpr, coeff: int) -> ortools.sat.python.cp_model_helper.LinearExpr

Returns expr * coeff.

  1. term(expr: ortools.sat.python.cp_model_helper.LinearExpr, coeff: float) -> ortools.sat.python.cp_model_helper.LinearExpr

Returns expr * coeff.

def affine(unknown):

affine(args, *kwargs) Overloaded function.

  1. affine(expr: ortools.sat.python.cp_model_helper.LinearExpr, coeff: int, offset: int) -> ortools.sat.python.cp_model_helper.LinearExpr

Returns expr * coeff + offset.

  1. affine(expr: ortools.sat.python.cp_model_helper.LinearExpr, coeff: float, offset: float) -> ortools.sat.python.cp_model_helper.LinearExpr

Returns expr * coeff + offset.

def constant(unknown):

constant(args, *kwargs) Overloaded function.

  1. constant(value: int) -> ortools.sat.python.cp_model_helper.LinearExpr

Returns a new LinearExpr that is the given constant.

  1. constant(value: float) -> ortools.sat.python.cp_model_helper.LinearExpr

Returns a new LinearExpr that is the given constant.

def Sum(unknown):
def WeightedSum(unknown):

WeightedSum(expressions: Sequence, coefficients: Sequence) -> ortools.sat.python.cp_model_helper.LinearExpr

def Term(unknown):

Term(args, *kwargs) Overloaded function.

  1. Term(expr: ortools.sat.python.cp_model_helper.LinearExpr, coeff: int) -> ortools.sat.python.cp_model_helper.LinearExpr

Returns expr * coeff.

  1. Term(expr: ortools.sat.python.cp_model_helper.LinearExpr, coeff: float) -> ortools.sat.python.cp_model_helper.LinearExpr

Returns expr * coeff.

def is_integer(unknown):
class FlatFloatExpr(LinearExpr):

A flattened and optimized floating point linear expression.

It can be used to cache complex expressions as parsing them is only done once.

vars

(arg0: ortools.sat.python.cp_model_helper.FlatFloatExpr) -> list[operations_research::sat::python::BaseIntVar]

coeffs
class FlatIntExpr(LinearExpr):

A flattened and optimized integer linear expression.

It can be used to cache complex expressions as parsing them is only done once.

vars

(arg0: ortools.sat.python.cp_model_helper.FlatIntExpr) -> list[operations_research::sat::python::BaseIntVar]

class SumArray(LinearExpr):

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).

SumArray()

__init__(self: ortools.sat.python.cp_model_helper.SumArray, arg0: list[ortools.sat.python.cp_model_helper.LinearExpr], arg1: int, arg2: float) -> None

double_offset
class FloatAffine(LinearExpr):

A class to hold linear_expr * a = b (a and b are floating point numbers).

FloatAffine()
coefficient
class IntAffine(LinearExpr):

A class to hold linear_expr * a = b (a and b are integers).

IntAffine()
class Literal(LinearExpr):

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)
Literal(*args, **kwargs)
def negated(unknown):

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.

def Index(unknown):
class BaseIntVar(Literal):

A class to hold a variable index. It is the base class for Integer variables.

BaseIntVar()

__init__(args, *kwargs) Overloaded function.

  1. __init__(self: ortools.sat.python.cp_model_helper.BaseIntVar, arg0: int) -> None

  2. __init__(self: ortools.sat.python.cp_model_helper.BaseIntVar, arg0: int, arg1: bool) -> None

def negated(unknown):

negated(self: ortools.sat.python.cp_model_helper.BaseIntVar) -> ortools.sat.python.cp_model_helper.Literal

Returns the negation of the current variable.

def Index(unknown):
class NotBooleanVariable(Literal):

A class to hold a negated variable index.

NotBooleanVariable(*args, **kwargs)
def negated(unknown):

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.

def Not(unknown):

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.

class BoundedLinearExpression(pybind11_builtins.pybind11_object):

A class to hold a linear expression with bounds.