OR-Tools  8.1
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"
19 #include "ortools/base/logging.h"
20 #if !defined(__PORTABLE_PLATFORM__)
21 #endif // !__PORTABLE_PLATFORM__
22 #include "absl/status/status.h"
23 
24 namespace operations_research {
25 namespace 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 
36 void DratWriter::AddClause(absl::Span<const Literal> clause) {
37  WriteClause(clause);
38 }
39 
40 void DratWriter::DeleteClause(absl::Span<const Literal> clause) {
41  buffer_ += "d ";
42  WriteClause(clause);
43 }
44 
45 void 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
drat_writer.h
CHECK_OK
#define CHECK_OK(x)
Definition: base/logging.h:40
File::Close
bool Close()
Definition: file.cc:48
file::WriteString
absl::Status WriteString(File *file, const absl::string_view &contents, int flags)
Definition: file.cc:176
logging.h
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
operations_research::sat::DratWriter::DeleteClause
void DeleteClause(absl::Span< const Literal > clause)
Definition: drat_writer.cc:40
operations_research::sat::DratWriter::~DratWriter
~DratWriter()
Definition: drat_writer.cc:27
operations_research::sat::Literal
Definition: sat_base.h:64
file::Defaults
int Defaults()
Definition: base/file.h:119
literal
Literal literal
Definition: optimization.cc:84
operations_research::sat::DratWriter::AddClause
void AddClause(absl::Span< const Literal > clause)
Definition: drat_writer.cc:36