Google OR-Tools v9.11
a fast and portable software suite for combinatorial optimization
Loading...
Searching...
No Matches
drat_writer.cc
Go to the documentation of this file.
1// Copyright 2010-2024 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#if !defined(__PORTABLE_PLATFORM__)
18#include "ortools/base/file.h"
21#endif // !__PORTABLE_PLATFORM__
22#include "absl/log/check.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
bool Close()
Closes the file.
Definition file.cc:66
void DeleteClause(absl::Span< const Literal > clause)
void AddClause(absl::Span< const Literal > clause)
int literal
absl::Status WriteString(File *file, absl::string_view contents, Options options)
Definition file.cc:231
Options Defaults()
Definition file.h:109
In SWIG mode, we don't want anything besides these top-level includes.