Google OR-Tools v9.12
a fast and portable software suite for combinatorial optimization
Loading...
Searching...
No Matches
combine_solutions.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 OR_TOOLS_SAT_COMBINE_SOLUTIONS_H_
15#define OR_TOOLS_SAT_COMBINE_SOLUTIONS_H_
16
17#include <cstdint>
18#include <memory>
19#include <optional>
20#include <string>
21#include <vector>
22
23#include "absl/types/span.h"
24#include "ortools/sat/cp_model.pb.h"
25#include "ortools/sat/model.h"
27
28namespace operations_research {
29namespace sat {
30
31// Given a `new_solution` that was created by changing a bit a `base_solution`,
32// try to apply the same changes to the other solutions stored in the
33// `response_manager` and return any such generated solution that is valid.
34std::optional<std::vector<int64_t>> FindCombinedSolution(
35 const CpModelProto& model, absl::Span<const int64_t> new_solution,
36 absl::Span<const int64_t> base_solution,
37 const SharedResponseManager* response_manager, std::string* solution_info);
38
39// This is equivalent to calling SharedResponseManager::NewSolution() then, if
40// `base_solution` is non-empty, trying to find a combined solution and calling
41// SharedResponseManager::NewSolution() again if an improved solution is found.
43 std::shared_ptr<const SharedSolutionRepository<int64_t>::Solution>
45 // nullptr if no improvement was found.
46 std::shared_ptr<const SharedSolutionRepository<int64_t>::Solution>
48};
50 SharedResponseManager* response_manager, const CpModelProto& model_proto,
51 absl::Span<const int64_t> new_solution, const std::string& solution_info,
52 absl::Span<const int64_t> base_solution = {}, Model* model = nullptr);
53
54} // namespace sat
55} // namespace operations_research
56
57#endif // OR_TOOLS_SAT_COMBINE_SOLUTIONS_H_
Definition model.h:341
std::optional< std::vector< int64_t > > FindCombinedSolution(const CpModelProto &model, absl::Span< const int64_t > new_solution, absl::Span< const int64_t > base_solution, const SharedResponseManager *response_manager, std::string *solution_info)
PushedSolutionPointers PushAndMaybeCombineSolution(SharedResponseManager *response_manager, const CpModelProto &model_proto, absl::Span< const int64_t > new_solution, const std::string &solution_info, absl::Span< const int64_t > base_solution, Model *model)
In SWIG mode, we don't want anything besides these top-level includes.
std::shared_ptr< const SharedSolutionRepository< int64_t >::Solution > improved_solution
nullptr if no improvement was found.
std::shared_ptr< const SharedSolutionRepository< int64_t >::Solution > pushed_solution