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