OR-Tools  9.3
sat_proto_solver.h
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
14#ifndef OR_TOOLS_LINEAR_SOLVER_SAT_PROTO_SOLVER_H_
15#define OR_TOOLS_LINEAR_SOLVER_SAT_PROTO_SOLVER_H_
16
17#include <functional>
18#include <string>
19
20#include "absl/status/statusor.h"
21#include "ortools/linear_solver/linear_solver.pb.h"
22#include "ortools/sat/sat_parameters.pb.h"
24
25namespace operations_research {
26
27// Solve the input MIP model with the SAT solver.
28//
29// If possible, std::move the request into this function call to avoid a copy.
30//
31// If you need to change the solver parameters, please use the
32// EncodeSatParametersAsString() function below to set the request's
33// solver_specific_parameters field.
34//
35// The optional interrupt_solve can be used to interrupt the solve early. It
36// must only be set to true, never reset to false. It is also used internally by
37// the solver that will set it to true for its own internal logic. As a
38// consequence the caller should ignore the stored value and should not use the
39// same atomic for different concurrent calls.
40//
41// The optional logging_callback will be called when the SAT parameter
42// log_search_progress is set to true. Passing a callback will disable the
43// default logging to INFO. Note though that by default the SAT parameter
44// log_to_stdout is true so even with a callback, the logs will appear on stdout
45// too unless log_to_stdout is set to false. The enable_internal_solver_output
46// in the request will act as the SAT parameter log_search_progress.
47//
48// The optional solution_callback will be called on each intermediate solution
49// found by the solver. The solver may call solution_callback from multiple
50// threads, but it will ensure that at most one thread executes
51// solution_callback at a time.
52absl::StatusOr<MPSolutionResponse> SatSolveProto(
53 MPModelRequest request, std::atomic<bool>* interrupt_solve = nullptr,
54 std::function<void(const std::string&)> logging_callback = nullptr,
55 std::function<void(const MPSolution&)> solution_callback = nullptr);
56
57// Returns a string that should be used in MPModelRequest's
58// solver_specific_parameters field to encode the SAT parameters.
59//
60// The returned string's content depends on the version of the proto library
61// that is linked in the binary.
62//
63// By default it will contain the textual representation of the input proto.
64// But when the proto-lite is used, it will contain the binary stream of the
65// proto instead since it is not possible to build the textual representation in
66// that case.
67//
68// The SatSolveProto() function will test if the proto-lite is used and expect a
69// binary stream when it is the case. So in order for your code to be portable,
70// you should always use this function to set the specific parameters.
71std::string EncodeSatParametersAsString(const sat::SatParameters& parameters);
72
73} // namespace operations_research
74
75#endif // OR_TOOLS_LINEAR_SOLVER_SAT_PROTO_SOLVER_H_
SatParameters parameters
Collection of objects used to extend the Constraint Solver library.
absl::StatusOr< MPSolutionResponse > SatSolveProto(MPModelRequest request, std::atomic< bool > *interrupt_solve, std::function< void(const std::string &)> logging_callback, std::function< void(const MPSolution &)> solution_callback)
std::string EncodeSatParametersAsString(const sat::SatParameters &parameters)