Skip to content

Commit

Permalink
revamp integral type, fix int64 to be int64_t; remove GG_LL_FORMAT ma…
Browse files Browse the repository at this point in the history
…cros
  • Loading branch information
Laurent Perron committed Dec 1, 2018
1 parent c2d56ed commit 123280f
Show file tree
Hide file tree
Showing 27 changed files with 201 additions and 281 deletions.
42 changes: 3 additions & 39 deletions ortools/base/integral_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
#ifndef OR_TOOLS_BASE_INTEGRAL_TYPES_H_
#define OR_TOOLS_BASE_INTEGRAL_TYPES_H_

#include <iostream> // NOLINT
#include <cstdint>

// Detect 64 bit.
#undef ARCH_K8
Expand All @@ -32,11 +32,7 @@ typedef signed char schar;
typedef signed char int8;
typedef short int16; // NOLINT
typedef int int32;
#ifdef COMPILER_MSVC
typedef __int64 int64; // NOLINT
#else
typedef long long int64; // NOLINT
#endif /* COMPILER_MSVC */
typedef int64_t int64;

// NOTE: unsigned types are DANGEROUS in loops and other arithmetical
// places. Use the signed types unless your variable represents a bit
Expand All @@ -47,11 +43,7 @@ typedef long long int64; // NOLINT
typedef unsigned char uint8;
typedef unsigned short uint16; // NOLINT
typedef unsigned int uint32;
#ifdef COMPILER_MSVC
typedef unsigned __int64 uint64;
#else
typedef unsigned long long uint64; // NOLINT
#endif /* COMPILER_MSVC */
typedef uint64_t uint64;

// A type to represent a Unicode code-point value. As of Unicode 4.0,
// such values require up to 21 bits.
Expand All @@ -78,25 +70,15 @@ typedef long sword_t; // NOLINT
// and different size specifiers in format strings
#undef GG_LONGLONG
#undef GG_ULONGLONG
#undef GG_LL_FORMAT

#ifdef COMPILER_MSVC /* if Visual C++ */

// VC++ long long suffixes
#define GG_LONGLONG(x) x##I64
#define GG_ULONGLONG(x) x##UI64

// Length modifier in printf format std::string for int64's (e.g. within %d)
#define GG_LL_FORMAT "I64" // As in printf("%I64d", ...)
#define GG_LL_FORMAT_W L"I64"

#else /* not Visual C++ */

#define GG_LONGLONG(x) x##LL
#define GG_ULONGLONG(x) x##ULL
#define GG_LL_FORMAT "ll" // As in "%lld". Note that "q" is poor form also.
#define GG_LL_FORMAT_W L"ll"

#endif // COMPILER_MSVC

static const uint8 kuint8max = static_cast<uint8>(0xFF);
Expand All @@ -115,22 +97,4 @@ static const int64 kint64min =
static const int64 kint64max =
static_cast<int64>(GG_LONGLONG(0x7FFFFFFFFFFFFFFF));

#ifdef STLPORT
#include <cstdio>
// int64 output not present in STL port.
inline std::ostream& operator<<(std::ostream& os, int64 i) {
char buffer[20];
snprintf(buffer, sizeof(buffer), "%lld", i);
os << buffer;
return os;
}

inline std::ostream& operator<<(std::ostream& os, uint64 i) {
char buffer[20];
snprintf(buffer, sizeof(buffer), "%llu", i);
os << buffer;
return os;
}
#endif // STLPORT

#endif // OR_TOOLS_BASE_INTEGRAL_TYPES_H_
4 changes: 2 additions & 2 deletions ortools/constraint_solver/alldiff_cst.cc
Original file line number Diff line number Diff line change
Expand Up @@ -572,7 +572,7 @@ class AllDifferentExcept : public Constraint {
}

