export from google3

This commit is contained in:
Corentin Le Molgat
2023-05-24 15:34:42 +02:00
parent 459f4ec380
commit 3be976f47b
27 changed files with 76 additions and 69 deletions

View File

@@ -14,7 +14,7 @@
set_property(SOURCE graph.i PROPERTY CPLUSPLUS ON)
set_property(SOURCE graph.i PROPERTY SWIG_MODULE_NAME operations_research_graph)
set_property(SOURCE graph.i PROPERTY COMPILE_DEFINITIONS
${OR_TOOLS_COMPILE_DEFINITIONS} ABSL_MUST_USE_RESULT=)
${OR_TOOLS_COMPILE_DEFINITIONS} ABSL_MUST_USE_RESULT)
set_property(SOURCE graph.i PROPERTY COMPILE_OPTIONS
-namespace ${DOTNET_PROJECT}.Graph
-dllimport google-ortools-native)

View File

@@ -65,8 +65,7 @@ GScipLinearExpr GScipNegate(GScipLinearExpr expr);
// Returns the range -inf <= left.terms - right.terms <= right.offset -
// left.offset
GScipLinearRange GScipLe(const GScipLinearExpr left,
const GScipLinearExpr& right);
GScipLinearRange GScipLe(GScipLinearExpr left, const GScipLinearExpr& right);
// Adds the constraint resultant = maximum(terms). Supports unbounded variables
// in terms.

View File

@@ -56,11 +56,11 @@ using MessageHandlerPtr =
// Captures the input handler and returns a unique pointer that will release it
// when destroyed.
MessageHandlerPtr CaptureMessageHandlerPtr(SCIP_MESSAGEHDLR* const handler);
MessageHandlerPtr CaptureMessageHandlerPtr(SCIP_MESSAGEHDLR* handler);
// Make a message handler for SCIP that calls the input function.
absl::StatusOr<MessageHandlerPtr> MakeSCIPMessageHandler(
const GScipMessageHandler gscip_message_handler);
GScipMessageHandler gscip_message_handler);
// Object to be instantiated on stack that, when destroyed, will disable the
// custom handler so that it does not call the GScipMessageHandler.

View File

