Google OR-Tools v9.15
a fast and portable software suite for combinatorial optimization
Loading...
Searching...
No Matches
sat_proto_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_LINEAR_SOLVER_PROTO_SOLVER_SAT_PROTO_SOLVER_H_
15#define ORTOOLS_LINEAR_SOLVER_PROTO_SOLVER_SAT_PROTO_SOLVER_H_
16
17#include <atomic>
18#include <functional>
19#include <string>
20
23#include "ortools/sat/model.h"
26
27namespace operations_research {
28
29// Solve the input MIP model with the SAT solver.
30//
31// If possible, std::move the request into this function call to avoid a copy.
32//
33// If you need to change the solver parameters, please use the
34// EncodeParametersAsString() function to set the request's
35// solver_specific_parameters field.
36//
37// The optional interrupt_solve can be used to interrupt the solve early. It
38// must only be set to true, never reset to false. It is also used internally by
39// the solver that will set it to true for its own internal logic. As a
40// consequence the caller should ignore the stored value and should not use the
41// same atomic for different concurrent calls.
42//
43// The optional logging_callback will be called when the SAT parameter
44// log_search_progress is set to true. Passing a callback will disable the
45// default logging to INFO. Note though that by default the SAT parameter
46// log_to_stdout is true so even with a callback, the logs will appear on stdout
47// too unless log_to_stdout is set to false. The enable_internal_solver_output
48// in the request will act as the SAT parameter log_search_progress.
49//
50// The optional solution_callback will be called on each intermediate solution
51// found by the solver. The solver may call solution_callback from multiple
52// threads, but it will ensure that at most one thread executes
53// solution_callback at a time.
54//
55// The optional best_bound_callback will be called each time the best bound is
56// improved. The solver may call solution_callback from multiple
57// threads, but it will ensure that at most one thread executes
58// solution_callback at a time. It is guaranteed that the best bound is strictly
59// improving.
62 std::atomic<bool>* interrupt_solve = nullptr,
63 std::function<void(const std::string&)> logging_callback = nullptr,
64 std::function<void(const MPSolution&)> solution_callback = nullptr,
65 std::function<void(const double)> best_bound_callback = nullptr);
66
67// Returns a string that describes the version of the CP-SAT solver.
68std::string SatSolverVersion();
69
70// Internal version of SatSolveProto that can configure a sat::Model object
71// before the solve and return the CpSolverResponse proto to extract statistics.
74 sat::CpSolverResponse* cp_response,
75 std::function<void(const MPSolution&)> solution_callback = nullptr);
76
77} // namespace operations_research
78
79#endif // ORTOOLS_LINEAR_SOLVER_PROTO_SOLVER_SAT_PROTO_SOLVER_H_
OR-Tools root namespace.
std::string SatSolverVersion()
MPSolutionResponse SatSolveProto(LazyMutableCopy< MPModelRequest > request, std::atomic< bool > *interrupt_solve, std::function< void(const std::string &)> logging_callback, std::function< void(const MPSolution &)> solution_callback, std::function< void(const double)> best_bound_callback)
MPSolutionResponse SatSolveProtoInternal(LazyMutableCopy< MPModelRequest > request, sat::Model *sat_model, sat::CpSolverResponse *cp_response, std::function< void(const MPSolution &)> solution_callback)