ortools.linear_solver.python.model_builder_helper
Holds an linear expression.
A linear expression is built from constants and variables.
For example, x + 2.0 * (y - z + 1.0)
.
Linear expressions are used in Model models in constraints and in the objective:
- You can define linear constraints as in:
model.add(x + 2 * y <= 5.0)
model.add(sum(array_of_vars) == 5.0)
- In Model, the objective is a linear expression:
model.minimize(x + 2.0 * 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(model_builder.LinearExpr.sum(expressions))
model.add(model_builder.LinearExpr.weighted_sum(expressions, coeffs) >= 0)
sum(args, *kwargs) -> ortools.linear_solver.python.model_builder_helper.LinearExpr
Creates sum(expressions) [+ constant]
.
weighted_sum(expressions: Sequence, coefficients: list[float], *, constant: float = 0.0) -> ortools.linear_solver.python.model_builder_helper.LinearExpr
Creates sum(expressions[i] * coefficients[i]) [+ constant]
.
term(args, *kwargs) Overloaded function.
- term(expr: ortools.linear_solver.python.model_builder_helper.LinearExpr, coeff: float) -> ortools.linear_solver.python.model_builder_helper.LinearExpr
Returns expr * coeff.
- term(expr: ortools.linear_solver.python.model_builder_helper.LinearExpr, coeff: float, *, constant: float) -> ortools.linear_solver.python.model_builder_helper.LinearExpr
Returns expr * coeff [+ constant].
- term(value: float, coeff: float, *, constant: float) -> ortools.linear_solver.python.model_builder_helper.LinearExpr
Returns value * coeff [+ constant].
affine(args, *kwargs) Overloaded function.
- affine(expr: ortools.linear_solver.python.model_builder_helper.LinearExpr, coeff: float, constant: float = 0.0) -> ortools.linear_solver.python.model_builder_helper.LinearExpr
Returns expr * coeff + constant.
- affine(value: float, coeff: float, constant: float = 0.0) -> ortools.linear_solver.python.model_builder_helper.LinearExpr
Returns value * coeff + constant.
constant(value: float) -> ortools.linear_solver.python.model_builder_helper.LinearExpr
Returns a constant linear expression.
Holds an linear expression.
A linear expression is built from constants and variables.
For example, x + 2.0 * (y - z + 1.0)
.
Linear expressions are used in Model models in constraints and in the objective:
- You can define linear constraints as in:
model.add(x + 2 * y <= 5.0)
model.add(sum(array_of_vars) == 5.0)
- In Model, the objective is a linear expression:
model.minimize(x + 2.0 * 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(model_builder.LinearExpr.sum(expressions))
model.add(model_builder.LinearExpr.weighted_sum(expressions, coeffs) >= 0)
__init__(args, *kwargs) Overloaded function.
__init__(self: ortools.linear_solver.python.model_builder_helper.FlatExpr, arg0: ortools.linear_solver.python.model_builder_helper.LinearExpr) -> None
__init__(self: ortools.linear_solver.python.model_builder_helper.FlatExpr, arg0: ortools.linear_solver.python.model_builder_helper.LinearExpr, arg1: ortools.linear_solver.python.model_builder_helper.LinearExpr) -> None
__init__(self: ortools.linear_solver.python.model_builder_helper.FlatExpr, arg0: list[operations_research::mb::Variable], arg1: list[float], arg2: float) -> None
__init__(self: ortools.linear_solver.python.model_builder_helper.FlatExpr, arg0: float) -> None
(arg0: ortools.linear_solver.python.model_builder_helper.FlatExpr) -> list[operations_research::mb::Variable]
variable_indices(self: ortools.linear_solver.python.model_builder_helper.FlatExpr) -> list[int]
Inherited Members
Holds a sum of linear expressions, and constants.
__init__(self: ortools.linear_solver.python.model_builder_helper.SumArray, arg0: list[ortools.linear_solver.python.model_builder_helper.LinearExpr], arg1: float) -> None
Inherited Members
Holds an linear expression.
A linear expression is built from constants and variables.
For example, x + 2.0 * (y - z + 1.0)
.
Linear expressions are used in Model models in constraints and in the objective:
- You can define linear constraints as in:
model.add(x + 2 * y <= 5.0)
model.add(sum(array_of_vars) == 5.0)
- In Model, the objective is a linear expression:
model.minimize(x + 2.0 * 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(model_builder.LinearExpr.sum(expressions))
model.add(model_builder.LinearExpr.weighted_sum(expressions, coeffs) >= 0)
__init__(self: ortools.linear_solver.python.model_builder_helper.AffineExpr, arg0: ortools.linear_solver.python.model_builder_helper.LinearExpr, arg1: float, arg2: float) -> None
Inherited Members
A variable (continuous or integral).
A Variable is an object that can take on any integer value within defined ranges. Variables appear in constraint like:
x + y >= 5
Solving a model is equivalent to finding, for each variable, a single value from the set of initial values (called the initial domain), such that the model is feasible, or optimal if you provided an objective function.
__init__(args, *kwargs) Overloaded function.
__init__(self: ortools.linear_solver.python.model_builder_helper.Variable, arg0: operations_research::mb::ModelBuilderHelper, arg1: int) -> None
__init__(self: ortools.linear_solver.python.model_builder_helper.Variable, arg0: operations_research::mb::ModelBuilderHelper, arg1: float, arg2: float, arg3: bool) -> None
__init__(self: ortools.linear_solver.python.model_builder_helper.Variable, arg0: operations_research::mb::ModelBuilderHelper, arg1: float, arg2: float, arg3: bool, arg4: str) -> None
__init__(self: ortools.linear_solver.python.model_builder_helper.Variable, arg0: operations_research::mb::ModelBuilderHelper, arg1: int, arg2: int, arg3: bool) -> None
__init__(self: ortools.linear_solver.python.model_builder_helper.Variable, arg0: operations_research::mb::ModelBuilderHelper, arg1: int, arg2: int, arg3: bool, arg4: str) -> None
(arg0: ortools.linear_solver.python.model_builder_helper.Variable) -> operations_research::mb::ModelBuilderHelper
Inherited Members
__init__(args, *kwargs) Overloaded function.
__init__(self: ortools.linear_solver.python.model_builder_helper.BoundedLinearExpression, arg0: ortools.linear_solver.python.model_builder_helper.LinearExpr, arg1: float, arg2: float) -> None
__init__(self: ortools.linear_solver.python.model_builder_helper.BoundedLinearExpression, arg0: ortools.linear_solver.python.model_builder_helper.LinearExpr, arg1: ortools.linear_solver.python.model_builder_helper.LinearExpr, arg2: float, arg3: float) -> None
__init__(self: ortools.linear_solver.python.model_builder_helper.BoundedLinearExpression, arg0: ortools.linear_solver.python.model_builder_helper.LinearExpr, arg1: int, arg2: int) -> None
__init__(self: ortools.linear_solver.python.model_builder_helper.BoundedLinearExpression, arg0: ortools.linear_solver.python.model_builder_helper.LinearExpr, arg1: ortools.linear_solver.python.model_builder_helper.LinearExpr, arg2: int, arg3: int) -> None
(arg0: ortools.linear_solver.python.model_builder_helper.BoundedLinearExpression) -> list[float]
to_mpmodel_proto(helper: operations_research::mb::ModelBuilderHelper) -> operations_research::MPModelProto
__init__(self: ortools.linear_solver.python.model_builder_helper.MPModelExportOptions) -> None
__init__(self: ortools.linear_solver.python.model_builder_helper.ModelBuilderHelper) -> None
overwrite_model(self: ortools.linear_solver.python.model_builder_helper.ModelBuilderHelper, other_helper: ortools.linear_solver.python.model_builder_helper.ModelBuilderHelper) -> None
export_to_mps_string(self: ortools.linear_solver.python.model_builder_helper.ModelBuilderHelper, options: ortools.linear_solver.python.model_builder_helper.MPModelExportOptions = <ortools.linear_solver.python.model_builder_helper.MPModelExportOptions object at 0x7fb800db5130>) -> str
export_to_lp_string(self: ortools.linear_solver.python.model_builder_helper.ModelBuilderHelper, options: ortools.linear_solver.python.model_builder_helper.MPModelExportOptions = <ortools.linear_solver.python.model_builder_helper.MPModelExportOptions object at 0x7fb803dc93f0>) -> str
write_to_mps_file(self: ortools.linear_solver.python.model_builder_helper.ModelBuilderHelper, filename: str, options: ortools.linear_solver.python.model_builder_helper.MPModelExportOptions = <ortools.linear_solver.python.model_builder_helper.MPModelExportOptions object at 0x7fb800f71230>) -> bool
read_model_from_proto_file(self: ortools.linear_solver.python.model_builder_helper.ModelBuilderHelper, filename: str) -> bool
write_model_to_proto_file(self: ortools.linear_solver.python.model_builder_helper.ModelBuilderHelper, filename: str) -> bool
import_from_mps_string(self: ortools.linear_solver.python.model_builder_helper.ModelBuilderHelper, mps_string: str) -> bool
import_from_mps_file(self: ortools.linear_solver.python.model_builder_helper.ModelBuilderHelper, mps_file: str) -> bool
import_from_lp_string(self: ortools.linear_solver.python.model_builder_helper.ModelBuilderHelper, lp_string: str) -> bool
import_from_lp_file(self: ortools.linear_solver.python.model_builder_helper.ModelBuilderHelper, lp_file: str) -> bool
fill_model_from_sparse_data(self: ortools.linear_solver.python.model_builder_helper.ModelBuilderHelper, variable_lower_bound: numpy.ndarray[numpy.float64[m, 1]], variable_upper_bound: numpy.ndarray[numpy.float64[m, 1]], objective_coefficients: numpy.ndarray[numpy.float64[m, 1]], constraint_lower_bounds: numpy.ndarray[numpy.float64[m, 1]], constraint_upper_bounds: numpy.ndarray[numpy.float64[m, 1]], constraint_matrix: scipy.sparse.csr_matrix[numpy.float64]) -> None
add_var(self: ortools.linear_solver.python.model_builder_helper.ModelBuilderHelper) -> int
add_var_array(self: ortools.linear_solver.python.model_builder_helper.ModelBuilderHelper, arg0: list[int], arg1: float, arg2: float, arg3: bool, arg4: str) -> numpy.ndarray[numpy.int32]
add_var_array_with_bounds(self: ortools.linear_solver.python.model_builder_helper.ModelBuilderHelper, arg0: numpy.ndarray[numpy.float64], arg1: numpy.ndarray[numpy.float64], arg2: numpy.ndarray[bool], arg3: str) -> numpy.ndarray[numpy.int32]
set_var_lower_bound(self: ortools.linear_solver.python.model_builder_helper.ModelBuilderHelper, var_index: int, lb: float) -> None
set_var_upper_bound(self: ortools.linear_solver.python.model_builder_helper.ModelBuilderHelper, var_index: int, ub: float) -> None
set_var_integrality(self: ortools.linear_solver.python.model_builder_helper.ModelBuilderHelper, var_index: int, is_integer: bool) -> None
set_var_objective_coefficient(self: ortools.linear_solver.python.model_builder_helper.ModelBuilderHelper, var_index: int, coeff: float) -> None
set_objective_coefficients(self: ortools.linear_solver.python.model_builder_helper.ModelBuilderHelper, arg0: list[int], arg1: list[float]) -> None
set_var_name(self: ortools.linear_solver.python.model_builder_helper.ModelBuilderHelper, var_index: int, name: str) -> None
var_lower_bound(self: ortools.linear_solver.python.model_builder_helper.ModelBuilderHelper, var_index: int) -> float
var_upper_bound(self: ortools.linear_solver.python.model_builder_helper.ModelBuilderHelper, var_index: int) -> float
var_is_integral(self: ortools.linear_solver.python.model_builder_helper.ModelBuilderHelper, var_index: int) -> bool
var_objective_coefficient(self: ortools.linear_solver.python.model_builder_helper.ModelBuilderHelper, var_index: int) -> float
var_name(self: ortools.linear_solver.python.model_builder_helper.ModelBuilderHelper, var_index: int) -> str
add_linear_constraint(self: ortools.linear_solver.python.model_builder_helper.ModelBuilderHelper) -> int
set_constraint_lower_bound(self: ortools.linear_solver.python.model_builder_helper.ModelBuilderHelper, ct_index: int, lb: float) -> None
set_constraint_upper_bound(self: ortools.linear_solver.python.model_builder_helper.ModelBuilderHelper, ct_index: int, ub: float) -> None
add_term_to_constraint(self: ortools.linear_solver.python.model_builder_helper.ModelBuilderHelper, ct_index: int, var_index: int, coeff: float) -> None
add_terms_to_constraint(self: ortools.linear_solver.python.model_builder_helper.ModelBuilderHelper, arg0: int, arg1: list[ortools.linear_solver.python.model_builder_helper.Variable], arg2: list[float]) -> None
safe_add_term_to_constraint(self: ortools.linear_solver.python.model_builder_helper.ModelBuilderHelper, ct_index: int, var_index: int, coeff: float) -> None
set_constraint_name(self: ortools.linear_solver.python.model_builder_helper.ModelBuilderHelper, ct_index: int, name: str) -> None
set_constraint_coefficient(self: ortools.linear_solver.python.model_builder_helper.ModelBuilderHelper, ct_index: int, var_index: int, coeff: float) -> None
constraint_lower_bound(self: ortools.linear_solver.python.model_builder_helper.ModelBuilderHelper, ct_index: int) -> float
constraint_upper_bound(self: ortools.linear_solver.python.model_builder_helper.ModelBuilderHelper, ct_index: int) -> float
constraint_name(self: ortools.linear_solver.python.model_builder_helper.ModelBuilderHelper, ct_index: int) -> str
constraint_var_indices(self: ortools.linear_solver.python.model_builder_helper.ModelBuilderHelper, ct_index: int) -> list[int]
constraint_coefficients(self: ortools.linear_solver.python.model_builder_helper.ModelBuilderHelper, ct_index: int) -> list[float]
add_enforced_linear_constraint(self: ortools.linear_solver.python.model_builder_helper.ModelBuilderHelper) -> int
is_enforced_linear_constraint(self: ortools.linear_solver.python.model_builder_helper.ModelBuilderHelper, arg0: int) -> bool
set_enforced_constraint_lower_bound(self: ortools.linear_solver.python.model_builder_helper.ModelBuilderHelper, ct_index: int, lb: float) -> None
set_enforced_constraint_upper_bound(self: ortools.linear_solver.python.model_builder_helper.ModelBuilderHelper, ct_index: int, ub: float) -> None
add_term_to_enforced_constraint(self: ortools.linear_solver.python.model_builder_helper.ModelBuilderHelper, ct_index: int, var_index: int, coeff: float) -> None
add_terms_to_enforced_constraint(self: ortools.linear_solver.python.model_builder_helper.ModelBuilderHelper, arg0: int, arg1: list[ortools.linear_solver.python.model_builder_helper.Variable], arg2: list[float]) -> None
safe_add_term_to_enforced_constraint(self: ortools.linear_solver.python.model_builder_helper.ModelBuilderHelper, ct_index: int, var_index: int, coeff: float) -> None
set_enforced_constraint_name(self: ortools.linear_solver.python.model_builder_helper.ModelBuilderHelper, ct_index: int, name: str) -> None
set_enforced_constraint_coefficient(self: ortools.linear_solver.python.model_builder_helper.ModelBuilderHelper, ct_index: int, var_index: int, coeff: float) -> None
enforced_constraint_lower_bound(self: ortools.linear_solver.python.model_builder_helper.ModelBuilderHelper, ct_index: int) -> float
enforced_constraint_upper_bound(self: ortools.linear_solver.python.model_builder_helper.ModelBuilderHelper, ct_index: int) -> float
enforced_constraint_name(self: ortools.linear_solver.python.model_builder_helper.ModelBuilderHelper, ct_index: int) -> str
enforced_constraint_var_indices(self: ortools.linear_solver.python.model_builder_helper.ModelBuilderHelper, ct_index: int) -> list[int]
enforced_constraint_coefficients(self: ortools.linear_solver.python.model_builder_helper.ModelBuilderHelper, ct_index: int) -> list[float]
set_enforced_constraint_indicator_variable_index(self: ortools.linear_solver.python.model_builder_helper.ModelBuilderHelper, ct_index: int, var_index: int) -> None
set_enforced_constraint_indicator_value(self: ortools.linear_solver.python.model_builder_helper.ModelBuilderHelper, ct_index: int, positive: bool) -> None
enforced_constraint_indicator_variable_index(self: ortools.linear_solver.python.model_builder_helper.ModelBuilderHelper, ct_index: int) -> int
enforced_constraint_indicator_value(self: ortools.linear_solver.python.model_builder_helper.ModelBuilderHelper, ct_index: int) -> bool
num_variables(self: ortools.linear_solver.python.model_builder_helper.ModelBuilderHelper) -> int
num_constraints(self: ortools.linear_solver.python.model_builder_helper.ModelBuilderHelper) -> int
name(self: ortools.linear_solver.python.model_builder_helper.ModelBuilderHelper) -> str
set_name(self: ortools.linear_solver.python.model_builder_helper.ModelBuilderHelper, name: str) -> None
clear_objective(self: ortools.linear_solver.python.model_builder_helper.ModelBuilderHelper) -> None
maximize(self: ortools.linear_solver.python.model_builder_helper.ModelBuilderHelper) -> bool
set_maximize(self: ortools.linear_solver.python.model_builder_helper.ModelBuilderHelper, maximize: bool) -> None
set_objective_offset(self: ortools.linear_solver.python.model_builder_helper.ModelBuilderHelper, offset: float) -> None
objective_offset(self: ortools.linear_solver.python.model_builder_helper.ModelBuilderHelper) -> float
clear_hints(self: ortools.linear_solver.python.model_builder_helper.ModelBuilderHelper) -> None
add_hint(self: ortools.linear_solver.python.model_builder_helper.ModelBuilderHelper, var_index: int, var_value: float) -> None
Members:
OPTIMAL
FEASIBLE
INFEASIBLE
UNBOUNDED
ABNORMAL
NOT_SOLVED
MODEL_IS_VALID
CANCELLED_BY_USER
UNKNOWN_STATUS
MODEL_INVALID
INVALID_SOLVER_PARAMETERS
SOLVER_TYPE_UNAVAILABLE
INCOMPATIBLE_OPTIONS
__init__(self: ortools.linear_solver.python.model_builder_helper.SolveStatus, value: int) -> None
__init__(self: ortools.linear_solver.python.model_builder_helper.ModelSolverHelper, arg0: str) -> None
solver_is_supported(self: ortools.linear_solver.python.model_builder_helper.ModelSolverHelper) -> bool
solve_serialized_request(self: ortools.linear_solver.python.model_builder_helper.ModelSolverHelper, arg0: str) -> bytes
interrupt_solve(self: ortools.linear_solver.python.model_builder_helper.ModelSolverHelper) -> bool
Returns true if the interrupt signal was correctly sent, that is, if the underlying solver supports it.
set_log_callback(self: ortools.linear_solver.python.model_builder_helper.ModelSolverHelper, arg0: std::function
clear_log_callback(self: ortools.linear_solver.python.model_builder_helper.ModelSolverHelper) -> None
set_time_limit_in_seconds(self: ortools.linear_solver.python.model_builder_helper.ModelSolverHelper, limit: float) -> None
set_solver_specific_parameters(self: ortools.linear_solver.python.model_builder_helper.ModelSolverHelper, solver_specific_parameters: str) -> None
enable_output(self: ortools.linear_solver.python.model_builder_helper.ModelSolverHelper, output: bool) -> None
has_solution(self: ortools.linear_solver.python.model_builder_helper.ModelSolverHelper) -> bool
has_response(self: ortools.linear_solver.python.model_builder_helper.ModelSolverHelper) -> bool
response(self: ortools.linear_solver.python.model_builder_helper.ModelSolverHelper) -> operations_research::MPSolutionResponse
status_string(self: ortools.linear_solver.python.model_builder_helper.ModelSolverHelper) -> str
wall_time(self: ortools.linear_solver.python.model_builder_helper.ModelSolverHelper) -> float
user_time(self: ortools.linear_solver.python.model_builder_helper.ModelSolverHelper) -> float
objective_value(self: ortools.linear_solver.python.model_builder_helper.ModelSolverHelper) -> float
best_objective_bound(self: ortools.linear_solver.python.model_builder_helper.ModelSolverHelper) -> float
variable_value(self: ortools.linear_solver.python.model_builder_helper.ModelSolverHelper, var_index: int) -> float
expression_value(self: ortools.linear_solver.python.model_builder_helper.ModelSolverHelper, arg0: ortools.linear_solver.python.model_builder_helper.LinearExpr) -> float
reduced_cost(self: ortools.linear_solver.python.model_builder_helper.ModelSolverHelper, var_index: int) -> float
dual_value(self: ortools.linear_solver.python.model_builder_helper.ModelSolverHelper, ct_index: int) -> float
activity(self: ortools.linear_solver.python.model_builder_helper.ModelSolverHelper, ct_index: int) -> float
variable_values(self: ortools.linear_solver.python.model_builder_helper.ModelSolverHelper) -> numpy.ndarray[numpy.float64[m, 1]]
reduced_costs(self: ortools.linear_solver.python.model_builder_helper.ModelSolverHelper) -> numpy.ndarray[numpy.float64[m, 1]]
dual_values(self: ortools.linear_solver.python.model_builder_helper.ModelSolverHelper) -> numpy.ndarray[numpy.float64[m, 1]]