OR-Tools  9.1
table.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_TABLE_H_
15 #define OR_TOOLS_SAT_TABLE_H_
16 
17 #include <cstdint>
18 #include <functional>
19 #include <vector>
20 
21 #include "absl/types/span.h"
23 #include "ortools/sat/integer.h"
24 #include "ortools/sat/model.h"
25 #include "ortools/sat/sat_base.h"
26 
27 namespace operations_research {
28 namespace sat {
29 
30 // Enforces that the given tuple of variables is equal to one of the given
31 // tuples. All the tuples must have the same size as var.size(), this is
32 // Checked.
33 void AddTableConstraint(absl::Span<const IntegerVariable> vars,
34  std::vector<std::vector<int64_t>> tuples, Model* model);
35 
36 // Enforces that none of the given tuple appear.
37 //
38 // TODO(user): we could propagate more than what we currently do which is simply
39 // adding one clause per tuples.
40 void AddNegatedTableConstraint(absl::Span<const IntegerVariable> vars,
41  std::vector<std::vector<int64_t>> tuples,
42  Model* model);
43 
44 // Enforces that exactly one literal in line_literals is true, and that
45 // all literals in the corresponding line of the literal_tuples matrix are true.
46 // This constraint assumes that exactly one literal per column of the
47 // literal_tuples matrix is true.
48 std::function<void(Model*)> LiteralTableConstraint(
49  const std::vector<std::vector<Literal>>& literal_tuples,
50  const std::vector<Literal>& line_literals);
51 
52 // Given an automaton defined by a set of 3-tuples:
53 // (state, transition_with_value_as_label, next_state)
54 // this accepts the sequences of vars.size() variables that are recognized by
55 // this automaton. That is:
56 // - We start from the initial state.
57 // - For each variable, we move along the transition labeled by this variable
58 // value. Moreover, the variable must take a value that correspond to a
59 // feasible transition.
60 // - We only accept sequences that ends in one of the final states.
61 //
62 // We CHECK that there is only one possible transition for a state/value pair.
63 // See the test for some examples.
64 std::function<void(Model*)> TransitionConstraint(
65  const std::vector<IntegerVariable>& vars,
66  const std::vector<std::vector<int64_t>>& automaton, int64_t initial_state,
67  const std::vector<int64_t>& final_states);
68 
69 } // namespace sat
70 } // namespace operations_research
71 
72 #endif // OR_TOOLS_SAT_TABLE_H_
void AddNegatedTableConstraint(absl::Span< const IntegerVariable > vars, std::vector< std::vector< int64_t >> tuples, Model *model)
Definition: sat/table.cc:460
Class that owns everything related to a particular optimization model.
Definition: sat/model.h:38
std::function< void(Model *)> TransitionConstraint(const std::vector< IntegerVariable > &vars, const std::vector< std::vector< int64_t >> &automaton, int64_t initial_state, const std::vector< int64_t > &final_states)
Definition: table.h:64
GRBmodel * model
void AddTableConstraint(absl::Span< const IntegerVariable > vars, std::vector< std::vector< int64_t >> tuples, Model *model)
Definition: sat/table.cc:250
Collection of objects used to extend the Constraint Solver library.
std::function< void(Model *)> LiteralTableConstraint(const std::vector< std::vector< Literal >> &literal_tuples, const std::vector< Literal > &line_literals)
Definition: table.h:48