Google OR-Tools v9.15
a fast and portable software suite for combinatorial optimization
Loading...
Searching...
No Matches
sparse_containers.proto
Go to the documentation of this file.
1// Copyright 2010-2025 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.
15
16syntax = "proto3";
17
18package operations_research.service.v1.mathopt;
19
20option java_multiple_files = true;
21option java_package = "com.google.ortools.service.v1.mathopt";
22
23option csharp_namespace = "Google.OrTools.Service";
24
25// A sparse representation of a vector of doubles.
26message SparseDoubleVectorProto {
27 // Must be sorted (in increasing ordering) with all elements distinct.
28 repeated int64 ids = 1;
29 // Must have equal length to ids. May not contain NaN.
30 repeated double values = 2;
31}
32
33// A sparse representation of a vector of bools.
34message SparseBoolVectorProto {
35 // Should be sorted (in increasing ordering) with all elements distinct.
36 repeated int64 ids = 1;
37 // Must have equal length to ids.
38 repeated bool values = 2;
39}
40
41// A sparse representation of a vector of ints.
42message SparseInt32VectorProto {
43 // Should be sorted (in increasing ordering) with all elements distinct.
44 repeated int64 ids = 1;
45 // Must have equal length to ids.
46 repeated int32 values = 2;
47}
48
49// This message allows to query/set specific parts of a SparseXxxxVector.
50// The default behavior is not to filter out anything.
51// A common usage is to query only parts of solutions (only non-zero values,
52// and/or just a hand-picked set of variable values).
53message SparseVectorFilterProto {
54 // For SparseBoolVectorProto "zero" is `false`.
55 bool skip_zero_values = 1;
56 // When true, return only the values corresponding to the IDs listed in
57 // filtered_ids.
58 bool filter_by_ids = 2;
59 // The list of IDs to use when filter_by_ids is true. Must be empty when
60 // filter_by_ids is false.
61 // NOTE: if this is empty, and filter_by_ids is true, you are saying that
62 // you do not want any information in the result.
63 repeated int64 filtered_ids = 3;
64}
65
66// A sparse representation of a matrix of doubles.
67//
68// The matrix is stored as triples of row id, column id, and coefficient. These
69// three vectors must be of equal length. For all i, the tuple (row_ids[i],
70// column_ids[i]) should be distinct. Entries must be in row major order.
71message SparseDoubleMatrixProto {
72 repeated int64 row_ids = 1;
73 repeated int64 column_ids = 2;
74 // May not contain NaN.
75 repeated double coefficients = 3;
76}
77
78// A sparse representation of a linear expression (a weighted sum of variables,
79// plus a constant offset).
80message LinearExpressionProto {
81 // Ids of variables. Must be sorted (in increasing ordering) with all elements
82 // distinct.
83 repeated int64 ids = 1;
84 // Must have equal length to ids. Values must be finite may not be NaN.
85 repeated double coefficients = 2;
86 // Must be finite and may not be NaN.
87 double offset = 3;
88}