Google OR-Tools v9.11
a fast and portable software suite for combinatorial optimization
Loading...
Searching...
No Matches
cp_model_postsolve.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_SAT_CP_MODEL_POSTSOLVE_H_
15#define OR_TOOLS_SAT_CP_MODEL_POSTSOLVE_H_
16
17#include <cstdint>
18#include <vector>
19
20#include "ortools/base/types.h"
21#include "ortools/sat/cp_model.pb.h"
24
25namespace operations_research {
26namespace sat {
27
28// Postsolves the given response using information filled by our presolver.
29//
30// This works as follow:
31// - First we fix fixed variables of the mapping_model according to the solution
32// of the presolved problem and the index mapping.
33// - Then, we process the mapping constraints in "reverse" order, and unit
34// propagate each of them when necessary. By construction this should never
35// give rise to any conflicts. And after each constraints, we should have
36// a feasible solution to the presolved problem + all already postsolved
37// constraints. This is the invariant we maintain.
38// - Finally, we arbitrarily fix any free variables left and update the given
39// response with the new solution.
40//
41// Note: Most of the postsolve operations require the constraints to have been
42// written in the correct way by the presolve.
43//
44// TODO(user): We could use the search strategy to fix free variables to some
45// chosen values? The feature might never be needed though.
46void PostsolveResponse(int64_t num_variables_in_original_model,
47 const CpModelProto& mapping_proto,
48 const std::vector<int>& postsolve_mapping,
49 std::vector<int64_t>* solution);
50
51// Try to postsolve with a "best-effort" the reduced domain from the presolved
52// model to the user given model. See the documentation of the CpSolverResponse
53// tightened_variables field for more information on the caveats.
54void FillTightenedDomainInResponse(const CpModelProto& original_model,
55 const CpModelProto& mapping_proto,
56 const std::vector<int>& postsolve_mapping,
57 const std::vector<Domain>& search_domains,
58 CpSolverResponse* response,
59 SolverLogger* logger);
60
61} // namespace sat
62} // namespace operations_research
63
64#endif // OR_TOOLS_SAT_CP_MODEL_POSTSOLVE_H_
double solution
void FillTightenedDomainInResponse(const CpModelProto &original_model, const CpModelProto &mapping_proto, const std::vector< int > &postsolve_mapping, const std::vector< Domain > &search_domains, CpSolverResponse *response, SolverLogger *logger)
void PostsolveResponse(const int64_t num_variables_in_original_model, const CpModelProto &mapping_proto, const std::vector< int > &postsolve_mapping, std::vector< int64_t > *solution)
In SWIG mode, we don't want anything besides these top-level includes.