1// Copyright 2010-2021 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
5//
6//     http://www.apache.org/licenses/LICENSE-2.0
7//
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.
13
14// Data structures used throughout MathOpt to model sparse vectors and matrices.
15syntax = "proto3";
16
17package operations_research.math_opt;
18
19// A sparse representation of a vector of doubles.
20message SparseDoubleVectorProto {
21  // Must be sorted (in increasing ordering) with all elements distinct.
22  repeated int64 ids = 1;
23  // Must have equal length to ids. May not contain NaN.
24  repeated double values = 2;
25}
26
27// A sparse representation of a vector of bools.
28message SparseBoolVectorProto {
29  // Should be sorted (in increasing ordering) with all elements distinct.
30  repeated int64 ids = 1;
31  // Must have equal length to ids.
32  repeated bool values = 2;
33}
34
35// This message allows to query/set specific parts of a SparseXxxxVector.
36// The default behavior is not to filter out anything.
37// A common usage is to query only parts of solutions (only non-zero values,
38// and/or just a hand-picked set of variable values).
39message SparseVectorFilterProto {
40  // For SparseBoolVectorProto "zero" is `false`.
41  bool skip_zero_values = 1;
42  // When true, return only the values corresponding to the IDs listed in
43  // filtered_ids.
44  bool filter_by_ids = 2;
45  // The list of IDs to use when filter_by_ids is true. Must be empty when
46  // filter_by_ids is false.
47  // NOTE: if this is empty, and filter_by_ids is true, you are saying that
48  // you do not want any information in the result.
49  repeated int64 filtered_ids = 3;
50}
51
52// A sparse representation of a matrix of doubles.
53//
54// The matrix is stored as triples of row id, column id, and coefficient. These
55// three vectors must be of equal length. For all i, the tuple (row_ids[i],
56// column_ids[i]) should be distinct. Entries must be in row major order.
57//
58// TODO(user): consider CSR.
59message SparseDoubleMatrixProto {
60  repeated int64 row_ids = 1;
61  repeated int64 column_ids = 2;
62  // May not contain NaN.
63  repeated double coefficients = 3;
64}
65