Google OR-Tools v9.14
a fast and portable software suite for combinatorial optimization
Loading...
Searching...
No Matches
primary_variables.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_PRIMARY_VARIABLES_H_
15#define OR_TOOLS_SAT_PRIMARY_VARIABLES_H_
16
17#include <cstdint>
18#include <utility>
19#include <vector>
20
22
23namespace operations_research {
24namespace sat {
25
26// This structs defines a way of splitting the variables of the model in two
27// groups: primary variables and secondary variables. Those are specified so
28// that the value of secondary_variables[i] is uniquely fixed by applying the
29// constraint dependency_resolution_constraint_index[i] to the values of the
30// primary variables and the values of the variables in the set
31// {secondary_variables[0], ..., secondary_variables[i-1]}.
32//
33// The set of primary variables is implicitly defined by the set of variables
34// that are not in secondary_variables.
35//
36// A useful property of this structure is that given an assignment of primary
37// variables that corresponds to a feasible solution, we can deduce all the
38// values of the secondary variables. Note that if the values of the primary
39// variables are unfeasible, then it might not be possible to deduce the values
40// of the secondary variables.
42 std::vector<int> secondary_variables;
43 std::vector<ConstraintProto> dependency_resolution_constraint;
44
45 // A pair of(x, y) means that one needs to compute the value of y before
46 // computing the value of x. This defines an implicit dependency DAG for
47 // computing the secondary variables from the primary.
48 std::vector<std::pair<int, int>> variable_dependencies;
49
50 // The list of model constraints that are redundant (ie., satisfied by
51 // construction) when the secondary variables are computed from the primary
52 // ones. In other words, a model has a solution for a set of primary
53 // variables {x_i} if and only if all the variable bounds and non-redundant
54 // constraints are satisfied after the secondary variables have been computed
55 // from the primary ones.
57};
58
59// Compute the variable relationships for a given model. Note that there are
60// multiple possible ways variables can be split in primary and secondary, so
61// this function will use an heuristic to try to find as many secondary
62// variables as possible. This runs in linear time in the model size (ie., the
63// sum of the number of variables over the constraints).
65
66// Given a vector with a partial solution where only the primary variables have
67// a correct value, this function will overwrite the values of the secondary
68// variables so that the solution is complete and valid.
70 const CpModelProto& model, const VariableRelationships& relationships,
71 std::vector<int64_t>* solution);
72
73} // namespace sat
74} // namespace operations_research
75
76#endif // OR_TOOLS_SAT_PRIMARY_VARIABLES_H_
bool ComputeAllVariablesFromPrimaryVariables(const CpModelProto &model, const VariableRelationships &relationships, std::vector< int64_t > *solution)
VariableRelationships ComputeVariableRelationships(const CpModelProto &model)
In SWIG mode, we don't want anything besides these top-level includes.
Select next search node to expand Select next item_i to add this new search node to the search Generate a new search node where item_i is not in the knapsack Check validity of this new partial solution(using propagators) - If valid
std::vector< ConstraintProto > dependency_resolution_constraint
std::vector< std::pair< int, int > > variable_dependencies