OR-Tools  9.3
drat_writer.cc
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
15
16#include <string>
17
19#if !defined(__PORTABLE_PLATFORM__)
20#include "ortools/base/file.h"
21#endif // !__PORTABLE_PLATFORM__
22#include "absl/status/status.h"
23#include "absl/strings/str_format.h"
24#include "absl/types/span.h"
26
27namespace operations_research {
28namespace sat {
29
31 if (output_ != nullptr) {
32#if !defined(__PORTABLE_PLATFORM__)
33 CHECK_OK(file::WriteString(output_, buffer_, file::Defaults()));
34 CHECK_OK(output_->Close(file::Defaults()));
35#endif // !__PORTABLE_PLATFORM__
36 }
37}
38
39void DratWriter::AddClause(absl::Span<const Literal> clause) {
40 WriteClause(clause);
41}
42
43void DratWriter::DeleteClause(absl::Span<const Literal> clause) {
44 buffer_ += "d ";
45 WriteClause(clause);
46}
47
48void DratWriter::WriteClause(absl::Span<const Literal> clause) {
49 for (const Literal literal : clause) {
50 absl::StrAppendFormat(&buffer_, "%d ", literal.SignedValue());
51 }
52 buffer_ += "0\n";
53 if (buffer_.size() > 10000) {
54#if !defined(__PORTABLE_PLATFORM__)
55 CHECK_OK(file::WriteString(output_, buffer_, file::Defaults()));
56#endif // !__PORTABLE_PLATFORM__
57 buffer_.clear();
58 }
59}
60
61} // namespace sat
62} // namespace operations_research
#define CHECK_OK(x)
Definition: base/logging.h:44
bool Close()
Definition: base/file.cc:48
void DeleteClause(absl::Span< const Literal > clause)
Definition: drat_writer.cc:43
void AddClause(absl::Span< const Literal > clause)
Definition: drat_writer.cc:39
absl::Status WriteString(File *file, const absl::string_view &contents, int flags)
Definition: base/file.cc:184
int Defaults()
Definition: base/file.h:120
Collection of objects used to extend the Constraint Solver library.
Literal literal
Definition: optimization.cc:89