![]() |
Google OR-Tools v9.12
a fast and portable software suite for combinatorial optimization
|
Public Member Functions | |
str | name (self) |
int | add_variable (self, float lb, float ub, bool is_integer, str name) |
None | delete_variable (self, int variable_id) |
bool | variable_exists (self, int variable_id) |
int | next_variable_id (self) |
None | set_variable_lb (self, int variable_id, float lb) |
None | set_variable_ub (self, int variable_id, float ub) |
None | set_variable_is_integer (self, int variable_id, bool is_integer) |
float | get_variable_lb (self, int variable_id) |
float | get_variable_ub (self, int variable_id) |
bool | get_variable_is_integer (self, int variable_id) |
str | get_variable_name (self, int variable_id) |
Iterator[int] | get_variables (self) |
int | add_linear_constraint (self, float lb, float ub, str name) |
None | delete_linear_constraint (self, int linear_constraint_id) |
bool | linear_constraint_exists (self, int linear_constraint_id) |
int | next_linear_constraint_id (self) |
None | set_linear_constraint_lb (self, int linear_constraint_id, float lb) |
None | set_linear_constraint_ub (self, int linear_constraint_id, float ub) |
float | get_linear_constraint_lb (self, int linear_constraint_id) |
float | get_linear_constraint_ub (self, int linear_constraint_id) |
str | get_linear_constraint_name (self, int linear_constraint_id) |
Iterator[int] | get_linear_constraints (self) |
None | set_linear_constraint_coefficient (self, int linear_constraint_id, int variable_id, float lb) |
float | get_linear_constraint_coefficient (self, int linear_constraint_id, int variable_id) |
Iterator[int] | get_linear_constraints_with_variable (self, int variable_id) |
Iterator[int] | get_variables_for_linear_constraint (self, int linear_constraint_id) |
Iterator[LinearConstraintMatrixIdEntry] | get_linear_constraint_matrix_entries (self) |
None | clear_objective (self) |
None | set_linear_objective_coefficient (self, int variable_id, float value) |
float | get_linear_objective_coefficient (self, int variable_id) |
Iterator[LinearObjectiveEntry] | get_linear_objective_coefficients (self) |
None | set_quadratic_objective_coefficient (self, int first_variable_id, int second_variable_id, float value) |
float | get_quadratic_objective_coefficient (self, int first_variable_id, int second_variable_id) |
Iterator[QuadraticEntry] | get_quadratic_objective_coefficients (self) |
Iterator[int] | get_quadratic_objective_adjacent_variables (self, int variable_id) |
None | set_is_maximize (self, bool is_maximize) |
bool | get_is_maximize (self) |
None | set_objective_offset (self, float offset) |
float | get_objective_offset (self) |
model_pb2.ModelProto | export_model (self) |
StorageUpdateTracker | add_update_tracker (self) |
remove_update_tracker (self, StorageUpdateTracker tracker) | |
An interface for in memory storage of an optimization model. Most users should not use this class directly and use Model defined in model.py. Stores an mixed integer programming problem of the form: {max/min} c*x + d s.t. lb_c <= A * x <= ub_c lb_v <= x <= ub_v x_i integer for i in I where x is a vector of n decision variables, d is a number, lb_v, ub_v, and c are vectors of n numbers, lb_c and ub_c are vectors of m numbers, A is a m by n matrix, and I is a subset of {1,..., n}. Each of the n variables and m constraints have an integer id that you use to get/set the problem data (c, A, lb_c etc.). Ids begin at zero and increase sequentially. They are not reused after deletion. Note that if a variable is deleted, your model has nonconsecutive variable ids. For all methods taking an id (e.g. set_variable_lb), providing a bad id (including the id of a deleted variable) will raise a BadVariableIdError or BadLinearConstraintIdError. Further, the ModelStorage instance is assumed to be in a bad state after any such error and there are no guarantees on further interactions. All implementations must have a constructor taking a str argument for the model name with a default value of the empty string. Any ModelStorage can be exported to model_pb2.ModelProto, the format consumed by MathOpt solvers. Changes to a model can be exported to a model_update_pb2.ModelUpdateProto with an UpdateTracker, see the UpdateTracker documentation for details. When solving this optimization problem we will additionally require that: * No numbers are NaN, * c, d, and A are all finite, * lb_c and lb_v are not +inf, * ub_c and ub_v are not -inf, but those assumptions are not checked or enforced here (NaNs and infinite values can be used anywhere).
Definition at line 143 of file model_storage.py.
int ortools.math_opt.python.model_storage.ModelStorage.add_linear_constraint | ( | self, | |
float | lb, | ||
float | ub, | ||
str | name ) |
Reimplemented in ortools.math_opt.python.hash_model_storage.HashModelStorage.
Definition at line 243 of file model_storage.py.
StorageUpdateTracker ortools.math_opt.python.model_storage.ModelStorage.add_update_tracker | ( | self | ) |
Creates a StorageUpdateTracker registered with self to view model changes.
Reimplemented in ortools.math_opt.python.hash_model_storage.HashModelStorage.
Definition at line 417 of file model_storage.py.
int ortools.math_opt.python.model_storage.ModelStorage.add_variable | ( | self, | |
float | lb, | ||
float | ub, | ||
bool | is_integer, | ||
str | name ) |
Reimplemented in ortools.math_opt.python.hash_model_storage.HashModelStorage.
Definition at line 194 of file model_storage.py.
None ortools.math_opt.python.model_storage.ModelStorage.clear_objective | ( | self | ) |
Clears objective coefficients and offset. Does not change direction.
Reimplemented in ortools.math_opt.python.hash_model_storage.HashModelStorage.
Definition at line 315 of file model_storage.py.
None ortools.math_opt.python.model_storage.ModelStorage.delete_linear_constraint | ( | self, | |
int | linear_constraint_id ) |
Reimplemented in ortools.math_opt.python.hash_model_storage.HashModelStorage.
Definition at line 247 of file model_storage.py.
None ortools.math_opt.python.model_storage.ModelStorage.delete_variable | ( | self, | |
int | variable_id ) |
Reimplemented in ortools.math_opt.python.hash_model_storage.HashModelStorage.
Definition at line 198 of file model_storage.py.
model_pb2.ModelProto ortools.math_opt.python.model_storage.ModelStorage.export_model | ( | self | ) |
Reimplemented in ortools.math_opt.python.hash_model_storage.HashModelStorage.
Definition at line 413 of file model_storage.py.
bool ortools.math_opt.python.model_storage.ModelStorage.get_is_maximize | ( | self | ) |
Reimplemented in ortools.math_opt.python.hash_model_storage.HashModelStorage.
Definition at line 401 of file model_storage.py.
float ortools.math_opt.python.model_storage.ModelStorage.get_linear_constraint_coefficient | ( | self, | |
int | linear_constraint_id, | ||
int | variable_id ) |
Reimplemented in ortools.math_opt.python.hash_model_storage.HashModelStorage.
Definition at line 290 of file model_storage.py.
float ortools.math_opt.python.model_storage.ModelStorage.get_linear_constraint_lb | ( | self, | |
int | linear_constraint_id ) |
Reimplemented in ortools.math_opt.python.hash_model_storage.HashModelStorage.
Definition at line 267 of file model_storage.py.
Iterator[LinearConstraintMatrixIdEntry] ortools.math_opt.python.model_storage.ModelStorage.get_linear_constraint_matrix_entries | ( | self | ) |
Yields the nonzero elements of the linear constraint matrix in undefined order.
Reimplemented in ortools.math_opt.python.hash_model_storage.HashModelStorage.
Definition at line 308 of file model_storage.py.
str ortools.math_opt.python.model_storage.ModelStorage.get_linear_constraint_name | ( | self, | |
int | linear_constraint_id ) |
Reimplemented in ortools.math_opt.python.hash_model_storage.HashModelStorage.
Definition at line 275 of file model_storage.py.
float ortools.math_opt.python.model_storage.ModelStorage.get_linear_constraint_ub | ( | self, | |
int | linear_constraint_id ) |
Reimplemented in ortools.math_opt.python.hash_model_storage.HashModelStorage.
Definition at line 271 of file model_storage.py.
Iterator[int] ortools.math_opt.python.model_storage.ModelStorage.get_linear_constraints | ( | self | ) |
Yields the linear constraint ids in order of creation.
Reimplemented in ortools.math_opt.python.hash_model_storage.HashModelStorage.
Definition at line 279 of file model_storage.py.
Iterator[int] ortools.math_opt.python.model_storage.ModelStorage.get_linear_constraints_with_variable | ( | self, | |
int | variable_id ) |
Yields the linear constraints with nonzero coefficient for a variable in undefined order.
Reimplemented in ortools.math_opt.python.hash_model_storage.HashModelStorage.
Definition at line 296 of file model_storage.py.
float ortools.math_opt.python.model_storage.ModelStorage.get_linear_objective_coefficient | ( | self, | |
int | variable_id ) |
Reimplemented in ortools.math_opt.python.hash_model_storage.HashModelStorage.
Definition at line 323 of file model_storage.py.
Iterator[LinearObjectiveEntry] ortools.math_opt.python.model_storage.ModelStorage.get_linear_objective_coefficients | ( | self | ) |
Yields the nonzero linear objective terms in undefined order.
Reimplemented in ortools.math_opt.python.hash_model_storage.HashModelStorage.
Definition at line 327 of file model_storage.py.
float ortools.math_opt.python.model_storage.ModelStorage.get_objective_offset | ( | self | ) |
Reimplemented in ortools.math_opt.python.hash_model_storage.HashModelStorage.
Definition at line 409 of file model_storage.py.
Iterator[int] ortools.math_opt.python.model_storage.ModelStorage.get_quadratic_objective_adjacent_variables | ( | self, | |
int | variable_id ) |
Yields the variables multiplying a variable in the objective function. Variables are returned in an unspecified order. For example, if variables x and y have ids 0 and 1 respectively, and the quadratic portion of the objective is x^2 + 2 x*y, then get_quadratic_objective_adjacent_variables(0) = (0, 1). Args: variable_id: Function yields the variables multiplying variable_id in the objective function. Yields: The variables multiplying variable_id in the objective function. Raises: BadVariableIdError if variable_id is not in the model.
Reimplemented in ortools.math_opt.python.hash_model_storage.HashModelStorage.
Definition at line 374 of file model_storage.py.
float ortools.math_opt.python.model_storage.ModelStorage.get_quadratic_objective_coefficient | ( | self, | |
int | first_variable_id, | ||
int | second_variable_id ) |
Gets the objective coefficient for the product of two variables. The ordering of the input variables does not matter. Args: first_variable_id: The first variable in the product. second_variable_id: The second variable in the product. Raises: BadVariableIdError if first_variable_id or second_variable_id are not in the model. Returns: The value of the coefficient.
Reimplemented in ortools.math_opt.python.hash_model_storage.HashModelStorage.
Definition at line 350 of file model_storage.py.
Iterator[QuadraticEntry] ortools.math_opt.python.model_storage.ModelStorage.get_quadratic_objective_coefficients | ( | self | ) |
Yields the nonzero quadratic objective terms in undefined order.
Reimplemented in ortools.math_opt.python.hash_model_storage.HashModelStorage.
Definition at line 370 of file model_storage.py.
bool ortools.math_opt.python.model_storage.ModelStorage.get_variable_is_integer | ( | self, | |
int | variable_id ) |
Reimplemented in ortools.math_opt.python.hash_model_storage.HashModelStorage.
Definition at line 230 of file model_storage.py.
float ortools.math_opt.python.model_storage.ModelStorage.get_variable_lb | ( | self, | |
int | variable_id ) |
Reimplemented in ortools.math_opt.python.hash_model_storage.HashModelStorage.
Definition at line 222 of file model_storage.py.
str ortools.math_opt.python.model_storage.ModelStorage.get_variable_name | ( | self, | |
int | variable_id ) |
Reimplemented in ortools.math_opt.python.hash_model_storage.HashModelStorage.
Definition at line 234 of file model_storage.py.
float ortools.math_opt.python.model_storage.ModelStorage.get_variable_ub | ( | self, | |
int | variable_id ) |
Reimplemented in ortools.math_opt.python.hash_model_storage.HashModelStorage.
Definition at line 226 of file model_storage.py.
Iterator[int] ortools.math_opt.python.model_storage.ModelStorage.get_variables | ( | self | ) |
Yields the variable ids in order of creation.
Reimplemented in ortools.math_opt.python.hash_model_storage.HashModelStorage.
Definition at line 238 of file model_storage.py.
Iterator[int] ortools.math_opt.python.model_storage.ModelStorage.get_variables_for_linear_constraint | ( | self, | |
int | linear_constraint_id ) |
Yields the variables with nonzero coefficient in a linear constraint in undefined order.
Reimplemented in ortools.math_opt.python.hash_model_storage.HashModelStorage.
Definition at line 301 of file model_storage.py.
bool ortools.math_opt.python.model_storage.ModelStorage.linear_constraint_exists | ( | self, | |
int | linear_constraint_id ) |
Reimplemented in ortools.math_opt.python.hash_model_storage.HashModelStorage.
Definition at line 251 of file model_storage.py.
str ortools.math_opt.python.model_storage.ModelStorage.name | ( | self | ) |
Reimplemented in ortools.math_opt.python.hash_model_storage.HashModelStorage.
Definition at line 190 of file model_storage.py.
int ortools.math_opt.python.model_storage.ModelStorage.next_linear_constraint_id | ( | self | ) |
Reimplemented in ortools.math_opt.python.hash_model_storage.HashModelStorage.
Definition at line 255 of file model_storage.py.
int ortools.math_opt.python.model_storage.ModelStorage.next_variable_id | ( | self | ) |
Reimplemented in ortools.math_opt.python.hash_model_storage.HashModelStorage.
Definition at line 206 of file model_storage.py.
ortools.math_opt.python.model_storage.ModelStorage.remove_update_tracker | ( | self, | |
StorageUpdateTracker | tracker ) |
Stops tracker from getting updates on model changes in self. An error will be raised if tracker is not a StorageUpdateTracker created by this Model that has not previously been removed. Using an UpdateTracker (via checkpoint or export_update) after it has been removed will result in an error. Args: tracker: The StorageUpdateTracker to unregister. Raises: KeyError: The tracker was created by another model or was already removed.
Reimplemented in ortools.math_opt.python.hash_model_storage.HashModelStorage.
Definition at line 422 of file model_storage.py.
None ortools.math_opt.python.model_storage.ModelStorage.set_is_maximize | ( | self, | |
bool | is_maximize ) |
Reimplemented in ortools.math_opt.python.hash_model_storage.HashModelStorage.
Definition at line 397 of file model_storage.py.
None ortools.math_opt.python.model_storage.ModelStorage.set_linear_constraint_coefficient | ( | self, | |
int | linear_constraint_id, | ||
int | variable_id, | ||
float | lb ) |
Reimplemented in ortools.math_opt.python.hash_model_storage.HashModelStorage.
Definition at line 284 of file model_storage.py.
None ortools.math_opt.python.model_storage.ModelStorage.set_linear_constraint_lb | ( | self, | |
int | linear_constraint_id, | ||
float | lb ) |
Reimplemented in ortools.math_opt.python.hash_model_storage.HashModelStorage.
Definition at line 259 of file model_storage.py.
None ortools.math_opt.python.model_storage.ModelStorage.set_linear_constraint_ub | ( | self, | |
int | linear_constraint_id, | ||
float | ub ) |
Reimplemented in ortools.math_opt.python.hash_model_storage.HashModelStorage.
Definition at line 263 of file model_storage.py.
None ortools.math_opt.python.model_storage.ModelStorage.set_linear_objective_coefficient | ( | self, | |
int | variable_id, | ||
float | value ) |
Reimplemented in ortools.math_opt.python.hash_model_storage.HashModelStorage.
Definition at line 319 of file model_storage.py.
None ortools.math_opt.python.model_storage.ModelStorage.set_objective_offset | ( | self, | |
float | offset ) |
Reimplemented in ortools.math_opt.python.hash_model_storage.HashModelStorage.
Definition at line 405 of file model_storage.py.
None ortools.math_opt.python.model_storage.ModelStorage.set_quadratic_objective_coefficient | ( | self, | |
int | first_variable_id, | ||
int | second_variable_id, | ||
float | value ) |
Sets the objective coefficient for the product of two variables. The ordering of the input variables does not matter. Args: first_variable_id: The first variable in the product. second_variable_id: The second variable in the product. value: The value of the coefficient. Raises: BadVariableIdError if first_variable_id or second_variable_id are not in the model.
Reimplemented in ortools.math_opt.python.hash_model_storage.HashModelStorage.
Definition at line 332 of file model_storage.py.
None ortools.math_opt.python.model_storage.ModelStorage.set_variable_is_integer | ( | self, | |
int | variable_id, | ||
bool | is_integer ) |
Reimplemented in ortools.math_opt.python.hash_model_storage.HashModelStorage.
Definition at line 218 of file model_storage.py.
None ortools.math_opt.python.model_storage.ModelStorage.set_variable_lb | ( | self, | |
int | variable_id, | ||
float | lb ) |
Reimplemented in ortools.math_opt.python.hash_model_storage.HashModelStorage.
Definition at line 210 of file model_storage.py.
None ortools.math_opt.python.model_storage.ModelStorage.set_variable_ub | ( | self, | |
int | variable_id, | ||
float | ub ) |
Reimplemented in ortools.math_opt.python.hash_model_storage.HashModelStorage.
Definition at line 214 of file model_storage.py.
bool ortools.math_opt.python.model_storage.ModelStorage.variable_exists | ( | self, | |
int | variable_id ) |
Reimplemented in ortools.math_opt.python.hash_model_storage.HashModelStorage.
Definition at line 202 of file model_storage.py.