std::string DebugString() const override {
return absl::StrFormat("AllDifferentExcept([%s], %" GG_LL_FORMAT "d",
return absl::StrFormat("AllDifferentExcept([%s], %d",
JoinDebugStringPtr(vars_, ", "), escape_value_);
}

Expand Down Expand Up @@ -664,7 +664,7 @@ class NullIntersectArrayExcept : public Constraint {

std::string DebugString() const override {
return absl::StrFormat(
"NullIntersectArray([%s], [%s], escape = %" GG_LL_FORMAT "d",
"NullIntersectArray([%s], [%s], escape = %d",
JoinDebugStringPtr(first_vars_, ", "),
JoinDebugStringPtr(second_vars_, ", "), escape_value_);
}
Expand Down
16 changes: 8 additions & 8 deletions ortools/constraint_solver/assignment.cc
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,9 @@ void IntVarElement::WriteToProto(
std::string IntVarElement::DebugString() const {
if (Activated()) {
if (min_ == max_) {
return absl::StrFormat("(%" GG_LL_FORMAT "d)", min_);
return absl::StrFormat("(%d)", min_);
} else {
return absl::StrFormat("(%" GG_LL_FORMAT "d..%" GG_LL_FORMAT "d)", min_,
return absl::StrFormat("(%d..%d)", min_,
max_);
}
} else {
Expand Down Expand Up @@ -201,19 +201,19 @@ void IntervalVarElement::WriteToProto(
std::string IntervalVarElement::DebugString() const {
if (Activated()) {
std::string out;
absl::StrAppendFormat(&out, "(start = %" GG_LL_FORMAT "d", start_min_);
absl::StrAppendFormat(&out, "(start = %d", start_min_);
if (start_max_ != start_min_) {
absl::StrAppendFormat(&out, "..%" GG_LL_FORMAT "d", start_max_);
absl::StrAppendFormat(&out, "..%d", start_max_);
}
absl::StrAppendFormat(&out, ", duration = %" GG_LL_FORMAT "d",
absl::StrAppendFormat(&out, ", duration = %d",
duration_min_);
if (duration_max_ != duration_min_) {
absl::StrAppendFormat(&out, "..%" GG_LL_FORMAT "d", duration_max_);
absl::StrAppendFormat(&out, "..%d", duration_max_);
}
absl::StrAppendFormat(&out, ", status = %" GG_LL_FORMAT "d",
absl::StrAppendFormat(&out, ", status = %d",
performed_min_);
if (performed_max_ != performed_min_) {
absl::StrAppendFormat(&out, "..%" GG_LL_FORMAT "d", performed_max_);
absl::StrAppendFormat(&out, "..%d", performed_max_);
}
out.append(")");
return out;
Expand Down
8 changes: 3 additions & 5 deletions ortools/constraint_solver/constraint_solver.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1462,11 +1462,9 @@ std::string Solver::DebugString() const {
}
absl::StrAppendFormat(
&out,
", branches = %" GG_LL_FORMAT "d, fails = %" GG_LL_FORMAT
"d, decisions = %" GG_LL_FORMAT "d, delayed demon runs = %" GG_LL_FORMAT
"d, var demon runs = %" GG_LL_FORMAT
"d, normal demon runs = %" GG_LL_FORMAT "d, Run time = %" GG_LL_FORMAT
"d ms)",
", branches = %d, fails = %d, decisions = %d, "
"delayed demon runs = %d, var demon runs = %d, normal demon runs = %d, "
"Run time = %d ms)",
branches_, fails_, decisions_, demon_runs_[DELAYED_PRIORITY],
demon_runs_[VAR_PRIORITY], demon_runs_[NORMAL_PRIORITY], wall_time());
return out;
Expand Down
2 changes: 1 addition & 1 deletion ortools/constraint_solver/count_cst.cc
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ class AtMost : public Constraint {
}

std::string DebugString() const override {
return absl::StrFormat("AtMost(%s, %" GG_LL_FORMAT "d, %" GG_LL_FORMAT "d)",
return absl::StrFormat("AtMost(%s, %d, %d)",
JoinDebugStringPtr(vars_, ", "), value_, max_count_);
}

Expand Down
13 changes: 6 additions & 7 deletions ortools/constraint_solver/demon_profiler.cc
Original file line number Diff line number Diff line change
Expand Up @@ -256,14 +256,13 @@ class DemonProfiler : public PropagationMonitor {
// Exports collected data as human-readable text.
void PrintOverview(Solver* const solver, const std::string& filename) {
const char* const kConstraintFormat =
" - Constraint: %s\n failures=%" GG_LL_FORMAT
"d, initial propagation runtime=%" GG_LL_FORMAT
"d us, demons=%d, demon invocations=%" GG_LL_FORMAT
"d, total demon runtime=%" GG_LL_FORMAT "d us\n";
" - Constraint: %s\n"
" failures=%d, initial propagation runtime=%d us, "
"demons=%d, demon invocations=%d, total demon runtime=%d us\n";
const char* const kDemonFormat =
" --- Demon: %s\n invocations=%" GG_LL_FORMAT
"d, failures=%" GG_LL_FORMAT "d, total runtime=%" GG_LL_FORMAT
"d us, [average=%.2lf, median=%.2lf, stddev=%.2lf]\n";
" --- Demon: %s\n"
"invocations=%d, failures=%d, total runtime=%d us, "
"[average=%.2lf, median=%.2lf, stddev=%.2lf]\n";
File* file;
const std::string model =
absl::StrFormat("Model %s:\n", solver->model_name());
Expand Down
10 changes: 5 additions & 5 deletions ortools/constraint_solver/element.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1323,7 +1323,7 @@ std::string StringifyEvaluatorBare(const Solver::Int64ToIntVar& evaluator,
if (i != range_start) {
out += ", ";
}
out += absl::StrFormat("%" GG_LL_FORMAT "d -> %s", i,
out += absl::StrFormat("%d -> %s", i,
evaluator(i)->DebugString());
}
return out;
Expand Down Expand Up @@ -1390,7 +1390,7 @@ std::string IntExprArrayElementCt::DebugString() const {
int64 size = vars_.size();
if (size > 10) {
return absl::StrFormat(
"IntExprArrayElement(var array of size %" GG_LL_FORMAT "d, %s) == %s",
"IntExprArrayElement(var array of size %d, %s) == %s",
size, index_->DebugString(), target_var_->DebugString());
} else {
return absl::StrFormat("IntExprArrayElement([%s], %s) == %s",
Expand Down Expand Up @@ -1459,7 +1459,7 @@ class IntExprArrayElementCstCt : public Constraint {

std::string DebugString() const override {
return absl::StrFormat(
"IntExprArrayElement([%s], %s) == %" GG_LL_FORMAT "d",
"IntExprArrayElement([%s], %s) == %d",
JoinDebugStringPtr(vars_, ", "), index_->DebugString(), target_);
}

Expand Down Expand Up @@ -1551,7 +1551,7 @@ class IntExprIndexOfCt : public Constraint {
}

std::string DebugString() const override {
return absl::StrFormat("IntExprIndexOf([%s], %s) == %" GG_LL_FORMAT "d",
return absl::StrFormat("IntExprIndexOf([%s], %s) == %d",
JoinDebugStringPtr(vars_, ", "),
index_->DebugString(), target_);
}
Expand Down Expand Up @@ -1752,7 +1752,7 @@ IntExpr* Solver::MakeIndexExpression(const std::vector<IntVar*>& vars,
if (cache != nullptr) {
return cache->Var();
} else {
const std::string name = absl::StrFormat("Index(%s, %" GG_LL_FORMAT "d)",
const std::string name = absl::StrFormat("Index(%s, %d)",
JoinNamePtr(vars, ", "), value);
IntVar* const index = MakeIntVar(0, vars.size() - 1, name);
AddConstraint(MakeIndexOfConstraint(vars, index, value));
Expand Down
4 changes: 2 additions & 2 deletions ortools/constraint_solver/expr_array.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1985,7 +1985,7 @@ class BooleanScalProdLessConstant : public Constraint {
}

std::string DebugString() const override {
return absl::StrFormat("BooleanScalProd([%s], [%s]) <= %" GG_LL_FORMAT "d)",
return absl::StrFormat("BooleanScalProd([%s], [%s]) <= %d)",
JoinDebugStringPtr(vars_, ", "),
absl::StrJoin(coefs_, ", "), upper_bound_);
}
Expand Down Expand Up @@ -2352,7 +2352,7 @@ class PositiveBooleanScalProdEqCst : public Constraint {

std::string DebugString() const override {
return absl::StrFormat(
"PositiveBooleanScalProd([%s], [%s]) == %" GG_LL_FORMAT "d",
"PositiveBooleanScalProd([%s], [%s]) == %d",
JoinDebugStringPtr(vars_, ", "), absl::StrJoin(coefs_, ", "),
constant_);
}
Expand Down
30 changes: 14 additions & 16 deletions ortools/constraint_solver/expr_cst.cc
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ void EqualityExprCst::Post() {
void EqualityExprCst::InitialPropagate() { expr_->SetValue(value_); }

std::string EqualityExprCst::DebugString() const {
return absl::StrFormat("(%s == %" GG_LL_FORMAT "d)", expr_->DebugString(),
return absl::StrFormat("(%s == %d)", expr_->DebugString(),
value_);
}
} // namespace
Expand Down Expand Up @@ -162,7 +162,7 @@ void GreaterEqExprCst::InitialPropagate() {
}

std::string GreaterEqExprCst::DebugString() const {
return absl::StrFormat("(%s >= %" GG_LL_FORMAT "d)", expr_->DebugString(),
return absl::StrFormat("(%s >= %d)", expr_->DebugString(),
value_);
}
} // namespace
Expand Down Expand Up @@ -260,7 +260,7 @@ void LessEqExprCst::InitialPropagate() {
}

std::string LessEqExprCst::DebugString() const {
return absl::StrFormat("(%s <= %" GG_LL_FORMAT "d)", expr_->DebugString(),
return absl::StrFormat("(%s <= %d)", expr_->DebugString(),
value_);
}
} // namespace
Expand Down Expand Up @@ -367,7 +367,7 @@ void DiffCst::BoundPropagate() {
}

std::string DiffCst::DebugString() const {
return absl::StrFormat("(%s != %" GG_LL_FORMAT "d)", var_->DebugString(),
return absl::StrFormat("(%s != %d)", var_->DebugString(),
value_);
}
} // namespace
Expand Down Expand Up @@ -434,7 +434,7 @@ class IsEqualCstCt : public CastConstraint {
}
}
std::string DebugString() const override {
return absl::StrFormat("IsEqualCstCt(%s, %" GG_LL_FORMAT "d, %s)",
return absl::StrFormat("IsEqualCstCt(%s, %d, %s)",
var_->DebugString(), cst_,
target_var_->DebugString());
}
Expand Down Expand Up @@ -475,7 +475,7 @@ IntVar* Solver::MakeIsEqualCstVar(IntExpr* const var, int64 value) {
return var->Var()->IsEqual(value);
} else {
IntVar* const boolvar = MakeBoolVar(absl::StrFormat(
"Is(%s == %" GG_LL_FORMAT "d)", var->DebugString(), value));
"Is(%s == %d)", var->DebugString(), value));
AddConstraint(MakeIsEqualCstCt(var, value, boolvar));
return boolvar;
}
Expand Down Expand Up @@ -553,7 +553,7 @@ class IsDiffCstCt : public CastConstraint {
}

std::string DebugString() const override {
return absl::StrFormat("IsDiffCstCt(%s, %" GG_LL_FORMAT "d, %s)",
return absl::StrFormat("IsDiffCstCt(%s, %d, %s)",
var_->DebugString(), cst_,
target_var_->DebugString());
}
Expand Down Expand Up @@ -652,7 +652,7 @@ class IsGreaterEqualCstCt : public CastConstraint {
}
}
std::string DebugString() const override {
return absl::StrFormat("IsGreaterEqualCstCt(%s, %" GG_LL_FORMAT "d, %s)",
return absl::StrFormat("IsGreaterEqualCstCt(%s, %d, %s)",
expr_->DebugString(), cst_,
target_var_->DebugString());
}
Expand Down Expand Up @@ -685,7 +685,7 @@ IntVar* Solver::MakeIsGreaterOrEqualCstVar(IntExpr* const var, int64 value) {
return var->Var()->IsGreaterOrEqual(value);
} else {
IntVar* const boolvar = MakeBoolVar(absl::StrFormat(
"Is(%s >= %" GG_LL_FORMAT "d)", var->DebugString(), value));
"Is(%s >= %d)", var->DebugString(), value));
AddConstraint(MakeIsGreaterOrEqualCstCt(var, value, boolvar));
return boolvar;
}
Expand Down Expand Up @@ -752,7 +752,7 @@ class IsLessEqualCstCt : public CastConstraint {
}

std::string DebugString() const override {
return absl::StrFormat("IsLessEqualCstCt(%s, %" GG_LL_FORMAT "d, %s)",
return absl::StrFormat("IsLessEqualCstCt(%s, %d, %s)",
expr_->DebugString(), cst_,
target_var_->DebugString());
}
Expand Down Expand Up @@ -785,7 +785,7 @@ IntVar* Solver::MakeIsLessOrEqualCstVar(IntExpr* const var, int64 value) {
return var->Var()->IsLessOrEqual(value);
} else {
IntVar* const boolvar = MakeBoolVar(absl::StrFormat(
"Is(%s <= %" GG_LL_FORMAT "d)", var->DebugString(), value));
"Is(%s <= %d)", var->DebugString(), value));
AddConstraint(MakeIsLessOrEqualCstCt(var, value, boolvar));
return boolvar;
}
Expand Down Expand Up @@ -842,8 +842,7 @@ class BetweenCt : public Constraint {
}

std::string DebugString() const override {
return absl::StrFormat("BetweenCt(%s, %" GG_LL_FORMAT "d, %" GG_LL_FORMAT
"d)",
return absl::StrFormat("BetweenCt(%s, %d, %d)",
expr_->DebugString(), min_, max_);
}

Expand Down Expand Up @@ -891,8 +890,7 @@ class NotBetweenCt : public Constraint {
}

std::string DebugString() const override {
return absl::StrFormat("NotBetweenCt(%s, %" GG_LL_FORMAT "d, %" GG_LL_FORMAT
"d)",
return absl::StrFormat("NotBetweenCt(%s, %d, %d)",
expr_->DebugString(), min_, max_);
}

Expand Down Expand Up @@ -1025,7 +1023,7 @@ class IsBetweenCt : public Constraint {

std::string DebugString() const override {
return absl::StrFormat(
"IsBetweenCt(%s, %" GG_LL_FORMAT "d, %" GG_LL_FORMAT "d, %s)",
"IsBetweenCt(%s, %d, %d, %s)",
expr_->DebugString(), min_, max_, boolvar_->DebugString());
}

Expand Down
Loading

0 comments on commit 123280f

Please sign in to comment.