OR-Tools  9.3
cp_model_postsolve.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_SAT_CP_MODEL_POSTSOLVE_H_
15#define OR_TOOLS_SAT_CP_MODEL_POSTSOLVE_H_
16
17#include <cstdint>
18#include <vector>
19
21#include "ortools/sat/cp_model.pb.h"
22
23namespace operations_research {
24namespace sat {
25
26// Postsolves the given response using information filled by our presolver.
27//
28// This works as follow:
29// - First we fix fixed variables of the mapping_model according to the solution
30// of the presolved problem and the index mapping.
31// - Then, we process the mapping constraints in "reverse" order, and unit
32// propagate each of them when necessary. By construction this should never
33// give rise to any conflicts. And after each constraints, we should have
34// a feasible solution to the presolved problem + all already postsolved
35// constraints. This is the invariant we maintain.
36// - Finally, we arbitrarily fix any free variables left and update the given
37// response with the new solution.
38//
39// Note: Most of the postsolve operations require the constraints to have been
40// written in the correct way by the presolve.
41//
42// TODO(user): We could use the search strategy to fix free variables to some
43// chosen values? The feature might never be needed though.
44void PostsolveResponse(const int64_t num_variables_in_original_model,
45 const CpModelProto& mapping_proto,
46 const std::vector<int>& postsolve_mapping,
47 std::vector<int64_t>* solution);
48
49} // namespace sat
50} // namespace operations_research
51
52#endif // OR_TOOLS_SAT_CP_MODEL_POSTSOLVE_H_
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)
Collection of objects used to extend the Constraint Solver library.