1// Copyright 2010-2024 Google LLC
2// Licensed under the Apache License, Version 2.0 (the "License");
3// you may not use this file except in compliance with the License.
4// You may obtain a copy of the License at
6// http://www.apache.org/licenses/LICENSE-2.0
8// Unless required by applicable law or agreed to in writing, software
9// distributed under the License is distributed on an "AS IS" BASIS,
10// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11// See the License for the specific language governing permissions and
12// limitations under the License.
14// Updates an existing Model proto.
17package operations_research.math_opt;
19import "ortools/math_opt/model.proto";
20import "ortools/math_opt/sparse_containers.proto";
22option java_package = "com.google.ortools.mathopt";
23option java_multiple_files = true;
25// Updates to existing variables in a ModelProto.
27// Applies only to existing variables in a model, for new variables, see
28// ModelUpdateProto.new_variables.
29message VariableUpdatesProto {
30 // Updates ModelProto.variables.lower_bounds.
33 // * lower_bounds.ids must be from ModelProto.variables.ids.
34 // * lower_bounds.values must be < infinity.
35 // * Unset values are unchanged.
36 SparseDoubleVectorProto lower_bounds = 1;
38 // Updates ModelProto.variables.upper_bounds.
41 // * upper_bounds.ids must be from ModelProto.variables.ids.
42 // * upper_bounds.values must be > -infinity.
43 // * Unset values are unchanged.
44 SparseDoubleVectorProto upper_bounds = 2;
46 // Updates ModelProto.variables.integers.
49 // * integers.ids must be from ModelProto.variables.ids.
50 // * Unset values are unchanged.
51 SparseBoolVectorProto integers = 3;
54// Updates the objective of a Model, both for existing and new variables.
55message ObjectiveUpdatesProto {
56 // Not set indicates no change, false is minimize, true is maximize.
57 optional bool direction_update = 1;
58 // Not set indicates not change, otherwise the new offset.
59 optional double offset_update = 2;
61 // Updates ObjectiveProto.linear_coefficients.
64 // * linear_coefficients.ids must be variable ids, either existing one (from
65 // ModelProto.variables.ids) or new ones (from
66 // ModelUpdateProto.new_variables.ids).
67 // * linear_coefficients.values must be finite
68 // * Unset values are unchanged.
69 // * The value 0.0 removes a variable from the linear objective. This
70 // value should only be used for existing variables.
71 SparseDoubleVectorProto linear_coefficients = 3;
73 // Updates ObjectiveProto.quadratic_coefficients
75 // Requirements in addition to those on SparseDoubleMatrixProto messages:
76 // * Each element of quadratic_coefficients.row_ids and each element of
77 // quadratic_coefficients.column_ids must be a variable id, either an
78 // existing one (from ModelProto.variables.ids) or a new one (from
79 // ModelUpdateProto.new_variables.ids).
80 // * The matrix must be upper triangular: for each i,
81 // quadratic_coefficients.row_ids[i] <=
82 // quadratic_coefficients.column_ids[i].
85 // * Unset values are unchanged.
86 // * The value 0.0 removes a quadratic term (i.e. product of two variables)
87 // from the quadratic objective. This value should only be used for
88 // existing quadratic terms appearing in the objective.
89 SparseDoubleMatrixProto quadratic_coefficients = 4;
91 // Not set indicates no change, otherwise the new priority. If set, the value
92 // must be nonnegative. Furthermore, each objective priority must be distinct
93 // at solve time; this condition is not validated at the proto level, so
94 // models may temporarily have objectives with the same priority.
95 optional int64 priority_update = 5;
98// Updates the auxiliary objectives of a Model, both for existing and new
99// variables. Auxiliary objectives can be deleted, added, or modified in place.
100message AuxiliaryObjectivesUpdatesProto {
101 // Removes auxiliary objectives from the model.
103 // Each value must be in [0, max(int64)). Values must be in strictly
104 // increasing order. Applies only to existing auxiliary objective IDs that
105 // have not yet been deleted.
106 repeated int64 deleted_objective_ids = 1;
108 // Add new auxiliary objectives to the model. All keys must be in
109 // [0, max(int64)), and must be greater than any ids used in the initial model
110 // and previous updates. All nonempty names should be distinct from existing
111 // names for the primary and other auxiliary objectives.
112 map<int64, ObjectiveProto> new_objectives = 2;
114 // Updates existing auxiliary objectives in the model. All key IDs must be
115 // existing in the model and not included in `deleted_objective_ids`.
116 map<int64, ObjectiveUpdatesProto> objective_updates = 3;
119// Updates to existing linear constraints in a ModelProto.
120message LinearConstraintUpdatesProto {
121 // Updates ModelProto.linear_constraints.lower_bounds.
124 // * lower_bounds.ids must be from ModelProto.linear_constraints.ids.
125 // * lower_bounds.values must be < infinity.
126 // * Unset values are unchanged.
127 SparseDoubleVectorProto lower_bounds = 1;
128 // Updates ModelProto.linear_constraints.upper_bounds.
131 // * upper_bounds.ids must be from ModelProto.linear_constraints.ids.
132 // * upper_bounds.values must be > -infinity.
133 // * Unset values are unchanged.
134 SparseDoubleVectorProto upper_bounds = 2;
137// Updates to quadratic constraints; only addition and deletion, no support for
138// in-place constraint updates.
139message QuadraticConstraintUpdatesProto {
140 // Removes quadratic constraints from the model.
142 // Each value must be in [0, max(int64)). Values must be in strictly
143 // increasing order. Applies only to existing quadratic constraint ids that
144 // have not yet been deleted.
145 repeated int64 deleted_constraint_ids = 1;
147 // Add new quadratic constraints to the model. All keys must be in
148 // [0, max(int64)), and must be greater than any ids used in the initial model
149 // and previous updates. All nonempty names should be distinct from existing
150 // names and each other.
151 map<int64, QuadraticConstraintProto> new_constraints = 2;
154// Updates to second-order cone constraints; only addition and deletion, no
155// support for in-place constraint updates.
156message SecondOrderConeConstraintUpdatesProto {
157 // Removes second-order cone constraints from the model.
159 // Each value must be in [0, max(int64)). Values must be in strictly
160 // increasing order. Applies only to existing second-order cone constraint ids
161 // that have not yet been deleted.
162 repeated int64 deleted_constraint_ids = 1;
164 // Add new second-order cone constraints to the model. All keys must be in
165 // [0, max(int64)), and must be greater than any ids used in the initial model
166 // and previous updates. All nonempty names should be distinct from existing
167 // names and each other.
168 map<int64, SecondOrderConeConstraintProto> new_constraints = 2;
171// Data for updates to SOS1 and SOS2 constraints; only addition and deletion, no
172// support for in-place constraint updates.
173message SosConstraintUpdatesProto {
174 // Removes SOS constraints from the model.
176 // Each value must be in [0, max(int64)). Values must be in strictly
177 // increasing order. Applies only to existing SOS constraint ids that have not
179 repeated int64 deleted_constraint_ids = 1;
181 // Add new SOS constraints to the model. All keys must be in [0, max(int64)),
182 // and must be greater than any ids used in the initial model and previous
183 // updates. All nonempty names should be distinct from existing names and each
185 map<int64, SosConstraintProto> new_constraints = 2;
188// Data for updates to indicator constraints; only addition and deletion, no
189// support for in-place constraint updates.
190message IndicatorConstraintUpdatesProto {
191 // Removes indicator constraints from the model.
193 // Each value must be in [0, max(int64)). Values must be in strictly
194 // increasing order. Applies only to existing indicator constraint ids that
195 // have not yet been deleted.
196 repeated int64 deleted_constraint_ids = 1;
198 // Add new indicator constraints to the model. All keys must be in
199 // [0, max(int64)), and must be greater than any ids used in the initial model
200 // and previous updates. All nonempty names should be distinct from existing
201 // names and each other.
202 map<int64, IndicatorConstraintProto> new_constraints = 2;
205// Updates to a ModelProto.
206message ModelUpdateProto {
207 // Removes variables from the model.
209 // Values must be in strictly increasing order. Apply only to existing
210 // variable ids that have not yet been deleted. The ids of deleted variables
211 // should not appear in other fields (e.g. variable_updates,
212 // objective_updates, linear_constraint_matrix_updates).
213 repeated int64 deleted_variable_ids = 1;
215 // Removes linear constraints from the model.
217 // Values must be in strictly increasing order. Apply only to existing
218 // linear constraint ids that have not yet been deleted. The ids of deleted
219 // linear constraints should not appear in other fields (e.g.
220 // linear_constraint_updates, linear_constraint_matrix_updates).
221 repeated int64 deleted_linear_constraint_ids = 2;
223 // Updates properties of existing variables. Should not contain any deleted
225 VariableUpdatesProto variable_updates = 3;
227 // Updates properties of existing linear constraints. Should not contain any
228 // deleted linear constraints ids.
229 LinearConstraintUpdatesProto linear_constraint_updates = 4;
231 // Add new variables to the model. All new_variables.ids must be greater than
232 // any ids used in the initial model and previous updates. All nonempty names
233 // should be distinct from existing names.
234 VariablesProto new_variables = 5;
236 // Add new linear constraints to the model. All new_linear_constraints.ids
237 // must be greater than any ids used in the initial model and previous
238 // updates. All nonempty names should be distinct from existing names.
239 LinearConstraintsProto new_linear_constraints = 6;
241 // Updates the primary objective, both for existing and new variables.
242 ObjectiveUpdatesProto objective_updates = 7;
244 // Updates the auxiliary objectives, both for existing and new variables.
245 AuxiliaryObjectivesUpdatesProto auxiliary_objectives_updates = 13;
247 // Updates the linear constraint matrix, both for existing and new
248 // variables/linear constraints.
251 // * linear_constraint_matrix_updates.row_ids are linear constraint ids,
252 // either existing or new.
253 // * linear_constraint_matrix_updates.column_ids are variables ids, either
255 // * Matrix entries are unchanged if the (constraint, variable) pair is
256 // existing and unset.
257 // * Matrix entries are zero if either the constraint or variable is new and
258 // the (constraint, variable) pair is unset.
259 // * Zero values delete existing entries, and have no effect for new entries.
260 // * linear_constraint_matrix.values must all be finite.
261 SparseDoubleMatrixProto linear_constraint_matrix_updates = 8;
263 // Updates the quadratic constraints (addition and deletion only).
264 QuadraticConstraintUpdatesProto quadratic_constraint_updates = 9;
266 // Updates the second-order cone constraints (addition and deletion only).
267 SecondOrderConeConstraintUpdatesProto second_order_cone_constraint_updates =
270 // Updates the general constraints (addition and deletion only).
271 SosConstraintUpdatesProto sos1_constraint_updates = 10;
272 SosConstraintUpdatesProto sos2_constraint_updates = 11;
273 IndicatorConstraintUpdatesProto indicator_constraint_updates = 12;