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// Data structures used throughout MathOpt to model sparse vectors and matrices.
17package operations_research.math_opt;
19option java_package = "com.google.ortools.mathopt";
20option java_multiple_files = true;
22// A sparse representation of a vector of doubles.
23message SparseDoubleVectorProto {
24 // Must be sorted (in increasing ordering) with all elements distinct.
25 repeated int64 ids = 1;
26 // Must have equal length to ids. May not contain NaN.
27 repeated double values = 2;
30// A sparse representation of a vector of bools.
31message SparseBoolVectorProto {
32 // Should be sorted (in increasing ordering) with all elements distinct.
33 repeated int64 ids = 1;
34 // Must have equal length to ids.
35 repeated bool values = 2;
38// A sparse representation of a vector of ints.
39message SparseInt32VectorProto {
40 // Should be sorted (in increasing ordering) with all elements distinct.
41 repeated int64 ids = 1;
42 // Must have equal length to ids.
43 repeated int32 values = 2;
46// This message allows to query/set specific parts of a SparseXxxxVector.
47// The default behavior is not to filter out anything.
48// A common usage is to query only parts of solutions (only non-zero values,
49// and/or just a hand-picked set of variable values).
50message SparseVectorFilterProto {
51 // For SparseBoolVectorProto "zero" is `false`.
52 bool skip_zero_values = 1;
53 // When true, return only the values corresponding to the IDs listed in
55 bool filter_by_ids = 2;
56 // The list of IDs to use when filter_by_ids is true. Must be empty when
57 // filter_by_ids is false.
58 // NOTE: if this is empty, and filter_by_ids is true, you are saying that
59 // you do not want any information in the result.
60 repeated int64 filtered_ids = 3;
63// A sparse representation of a matrix of doubles.
65// The matrix is stored as triples of row id, column id, and coefficient. These
66// three vectors must be of equal length. For all i, the tuple (row_ids[i],
67// column_ids[i]) should be distinct. Entries must be in row major order.
69// TODO(user): consider CSR.
70message SparseDoubleMatrixProto {
71 repeated int64 row_ids = 1;
72 repeated int64 column_ids = 2;
73 // May not contain NaN.
74 repeated double coefficients = 3;
77// A sparse representation of a linear expression (a weighted sum of variables,
78// plus a constant offset).
79message LinearExpressionProto {
80 // Ids of variables. Must be sorted (in increasing ordering) with all elements
82 repeated int64 ids = 1;
83 // Must have equal length to ids. Values must be finite may not be NaN.
84 repeated double coefficients = 2;
85 // Must be finite and may not be NaN.