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