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