remove stderrthreshold flag, use absl globals method

This commit is contained in:
Laurent Perron
2025-02-19 17:00:34 +01:00
parent 8fb364a103
commit 7fec12bc35
44 changed files with 159 additions and 99 deletions

View File

@@ -28,6 +28,7 @@
#include "absl/container/btree_set.h"
#include "absl/flags/flag.h"
#include "absl/log/check.h"
#include "absl/log/globals.h"
#include "absl/strings/str_cat.h"
#include "absl/types/span.h"
#include "google/protobuf/text_format.h"
@@ -555,7 +556,7 @@ void LoadAndSolve(const std::string& file_name, int instance) {
} // namespace operations_research
int main(int argc, char** argv) {
absl::SetFlag(&FLAGS_stderrthreshold, 0);
absl::SetStderrThreshold(absl::LogSeverityAtLeast::kInfo);
InitGoogle(argv[0], &argc, &argv, true);
if (absl::GetFlag(FLAGS_input).empty()) {
LOG(FATAL) << "Please supply a data file with --input=";

View File

@@ -13,8 +13,12 @@
// Constraint programming example that shows how to use the API.
#include <cstdint>
#include <cstdlib>
#include <vector>
#include "absl/base/log_severity.h"
#include "absl/log/globals.h"
#include "ortools/base/init_google.h"
#include "ortools/base/logging.h"
#include "ortools/constraint_solver/constraint_solver.h"
@@ -23,12 +27,12 @@ namespace operations_research {
void RunConstraintProgrammingExample() {
// Instantiate the solver.
Solver solver("ConstraintProgrammingExample");
const int64_t numVals = 3;
const int64_t kNumVals = 3;
// Define decision variables.
IntVar* const x = solver.MakeIntVar(0, numVals - 1, "x");
IntVar* const y = solver.MakeIntVar(0, numVals - 1, "y");
IntVar* const z = solver.MakeIntVar(0, numVals - 1, "z");
IntVar* const x = solver.MakeIntVar(0, kNumVals - 1, "x");
IntVar* const y = solver.MakeIntVar(0, kNumVals - 1, "y");
IntVar* const z = solver.MakeIntVar(0, kNumVals - 1, "z");
// Define constraints.
std::vector<IntVar*> xyvars = {x, y};
@@ -57,7 +61,7 @@ void RunConstraintProgrammingExample() {
} // namespace operations_research
int main(int argc, char** argv) {
absl::SetFlag(&FLAGS_stderrthreshold, 0);
absl::SetStderrThreshold(absl::LogSeverityAtLeast::kInfo);
InitGoogle(argv[0], &argc, &argv, true);
operations_research::RunConstraintProgrammingExample();
return EXIT_SUCCESS;

View File

@@ -28,7 +28,9 @@
#include <utility>
#include <vector>
#include "absl/base/log_severity.h"
#include "absl/flags/flag.h"
#include "absl/log/globals.h"
#include "absl/strings/str_cat.h"
#include "absl/strings/str_format.h"
#include "absl/types/span.h"
@@ -297,7 +299,7 @@ void CostasBoolSoft(const int dim) {
} // namespace operations_research
int main(int argc, char** argv) {
absl::SetFlag(&FLAGS_stderrthreshold, 0);
absl::SetStderrThreshold(absl::LogSeverityAtLeast::kInfo);
InitGoogle(argv[0], &argc, &argv, true);
int min = 1;

View File

@@ -28,7 +28,9 @@
#include <cstdio>
#include <vector>
#include "absl/base/log_severity.h"
#include "absl/flags/flag.h"
#include "absl/log/globals.h"
#include "absl/strings/str_format.h"
#include "google/protobuf/text_format.h"
#include "ortools/base/init_google.h"
@@ -120,7 +122,7 @@ void GolombRuler(int size) {
} // namespace operations_research
int main(int argc, char** argv) {
absl::SetFlag(&FLAGS_stderrthreshold, 0);
absl::SetStderrThreshold(absl::LogSeverityAtLeast::kInfo);
InitGoogle(argv[0], &argc, &argv, true);
if (absl::GetFlag(FLAGS_size) != 0) {

View File

@@ -16,7 +16,9 @@
#include <string>
#include <vector>
#include "absl/base/log_severity.h"
#include "absl/flags/flag.h"
#include "absl/log/globals.h"
#include "absl/strings/match.h"
#include "absl/strings/string_view.h"
#include "ortools/base/init_google.h"
@@ -94,7 +96,7 @@ void RunAllExamples() {
} // namespace operations_research
int main(int argc, char** argv) {
absl::SetFlag(&FLAGS_stderrthreshold, 0);
absl::SetStderrThreshold(absl::LogSeverityAtLeast::kInfo);
InitGoogle(argv[0], &argc, &argv, true);
operations_research::RunAllExamples();
return EXIT_SUCCESS;

View File

@@ -18,10 +18,12 @@
#include <string>
#include <vector>
#include "absl/base/log_severity.h"
#include "absl/container/flat_hash_map.h"
#include "absl/container/flat_hash_set.h"
#include "absl/flags/flag.h"
#include "absl/log/check.h"
#include "absl/log/globals.h"
#include "absl/strings/str_join.h"
#include "absl/types/span.h"
#include "google/protobuf/text_format.h"
@@ -848,7 +850,7 @@ void Solve(const JsspInputProblem& problem) {
} // namespace operations_research
int main(int argc, char** argv) {
absl::SetFlag(&FLAGS_stderrthreshold, 0);
absl::SetStderrThreshold(absl::LogSeverityAtLeast::kInfo);
InitGoogle(argv[0], &argc, &argv, true);
if (absl::GetFlag(FLAGS_input).empty()) {

View File

@@ -21,7 +21,9 @@
#include <string>
#include <vector>
#include "absl/base/log_severity.h"
#include "absl/flags/flag.h"
#include "absl/log/globals.h"
#include "absl/types/span.h"
#include "google/protobuf/text_format.h"
#include "ortools/base/commandlineflags.h"
@@ -106,7 +108,7 @@ void CheckAndPrint2DSolution(
}
}
// Load a 2d binpacking problem and solve it as a 2d knapsack problem.
// Load a 2d bin-packing problem and solve it as a 2d knapsack problem.
// That is fit the max number of object in one box.
void LoadAndSolve(const std::string& file_name, int instance) {
packing::BinPacking2dParser parser;
@@ -226,7 +228,7 @@ void LoadAndSolve(const std::string& file_name, int instance) {
} // namespace operations_research
int main(int argc, char** argv) {
absl::SetFlag(&FLAGS_stderrthreshold, 0);
absl::SetStderrThreshold(absl::LogSeverityAtLeast::kInfo);
InitGoogle(argv[0], &argc, &argv, true);
if (absl::GetFlag(FLAGS_input).empty()) {
LOG(FATAL) << "Please supply a data file with --input=";

View File

@@ -17,7 +17,9 @@
#include <string>
#include <vector>
#include "absl/base/log_severity.h"
#include "absl/flags/flag.h"
#include "absl/log/globals.h"
#include "absl/strings/match.h"
#include "absl/strings/string_view.h"
#include "ortools/base/commandlineflags.h"
@@ -122,7 +124,7 @@ void RunAllExamples() {
} // namespace operations_research
int main(int argc, char** argv) {
absl::SetFlag(&FLAGS_stderrthreshold, 0);
absl::SetStderrThreshold(absl::LogSeverityAtLeast::kInfo);
InitGoogle(argv[0], &argc, &argv, true);
operations_research::RunAllExamples();
return EXIT_SUCCESS;

View File

@@ -11,15 +11,16 @@
// See the License for the specific language governing permissions and
// limitations under the License.
#include <limits>
#include <string>
#include "ortools/base/init_google.h"
#include "ortools/base/logging.h"
#include "ortools/linear_solver/linear_solver.h"
#include "ortools/linear_solver/linear_solver.pb.h"
#include "ortools/linear_solver/solve_mp_model.h"
namespace operations_research {
void BuildLinearProgrammingMaxExample(MPSolver::OptimizationProblemType type) {
void BuildLinearProgrammingMaxExample(MPModelRequest::SolverType type) {
const double kObjCoef[] = {10.0, 6.0, 4.0};
const std::string kVarName[] = {"x1", "x2", "x3"};
const int numVars = 3;
@@ -32,7 +33,7 @@ void BuildLinearProgrammingMaxExample(MPSolver::OptimizationProblemType type) {
kConstraintCoef3};
const double kConstraintUb[] = {100.0, 600.0, 300.0};
const double infinity = MPSolver::infinity();
const double infinity = std::numeric_limits<double>::infinity();
MPModelProto model_proto;
model_proto.set_name("Max_Example");
@@ -62,19 +63,9 @@ void BuildLinearProgrammingMaxExample(MPSolver::OptimizationProblemType type) {
MPModelRequest model_request;
*model_request.mutable_model() = model_proto;
#if defined(USE_GLOP)
if (type == MPSolver::GLOP_LINEAR_PROGRAMMING) {
model_request.set_solver_type(MPModelRequest::GLOP_LINEAR_PROGRAMMING);
}
#endif // USE_GLOP
#if defined(USE_CLP)
if (type == MPSolver::CLP_LINEAR_PROGRAMMING) {
model_request.set_solver_type(MPModelRequest::CLP_LINEAR_PROGRAMMING);
}
#endif // USE_CLP
model_request.set_solver_type(type);
MPSolutionResponse solution_response;
MPSolver::SolveWithProto(model_request, &solution_response);
const MPSolutionResponse solution_response = SolveMPModel(model_request);
// The problem has an optimal solution.
CHECK_EQ(MPSOLVER_OPTIMAL, solution_response.status());
@@ -89,11 +80,11 @@ void BuildLinearProgrammingMaxExample(MPSolver::OptimizationProblemType type) {
void RunAllExamples() {
#if defined(USE_GLOP)
LOG(INFO) << "----- Running Max Example with GLOP -----";
BuildLinearProgrammingMaxExample(MPSolver::GLOP_LINEAR_PROGRAMMING);
BuildLinearProgrammingMaxExample(MPModelRequest::GLOP_LINEAR_PROGRAMMING);
#endif // USE_GLOP
#if defined(USE_CLP)
LOG(INFO) << "----- Running Max Example with Coin LP -----";
BuildLinearProgrammingMaxExample(MPSolver::CLP_LINEAR_PROGRAMMING);
BuildLinearProgrammingMaxExample(MPModelRequest::CLP_LINEAR_PROGRAMMING);
#endif // USE_CLP
}
} // namespace operations_research

View File

@@ -22,7 +22,9 @@
#include <string>
#include <vector>
#include "absl/base/log_severity.h"
#include "absl/flags/flag.h"
#include "absl/log/globals.h"
#include "absl/strings/str_format.h"
#include "ortools/base/init_google.h"
#include "ortools/base/logging.h"
@@ -92,7 +94,7 @@ void MagicSequence(int size) {
} // namespace operations_research
int main(int argc, char** argv) {
absl::SetFlag(&FLAGS_stderrthreshold, 0);
absl::SetStderrThreshold(absl::LogSeverityAtLeast::kInfo);
InitGoogle(argv[0], &argc, &argv, true);
operations_research::sat::MagicSequence(absl::GetFlag(FLAGS_size));

View File

@@ -14,7 +14,9 @@
#include <string>
#include <vector>
#include "absl/base/log_severity.h"
#include "absl/flags/flag.h"
#include "absl/log/globals.h"
#include "absl/strings/str_cat.h"
#include "absl/strings/str_format.h"
#include "ortools/base/init_google.h"
@@ -101,7 +103,7 @@ void MagicSquare(int size) {
} // namespace operations_research
int main(int argc, char** argv) {
absl::SetFlag(&FLAGS_stderrthreshold, 0);
absl::SetStderrThreshold(absl::LogSeverityAtLeast::kInfo);
InitGoogle(argv[0], &argc, &argv, true);
operations_research::sat::MagicSquare(absl::GetFlag(FLAGS_size));

View File

@@ -14,7 +14,9 @@
#include <utility>
#include <vector>
#include "absl/base/log_severity.h"
#include "absl/flags/flag.h"
#include "absl/log/globals.h"
#include "ortools/base/init_google.h"
#include "ortools/base/logging.h"
#include "ortools/graph/generic_max_flow.h"
@@ -64,7 +66,7 @@ void SolveMaxFlow() {
} // namespace operations_research
int main(int argc, char** argv) {
absl::SetFlag(&FLAGS_stderrthreshold, 0);
absl::SetStderrThreshold(absl::LogSeverityAtLeast::kInfo);
InitGoogle(argv[0], &argc, &argv, true);
operations_research::SolveMaxFlow();
return EXIT_SUCCESS;

View File

@@ -16,7 +16,9 @@
#include <utility>
#include <vector>
#include "absl/base/log_severity.h"
#include "absl/flags/flag.h"
#include "absl/log/globals.h"
#include "ortools/base/init_google.h"
#include "ortools/base/logging.h"
@@ -73,7 +75,7 @@ void SolveMinCostFlow() {
} // namespace operations_research
int main(int argc, char** argv) {
absl::SetFlag(&FLAGS_stderrthreshold, 0);
absl::SetStderrThreshold(absl::LogSeverityAtLeast::kInfo);
InitGoogle(argv[0], &argc, &argv, true);
operations_research::SolveMinCostFlow();
return EXIT_SUCCESS;

View File

@@ -28,7 +28,6 @@
#include "ortools/base/file.h"
#include "ortools/base/helpers.h"
#include "ortools/base/init_google.h"
#include "ortools/base/logging.h"
#include "ortools/base/timer.h"
#include "ortools/glop/lp_solver.h"
#include "ortools/glop/parameters.pb.h"
@@ -90,7 +89,7 @@ int main(int argc, char* argv[]) {
"The files must be in Mps or linear_solver.proto format and can be "
"compressed with gzip.",
&argc, &argv, true);
absl::SetFlag(&FLAGS_stderrthreshold, 0);
absl::SetStderrThreshold(absl::LogSeverityAtLeast::kInfo);
GlopParameters parameters;
ReadGlopParameters(&parameters);

View File

@@ -23,7 +23,9 @@
#include <string>
#include <vector>
#include "absl/base/log_severity.h"
#include "absl/flags/flag.h"
#include "absl/log/globals.h"
#include "ortools/base/commandlineflags.h"
#include "ortools/base/init_google.h"
#include "ortools/base/logging.h"
@@ -33,7 +35,6 @@ ABSL_FLAG(int, size, 16, "scaling factor of the model");
ABSL_FLAG(std::string, params,
"num_workers:8,log_search_progress:true,max_time_in_seconds:10.0",
"Sat parameters");
namespace operations_research {
namespace sat {
@@ -111,7 +112,7 @@ void MultiKnapsackSat(int scaling, const std::string& params) {
} // namespace operations_research
int main(int argc, char** argv) {
absl::SetFlag(&FLAGS_stderrthreshold, 0);
absl::SetStderrThreshold(absl::LogSeverityAtLeast::kInfo);
InitGoogle(argv[0], &argc, &argv, true);
operations_research::sat::MultiKnapsackSat(absl::GetFlag(FLAGS_size),
absl::GetFlag(FLAGS_params));

View File

@@ -33,10 +33,12 @@
#include <utility>
#include <vector>
#include "absl/base/log_severity.h"
#include "absl/container/btree_set.h"
#include "absl/container/flat_hash_map.h"
#include "absl/container/flat_hash_set.h"
#include "absl/flags/flag.h"
#include "absl/log/globals.h"
#include "absl/random/uniform_int_distribution.h"
#include "absl/strings/str_format.h"
#include "ortools/base/init_google.h"
@@ -673,7 +675,7 @@ class NetworkRoutingSolver {
} // namespace operations_research
int main(int argc, char** argv) {
absl::SetFlag(&FLAGS_stderrthreshold, 0);
absl::SetStderrThreshold(absl::LogSeverityAtLeast::kInfo);
InitGoogle(argv[0], &argc, &argv, true);
operations_research::sat::NetworkRoutingData data;

View File

@@ -131,7 +131,7 @@ void Solve(const std::string& input, absl::string_view params_str,
} // namespace operations_research::pdlp
int main(int argc, char** argv) {
absl::SetFlag(&FLAGS_stderrthreshold, 0);
absl::SetStderrThreshold(absl::LogSeverityAtLeast::kInfo);
InitGoogle(argv[0], &argc, &argv, /*remove_flags=*/true);
operations_research::pdlp::Solve(

View File

@@ -47,8 +47,10 @@
#include <vector>
#include "absl/algorithm/container.h"
#include "absl/base/log_severity.h"
#include "absl/flags/flag.h"
#include "absl/log/check.h"
#include "absl/log/globals.h"
#include "absl/strings/str_format.h"
#include "absl/strings/string_view.h"
#include "google/protobuf/text_format.h"
@@ -359,7 +361,7 @@ bool LoadAndSolve(absl::string_view pdp_file,
} // namespace operations_research
int main(int argc, char** argv) {
absl::SetFlag(&FLAGS_stderrthreshold, 0);
absl::SetStderrThreshold(absl::LogSeverityAtLeast::kInfo);
InitGoogle(argv[0], &argc, &argv, true);
operations_research::routing::RoutingModelParameters model_parameters =
operations_research::routing::DefaultRoutingModelParameters();

View File

@@ -32,8 +32,10 @@
#include <string>
#include <vector>
#include "absl/base/log_severity.h"
#include "absl/container/btree_set.h"
#include "absl/flags/flag.h"
#include "absl/log/globals.h"
#include "absl/strings/numbers.h"
#include "absl/strings/str_split.h"
#include "absl/strings/string_view.h"
@@ -305,7 +307,7 @@ void LoadAndSolve(const std::string& file_name) {
} // namespace operations_research
int main(int argc, char** argv) {
absl::SetFlag(&FLAGS_stderrthreshold, 0);
absl::SetStderrThreshold(absl::LogSeverityAtLeast::kInfo);
InitGoogle(argv[0], &argc, &argv, true);
if (absl::GetFlag(FLAGS_input).empty()) {

View File

@@ -46,6 +46,9 @@
#include <string>
#include <vector>
#include "absl/base/log_severity.h"
#include "absl/flags/flag.h"
#include "absl/log/globals.h"
#include "absl/strings/str_cat.h"
#include "absl/strings/str_format.h"
#include "absl/strings/str_join.h"
@@ -321,7 +324,7 @@ static const char kUsage[] =
"There is no output besides the LOGs of the solver.";
int main(int argc, char** argv) {
absl::SetFlag(&FLAGS_stderrthreshold, 0);
absl::SetStderrThreshold(absl::LogSeverityAtLeast::kInfo);
InitGoogle(kUsage, &argc, &argv, true);
CHECK_EQ(0, absl::GetFlag(FLAGS_num_teams) % 2)
<< "The number of teams must be even";

View File

@@ -606,7 +606,7 @@ int main(int argc, char** argv) {
usage += " --colgen_max_iterations <n> max columns to generate\n";
usage += " --colgen_complete generate all columns at start\n";
absl::SetFlag(&FLAGS_stderrthreshold, 0);
absl::SetStderrThreshold(absl::LogSeverityAtLeast::kInfo);
InitGoogle(usage.c_str(), &argc, &argv, true);
operations_research::MPSolver::OptimizationProblemType solver_type;

View File

@@ -28,6 +28,7 @@
#include "absl/flags/flag.h"
#include "absl/flags/parse.h"
#include "absl/flags/usage.h"
#include "absl/log/globals.h"
#include "absl/log/initialize.h"
#include "absl/random/random.h"
#include "ortools/base/logging.h"
@@ -239,7 +240,7 @@ int main(int argc, char** argv) {
<< "Specify a non-null client size.";
CHECK_LT(0, absl::GetFlag(FLAGS_fix_cost))
<< "Specify a non-null client size.";
absl::SetFlag(&FLAGS_stderrthreshold, 0);
absl::SetStderrThreshold(absl::LogSeverityAtLeast::kInfo);
operations_research::RunAllExamples(absl::GetFlag(FLAGS_facilities),
absl::GetFlag(FLAGS_clients),
absl::GetFlag(FLAGS_fix_cost));

View File

@@ -15,6 +15,7 @@
#include <string>
#include "absl/flags/flag.h"
#include "absl/log/globals.h"
#include "absl/status/status.h"
#include "absl/strings/match.h"
#include "absl/strings/str_cat.h"
@@ -98,7 +99,7 @@ void ParseAndSolve(const std::string& filename, absl::string_view solver,
} // namespace operations_research
int main(int argc, char** argv) {
absl::SetFlag(&FLAGS_stderrthreshold, 0);
absl::SetStderrThreshold(absl::LogSeverityAtLeast::kInfo);
InitGoogle(argv[0], &argc, &argv, true);
if (absl::GetFlag(FLAGS_input).empty()) {
LOG(FATAL) << "Please supply a data file with --input=";

View File

@@ -19,6 +19,7 @@
#include "absl/flags/flag.h"
#include "absl/log/check.h"
#include "absl/log/globals.h"
#include "absl/strings/numbers.h"
#include "absl/strings/str_cat.h"
#include "absl/strings/str_split.h"
@@ -252,7 +253,7 @@ void ParseAndSolve() {
} // namespace operations_research
int main(int argc, char** argv) {
absl::SetFlag(&FLAGS_stderrthreshold, 0);
absl::SetStderrThreshold(absl::LogSeverityAtLeast::kInfo);
InitGoogle(argv[0], &argc, &argv, true);
if (absl::GetFlag(FLAGS_input).empty()) {
LOG(FATAL) << "Please supply a data file with --input=";

View File

@@ -90,7 +90,7 @@ void useXpressSolver(bool solveAsMip, bool useFactory) {
}
#define ABSL_MIN_LOG_LEVEL INFO;
int main(int argc, char** argv) {
absl::SetFlag(&FLAGS_stderrthreshold, 0);
absl::SetStderrThreshold(absl::LogSeverityAtLeast::kInfo);
InitGoogle(argv[0], &argc, &argv, true);
std::cout << "start\n";
LOG(WARNING) << "start";

View File

@@ -226,7 +226,7 @@ void RunAllExamples() {
int main(int argc, char** argv) {
google::InitGoogleLogging(argv[0]);
absl::SetFlag(&FLAGS_stderrthreshold, 0);
absl::SetStderrThreshold(absl::LogSeverityAtLeast::kInfo);
operations_research::RunAllExamples();
return 0;
}

View File

@@ -73,7 +73,10 @@ cc_library(
"@com_google_absl//absl/flags:flag",
"@com_google_absl//absl/flags:parse",
"@com_google_absl//absl/flags:usage",
"@com_google_absl//absl/log",
"@com_google_absl//absl/log:check",
"@com_google_absl//absl/log:die_if_null",
"@com_google_absl//absl/log:globals",
"@com_google_absl//absl/log:initialize",
"@com_google_absl//absl/strings",
"@com_google_absl//absl/synchronization",

View File

@@ -34,6 +34,4 @@ void FixFlagsAndEnvironmentForSwig() {
absl::EnableLogPrefix(false);
}
void KeepAbslSymbols() { absl::SetFlag(&FLAGS_stderrthreshold, 0); }
} // namespace operations_research

View File

@@ -14,21 +14,19 @@
#ifndef OR_TOOLS_BASE_LOGGING_H_
#define OR_TOOLS_BASE_LOGGING_H_
#include "absl/base/log_severity.h"
#include "absl/flags/declare.h"
#include "absl/flags/flag.h"
#include "absl/log/check.h"
#include "absl/log/die_if_null.h"
#include "absl/log/log.h"
#include "absl/log/vlog_is_on.h"
#include "absl/memory/memory.h"
#include "absl/status/status.h"
#include "absl/strings/str_cat.h"
#include "absl/strings/string_view.h"
#include "ortools/base/macros.h"
// Forward the new flag.
ABSL_DECLARE_FLAG(int, stderrthreshold);
#include "absl/base/log_severity.h" // IWYU pragma: keep
#include "absl/flags/declare.h" // IWYU pragma: keep
#include "absl/flags/flag.h" // IWYU pragma: keep
#include "absl/log/check.h" // IWYU pragma: keep
#include "absl/log/die_if_null.h" // IWYU pragma: keep
#include "absl/log/globals.h" // IWYU pragma: keep
#include "absl/log/log.h" // IWYU pragma: keep
#include "absl/log/vlog_is_on.h" // IWYU pragma: keep
#include "absl/memory/memory.h" // IWYU pragma: keep
#include "absl/status/status.h" // IWYU pragma: keep
#include "absl/strings/str_cat.h" // IWYU pragma: keep
#include "absl/strings/string_view.h" // IWYU pragma: keep
#include "ortools/base/macros.h" // IWYU pragma: keep
namespace operations_research {

View File

@@ -20,10 +20,14 @@
// This problem has 72 different solutions in base 10.
// [START import]
#include <cstdint>
#include <cstdlib>
#include <vector>
#include "absl/base/log_severity.h"
#include "absl/flags/flag.h"
#include "absl/log/check.h"
#include "absl/log/flags.h"
#include "absl/log/globals.h"
#include "ortools/base/init_google.h"
#include "ortools/base/logging.h"
#include "ortools/constraint_solver/constraint_solver.h"
@@ -147,7 +151,7 @@ void CPIsFunCp() {
int main(int argc, char** argv) {
InitGoogle(argv[0], &argc, &argv, true);
absl::SetFlag(&FLAGS_stderrthreshold, 0);
absl::SetStderrThreshold(absl::LogSeverityAtLeast::kInfo);
operations_research::CPIsFunCp();
return EXIT_SUCCESS;
}

View File

@@ -12,6 +12,7 @@
// limitations under the License.
#include <array>
#include <cstdlib>
#include <iomanip>
#include <iterator>
#include <numeric> // std::iota
@@ -21,8 +22,10 @@
#include <utility>
#include <vector>
#include "absl/base/log_severity.h"
#include "absl/flags/flag.h"
#include "absl/log/flags.h"
#include "absl/log/globals.h"
#include "ortools/base/init_google.h"
#include "ortools/base/logging.h"
#include "ortools/constraint_solver/constraint_solver.h"
@@ -198,7 +201,7 @@ void SolveJobShopExample() {
int main(int argc, char** argv) {
InitGoogle(argv[0], &argc, &argv, true);
absl::SetFlag(&FLAGS_stderrthreshold, 0);
absl::SetStderrThreshold(absl::LogSeverityAtLeast::kInfo);
operations_research::SolveJobShopExample();
return EXIT_SUCCESS;
}

View File

@@ -13,13 +13,16 @@
#include <array>
#include <cstddef>
#include <cstdlib>
#include <iterator>
#include <numeric> // std::iota
#include <sstream>
#include <vector>
#include "absl/base/log_severity.h"
#include "absl/flags/flag.h"
#include "absl/log/flags.h"
#include "absl/log/globals.h"
#include "ortools/base/init_google.h"
#include "ortools/base/logging.h"
#include "ortools/constraint_solver/constraint_solver.h"
@@ -205,7 +208,7 @@ void SolveNursesExample() {
int main(int argc, char** argv) {
InitGoogle(argv[0], &argc, &argv, true);
absl::SetFlag(&FLAGS_stderrthreshold, 0);
absl::SetStderrThreshold(absl::LogSeverityAtLeast::kInfo);
operations_research::SolveNursesExample();
return EXIT_SUCCESS;
}

View File

@@ -13,8 +13,12 @@
// Knowing that we see 20 heads and 56 legs,
// how many pheasants and rabbits are we looking at ?
#include <cstdlib>
#include "absl/base/log_severity.h"
#include "absl/flags/flag.h"
#include "absl/log/flags.h"
#include "absl/log/globals.h"
#include "ortools/base/init_google.h"
#include "ortools/base/logging.h"
#include "ortools/constraint_solver/constraint_solver.h"
@@ -60,7 +64,7 @@ void RunConstraintProgrammingExample() {
int main(int argc, char** argv) {
InitGoogle(argv[0], &argc, &argv, true);
absl::SetFlag(&FLAGS_stderrthreshold, 0);
absl::SetStderrThreshold(absl::LogSeverityAtLeast::kInfo);
operations_research::RunConstraintProgrammingExample();
return EXIT_SUCCESS;
}

View File

@@ -15,9 +15,13 @@
// Local Search. It solves the same trivial problem with a Large
// Neighborhood Search approach, a Local Search approach, and a Local
// Search with Filter approach.
#include <cstdint>
#include <cstdlib>
#include <vector>
#include "absl/log/flags.h"
#include "absl/base/log_severity.h"
#include "absl/log/check.h"
#include "absl/log/globals.h"
#include "ortools/base/init_google.h"
#include "ortools/base/logging.h"
#include "ortools/constraint_solver/constraint_solver.h"
@@ -199,7 +203,7 @@ void SolveProblem(SolveType solve_type) {
int main(int argc, char** argv) {
InitGoogle(argv[0], &argc, &argv, true);
absl::SetFlag(&FLAGS_stderrthreshold, 0);
absl::SetStderrThreshold(absl::LogSeverityAtLeast::kInfo);
operations_research::SolveProblem(operations_research::LNS);
operations_research::SolveProblem(operations_research::LS);
operations_research::SolveProblem(operations_research::LS_WITH_FILTER);

View File

@@ -30,11 +30,10 @@
#include "absl/flags/flag.h"
#include "absl/log/check.h"
#include "absl/log/globals.h"
#include "absl/strings/match.h"
#include "absl/strings/str_format.h"
#include "absl/strings/string_view.h"
#include "ortools/base/commandlineflags.h"
#include "ortools/base/file.h"
#include "ortools/base/filesystem.h"
#include "ortools/base/helpers.h"
#include "ortools/base/init_google.h"
@@ -303,7 +302,7 @@ int main(int argc, char** argv) {
"The files must be in Dimacs text format or in binary FlowModelProto "
"format.",
&argc, &argv, true);
absl::SetFlag(&FLAGS_stderrthreshold, 0);
absl::SetStderrThreshold(absl::LogSeverityAtLeast::kInfo);
if (absl::GetFlag(FLAGS_input).empty()) {
LOG(FATAL) << "Please specify input pattern via --input=...";
}

View File

@@ -28,7 +28,7 @@ void CppBridge::InitLogging(const std::string& usage) {
}
void CppBridge::SetFlags(const CppFlags& flags) {
absl::SetFlag(&FLAGS_stderrthreshold, flags.stderrthreshold);
absl::SetStderrThreshold(absl::LogSeverityAtLeast::kInfo);
absl::EnableLogPrefix(flags.log_prefix);
if (!flags.cp_model_dump_prefix.empty()) {
absl::SetFlag(&FLAGS_cp_model_dump_prefix, flags.cp_model_dump_prefix);

View File

@@ -17,8 +17,8 @@
#include <cstdlib>
#include <memory>
#include "absl/flags/flag.h"
#include "absl/log/flags.h"
#include "absl/base/log_severity.h"
#include "absl/log/globals.h"
#include "ortools/base/init_google.h"
#include "ortools/base/logging.h"
#include "ortools/init/init.h"
@@ -98,7 +98,7 @@ void BasicExample() {
int main(int argc, char* argv[]) {
InitGoogle(argv[0], &argc, &argv, true);
absl::SetFlag(&FLAGS_stderrthreshold, 0);
absl::SetStderrThreshold(absl::LogSeverityAtLeast::kInfo);
operations_research::BasicExample();
return EXIT_SUCCESS;
}

View File

@@ -16,13 +16,14 @@
// [START import]
#include <array>
#include <cstddef>
#include <cstdlib>
#include <memory>
#include <string>
#include <utility> // std::pair
#include <vector>
#include "absl/flags/flag.h"
#include "absl/log/flags.h"
#include "absl/base/log_severity.h"
#include "absl/log/globals.h"
#include "ortools/base/init_google.h"
#include "ortools/base/logging.h"
#include "ortools/linear_solver/linear_solver.h"
@@ -321,7 +322,7 @@ void StiglerDiet() {
int main(int argc, char** argv) {
InitGoogle(argv[0], &argc, &argv, true);
absl::SetFlag(&FLAGS_stderrthreshold, 0);
absl::SetStderrThreshold(absl::LogSeverityAtLeast::kInfo);
operations_research::StiglerDiet();
return EXIT_SUCCESS;
}

View File

@@ -1414,7 +1414,7 @@ TEST_F(XpressFixtureMIP, CallbackThrowsException) {
} // namespace operations_research
int main(int argc, char** argv) {
absl::SetFlag(&FLAGS_stderrthreshold, 0);
absl::SetStderrThreshold(absl::LogSeverityAtLeast::kInfo);
testing::InitGoogleTest(&argc, argv);
auto solver = operations_research::MPSolver::CreateSolver("XPRESS_LP");
if (solver == nullptr) {

View File

@@ -16,6 +16,7 @@
#include <string>
#include "absl/flags/flag.h"
#include "absl/log/globals.h"
#include "absl/strings/match.h"
#include "absl/strings/string_view.h"
#include "ortools/base/helpers.h"
@@ -94,7 +95,7 @@ void ParseAndSolve(const std::string& filename, absl::string_view solver,
} // namespace operations_research
int main(int argc, char** argv) {
absl::SetFlag(&FLAGS_stderrthreshold, 0);
absl::SetStderrThreshold(absl::LogSeverityAtLeast::kInfo);
InitGoogle(argv[0], &argc, &argv, true);
if (absl::GetFlag(FLAGS_input).empty()) {
LOG(FATAL) << "Please supply a data file with --input=";

View File

@@ -524,6 +524,14 @@ bool ModelCopy::CopyLinear(const ConstraintProto& ct, bool canonicalize) {
FillDomainInProto(tight_domain, linear);
if (canonicalize) {
context_->CanonicalizeLinearConstraint(new_ct);
// We checked if the constraint was trivial above, but canonicalization can
// make it trivial again by simplifying expressions like (x - x).
if (new_ct->linear().vars().empty() &&
ReadDomainFromProto(new_ct->linear()).Contains(0)) {
context_->UpdateRuleStats("linear: trivial 0=0");
context_->working_model->mutable_constraints()->RemoveLast();
return true;
}
}
return true;
}

View File

@@ -15,11 +15,13 @@
#include <algorithm>
#include <cmath>
#include <memory>
#include <string>
#include <vector>
#include "absl/log/check.h"
#include "absl/strings/str_format.h"
#include "absl/strings/string_view.h"
#include "ortools/base/logging.h"
#include "ortools/base/stl_util.h"
#include "ortools/base/types.h"
@@ -51,8 +53,6 @@ Stat::Stat(absl::string_view name, StatsGroup* group) : name_(name) {
std::string Stat::StatString() const { return name_ + ": " + ValueAsString(); }
StatsGroup::~StatsGroup() { gtl::STLDeleteValues(&time_distributions_); }
void StatsGroup::Register(Stat* stat) { stats_.push_back(stat); }
void StatsGroup::Reset() {
@@ -117,13 +117,14 @@ std::string StatsGroup::StatString() const {
return result;
}
TimeDistribution* StatsGroup::LookupOrCreateTimeDistribution(std::string name) {
TimeDistribution*& ref = time_distributions_[name];
TimeDistribution* StatsGroup::LookupOrCreateTimeDistribution(
absl::string_view name) {
std::unique_ptr<TimeDistribution>& ref = time_distributions_[name];
if (ref == nullptr) {
ref = new TimeDistribution(name);
Register(ref);
ref = std::make_unique<TimeDistribution>(name);
Register(ref.get());
}
return ref;
return ref.get();
}
DistributionStat::DistributionStat(absl::string_view name)

View File

@@ -69,10 +69,13 @@
#define OR_TOOLS_UTIL_STATS_H_
#include <cstdint>
#include <functional>
#include <map>
#include <memory>
#include <string>
#include <vector>
#include "absl/container/flat_hash_map.h"
#include "absl/strings/string_view.h"
#include "absl/time/time.h"
#include "ortools/base/timer.h"
@@ -138,7 +141,7 @@ class StatsGroup {
// This type is neither copyable nor movable.
StatsGroup(const StatsGroup&) = delete;
StatsGroup& operator=(const StatsGroup&) = delete;
~StatsGroup();
~StatsGroup() = default;
// Registers a Stat, which will appear in the string returned by StatString().
// The Stat object must live as long as this StatsGroup.
@@ -154,9 +157,9 @@ class StatsGroup {
void SetPrintOrder(PrintOrder print_order) { print_order_ = print_order; }
// Returns and if needed creates and registers a TimeDistribution with the
// given name. Note that this involve a map lookup and his thus slower than
// directly accessing a TimeDistribution variable.
TimeDistribution* LookupOrCreateTimeDistribution(std::string name);
// given name. Note that this involve a hash map lookup and is thus slower
// than directly accessing a TimeDistribution variable.
TimeDistribution* LookupOrCreateTimeDistribution(absl::string_view name);
// Calls Reset() on all the statistics registered with this group.
void Reset();
@@ -165,7 +168,8 @@ class StatsGroup {
std::string name_;
PrintOrder print_order_ = SORT_BY_PRIORITY_THEN_VALUE;
std::vector<Stat*> stats_;
std::map<std::string, TimeDistribution*> time_distributions_;
absl::flat_hash_map<std::string, std::unique_ptr<TimeDistribution>>
time_distributions_;
};
// Base class to track and compute statistics about the distribution of a
@@ -376,7 +380,8 @@ class DisabledScopedTimeStats {
// per measurement compared to about 20ns (as of 2012-06, on my workstation).
class EnabledScopedTimeStats {
public:
explicit EnabledScopedTimeStats(StatsGroup* stats, const char* function_name)
explicit EnabledScopedTimeStats(StatsGroup* stats,
absl::string_view function_name)
: scoped_time_stat_(
stats->LookupOrCreateTimeDistribution(function_name)) {}
EnabledScopedTimeStats(const EnabledScopedTimeStats&) = delete;

View File

@@ -15,13 +15,13 @@ index a90120188a..2c068e5e30 100644
if ( ival == 0 )
{
- (void) google::SetVLOGLevel("*", google::GLOG_INFO);
+ absl::SetFlag(&FLAGS_stderrthreshold, 2);
+ absl::SetStderrThreshold(absl::LogSeverityAtLeast::kInfo);
lpi->lp_info = false;
}
else
{
- (void) google::SetVLOGLevel("*", google::GLOG_ERROR);
+ absl::SetFlag(&FLAGS_stderrthreshold, 0);
+ absl::SetStderrThreshold(absl::LogSeverityAtLeast::kError);
lpi->lp_info = true;
}
break;