OR-Tools
8.0
lp_print_utils.h
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
14
// Utilities to display linear expression in a human-readable way.
15
16
#ifndef OR_TOOLS_LP_DATA_LP_PRINT_UTILS_H_
17
#define OR_TOOLS_LP_DATA_LP_PRINT_UTILS_H_
18
19
#include <string>
20
21
#include "absl/strings/str_format.h"
22
#include "
ortools/base/integral_types.h
"
23
#include "
ortools/lp_data/lp_types.h
"
24
25
namespace
operations_research
{
26
namespace
glop {
27
28
// Returns a string representing a floating-point number in decimal,
29
// with a precision corresponding to the type of the argument.
30
inline
std::string
Stringify
(
const
float
a
) {
31
return
absl::StrFormat(
"%.7g"
,
a
);
32
}
33
34
inline
std::string
Stringify
(
const
double
a
) {
35
return
absl::StrFormat(
"%.16g"
,
a
);
36
}
37
38
inline
std::string
Stringify
(
const
long
double
a
) {
39
return
absl::StrFormat(
"%.19g"
,
a
);
40
}
41
42
// Returns a string "num/den" representing the rational approximation of x.
43
// The absolute difference between the output fraction and the input "x" will
44
// not exceed "precision".
45
std::string
StringifyRational
(
const
double
x,
const
double
precision);
46
47
// If fraction is true, returns a string corresponding to the rational
48
// approximation or a decimal approximation otherwise. Note that the absolute
49
// difference between the output fraction and "x" will never exceed
50
// std::numeric_limits<T>::epsilon().
51
std::string
Stringify
(
const
Fractional
x,
bool
fraction);
52
53
// Pretty prints a monomial a*x using Stringify(x, fraction) to display a,
54
// taking care of the sign of x, whether a is 0, 1, -1, integer. Note that the
55
// absolute difference between the output fraction and "x" will never exceed
56
// std::numeric_limits<T>::epsilon().
57
std::string
StringifyMonomial
(
const
Fractional
a
,
const
std::string& x,
58
bool
fraction);
59
60
}
// namespace glop
61
}
// namespace operations_research
62
63
#endif // OR_TOOLS_LP_DATA_LP_PRINT_UTILS_H_
integral_types.h
operations_research::glop::StringifyMonomial
std::string StringifyMonomial(const Fractional a, const std::string &x, bool fraction)
Definition:
lp_print_utils.cc:53
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::glop::Stringify
std::string Stringify(const Fractional x, bool fraction)
Definition:
lp_print_utils.cc:45
operations_research::glop::StringifyRational
std::string StringifyRational(const double x, const double precision)
Definition:
lp_print_utils.cc:32
operations_research::glop::Fractional
double Fractional
Definition:
lp_types.h:77
a
int64 a
Definition:
constraint_solver/table.cc:42
lp_types.h
ortools
lp_data
lp_print_utils.h
Generated by
1.8.18