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