OR-Tools  9.1
result.cc
Go to the documentation of this file.
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 
15 
16 #include <string>
17 #include <utility>
18 #include <vector>
19 
21 #include "ortools/math_opt/result.pb.h"
22 
23 namespace operations_research {
24 namespace math_opt {
25 
27  IndexedPrimalSolution indexed_solution)
28  : variable_values(model, std::move(indexed_solution.variable_values)),
29  objective_value(indexed_solution.objective_value) {}
30 
32  IndexedPrimalRay indexed_ray)
33  : variable_values(model, std::move(indexed_ray.variable_values)) {}
34 
36  IndexedDualSolution indexed_solution)
37  : dual_values(model, std::move(indexed_solution.dual_values)),
38  reduced_costs(model, std::move(indexed_solution.reduced_costs)),
39  objective_value(indexed_solution.objective_value) {}
40 
42  : dual_values(model, std::move(indexed_ray.dual_values)),
43  reduced_costs(model, std::move(indexed_ray.reduced_costs)) {}
44 
46  : constraint_status(model, std::move(indexed_basis.constraint_status)),
47  variable_status(model, std::move(indexed_basis.variable_status)) {}
48 
49 Result::Result(IndexedModel* const model, const SolveResultProto& solve_result)
50  : warnings(solve_result.warnings().begin(), solve_result.warnings().end()),
51  termination_reason(solve_result.termination_reason()),
52  termination_detail(solve_result.termination_detail()),
53  solve_stats(solve_result.solve_stats()) {
54  IndexedSolutions solutions = IndexedSolutionsFromProto(solve_result);
55  for (auto& primal_solution : solutions.primal_solutions) {
56  primal_solutions.emplace_back(model, std::move(primal_solution));
57  }
58  for (auto& primal_ray : solutions.primal_rays) {
59  primal_rays.emplace_back(model, std::move(primal_ray));
60  }
61  for (auto& dual_solution : solutions.dual_solutions) {
62  dual_solutions.emplace_back(model, std::move(dual_solution));
63  }
64  for (auto& dual_ray : solutions.dual_rays) {
65  dual_rays.emplace_back(model, std::move(dual_ray));
66  }
67  for (auto& base : solutions.basis) {
68  basis.emplace_back(model, std::move(base));
69  }
70 }
71 
72 } // namespace math_opt
73 } // namespace operations_research
std::vector< IndexedPrimalSolution > primal_solutions
SolveResultProto::TerminationReason termination_reason
Definition: result.h:270
const VariableMap< double > & reduced_costs() const
Definition: result.h:227
std::vector< IndexedDualSolution > dual_solutions
GRBmodel * model
std::vector< std::string > warnings
Definition: result.h:269
const VariableMap< BasisStatus > & variable_status() const
Definition: result.h:264
std::vector< DualSolution > dual_solutions
Definition: result.h:280
std::vector< Basis > basis
Definition: result.h:287
std::vector< PrimalSolution > primal_solutions
Definition: result.h:276
const LinearConstraintMap< BasisStatus > & constraint_status() const
Definition: result.h:258
IndexedSolutions IndexedSolutionsFromProto(const SolveResultProto &solve_result)
Result(IndexedModel *model, const SolveResultProto &solve_result)
Definition: result.cc:49
std::vector< PrimalRay > primal_rays
Definition: result.h:277
const LinearConstraintMap< double > & dual_values() const
Definition: result.h:217
Collection of objects used to extend the Constraint Solver library.
std::vector< DualRay > dual_rays
Definition: result.h:281
std::vector< IndexedPrimalRay > primal_rays
const VariableMap< double > & variable_values() const
Definition: result.h:191