Google OR-Tools v9.15
a fast and portable software suite for combinatorial optimization
Loading...
Searching...
No Matches
glop_solver.h
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#ifndef ORTOOLS_MATH_OPT_SOLVERS_GLOP_SOLVER_H_
15#define ORTOOLS_MATH_OPT_SOLVERS_GLOP_SOLVER_H_
16
17#include <stdint.h>
18
19#include <memory>
20
21#include "absl/base/nullability.h"
22#include "absl/container/flat_hash_map.h"
23#include "absl/status/status.h"
24#include "absl/status/statusor.h"
25#include "absl/time/time.h"
26#include "absl/types/span.h"
43
44namespace operations_research {
45namespace math_opt {
46
47class GlopSolver : public SolverInterface {
48 public:
49 static absl::StatusOr<std::unique_ptr<SolverInterface>> New(
50 const ModelProto& model, const InitArgs& init_args);
51
52 absl::StatusOr<SolveResultProto> Solve(
53 const SolveParametersProto& parameters,
54 const ModelSolveParametersProto& model_parameters,
55 MessageCallback message_cb,
56 const CallbackRegistrationProto& callback_registration, Callback cb,
57 const SolveInterrupter* absl_nullable interrupter) override;
58 absl::StatusOr<bool> Update(const ModelUpdateProto& model_update) override;
59 absl::StatusOr<ComputeInfeasibleSubsystemResultProto>
61 const SolveParametersProto& parameters, MessageCallback message_cb,
62 const SolveInterrupter* absl_nullable interrupter) override;
63
64 // Returns the merged parameters and a list of warnings from any parameter
65 // settings that are invalid for this solver.
66 static absl::StatusOr<glop::GlopParameters> MergeSolveParameters(
67 const SolveParametersProto& solve_parameters, bool setting_initial_basis,
68 bool has_message_callback, bool is_maximization);
69
70 private:
71 GlopSolver();
72
73 void AddVariables(const VariablesProto& variables);
74 void AddLinearConstraints(const LinearConstraintsProto& linear_constraints);
75
76 void DeleteVariables(absl::Span<const int64_t> ids_to_delete);
77 void DeleteLinearConstraints(absl::Span<const int64_t> ids_to_delete);
78
79 void SetOrUpdateObjectiveCoefficients(
80 const SparseDoubleVectorProto& linear_objective_coefficients);
81 void SetOrUpdateConstraintMatrix(
82 const SparseDoubleMatrixProto& linear_constraint_matrix);
83
84 void UpdateVariableBounds(const VariableUpdatesProto& variable_updates);
85 void UpdateLinearConstraintBounds(
86 const LinearConstraintUpdatesProto& linear_constraint_updates);
87
88 // Returns the ids of variables and linear constraints with inverted bounds.
89 InvertedBounds ListInvertedBounds() const;
90
91 void FillSolution(glop::ProblemStatus status,
92 const ModelSolveParametersProto& model_parameters,
93 SolveResultProto& solve_result);
94 absl::StatusOr<SolveResultProto> MakeSolveResult(
96 const ModelSolveParametersProto& model_parameters,
97 const SolveInterrupter* absl_nullable interrupter,
98 absl::Duration solve_time);
99
100 absl::Status FillSolveStats(absl::Duration solve_time,
101 SolveStatsProto& solve_stats);
102
103 void SetGlopBasis(const BasisProto& basis);
104
105 glop::LinearProgram linear_program_;
106 glop::LPSolver lp_solver_;
107
108 absl::flat_hash_map<int64_t, glop::ColIndex> variables_;
109 absl::flat_hash_map<int64_t, glop::RowIndex> linear_constraints_;
110};
111
112} // namespace math_opt
113} // namespace operations_research
114
115#endif // ORTOOLS_MATH_OPT_SOLVERS_GLOP_SOLVER_H_
absl::StatusOr< ComputeInfeasibleSubsystemResultProto > ComputeInfeasibleSubsystem(const SolveParametersProto &parameters, MessageCallback message_cb, const SolveInterrupter *absl_nullable interrupter) override
absl::StatusOr< bool > Update(const ModelUpdateProto &model_update) override
absl::StatusOr< SolveResultProto > Solve(const SolveParametersProto &parameters, const ModelSolveParametersProto &model_parameters, MessageCallback message_cb, const CallbackRegistrationProto &callback_registration, Callback cb, const SolveInterrupter *absl_nullable interrupter) override
static absl::StatusOr< glop::GlopParameters > MergeSolveParameters(const SolveParametersProto &solve_parameters, bool setting_initial_basis, bool has_message_callback, bool is_maximization)
static absl::StatusOr< std::unique_ptr< SolverInterface > > New(const ModelProto &model, const InitArgs &init_args)
std::function< void(const std::vector< std::string > &)> MessageCallback
std::function< absl::StatusOr< CallbackResultProto >( const CallbackDataProto &)> Callback
OR-Tools root namespace.