Google OR-Tools v9.15
a fast and portable software suite for combinatorial optimization
Loading...
Searching...
No Matches
solution.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// The solution to an optimization model.
15
16syntax = "proto3";
17
18package operations_research.service.v1.mathopt;
19
20import "ortools/service/v1/mathopt/sparse_containers.proto";
21
22option java_multiple_files = true;
23option java_package = "com.google.ortools.service.v1.mathopt";
24
25option csharp_namespace = "Google.OrTools.Service";
26
27// Feasibility of a primal or dual solution as claimed by the solver.
28enum SolutionStatusProto {
29 // Guard value representing no status.
30 SOLUTION_STATUS_UNSPECIFIED = 0;
31
32 // Solver does not claim a feasibility status.
33 SOLUTION_STATUS_UNDETERMINED = 1;
34
35 // Solver claims the solution is feasible.
36 SOLUTION_STATUS_FEASIBLE = 2;
37
38 // Solver claims the solution is infeasible.
39 SOLUTION_STATUS_INFEASIBLE = 3;
40}
41
42// A solution to an optimization problem.
43//
44// E.g. consider a simple linear program:
45// min c * x
46// s.t. A * x >= b
47// x >= 0.
48// A primal solution is assignment values to x. It is feasible if it satisfies
49// A * x >= b and x >= 0 from above. In the message PrimalSolutionProto below,
50// variable_values is x and objective_value is c * x.
51message PrimalSolutionProto {
52 // Requirements:
53 // * variable_values.ids are elements of VariablesProto.ids.
54 // * variable_values.values must all be finite.
55 SparseDoubleVectorProto variable_values = 1;
56
57 // Objective value as computed by the underlying solver. Cannot be infinite or
58 // NaN.
59 double objective_value = 2;
60
61 // Auxiliary objective values as computed by the underlying solver. Keys must
62 // be valid auxiliary objective IDs. Values cannot be infinite or NaN.
63 map<int64, double> auxiliary_objective_values = 4;
64
65 // Feasibility status of the solution according to the underlying solver.
66 SolutionStatusProto feasibility_status = 3;
67}
68
69// A direction of unbounded improvement to an optimization problem;
70// equivalently, a certificate of infeasibility for the dual of the
71// optimization problem.
72//
73// E.g. consider a simple linear program:
74// min c * x
75// s.t. A * x >= b
76// x >= 0
77// A primal ray is an x that satisfies:
78// c * x < 0
79// A * x >= 0
80// x >= 0
81// Observe that given a feasible solution, any positive multiple of the primal
82// ray plus that solution is still feasible, and gives a better objective
83// value. A primal ray also proves the dual optimization problem infeasible.
84//
85// In the message PrimalRay below, variable_values is x.
86message PrimalRayProto {
87 // Requirements:
88 // * variable_values.ids are elements of VariablesProto.ids.
89 // * variable_values.values must all be finite.
90 SparseDoubleVectorProto variable_values = 1;
91
92 // TODO(b/185365397): indicate if the ray is feasible.
93}
94
95// A solution to the dual of an optimization problem.
96//
97// E.g. consider the primal dual pair linear program pair:
98// (Primal) (Dual)
99// min c * x max b * y
100// s.t. A * x >= b s.t. y * A + r = c
101// x >= 0 y, r >= 0.
102// The dual solution is the pair (y, r). It is feasible if it satisfies the
103// constraints from (Dual) above.
104//
105// In the message below, y is dual_values, r is reduced_costs, and
106// b * y is objective value.
107message DualSolutionProto {
108 // Requirements:
109 // * dual_values.ids are elements of LinearConstraints.ids.
110 // * dual_values.values must all be finite.
111 SparseDoubleVectorProto dual_values = 1;
112
113 // Requirements:
114 // * reduced_costs.ids are elements of VariablesProto.ids.
115 // * reduced_costs.values must all be finite.
116 SparseDoubleVectorProto reduced_costs = 2;
117
118 // TODO(b/195295177): consider making this non-optional
119 // Objective value as computed by the underlying solver.
120 optional double objective_value = 3;
121
122 // Feasibility status of the solution according to the underlying solver.
123 SolutionStatusProto feasibility_status = 4;
124}
125
126// A direction of unbounded improvement to the dual of an optimization,
127// problem; equivalently, a certificate of primal infeasibility.
128//
129// E.g. consider the primal dual pair linear program pair:
130// (Primal) (Dual)
131// min c * x max b * y
132// s.t. A * x >= b s.t. y * A + r = c
133// x >= 0 y, r >= 0.
134// The dual ray is the pair (y, r) satisfying:
135// b * y > 0
136// y * A + r = 0
137// y, r >= 0
138// Observe that adding a positive multiple of (y, r) to dual feasible solution
139// maintains dual feasibility and improves the objective (proving the dual is
140// unbounded). The dual ray also proves the primal problem is infeasible.
141//
142// In the message DualRay below, y is dual_values and r is reduced_costs.
143message DualRayProto {
144 // Requirements:
145 // * dual_values.ids are elements of LinearConstraints.ids.
146 // * dual_values.values must all be finite.
147 SparseDoubleVectorProto dual_values = 1;
148
149 // Requirements:
150 // * reduced_costs.ids are elements of VariablesProto.ids.
151 // * reduced_costs.values must all be finite.
152 SparseDoubleVectorProto reduced_costs = 2;
153
154 // TODO(b/185365397): indicate if the ray is feasible.
155}
156
157// Status of a variable/constraint in a LP basis.
158enum BasisStatusProto {
159 // Guard value representing no status.
160 BASIS_STATUS_UNSPECIFIED = 0;
161
162 // The variable/constraint is free (it has no finite bounds).
163 BASIS_STATUS_FREE = 1;
164
165 // The variable/constraint is at its lower bound (which must be finite).
166 BASIS_STATUS_AT_LOWER_BOUND = 2;
167
168 // The variable/constraint is at its upper bound (which must be finite).
169 BASIS_STATUS_AT_UPPER_BOUND = 3;
170
171 // The variable/constraint has identical finite lower and upper bounds.
172 BASIS_STATUS_FIXED_VALUE = 4;
173
174 // The variable/constraint is basic.
175 BASIS_STATUS_BASIC = 5;
176}
177
178// A sparse representation of a vector of basis statuses.
179message SparseBasisStatusVector {
180 // Must be sorted (in increasing ordering) with all elements distinct.
181 repeated int64 ids = 1;
182
183 // Must have equal length to ids.
184 repeated BasisStatusProto values = 2;
185}
186
187// A combinatorial characterization for a solution to a linear program.
188//
189// The simplex method for solving linear programs always returns a "basic
190// feasible solution" which can be described combinatorially by a Basis. A basis
191// assigns a BasisStatusProto for every variable and linear constraint.
192//
193// E.g. consider a standard form LP:
194// min c * x
195// s.t. A * x = b
196// x >= 0
197// that has more variables than constraints and with full row rank A.
198//
199// Let n be the number of variables and m the number of linear constraints. A
200// valid basis for this problem can be constructed as follows:
201// * All constraints will have basis status FIXED.
202// * Pick m variables such that the columns of A are linearly independent and
203// assign the status BASIC.
204// * Assign the status AT_LOWER for the remaining n - m variables.
205//
206// The basic solution for this basis is the unique solution of A * x = b that
207// has all variables with status AT_LOWER fixed to their lower bounds (all
208// zero). The resulting solution is called a basic feasible solution if it also
209// satisfies x >= 0.
210message BasisProto {
211 // Constraint basis status.
212 //
213 // Requirements:
214 // * constraint_status.ids is equal to LinearConstraints.ids.
215 SparseBasisStatusVector constraint_status = 1;
216
217 // Variable basis status.
218 //
219 // Requirements:
220 // * constraint_status.ids is equal to VariablesProto.ids.
221 SparseBasisStatusVector variable_status = 2;
222
223 // This is an advanced feature used by MathOpt to characterize feasibility of
224 // suboptimal LP solutions (optimal solutions will always have status
225 // SOLUTION_STATUS_FEASIBLE).
226 //
227 // For single-sided LPs it should be equal to the feasibility status of the
228 // associated dual solution. For two-sided LPs it may be different in some
229 // edge cases (e.g. incomplete solves with primal simplex).
230 //
231 // If you are providing a starting basis via
232 // ModelSolveParametersProto.initial_basis, this value is ignored. It is only
233 // relevant for the basis returned by SolutionProto.basis.
234 SolutionStatusProto basic_dual_feasibility = 3;
235}
236
237// What is included in a solution depends on the kind of problem and solver.
238// The current common patterns are
239// 1. MIP solvers return only a primal solution.
240// 2. Simplex LP solvers often return a basis and the primal and dual
241// solutions associated to this basis.
242// 3. Other continuous solvers often return a primal and dual solution
243// solution that are connected in a solver-dependent form.
244//
245// Requirements:
246// * at least one field must be set; a solution can't be empty.
247message SolutionProto {
248 optional PrimalSolutionProto primal_solution = 1;
249 optional DualSolutionProto dual_solution = 2;
250 optional BasisProto basis = 3;
251}