OR-Tools  8.1
drat_writer.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_DRAT_WRITER_H_
15 #define OR_TOOLS_SAT_DRAT_WRITER_H_
16 
17 #include <string>
18 
19 #if !defined(__PORTABLE_PLATFORM__)
20 #include "ortools/base/file.h"
21 #else
22 class File {};
23 #endif // !__PORTABLE_PLATFORM__
24 #include "absl/types/span.h"
25 #include "ortools/sat/sat_base.h"
26 
27 namespace operations_research {
28 namespace sat {
29 
30 // DRAT is a SAT proof format that allows a simple program to check that the
31 // problem is really UNSAT. The description of the format and a checker are
32 // available at: // http://www.cs.utexas.edu/~marijn/drat-trim/
33 //
34 // Note that DRAT proofs are often huge (can be GB), and take about as much time
35 // to check as it takes for the solver to find the proof in the first place!
36 class DratWriter {
37  public:
38  DratWriter(bool in_binary_format, File* output)
39  : in_binary_format_(in_binary_format), output_(output) {}
40  ~DratWriter();
41 
42  // Writes a new clause to the DRAT output. Note that the RAT property is only
43  // checked on the first literal.
44  void AddClause(absl::Span<const Literal> clause);
45 
46  // Writes a "deletion" information about a clause that has been added before
47  // to the DRAT output. Note that it is also possible to delete a clause from
48  // the problem.
49  void DeleteClause(absl::Span<const Literal> clause);
50 
51  private:
52  void WriteClause(absl::Span<const Literal> clause);
53 
54  // TODO(user): Support binary format as proof in text format can be large.
55  bool in_binary_format_;
56  File* output_;
57 
58  std::string buffer_;
59 };
60 
61 } // namespace sat
62 } // namespace operations_research
63 
64 #endif // OR_TOOLS_SAT_DRAT_WRITER_H_
operations_research::sat::DratWriter
Definition: drat_writer.h:36
operations_research
The vehicle routing library lets one model and solve generic vehicle routing problems ranging from th...
Definition: dense_doubly_linked_list.h:21
sat_base.h
file.h
operations_research::sat::DratWriter::DeleteClause
void DeleteClause(absl::Span< const Literal > clause)
Definition: drat_writer.cc:40
File
Definition: base/file.h:32
operations_research::sat::DratWriter::~DratWriter
~DratWriter()
Definition: drat_writer.cc:27
operations_research::sat::DratWriter::DratWriter
DratWriter(bool in_binary_format, File *output)
Definition: drat_writer.h:38
operations_research::sat::DratWriter::AddClause
void AddClause(absl::Span< const Literal > clause)
Definition: drat_writer.cc:36