OR-Tools  8.2
drat_writer.cc
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
15
16#include <cstdlib>
17
18#include "absl/strings/str_format.h"
20#if !defined(__PORTABLE_PLATFORM__)
21#endif // !__PORTABLE_PLATFORM__
22#include "absl/status/status.h"
23
24namespace operations_research {
25namespace sat {
26
28 if (output_ != nullptr) {
29#if !defined(__PORTABLE_PLATFORM__)
30 CHECK_OK(file::WriteString(output_, buffer_, file::Defaults()));
31 CHECK_OK(output_->Close(file::Defaults()));
32#endif // !__PORTABLE_PLATFORM__
33 }
34}
35
36void DratWriter::AddClause(absl::Span<const Literal> clause) {
37 WriteClause(clause);
38}
39
40void DratWriter::DeleteClause(absl::Span<const Literal> clause) {
41 buffer_ += "d ";
42 WriteClause(clause);
43}
44
45void DratWriter::WriteClause(absl::Span<const Literal> clause) {
46 for (const Literal literal : clause) {
47 absl::StrAppendFormat(&buffer_, "%d ", literal.SignedValue());
48 }
49 buffer_ += "0\n";
50 if (buffer_.size() > 10000) {
51#if !defined(__PORTABLE_PLATFORM__)
52 CHECK_OK(file::WriteString(output_, buffer_, file::Defaults()));
53#endif // !__PORTABLE_PLATFORM__
54 buffer_.clear();
55 }
56}
57
58} // namespace sat
59} // namespace operations_research
#define CHECK_OK(x)
Definition: base/logging.h:40
bool Close()
Definition: file.cc:48
void DeleteClause(absl::Span< const Literal > clause)
Definition: drat_writer.cc:40
void AddClause(absl::Span< const Literal > clause)
Definition: drat_writer.cc:36
absl::Status WriteString(File *file, const absl::string_view &contents, int flags)
Definition: file.cc:184
int Defaults()
Definition: base/file.h:119
The vehicle routing library lets one model and solve generic vehicle routing problems ranging from th...
Literal literal
Definition: optimization.cc:84