@@ -235,7 +235,7 @@ class LinearProgram {
}
// Returns a row vector of VariableType representing types of variables.
const StrictITIVector<ColIndex, VariableType> variable_types() const {
StrictITIVector<ColIndex, VariableType> variable_types() const {
return variable_types_;
}
@@ -565,11 +565,11 @@ class LinearProgram {
// A helper function to format problem statistics. Used by GetProblemStats()
// and GetPrettyProblemStats().
std::string ProblemStatFormatter(const absl::string_view format) const;
std::string ProblemStatFormatter(absl::string_view format) const;
// A helper function to format non-zero statistics. Used by GetNonZeroStats()
// and GetPrettyNonZeroStats().
std::string NonZeroStatFormatter(const absl::string_view format) const;
std::string NonZeroStatFormatter(absl::string_view format) const;
// Resizes all row vectors to include index 'row'.
void ResizeRowsIfNeeded(RowIndex row);

View File

@@ -20,6 +20,7 @@
#include <string>
#include "absl/strings/str_cat.h"
#include "absl/strings/string_view.h"
#include "ortools/base/integral_types.h"
#include "ortools/base/logging.h"
#include "ortools/lp_data/lp_types.h"
@@ -52,7 +53,7 @@ std::string Stringify(const Fractional x, bool fraction) {
// Returns a string that pretty-prints a monomial ax with coefficient
// a and variable name x
std::string StringifyMonomial(const Fractional a, const std::string& x,
std::string StringifyMonomial(const Fractional a, absl::string_view x,
bool fraction) {
if (a == 0.0) return "";
return a > 0.0

View File

@@ -19,6 +19,7 @@
#include <string>
#include "absl/strings/str_format.h"
#include "absl/strings/string_view.h"
#include "ortools/base/integral_types.h"
#include "ortools/lp_data/lp_types.h"
@@ -42,20 +43,19 @@ inline std::string Stringify(const long double a) {
// Returns a string "num/den" representing the rational approximation of x.
// The absolute difference between the output fraction and the input "x" will
// not exceed "precision".
std::string StringifyRational(const double x, const double precision);
std::string StringifyRational(double x, double precision);
// If fraction is true, returns a string corresponding to the rational
// approximation or a decimal approximation otherwise. Note that the absolute
// difference between the output fraction and "x" will never exceed
// std::numeric_limits<T>::epsilon().
std::string Stringify(const Fractional x, bool fraction);
std::string Stringify(Fractional x, bool fraction);
// Pretty prints a monomial a*x using Stringify(x, fraction) to display a,
// taking care of the sign of x, whether a is 0, 1, -1, integer. Note that the
// absolute difference between the output fraction and "x" will never exceed
// std::numeric_limits<T>::epsilon().
std::string StringifyMonomial(const Fractional a, const std::string& x,
bool fraction);
std::string StringifyMonomial(Fractional a, absl::string_view x, bool fraction);
} // namespace glop
} // namespace operations_research

View File

@@ -62,7 +62,7 @@ class Permutation {
IndexType& operator[](IndexType i) { return perm_[i]; }
const IndexType operator[](IndexType i) const { return perm_[i]; }
IndexType operator[](IndexType i) const { return perm_[i]; }
// Populates the calling object with the inverse permutation of the parameter
// inverse.

View File

@@ -22,6 +22,7 @@
#include "absl/status/statusor.h"
#include "absl/strings/str_cat.h"
#include "absl/strings/str_split.h"
#include "absl/strings/string_view.h"
#include "ortools/base/numbers.h"
#include "ortools/base/status_macros.h"
#include "ortools/linear_solver/linear_solver.pb.h"
@@ -31,13 +32,13 @@
namespace operations_research {
absl::StatusOr<glop::DenseRow> ParseSolFile(const std::string& file_name,
absl::StatusOr<glop::DenseRow> ParseSolFile(absl::string_view file_name,
const glop::LinearProgram& model) {
ASSIGN_OR_RETURN(std::string sol_file, ReadFileToString(file_name));
return ParseSolString(sol_file, model);
}
absl::StatusOr<MPSolutionResponse> ParseSolFile(const std::string& file_name,
absl::StatusOr<MPSolutionResponse> ParseSolFile(absl::string_view file_name,
const MPModelProto& model) {
ASSIGN_OR_RETURN(std::string sol_file, ReadFileToString(file_name));
return ParseSolString(sol_file, model);

View File

@@ -20,6 +20,7 @@
#include <string>
#include "absl/status/statusor.h"
#include "absl/strings/string_view.h"
#include "ortools/linear_solver/linear_solver.pb.h"
#include "ortools/lp_data/lp_data.h"
#include "ortools/lp_data/lp_types.h"
@@ -27,9 +28,9 @@
namespace operations_research {
// Parse a solution to `model` from a file.
absl::StatusOr<glop::DenseRow> ParseSolFile(const std::string& file_name,
absl::StatusOr<glop::DenseRow> ParseSolFile(absl::string_view file_name,
const glop::LinearProgram& model);
absl::StatusOr<MPSolutionResponse> ParseSolFile(const std::string& file_name,
absl::StatusOr<MPSolutionResponse> ParseSolFile(absl::string_view file_name,
const MPModelProto& model);
// Parse a solution to `model` from a string.

View File

@@ -220,7 +220,7 @@ class SparseMatrix {
// this class (and keep the same address in memory).
class MatrixView {
public:
MatrixView() {}
MatrixView() = default;
explicit MatrixView(const SparseMatrix& matrix) {
PopulateFromMatrix(matrix);
}
@@ -330,7 +330,7 @@ class CompactSparseMatrix {
const EntryIndex* const starts_;
};
CompactSparseMatrix() {}
CompactSparseMatrix() = default;
ConstView view() const { return ConstView(this); }
// Convenient constructors for tests.
@@ -559,7 +559,7 @@ class CompactSparseMatrixView {
bool IsEmpty() const { return compact_matrix_.IsEmpty(); }
RowIndex num_rows() const { return compact_matrix_.num_rows(); }
ColIndex num_cols() const { return ColIndex(columns_.size()); }
const ColumnView column(ColIndex col) const {
ColumnView column(ColIndex col) const {
return compact_matrix_.column(columns_[col.value()]);
}
EntryIndex num_entries() const;

View File

@@ -26,7 +26,7 @@ namespace glop {
RandomAccessSparseColumn::RandomAccessSparseColumn(RowIndex num_rows)
: column_(num_rows, 0.0), changed_(num_rows, false), row_change_() {}
RandomAccessSparseColumn::~RandomAccessSparseColumn() {}
RandomAccessSparseColumn::~RandomAccessSparseColumn() = default;
void RandomAccessSparseColumn::Clear() {
const size_t num_changes = row_change_.size();

View File

@@ -274,7 +274,7 @@ struct FirstStageProblem {
std::vector<math_opt::Variable> z;
math_opt::Variable w;
FirstStageProblem(const Network& network, const double facility_cost);
FirstStageProblem(const Network& network, double facility_cost);
};
FirstStageProblem::FirstStageProblem(const Network& network,

View File

@@ -19,6 +19,7 @@
#include "absl/strings/numbers.h"
#include "absl/strings/str_split.h"
#include "absl/strings/string_view.h"
#include "ortools/packing/vector_bin_packing.pb.h"
#include "ortools/util/filelineiter.h"
@@ -106,13 +107,13 @@ void VbpParser::ProcessLine(const std::string& line) {
}
}
int VbpParser::strtoint32(const std::string& word) {
int VbpParser::strtoint32(absl::string_view word) {
int result;
CHECK(absl::SimpleAtoi(word, &result));
return result;
}
int64_t VbpParser::strtoint64(const std::string& word) {
int64_t VbpParser::strtoint64(absl::string_view word) {
int64_t result;
CHECK(absl::SimpleAtoi(word, &result));
return result;

View File

@@ -24,6 +24,7 @@
#include <string>
#include <vector>
#include "absl/strings/string_view.h"
#include "ortools/base/integral_types.h"
#include "ortools/packing/vector_bin_packing.pb.h"
@@ -54,8 +55,8 @@ class VbpParser {
void ProcessLine(const std::string& line);
void ReportError(const std::string& line);
int strtoint32(const std::string& word);
int64_t strtoint64(const std::string& word);
int strtoint32(absl::string_view word);
int64_t strtoint64(absl::string_view word);
LoadStatus load_status_ = NOT_STARTED;
int num_declared_items_ = -1;

View File

@@ -25,6 +25,7 @@
#include "absl/strings/str_cat.h"
#include "absl/strings/str_format.h"
#include "absl/strings/string_view.h"
#include "ortools/base/file.h"
#include "ortools/base/helpers.h"
#include "ortools/base/logging.h"
@@ -243,7 +244,7 @@ class RoutingSolution {
// Formats a solution or solver statistic according to the given format.
template <typename T>
std::string FormatStatistic(const std::string& name, T value,
std::string FormatStatistic(absl::string_view name, T value,
RoutingOutputFormat format) {
// TODO(user): think about using an enum instead of names (or even a
// full-fledged struct/class) for the various types of fields.
@@ -266,7 +267,7 @@ std::string FormatStatistic(const std::string& name, T value,
// Specialization for doubles to show a higher precision: without this
// specialization, 591.556557 is displayed as 591.557.
template <>
inline std::string FormatStatistic(const std::string& name, double value,
inline std::string FormatStatistic(absl::string_view name, double value,
RoutingOutputFormat format) {
switch (format) {
case RoutingOutputFormat::kNone:
@@ -285,7 +286,7 @@ inline std::string FormatStatistic(const std::string& name, double value,
// Prints a formatted solution or solver statistic according to the given
// format.
template <typename T>
void PrintStatistic(const std::string& name, T value,
void PrintStatistic(absl::string_view name, T value,
RoutingOutputFormat format) {
absl::PrintF("%s\n", FormatStatistic(name, value, format));
}

View File

@@ -67,9 +67,7 @@ class TspLibParser final {
const std::vector<int64_t>& demands() const { return demands_; }
// Returns the pairs of nodes corresponding to forced edges (second node is
// directly after the first).
const std::set<std::pair<int, int>> fixed_edges() const {
return fixed_edges_;
}
std::set<std::pair<int, int>> fixed_edges() const { return fixed_edges_; }
// Returns edges of the graph on which Hamiltonian cycles need to be built.
// Edges are represented as adjacency lists for each node.
const std::vector<std::vector<int>>& edges() const { return edges_; }

View File

@@ -55,7 +55,7 @@ class JsspParser {
DONE
};
~JsspParser() {}
~JsspParser() = default;
// Parses a file to load a jobshop problem.
// Tries to auto detect the file format.

View File

@@ -83,7 +83,7 @@ class AffineRelation {
: representative(r), coeff(c), offset(o) {}
explicit Relation(int r) : representative(r) {}
const bool operator==(const Relation& other) const {
bool operator==(const Relation& other) const {
return representative == other.representative && coeff == other.coeff &&
offset == other.offset;
}

View File

@@ -368,37 +368,35 @@ inline void ClearBit32(uint32_t* const bitset, uint32_t pos) {
}
// Returns the number of bits set in bitset between positions start and end.
uint64_t BitCountRange64(const uint64_t* const bitset, uint64_t start,
uint64_t end);
uint32_t BitCountRange32(const uint32_t* const bitset, uint32_t start,
uint32_t end);
uint64_t BitCountRange64(const uint64_t* bitset, uint64_t start, uint64_t end);
uint32_t BitCountRange32(const uint32_t* bitset, uint32_t start, uint32_t end);
// Returns true if no bits are set in bitset between start and end.
bool IsEmptyRange64(const uint64_t* const bitset, uint64_t start, uint64_t end);
bool IsEmptyRange32(const uint32_t* const bitset, uint32_t start, uint32_t end);
bool IsEmptyRange64(const uint64_t* bitset, uint64_t start, uint64_t end);
bool IsEmptyRange32(const uint32_t* bitset, uint32_t start, uint32_t end);
// Returns the first bit set in bitset between start and max_bit.
int64_t LeastSignificantBitPosition64(const uint64_t* const bitset,
uint64_t start, uint64_t end);
int LeastSignificantBitPosition32(const uint32_t* const bitset, uint32_t start,
int64_t LeastSignificantBitPosition64(const uint64_t* bitset, uint64_t start,
uint64_t end);
int LeastSignificantBitPosition32(const uint32_t* bitset, uint32_t start,
uint32_t end);
// Returns the last bit set in bitset between min_bit and start.
int64_t MostSignificantBitPosition64(const uint64_t* const bitset,
uint64_t start, uint64_t end);
int MostSignificantBitPosition32(const uint32_t* const bitset, uint32_t start,
int64_t MostSignificantBitPosition64(const uint64_t* bitset, uint64_t start,
uint64_t end);
int MostSignificantBitPosition32(const uint32_t* bitset, uint32_t start,
uint32_t end);
// Unsafe versions of the functions above where respectively end and start
// are supposed to be set.
int64_t UnsafeLeastSignificantBitPosition64(const uint64_t* const bitset,
int64_t UnsafeLeastSignificantBitPosition64(const uint64_t* bitset,
uint64_t start, uint64_t end);
int32_t UnsafeLeastSignificantBitPosition32(const uint32_t* const bitset,
int32_t UnsafeLeastSignificantBitPosition32(const uint32_t* bitset,
uint32_t start, uint32_t end);
int64_t UnsafeMostSignificantBitPosition64(const uint64_t* const bitset,
int64_t UnsafeMostSignificantBitPosition64(const uint64_t* bitset,
uint64_t start, uint64_t end);
int32_t UnsafeMostSignificantBitPosition32(const uint32_t* const bitset,
int32_t UnsafeMostSignificantBitPosition32(const uint32_t* bitset,
uint32_t start, uint32_t end);
// Returns a mask with the bits pos % 64 and (pos ^ 1) % 64 sets.

View File

@@ -132,7 +132,7 @@ class FileLines {
// ...
// }
//
FileLines(const std::string& filename, File* const file,
FileLines(absl::string_view filename, File* const file,
const int options = FileLineIterator::DEFAULT)
: file_(file), options_(options) {
if (!file_) {

View File

@@ -78,7 +78,7 @@ class RoundTripDoubleFormat {
//
// This function offers a round-trip from string printed/built by this
// formatter.
static absl::StatusOr<double> Parse(const absl::string_view str_value);
static absl::StatusOr<double> Parse(absl::string_view str_value);
private:
const double value_;

View File

@@ -52,7 +52,7 @@ class GraphExporter {
const std::string& label) = 0;
// Creates a graph exporter that will write to file with a given format.
static GraphExporter* MakeFileExporter(File* const file,
static GraphExporter* MakeFileExporter(File* file,
GraphExporter::GraphFormat format);
};
} // namespace operations_research

View File

@@ -229,10 +229,10 @@ bool CanConvertTo ## Class(PyObject *py_obj) {
}
%}
%typemap(in) operations_research::Class* const {
%typemap(in) operations_research::Class* const, operations_research::Class* {
if (!PyObjAs($input, &$1)) SWIG_fail;
}
%typecheck(SWIG_TYPECHECK_POINTER) operations_research::Class* const {
%typecheck(SWIG_TYPECHECK_POINTER) operations_research::Class* const, operations_research::Class* {
$1 = CanConvertTo ## Class($input);
if ($1 == 0) PyErr_Clear();
}

View File

@@ -30,7 +30,7 @@ typedef std::pair<int64_t, int64_t> Fraction;
// output fraction and the input "x" will not exceed "precision".
// TODO(user): make a parameterized template with integer and floating-point
// type parameters.
Fraction RationalApproximation(const double x, const double precision);
Fraction RationalApproximation(double x, double precision);
} // namespace operations_research
#endif // OR_TOOLS_UTIL_RATIONAL_APPROXIMATION_H_

View File

@@ -385,7 +385,7 @@ class Domain {
*
* For instance Domain(1, 7).InverseMultiplicationBy(2) == Domain(1, 3).
*/
Domain InverseMultiplicationBy(const int64_t coeff) const;
Domain InverseMultiplicationBy(int64_t coeff) const;
/**
* Returns a superset of {x ∈ Int64, ∃ e ∈ D, ∃ m ∈ modulo, x = e % m }.

View File

@@ -53,15 +53,11 @@
#include <stddef.h>
#include <cstdint>
#include <functional>
#include <iosfwd>
#include <ostream> // NOLINT
#include <type_traits>
#include "absl/base/port.h"
#include "absl/strings/str_format.h"
#include "absl/strings/string_view.h"
#include "ortools/base/logging.h"
#include "ortools/base/macros.h"
namespace operations_research {
@@ -169,8 +165,8 @@ class StrongIndex {
return static_cast<ValType>(value_);
}
constexpr const ThisType operator+() const { return ThisType(value_); }
constexpr const ThisType operator-() const { return ThisType(-value_); }
constexpr ThisType operator+() const { return ThisType(value_); }
constexpr ThisType operator-() const { return ThisType(-value_); }
INCREMENT_AND_DECREMENT_OPERATORS;
@@ -225,9 +221,9 @@ class StrongInt64 {
INCREMENT_AND_DECREMENT_OPERATORS;
constexpr const ThisType operator+() const { return ThisType(value_); }
constexpr const ThisType operator-() const { return ThisType(-value_); }
constexpr const ThisType operator~() const { return ThisType(~value_); }
constexpr ThisType operator+() const { return ThisType(value_); }
constexpr ThisType operator-() const { return ThisType(-value_); }
constexpr ThisType operator~() const { return ThisType(~value_); }
STRONG_ASSIGNMENT_OP(StrongInt64, int64_t, +=);
STRONG_ASSIGNMENT_OP(StrongInt64, int64_t, -=);
@@ -253,12 +249,22 @@ std::ostream& operator<<(std::ostream& os, // NOLINT
return os << arg.value();
}
template <typename Sink, typename... T>
void AbslStringify(Sink& sink, StrongIndex<T...> arg) {
absl::Format(&sink, "%v", arg.value());
}
template <typename StrongIntegerName>
std::ostream& operator<<(std::ostream& os, // NOLINT
StrongInt64<StrongIntegerName> arg) {
return os << arg.value();
}
template <typename Sink, typename... T>
void AbslStringify(Sink& sink, StrongInt64<T...> arg) {
absl::Format(&sink, "%v", arg.value());
}
// -- NON-MEMBER ARITHMETIC OPERATORS ------------------------------------------
#define STRONG_TYPE_ARITHMETIC_OP(StrongType, IntType, op) \
template <typename StrongName> \

View File

@@ -81,7 +81,7 @@ class DoxygenFormatter(object):
# doesn't treat it like a code block.
(re.compile(r'(^\s*)//\s{4,}([-\d*].*)'), r'\1 \2', self.COMMENT),
# Replace TODO(someone) in a comment with @todo (someone)
# Replace TODO(user) in a comment with @todo (someone)
(re.compile(r'TODO'), r'@todo ', self.COMMENT),
# Replace leading 'Note:' or 'Note that' in a comment with @note