Google OR-Tools v9.11
a fast and portable software suite for combinatorial optimization
Loading...
Searching...
No Matches
cp_sat_solver.h
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#ifndef OR_TOOLS_MATH_OPT_SOLVERS_CP_SAT_SOLVER_H_
15#define OR_TOOLS_MATH_OPT_SOLVERS_CP_SAT_SOLVER_H_
16
17#include <cstdint>
18#include <memory>
19#include <vector>
20
21#include "absl/status/statusor.h"
22#include "absl/types/span.h"
23#include "ortools/linear_solver/linear_solver.pb.h"
24#include "ortools/math_opt/callback.pb.h"
27#include "ortools/math_opt/infeasible_subsystem.pb.h"
28#include "ortools/math_opt/model.pb.h"
29#include "ortools/math_opt/model_parameters.pb.h"
30#include "ortools/math_opt/model_update.pb.h"
31#include "ortools/math_opt/parameters.pb.h"
32#include "ortools/math_opt/result.pb.h"
33#include "ortools/math_opt/sparse_containers.pb.h"
35
36namespace operations_research {
37namespace math_opt {
38
40 public:
41 static absl::StatusOr<std::unique_ptr<SolverInterface>> New(
42 const ModelProto& model, const InitArgs& init_args);
43
44 absl::StatusOr<SolveResultProto> Solve(
45 const SolveParametersProto& parameters,
46 const ModelSolveParametersProto& model_parameters,
47 MessageCallback message_cb,
48 const CallbackRegistrationProto& callback_registration, Callback cb,
49 const SolveInterrupter* interrupter) override;
50 absl::StatusOr<bool> Update(const ModelUpdateProto& model_update) override;
51 absl::StatusOr<ComputeInfeasibleSubsystemResultProto>
52 ComputeInfeasibleSubsystem(const SolveParametersProto& parameters,
53 MessageCallback message_cb,
54 const SolveInterrupter* interrupter) override;
55
56 private:
57 CpSatSolver(MPModelProto cp_sat_model, std::vector<int64_t> variable_ids,
58 std::vector<int64_t> linear_constraint_ids);
59
60 // Extract the solution from CP-SAT's response.
61 SparseDoubleVectorProto ExtractSolution(
62 absl::Span<const double> cp_sat_variable_values,
63 const SparseVectorFilterProto& filter) const;
64
65 // Returns the ids of variables and linear constraints with inverted bounds.
66 InvertedBounds ListInvertedBounds() const;
67
68 const MPModelProto cp_sat_model_;
69
70 // For the i-th variable in `cp_sat_model_`, `variable_ids_[i]` contains the
71 // corresponding id in the input `Model`.
72 const std::vector<int64_t> variable_ids_;
73
74 // For the i-th linear constraint in `cp_sat_model_`,
75 // `linear_constraint_ids_[i]` contains the corresponding id in the input
76 // `Model`.
77 const std::vector<int64_t> linear_constraint_ids_;
78};
79
80} // namespace math_opt
81} // namespace operations_research
82
83#endif // OR_TOOLS_MATH_OPT_SOLVERS_CP_SAT_SOLVER_H_
absl::StatusOr< SolveResultProto > Solve(const SolveParametersProto &parameters, const ModelSolveParametersProto &model_parameters, MessageCallback message_cb, const CallbackRegistrationProto &callback_registration, Callback cb, const SolveInterrupter *interrupter) override
absl::StatusOr< ComputeInfeasibleSubsystemResultProto > ComputeInfeasibleSubsystem(const SolveParametersProto &parameters, MessageCallback message_cb, const SolveInterrupter *interrupter) override
static absl::StatusOr< std::unique_ptr< SolverInterface > > New(const ModelProto &model, const InitArgs &init_args)
absl::StatusOr< bool > Update(const ModelUpdateProto &model_update) override
std::function< void(const std::vector< std::string > &)> MessageCallback
std::function< absl::StatusOr< CallbackResultProto >( const CallbackDataProto &)> Callback
SatParameters parameters
absl::Span< const int64_t > variable_ids
GRBmodel * model
In SWIG mode, we don't want anything besides these top-level includes.